// Path: src/database/DatabaseConnection.java
// public class DatabaseConnection {
// 	Connection dbConnection;
// 	
// 	public DatabaseConnection() {
// 		dbConnection = DatabaseConnection.connector();
// 	}
// 	
// 	public static Connection connector() {
// 		// SQLite connection string
//         Connection conn = null;
//         try {
//         	Class.forName("org.sqlite.JDBC");
//         	//for Linux distribution
//             String url = "jdbc:sqlite:/home/"+System.getProperty("user.name")+"/Money-ManagerDB/Money_Manager.db";
//             
//         	//for Mac distribution
// //        	String url = "jdbc:sqlite:/Users/"+System.getProperty("user.name")+"/Money-ManagerDB/Money_Manager.db";
//         	
//           //for Windows distribution
// //            String url = "jdbc:sqlite:Money_Manager.db";
//             
//             conn = DriverManager.getConnection(url);
// //            System.out.println("Connection to SQLite has been established.");
//         } catch (SQLException | ClassNotFoundException e) {
//             System.out.println(e.getMessage());
//         }
//         return conn;
// 	}
// 	
// 	
// 	public boolean isDBConnected() {
// 		try {
// 			return !dbConnection.isClosed();
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 			return false;
// 		}
// 	}
// 	
// //	public static void main(String[] args) {
// //		DatabaseConnection access = new DatabaseConnection();
// //		System.out.println(access.isDBConnected());
// //	}
// }


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import database.DatabaseConnection;
package operation;



public class GlobalId extends DatabaseConnection {
		
	public static int getGlobalid() {
		int globalId = 0;
		
		String sql = "SELECT globalId \n"
				+ "FROM System_Settings";
		
		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)) {
			if (result.next()) {
				globalId = result.getInt("globalId");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		increseGlobalId(globalId);
		return globalId;
	}
	
	private static void increseGlobalId(int oldId) {
		String sql = "UPDATE System_Settings \n"
				+ "SET globalId = ?";
		
		try (Connection conn = connector();
				PreparedStatement pstmt = conn.prepareStatement(sql)) {
			
			pstmt.setLong(1, oldId+1);
			pstmt.executeUpdate();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public static void setGlobalId(int updateGID) {
// Path: src/database/DatabaseConnection.java
// public class DatabaseConnection {
// 	Connection dbConnection;
// 	
// 	public DatabaseConnection() {
// 		dbConnection = DatabaseConnection.connector();
// 	}
// 	
// 	public static Connection connector() {
// 		// SQLite connection string
//         Connection conn = null;
//         try {
//         	Class.forName("org.sqlite.JDBC");
//         	//for Linux distribution
//             String url = "jdbc:sqlite:/home/"+System.getProperty("user.name")+"/Money-ManagerDB/Money_Manager.db";
//             
//         	//for Mac distribution
// //        	String url = "jdbc:sqlite:/Users/"+System.getProperty("user.name")+"/Money-ManagerDB/Money_Manager.db";
//         	
//           //for Windows distribution
// //            String url = "jdbc:sqlite:Money_Manager.db";
//             
//             conn = DriverManager.getConnection(url);
// //            System.out.println("Connection to SQLite has been established.");
//         } catch (SQLException | ClassNotFoundException e) {
//             System.out.println(e.getMessage());
//         }
//         return conn;
// 	}
// 	
// 	
// 	public boolean isDBConnected() {
// 		try {
// 			return !dbConnection.isClosed();
// 		} catch (Exception e) {
// 			e.printStackTrace();
// 			return false;
// 		}
// 	}
// 	
// //	public static void main(String[] args) {
// //		DatabaseConnection access = new DatabaseConnection();
// //		System.out.println(access.isDBConnected());
// //	}
// }


// Path: src/operation/GlobalId.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import database.DatabaseConnection;

package operation;



public class GlobalId extends DatabaseConnection {
		
	public static int getGlobalid() {
		int globalId = 0;
		
		String sql = "SELECT globalId \n"
				+ "FROM System_Settings";
		
		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)) {
			if (result.next()) {
				globalId = result.getInt("globalId");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		increseGlobalId(globalId);
		return globalId;
	}
	
	private static void increseGlobalId(int oldId) {
		String sql = "UPDATE System_Settings \n"
				+ "SET globalId = ?";
		
		try (Connection conn = connector();
				PreparedStatement pstmt = conn.prepareStatement(sql)) {
			
			pstmt.setLong(1, oldId+1);
			pstmt.executeUpdate();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public static void setGlobalId(int updateGID) {
		String sql = "UPDATE System_Settings SET globalId = ? WHERE ID = 1";