// 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 java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import database.DatabaseConnection;
import javafx.util.StringConverter;
package system;



public class DateFormatManager extends StringConverter<LocalDate> {
	
	
//	return the user define date format from database
	public final String getDateFormat() {
		String sql = "SELECT dateFormat \n"
				+ "FROM System_Settings";
		String format = null;
		try (Connection conn = DatabaseConnection.connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql) ) {
			format = result.getString("dateFormat");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return format;
	}
	
	
	public void setDateFormate(String format) {
		String sql = "UPDATE System_Settings SET dateFormat = ? ";
		
		try (Connection conn = DatabaseConnection.connector();
				PreparedStatement pstmt = conn.prepareStatement(sql)) {
				
			pstmt.setString(1, format);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	public final String getTimeFormate() {
		String sql = "SELECT timeFormat \n"
				+ "FROM System_Settings";
		String format = null;
// 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/system/DateFormatManager.java
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import database.DatabaseConnection;
import javafx.util.StringConverter;

package system;



public class DateFormatManager extends StringConverter<LocalDate> {
	
	
//	return the user define date format from database
	public final String getDateFormat() {
		String sql = "SELECT dateFormat \n"
				+ "FROM System_Settings";
		String format = null;
		try (Connection conn = DatabaseConnection.connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql) ) {
			format = result.getString("dateFormat");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return format;
	}
	
	
	public void setDateFormate(String format) {
		String sql = "UPDATE System_Settings SET dateFormat = ? ";
		
		try (Connection conn = DatabaseConnection.connector();
				PreparedStatement pstmt = conn.prepareStatement(sql)) {
				
			pstmt.setString(1, format);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	
	public final String getTimeFormate() {
		String sql = "SELECT timeFormat \n"
				+ "FROM System_Settings";
		String format = null;
		try (Connection conn = DatabaseConnection.connector();