public class SettingsModel extends DateAndClock {
	
	public boolean validCharge(String charge) {
		if (charge.matches("[0-9]{1,3}(\\.[0-9]{1,2}){0,7}")) {
			return true;
		} else if (charge.matches("[0-9]{1,3}\\.")) {
			return true;
		} else {
			return false;
		}
	}
	
	public static String getUserFullName() {
		if (checkUserPresence()) {
			return userFullName();
		} else {
			return "No User";
		}
	}
	
	
//	public static boolean isbKashActive() {
//		String sql = "SELECT bKashActive FROM System_Settings WHERE ID = 1";
//		try (Connection conn = connector();
//				Statement stmt = conn.createStatement();
//				ResultSet result = stmt.executeQuery(sql)) {
//			if ((result.getString("bKashActive")).equals("true")) {
//				return true;
//			} else {
//				return false;
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//			return false;
//		}
//	}
//	
//	
//	public static boolean isRocketActive() {
//		String sql = "SELECT RocketActive FROM System_Settings WHERE ID = 1";
//		try (Connection conn = connector();
//				Statement stmt = conn.createStatement();
//				ResultSet result = stmt.executeQuery(sql)) {
//			if ((result.getString("RocketActive")).equals("true")) {
//				return true;
//			} else {
//				return false;
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//			return false;
//		}
//	}
//	
//	
//	public static boolean rocIsATMFree() {
//		return BankIssue.isATMFree();
//	}
	
	
	public Map<String, String> bkashChargeData() {
		return new SettingBank().getBkashChargeData();
	}
	
	
	public Map<String, String> rocketChargeData() {
		return new SettingBank().getRocketChargeData();
	}
	
	
//////////////////////  Source  ////////////////////////
	public ObservableList<String> getActiveSourceList() {
		ObservableList<String> list = FXCollections.observableArrayList((new ComboboxList()).getSourceList());
		return list;
	}
	
	
	public ObservableList<String> getArchivedSourceList() {
		ObservableList<String> list = FXCollections.observableArrayList((new ComboboxList()).getArchivedSourceList());
		return list;
	}
	
////////////////////// Sector  ////////////////////////
	public ObservableList<String> getActiveSectorList() {
		ObservableList<String> list = FXCollections.observableArrayList((new ComboboxList()).getSectorList());
		return list;
	}


	public ObservableList<String> getArchivedSectorList() {
		ObservableList<String> list = FXCollections.observableArrayList((new ComboboxList()).getArchivedSectorList());
		return list;
	}
	
////////////////////// Advanced Expense  ////////////////////////
	public ObservableList<String> getAdvancedSectorListInactive() {
		ObservableList<String> list = FXCollections.observableArrayList((new ComboboxList()).getAdvancedSectorListInactive());
		return list;
	}


	public ObservableList<String> getAdvancedSectorListActive() {
		ObservableList<String> list = FXCollections.observableArrayList((new ComboboxList()).getAdvancedSectorListActive());
		return list;
	}
	
} public class BankIssue extends DatabaseConnection {
	
	public long bKashChargeCalculate(long amount, String nature) {
		long charge = 0;
		
		switch (nature) {
			case "Cash Out":
				charge = (amount*bKashbnkCharge(nature)/100000);
				break;
				
			case "Buy Airtime":
				charge = bKashbnkCharge(nature);
				break;
				
			case "Send Money":
				charge = bKashbnkCharge(nature);
				break;
			
			case "Payment":
				charge = bKashbnkCharge(nature);
				break;
				
			case "ATM":
				charge = (amount*bKashbnkCharge(nature)/100000);
				break;
				
			default:
				charge = 0;
				break;
		}
		return charge;
	}
	
	
	private static long bKashbnkCharge(String nature) {
		long charge = 0;
		String sql = "SELECT * \n"
				+ "FROM bKash_Settings";
		
		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)){
			
			switch (nature) {
			case "Cash Out": 
				charge = result.getLong("bkCashOutAgentCharge");
				break;
				
			case "Buy Airtime":
				charge = 0;
				break;
				
			case "Send Money":
				charge = result.getLong("bkSendMoneyCharge");
				break;
			
			case "Payment":
				charge = 0;
				break;
				
			case "ATM":
				charge = result.getLong("bkATMCharge");
				break;
				
			default:
				charge = 0;
				break;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return charge;
	}
	
	
	public long rocketChargeCalculate(long amount, String method, String nature) {
		long charge = 0;
		
		if (method.equals("Cash In")) {
			switch (nature) {
			case "Agent":
				charge = (amount*rocketbnkCharge(method, nature)/100000);
				break;
				
			case "Send Money":
				charge = rocketbnkCharge(method, nature);
				break;
				
			case "Branch":
				charge = rocketbnkCharge(method, nature);
				break;
						
			default:
				charge = 0;
				break;
			}
		} else {
			switch (nature) {
			case "ATM":
				charge = (amount*rocketbnkCharge(method, nature)/100000);
				break;
				
			case "TopUp":
				charge = rocketbnkCharge(method, nature);
				break;
				
			case "Agent":
				charge = (amount*rocketbnkCharge(method, nature)/100000);
				break;
			
			case "Send Money":
				charge = rocketbnkCharge(method, nature);
				break;
				
			case "Branch":
				if (isATMFree()) {
					charge = rocketbnkCharge(method, nature);
				} else {
					charge = (amount*rocketbnkCharge(method, nature)/100000);
				}
				break;
				
			default:
				charge = 0;
				break;
			}
		}
		
		return charge;
	}
	
	
	private static long rocketbnkCharge(String method, String nature) {
		long charge = 0;
		
		String sqlAll = "SELECT * \n"
				+ "FROM Rocket_Settings";
		
		if (method.equals("Cash In")) {
			if (isATMFree()) {
				try (Connection conn = connector();
						Statement stmt = conn.createStatement();
						ResultSet result = stmt.executeQuery(sqlAll)){

					switch (nature) {
					case "Agent": 
						charge = result.getLong("rocATMCashInAgentCharge");
						break;
						
					case "Send Money":
						charge = 0;
						break;
						
					case "Branch":
						charge = result.getLong("rocATMCashInBranchCharge");
						break;
					
					default:
						charge = 0;
						break;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else {
				try (Connection conn = connector();
						Statement stmt = conn.createStatement();
						ResultSet result = stmt.executeQuery(sqlAll)){

					switch (nature) {
					case "Agent": 
						charge = result.getLong("rocCashCashInAgentCharge");
						break;
						
					case "Send Money":
						charge = 0;
						break;
						
					case "Branch":
						charge = result.getLong("rocCashCashInBranchCharge");
						break;
					
					default:
						charge = 0;
						break;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} else {
			if (isATMFree()) {
				try (Connection conn = connector();
						Statement stmt = conn.createStatement();
						ResultSet result = stmt.executeQuery(sqlAll)){

					switch (nature) {
					case "ATM": 
						charge = result.getLong("rocATMCashOutATMCharge");
						break;
						
					case "TopUp": 
						charge = 0;
						break;
						
					case "Agent": 
						charge = result.getLong("rocATMCashOutAgentCharge");
						break;
						
					case "Send Money":
						charge = result.getLong("rocATMSendMoneyCharge");
						break;
						
					case "Branch":
						charge = result.getLong("rocATMCashOutBranchCharge");
						break;
					
					default:
						charge = 0;
						break;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			} else {
				try (Connection conn = connector();
						Statement stmt = conn.createStatement();
						ResultSet result = stmt.executeQuery(sqlAll)){

					switch (nature) {
					case "ATM": 
						charge = result.getLong("rocCashCashOutATMCharge");
						break;
						
					case "TopUp": 
						charge = 0;
						break;
						
					case "Agent": 
						charge = result.getLong("rocCashCashOutAgentCharge");
						break;
						
					case "Send Money":
						charge = result.getLong("rocCashSendMoneyCharge");
						break;
						
					case "Branch":
						charge = result.getLong("rocCashCashOutBranchCharge");
						break;
					
					default:
						charge = 0;
						break;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
			
		return charge;
	}
	
	
	public static boolean isbKashActivated() {
		String sql = "SELECT activeMethods \n"
				+ "FROM Methods_List \n"
				+ "WHERE activeMethods = \"bKash\"";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)) {
			
			if (result.next()) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			return false;
		}
	}
	
	
	public static boolean isRocketActivated() {
		String sql = "SELECT activeMethods \n"
				+ "FROM Methods_List \n"
				+ "WHERE activeMethods = \"Rocket\"";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)) {
			
			if (result.next()) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			return false;
		}
	}
	
	
	public static boolean isATMFree() {
		String atmFree = null;
		boolean atmFreeb = false;
		
		String sqlATM = "SELECT atmFree \n"
				+ "FROM Rocket_Settings";
		
		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlATM)) {
			
			atmFree = result.getString("atmFree");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		if (atmFree.equals("true")) {
			atmFreeb = true;
		}
		return atmFreeb;
	}
	
	
	
//	public static void main(String[] args) {
//		BankIssue access = new BankIssue();
//		System.out.println(access.bKashChargeCalculate(100000, "ATM"));
//		System.out.println(access.rocketChargeCalculate(1500000, "Cash Out", "Agent"));
//		System.out.println(access.isATMFree());
//	}
	
} public class ComboboxList extends DatabaseConnection {

	//////////////////////////////////////////// Source Settings
	//////////////////////////////////////////// ////////////////////////////////////////////
	// ---------------------------------------------------------------------------------------------------------//
	public String[] getSourceList() {
		if (getSourceArraySize() > 0) {
			String list[] = new String[getSourceArraySize()];
			String sql = "SELECT sourceList \n" + "FROM Source_List";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("sourceList");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Source" };
			return list;
		}
	}

	public int getSourceArraySize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Source_List";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	public String[] getSourceListForDashboard() {
		if (getSourceArraySizeForDashboard() > 0) {
			String list[] = new String[getSourceArraySizeForDashboard()];
			String sql = "SELECT sourceList \n" + "FROM Source_List";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				list[0] = "All";
				int index = 1;
				if (BankIssue.isbKashActivated() && BankIssue.isRocketActivated()) {
					while (result.next()) {
						list[index] = result.getString("sourceList");
						++index;
					}
					list[getSourceArraySize() + 1] = "bKash";
					list[getSourceArraySize() + 2] = "Rocket";
					list[getSourceArraySize() + 3] = "Carried Over Amount";
				} else if (BankIssue.isbKashActivated()) {
					while (result.next()) {
						list[index] = result.getString("sourceList");
						++index;
					}
					list[getSourceArraySize() + 1] = "bKash";
					list[getSourceArraySize() + 2] = "Carried Over Amount";
				} else if (BankIssue.isRocketActivated()) {
					while (result.next()) {
						list[index] = result.getString("sourceList");
						++index;
					}
					list[getSourceArraySize() + 1] = "Rocket";
					list[getSourceArraySize() + 2] = "Carried Over Amount";
				} else {
					while (result.next()) {
						list[index] = result.getString("sourceList");
						++index;
					}
					list[getSourceArraySize() + 1] = "Carried Over Amount";
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Source" };
			return list;
		}
	}

	public int getSourceArraySizeForDashboard() {
		int size = 0;
		if (BankIssue.isbKashActivated() && BankIssue.isRocketActivated()) {
			size = getSourceArraySize() + 4;
		} else if (BankIssue.isbKashActivated()) {
			size = getSourceArraySize() + 3;
		} else if (BankIssue.isRocketActivated()) {
			size = getSourceArraySize() + 3;
		} else {
			size = getSourceArraySize() + 2;
		}
		return size;
	}

	public String[] getArchivedSourceList() {
		if (getArchivedSourceArraySize() > 0) {
			String list[] = new String[getArchivedSourceArraySize()];
			String sql = "SELECT sourceArchiveList \n" + "FROM Archived_Source_List";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("sourceArchiveList");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Source" };
			return list;
		}
	}

	public int getArchivedSourceArraySize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Archived_Source_List";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	//////////////////////////////////////////// Method Settings
	//////////////////////////////////////////// ////////////////////////////////////////////
	// ---------------------------------------------------------------------------------------------------------//
	public String[] getMethodList() {
		if (getMethodArraySize() > 0) {
			String list[] = new String[getMethodArraySize()];
			String sql = "SELECT activeMethods \n" + "FROM Methods_List";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("activeMethods");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Method" };
			return list;
		}
	}

	public int getMethodArraySize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Methods_List";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	//////////////////////////////////////////// Sector Settings
	//////////////////////////////////////////// ////////////////////////////////////////////
	// ------------------------------------------------------------------------------------------------------//
	public String[] getSectorList() {
		if (getSectorArraySize() > 0) {
			String list[] = new String[getSectorArraySize()];
			String sql = "SELECT sectorList \n" + "FROM Sector_List WHERE sectorActive = \"active\"";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("sectorList");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Sector" };
			return list;
		}
	}

	public String[] getSectorListForDashboard() {
		if (getSectorArraySize() > 0) {
			String list[] = new String[getSectorArraySize() + 2];
			String sql = "SELECT sectorList \n" + "FROM Sector_List WHERE sectorActive = \"active\"";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				list[0] = "All";
				int index = 1;
				while (result.next()) {
					list[index] = result.getString("sectorList");
					++index;
				}
				list[getSectorArraySize() + 1] = "Adjusted Balance";
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Sector" };
			return list;
		}
	}

	public int getSectorArraySize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Sector_List WHERE sectorActive = \"active\"";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	public String[] getArchivedSectorList() {
		if (getArchivedSectorArraySize() > 0) {
			String list[] = new String[getArchivedSectorArraySize()];
			String sql = "SELECT sectorList \n" + "FROM Sector_List WHERE sectorArchived = \"archived\"";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("sectorList");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Sector" };
			return list;
		}
	}

	public int getArchivedSectorArraySize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Sector_List WHERE sectorArchived = \"archived\"";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	public String[] getAdvancedSectorListInactive() {
		if (getAdvancedSectorInactiveArraySize() > 0) {
			String list[] = new String[getAdvancedSectorInactiveArraySize()];
			String sql = "SELECT sectorList \n" + "FROM Sector_List WHERE ASL_Queue = \"aslQueue\"";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("sectorList");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Sector" };
			return list;
		}
	}

	public int getAdvancedSectorInactiveArraySize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Sector_List WHERE ASL_Queue = \"aslQueue\"";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	public String[] getAdvancedSectorListActive() {
		if (getAdvancedSectorActiveArraySize() > 0) {
			String list[] = new String[getAdvancedSectorActiveArraySize()];
			String sql = "SELECT sectorList \n" + "FROM Sector_List WHERE ASL_Active = \"aslActive\"";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("sectorList");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Sector" };
			return list;
		}
	}

	public int getAdvancedSectorActiveArraySize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Sector_List WHERE ASL_Active = \"aslActive\"";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	//////////////////////////////////////////// Borrow Settings
	//////////////////////////////////////////// ////////////////////////////////////////////
	// ---------------------------------------------------------------------------------------------------------//
	public String[] getBoRepayPersonNameList() {
		if (getBoRepayPersonNameSize() > 0) {
			String list[] = new String[getBoRepayPersonNameSize()];
			String sql = "SELECT boWhom \n" + "FROM Borrow_Summary";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("boWhom");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No One" };
			return list;
		}
	}

	public int getBoRepayPersonNameSize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Borrow_Summary";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	//////////////////////////////////////////// Lend Settings
	//////////////////////////////////////////// ////////////////////////////////////////////
	// ---------------------------------------------------------------------------------------------------------//
	public String[] getLeRepayPersonNameList() {
		if (getLeRepayPersonNameSize() > 0) {
			String list[] = new String[getLeRepayPersonNameSize()];
			String sql = "SELECT leWhom \n" + "FROM Lend_Summary";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("leWhom");
					++index;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No One" };
			return list;
		}
	}

	public int getLeRepayPersonNameSize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM Lend_Summary";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	//////////////////////////////////////////// Months Settings
	//////////////////////////////////////////// ////////////////////////////////////////////
	// ---------------------------------------------------------------------------------------------------------//
	public String[] getAllMonth() {
		List<Date> dates = new ArrayList<Date>();
		if (getAllMonthSize() > 0) {
			String list[] = new String[getAllMonthSize()];
			String sql = "SELECT allTransactionMonth \n" + "FROM All_Months \n" + "ORDER BY allTransactionMonth DESC";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("allTransactionMonth");
					++index;
				}
				for (String dateString : list) {
					Date date;
					date = new SimpleDateFormat("MMM-yy").parse(dateString);
					dates.add(date);
				}
				Collections.sort(dates, new Comparator<Date>() {

					@Override
					public int compare(Date o1, Date o2) {
						return o2.compareTo(o1);
					}
				});
				int index2 = 0;
				for (Date date : dates) {
					list[index2] = new SimpleDateFormat("MMM-yy").format(date);
					++index2;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list;

		} else {
			String list[] = { "No Month" };
			return list;
		}
	}

	public int getAllMonthSize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM All_Months";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	public void setAllMonth(String monthName, String yearName) {
		String getDBMonth = "SELECT * FROM All_Months WHERE allTransactionMonth = ?";
		String addMonthYear = "INSERT INTO All_Months(allYear, allTransactionMonth) VALUES(?,?)";
		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(getDBMonth)) {
			pstmt.setString(1, monthName);
			ResultSet result = pstmt.executeQuery();
			if (!result.next()) {
				try (Connection conn2 = connector(); PreparedStatement pstmt2 = conn2.prepareStatement(addMonthYear)) {
					pstmt2.setString(1, yearName);
					pstmt2.setString(2, monthName);
					pstmt2.executeUpdate();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String[] getAllGmMonth() {
		List<Date> dates = new ArrayList<Date>();
		if (getAllGmMonthSize() > 0) {
			String list[] = new String[getAllGmMonthSize()];
			String list2[] = new String[getAllGmMonthSize() + 1];

			String sql = "SELECT gmAllMonth \n" + "FROM All_GetMoney_Months \n" + "ORDER BY gmAllMonth DESC";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("gmAllMonth");
					++index;
				}

				for (String dateString : list) {
					Date date;
					date = new SimpleDateFormat("MMM-yy").parse(dateString);
					dates.add(date);
				}
				Collections.sort(dates, new Comparator<Date>() {

					@Override
					public int compare(Date o1, Date o2) {
						return o2.compareTo(o1);
					}
				});

				int index2 = 1;
				list2[0] = "Total";
				for (Date date : dates) {
					list2[index2] = new SimpleDateFormat("MMM-yy").format(date);
					++index2;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list2;

		} else {
			String list[] = { "No Month", "No Month" };
			return list;
		}
	}

	public int getAllGmMonthSize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM All_GetMoney_Months";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	public void setAllGmMonth(String monthName, String yearName) {
		String getDBMonth = "SELECT * FROM All_GetMoney_Months WHERE gmAllMonth = ?";
		String addMonthYear = "INSERT INTO All_GetMoney_Months(allYear, gmAllMonth) VALUES(?,?)";
		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(getDBMonth)) {
			pstmt.setString(1, monthName);
			ResultSet result = pstmt.executeQuery();
			if (!result.next()) {
				try (Connection conn2 = connector(); PreparedStatement pstmt2 = conn2.prepareStatement(addMonthYear)) {
					pstmt2.setString(1, yearName);
					pstmt2.setString(2, monthName);
					pstmt2.executeUpdate();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String[] getAllExMonth() {
		List<Date> dates = new ArrayList<Date>();
		if (getAllExMonthSize() > 0) {
			String list[] = new String[getAllExMonthSize()];
			String list2[] = new String[getAllExMonthSize() + 1];

			String sql = "SELECT exAllMonth \n" + "FROM All_Expense_Months \n" + "ORDER BY exAllMonth DESC";
			try (Connection conn = connector();
					Statement stmt = conn.createStatement();
					ResultSet result = stmt.executeQuery(sql)) {
				int index = 0;
				while (result.next()) {
					list[index] = result.getString("exAllMonth");
					++index;
				}

				for (String dateString : list) {
					Date date;
					date = new SimpleDateFormat("MMM-yy").parse(dateString);
					dates.add(date);
				}
				Collections.sort(dates, new Comparator<Date>() {

					@Override
					public int compare(Date o1, Date o2) {
						return o2.compareTo(o1);
					}
				});

				int index2 = 1;
				list2[0] = "Total";
				for (Date date : dates) {
					list2[index2] = new SimpleDateFormat("MMM-yy").format(date);
					++index2;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return list2;

		} else {
			String list[] = { "No Month" };
			return list;
		}
	}

	public int getAllExMonthSize() {
		int size = 0;
		String sqlid = "SELECT * \n" + "FROM All_Expense_Months";

		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sqlid)) {
			while (result.next()) {
				size = size + 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return size;
	}

	public void setAllExMonth(String monthName, String yearName) {
		String getDBMonth = "SELECT * FROM All_Expense_Months WHERE exAllMonth = ?";
		String addMonthYear = "INSERT INTO All_Expense_Months(allYear, exAllMonth) VALUES(?,?)";
		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(getDBMonth)) {
			pstmt.setString(1, monthName);
			ResultSet result = pstmt.executeQuery();
			if (!result.next()) {
				try (Connection conn2 = connector(); PreparedStatement pstmt2 = conn2.prepareStatement(addMonthYear)) {
					pstmt2.setString(1, yearName);
					pstmt2.setString(2, monthName);
					pstmt2.executeUpdate();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	//////////////////////////////////////////// History Settings
	//////////////////////////////////////////// ////////////////////////////////////////////
	// ---------------------------------------------------------------------------------------------------------//
	public String[] getFilterList() {
		String sourceList[] = getSourceList();
		String sectorList[] = getSectorList();
		String allList[] = new String[permanantFilterSize() + getSourceArraySize() + getSectorArraySize()];
		allList[0] = "All";
		allList[1] = "Get Money";
		allList[2] = "Expense";
		allList[3] = "Borrow";
		allList[4] = "Lend";
		int index = 5;
		if (BankIssue.isbKashActivated() && BankIssue.isRocketActivated()) {
			allList[index] = "bKash";
			++index;
			allList[index] = "Rocket";
			++index;
			allList[index] = "Personal";
			++index;
		} else if (BankIssue.isbKashActivated()) {
			allList[index] = "bKash";
			++index;
			allList[index] = "Personal";
			++index;
		} else if (BankIssue.isRocketActivated()) {
			allList[index] = "Rocket";
			++index;
			allList[index] = "Personal";
			++index;
		} else {
			allList[index] = "Personal";
			++index;
		}
		if (getSourceArraySize() != 0) {
			for (String string : sourceList) {
				allList[index] = string;
				++index;
			}
		}
		if (getSectorArraySize() != 0) {
			for (String string : sectorList) {
				allList[index] = string;
				++index;
			}
		}
		return allList;
	}

	private int permanantFilterSize() {
		int size = 5;
		if (BankIssue.isbKashActivated() && BankIssue.isRocketActivated()) {
			size = 8;
		} else if (BankIssue.isbKashActivated()) {
			size = 7;
		} else if (BankIssue.isRocketActivated()) {
			size = 7;
		} else {
			size = 6;
		}
		return size;
	}

	public boolean isFilterInSource(String filterName) {
		String sourceList[] = getSourceList();
		boolean status = false;
		for (String string : sourceList) {
			if (string.equals(filterName)) {
				status = true;
			}
		}
		return status;
	}

	public boolean isFilterInSector(String filterName) {
		String sectorList[] = getSectorList();
		boolean status = false;
		for (String string : sectorList) {
			if (string.equals(filterName)) {
				status = true;
			}
		}
		return status;
	}

	public String[] getSecurityQuestionList() {
		String list[] = { "What was Your First Phone Number?", "What is Your Favourite Teacher's Name?",
				"What is Your Special One's Name?", "What was your childhood nickname?", "What is your favorite team?",
				"What is your favorite movie?", "In what town was your first job?" };
		return list;
	}

	// public static void main(String[] args) {
	// ComboboxList access = new ComboboxList();
	// System.out.println(access.permanantFilterSize());
	// System.out.println(access.getSourceArraySize());
	// System.out.println(access.getSectorArraySize());
	// String list[] = access.getSourceList();
	// for (String string : list) {
	// System.out.println("Source :"+string);
	// }
	//
	// String list2[] = access.getMethodList();
	// for (String string : list2) {
	// System.out.println("Method: "+string);
	// }
	// }

} public class GoToOperation extends UnitConverter {

	public void goToSignIn(Stage SignInStage) {
		try {
			Parent root = FXMLLoader.load(getClass().getResource("/view/SignIn.fxml"));
			Scene scene = new Scene(root, 800, 550);
			SignInStage.setScene(scene);
			SignInStage.setTitle("Money Manager");
			SignInStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void goToDashboard(Stage DashboardStage) {
		try {
			Parent root = FXMLLoader.load(getClass().getResource("/view/Dashboard.fxml"));
			Scene scene = new Scene(root, 800, 550);
			DashboardStage.setScene(scene);
			DashboardStage.setTitle("Dashboard");
			DashboardStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void goToMakeATransaction(Stage MakeATransactionStage) {
		try {
			Parent root = FXMLLoader.load(getClass().getResource("/view/MakeATransaction.fxml"));
			Scene scene = new Scene(root, 800, 550);
			MakeATransactionStage.setScene(scene);
			MakeATransactionStage.setTitle("Make A Transaction");
			MakeATransactionStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void goToSettings(Stage SettingsStage) {
		try {
			Parent root = FXMLLoader.load(getClass().getResource("/view/Settings.fxml"));
			Scene scene = new Scene(root, 800, 550);
			SettingsStage.setScene(scene);
			SettingsStage.setTitle("Settings");
			SettingsStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void goToTransactionHistory(Stage TransactionHistoryStage) {
		try {
			Parent root = FXMLLoader.load(getClass().getResource("/view/TransactionHistory.fxml"));
			Scene scene = new Scene(root, 800, 550);
			TransactionHistoryStage.setScene(scene);
			TransactionHistoryStage.setTitle("Transaction History");
			TransactionHistoryStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void goToCashCalculate(Stage CashCalculateStage) {
		try {
			Parent root = FXMLLoader.load(getClass().getResource("/view/CashCalculate.fxml"));
			Scene scene = new Scene(root, 800, 550);
			CashCalculateStage.setScene(scene);
			CashCalculateStage.setTitle("Cash Calculate");
			CashCalculateStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void goToAbout(Stage AboutStage) {
		try {
			Parent root = FXMLLoader.load(getClass().getResource("/view/About.fxml"));
			Scene scene = new Scene(root, 800, 550);
			AboutStage.setScene(scene);
			AboutStage.setTitle("About");
			AboutStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void goToHelp(Stage HelpStage) {
		try {
			Parent root = FXMLLoader.load(getClass().getResource("/view/Help.fxml"));
			Scene scene = new Scene(root, 800, 550);
			HelpStage.setScene(scene);
			HelpStage.setTitle("Help");
			HelpStage.show();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

} 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();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql) ) {
			format = result.getString("timeFormat");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return format;

	}
	
	
	public void setTimeFormate(String format) {
		String sql = "UPDATE System_Settings SET timeFormat = ? ";
		
		try (Connection conn = DatabaseConnection.connector();
				PreparedStatement pstmt = conn.prepareStatement(sql)) {
				
			pstmt.setString(1, format);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

	@Override
	public String toString(LocalDate date) {
		DateTimeFormatter dtFormatter = DateTimeFormatter.ofPattern(getDateFormat());
		String text = null;
		if (date != null) {
			text = dtFormatter.format(date);
		}
		return text;
	}


	@Override
	public LocalDate fromString(String stringDate) {
		DateTimeFormatter dtFormatter = DateTimeFormatter.ofPattern(getDateFormat());
		LocalDate date = null;
		if (stringDate != null && !stringDate.trim().isEmpty()) {
			date = LocalDate.parse(stringDate, dtFormatter);
		}
		return date;
	}
	
	
//	public static void main(String[] args) {
//		DateFormatManager access = new DateFormatManager();
//		access.fromString("01 December, 2017");
//		DateFormat monthFormat = new SimpleDateFormat("MMM-yy");
//		Calendar today = Calendar.getInstance();
//		java.util.Date date = java.sql.Date.valueOf(access.fromString("01 December, 2017"));
//    	String thisMonth = monthFormat.format(date);
//    	System.out.println(thisMonth);
//	}

} public class AdvancedExpense extends DateAndClock {

	public void addSectorToList(String sectorName) {
		String sqltoactive = "UPDATE Sector_List SET sectorActive = ?, sectorArchived = ?, ASL_Queue = ?, ASL_Active = ? WHERE sectorList = ?";

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sqltoactive)) {
			pstmt.setString(1, "active");
			pstmt.setString(2, "");
			pstmt.setString(3, "");
			pstmt.setString(4, "aslActive");
			pstmt.setString(5, sectorName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void removeSectorFromList(String sectorName) {
		String sqltoqueue = "UPDATE Sector_List SET sectorActive = ?, sectorArchived = ?, ASL_Queue = ?, ASL_Active = ? WHERE sectorList = ?";

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sqltoqueue)) {
			pstmt.setString(1, "active");
			pstmt.setString(2, "");
			pstmt.setString(3, "aslQueue");
			pstmt.setString(4, "");
			pstmt.setString(5, sectorName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
} public class Sector extends DashboardModel {

	public boolean createSector(String sectorName) {

		boolean exists = false;

		String sqlexists = "SELECT sectorList FROM Sector_List WHERE sectorList = ? ";
		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sqlexists)) {
			pstmt.setString(1, sectorName);
			ResultSet result = pstmt.executeQuery();

			while (result.next()) {
				exists = true;
			}

		} catch (Exception e) {
			e.printStackTrace();
		}

		if (!exists) {

			String sql = "INSERT INTO Sector_List (sectorList) VALUES(?)";
			try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sql)) {
				pstmt.setString(1, sectorName);
				pstmt.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}

			String sqlupdate = "UPDATE Sector_List SET sectorActive = ?, ASL_Queue = ? WHERE sectorList = ?";
			try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sqlupdate)) {
				pstmt.setString(1, "active");
				pstmt.setString(2, "aslQueue");
				pstmt.setString(3, sectorName);
				pstmt.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return exists;
	}

	public void deleteSector(String sectorName) {
		String delete = "DELETE FROM Sector_List WHERE sectorList = ?";

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(delete)) {
			pstmt.setString(1, sectorName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void archiveSector(String sectorName) {
		String sqlarchived = "UPDATE Sector_List SET sectorActive = ?, sectorArchived = ?, ASL_Queue = ?, ASL_Active = ? WHERE sectorList = ?";

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sqlarchived)) {
			pstmt.setString(1, "");
			pstmt.setString(2, "archived");
			pstmt.setString(3, "");
			pstmt.setString(4, "");
			pstmt.setString(5, sectorName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void unarchiveSector(String sectorName) {
		String sqlunarchived = "UPDATE Sector_List SET sectorActive = ?, sectorArchived = ?, ASL_Queue = ?, ASL_Active = ? WHERE sectorList = ?";

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sqlunarchived)) {
			pstmt.setString(1, "active");
			pstmt.setString(2, "");
			pstmt.setString(3, "aslQueue");
			pstmt.setString(4, "");
			pstmt.setString(5, sectorName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public long getAmountBySectorFromExpense(String monthName, String sectorName) {
		String sql = "SELECT exAmount FROM Expense WHERE exMonth = ? AND exSector = ? ";
		long amount = 0;
		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sql)) {
			pstmt.setString(1, monthName);
			pstmt.setString(2, sectorName);
			ResultSet result = pstmt.executeQuery();
			while (result.next()) {
				if (sectorName.equals("Adjusted Balance")) {
					if (!result.getString("exAmount").matches(".*\\badded\\b.*")) {
						amount += stringToLong(removeThousandSeparator(result.getString("exAmount")));
					}
				} else {
					amount += stringToLong(removeThousandSeparator(result.getString("exAmount")));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return amount;
	}

	public long addedAdjustBalance(String monthName) {
		long amount = 0;

		String sql = "SELECT exAmount FROM Expense WHERE exMonth = ? AND exSector = ? ";
		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sql)) {
			pstmt.setString(1, monthName);
			pstmt.setString(2, "Adjusted Balance");
			ResultSet result = pstmt.executeQuery();
			while (result.next()) {
				if (result.getString("exAmount").matches(".*\\badded\\b.*")) {
					amount += stringToLong(
							removeThousandSeparator(result.getString("exAmount").replaceAll("[^0-9.*]", "")));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return amount;
	}

	// public static void main(String[] args) {
	// String text = "I will come and meet you at the woods 123woods and all the
	// woods";
	//
	// List<String> tokens = new ArrayList<String>();
	// tokens.add("123woods");
	// tokens.add("woods");
	//
	// String patternString = "\\b(" + StringUtils.join(tokens, "|") + ")\\b";
	// Pattern pattern = Pattern.compile(patternString);
	// Matcher matcher = pattern.matcher(text);
	//
	// while (matcher.find()) {
	// System.out.println(matcher.group(1));
	// }

	// System.out.println("I will come and meet you at the
	// 123woods".matches(".*\\badded\\b.*"));
	// System.out.println(new Sector().addedAdjustBalance("Dec-17"));
	// }

} public class SettingBank extends DatabaseConnection {
	
	public Map<String, String> getBkashChargeData() {
		Map<String, String> bkData = new HashMap<>();
		
		String sql = "SELECT * FROM bKash_Settings WHERE ID = 1 ";
		
		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)) {
			
			bkData.put("bkCashInCharge", UnitConverter.longToString(result.getLong("bkCashInCharge")));
			bkData.put("bkCashOutAgentCharge", UnitConverter.longToString(result.getLong("bkCashOutAgentCharge")));
			bkData.put("bkSendMoneyCharge", UnitConverter.longToString(result.getLong("bkSendMoneyCharge")));
			bkData.put("bkATMCharge", UnitConverter.longToString(result.getLong("bkATMCharge")));
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return bkData;
	}
	
	
	public Map<String, String> getRocketChargeData() {
		Map<String, String> rocData = new HashMap<>();
		
		String sql = "SELECT * FROM Rocket_Settings WHERE ID = 1 ";
		
		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)) {
			
			rocData.put("rocATMCashInAgentCharge", UnitConverter.longToString(result.getLong("rocATMCashInAgentCharge")));
			rocData.put("rocATMCashInBranchCharge", UnitConverter.longToString(result.getLong("rocATMCashInBranchCharge")));
			rocData.put("rocATMCashOutATMCharge", UnitConverter.longToString(result.getLong("rocATMCashOutATMCharge")));
			rocData.put("rocATMSendMoneyCharge", UnitConverter.longToString(result.getLong("rocATMSendMoneyCharge")));
			rocData.put("rocATMCashOutAgentCharge", UnitConverter.longToString(result.getLong("rocATMCashOutAgentCharge")));
			rocData.put("rocATMCashOutBranchCharge", UnitConverter.longToString(result.getLong("rocATMCashOutBranchCharge")));
			rocData.put("rocCashCashInAgentCharge", UnitConverter.longToString(result.getLong("rocCashCashInAgentCharge")));
			rocData.put("rocCashCashInBranchCharge", UnitConverter.longToString(result.getLong("rocCashCashInBranchCharge")));
			rocData.put("rocCashCashOutATMCharge", UnitConverter.longToString(result.getLong("rocCashCashOutATMCharge")));
			rocData.put("rocCashSendMoneyCharge", UnitConverter.longToString(result.getLong("rocCashSendMoneyCharge")));
			rocData.put("rocCashCashOutAgentCharge", UnitConverter.longToString(result.getLong("rocCashCashOutAgentCharge")));
			rocData.put("rocCashCashOutBranchCharge", UnitConverter.longToString(result.getLong("rocCashCashOutBranchCharge")));
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return rocData;
	}
	
	
	public void savebkYes(Map<String, String> bnkSettingData) {
		String sql = "UPDATE bKash_Settings \n"
				+ "SET bkCashInCharge = ?, bkCashOutAgentCharge = ?, bkSendMoneyCharge = ?, bkATMCharge = ? \n"
				+ "WHERE ID = 1";
		
		try (Connection conn = connector();
				PreparedStatement pstmt = conn.prepareStatement(sql)) {		
			
			pstmt.setLong(1, UnitConverter.stringToLong(bnkSettingData.get("bkCashInCharge")));
			pstmt.setLong(2, UnitConverter.stringToLong(bnkSettingData.get("bkCashOutAgentCharge")));
			pstmt.setLong(3, UnitConverter.stringToLong(bnkSettingData.get("bkSendMoneyCharge")));
			pstmt.setLong(4, UnitConverter.stringToLong(bnkSettingData.get("bkATMCharge")));
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		String sql1 = "INSERT INTO Methods_List (activeMethods) \n"
				+ "VALUES(?)";
		
		if (!BankIssue.isbKashActivated()) {
			try (Connection conn = connector();
					PreparedStatement pstmt = conn.prepareStatement(sql1)) {
					pstmt.setString(1, "bKash");
					pstmt.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}
	
	
	public void savebkNo() {
		String sql = "DELETE FROM Methods_List WHERE activeMethods = ?";
		
		if (BankIssue.isbKashActivated()) {
			try (Connection conn = connector();
					PreparedStatement pstmt = conn.prepareStatement(sql)) {
					pstmt.setString(1, "bKash");
					pstmt.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	
	private void saverocYes() {
		String sql = "INSERT INTO Methods_List (activeMethods) \n"
				+ "VALUES(?)";
		if (!BankIssue.isRocketActivated()) {
			try (Connection conn = connector();
					PreparedStatement pstmt = conn.prepareStatement(sql)) {
					pstmt.setString(1, "Rocket");
					pstmt.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	
	public void saverocATMYes(Map<String, String> bnkSettingData) {
		saverocYes();
		
		String sql = "UPDATE Rocket_Settings \n"
				+ "SET atmFree = ?, cashInFree = ?, rocATMCashInAgentCharge = ?, rocATMCashInBranchCharge = ? ,\n"
				+ "rocATMCashOutATMCharge = ?, rocATMSendMoneyCharge = ?, rocATMCashOutAgentCharge = ?, rocATMCashOutBranchCharge = ? \n"
				+ "WHERE ID = 1";
		try (Connection conn = connector();
				PreparedStatement pstmt = conn.prepareStatement(sql)) {	
			pstmt.setString(1, "true");
			pstmt.setString(2, "false");
			pstmt.setLong(3, UnitConverter.stringToLong(bnkSettingData.get("rocATMCashInAgentCharge")));
			pstmt.setLong(4, UnitConverter.stringToLong(bnkSettingData.get("rocATMCashInBranchCharge")));
			pstmt.setLong(5, UnitConverter.stringToLong(bnkSettingData.get("rocATMCashOutATMCharge")));
			pstmt.setLong(6, UnitConverter.stringToLong(bnkSettingData.get("rocATMSendMoneyCharge")));
			pstmt.setLong(7, UnitConverter.stringToLong(bnkSettingData.get("rocATMCashOutAgentCharge")));
			pstmt.setLong(8, UnitConverter.stringToLong(bnkSettingData.get("rocATMCashOutBranchCharge")));
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	
	}
	
	
	public void saverocCashInYes(Map<String, String> bnkSettingData) {
		saverocYes();
		
		String sql = "UPDATE Rocket_Settings \n"
				+ "SET atmFree = ?, cashInFree = ?, rocCashCashInAgentCharge = ?, rocCashCashInBranchCharge = ? ,\n"
				+ "rocCashCashOutATMCharge = ?, rocCashSendMoneyCharge = ?, rocCashCashOutAgentCharge = ?, rocCashCashOutBranchCharge = ? \n"
				+ "WHERE ID = 1";
		try (Connection conn = connector();
				PreparedStatement pstmt = conn.prepareStatement(sql)) {	
			pstmt.setString(1, "false");
			pstmt.setString(2, "true");
			pstmt.setLong(3, UnitConverter.stringToLong(bnkSettingData.get("rocCashCashInAgentCharge")));
			pstmt.setLong(4, UnitConverter.stringToLong(bnkSettingData.get("rocCashCashInBranchCharge")));
			pstmt.setLong(5, UnitConverter.stringToLong(bnkSettingData.get("rocCashCashOutATMCharge")));
			pstmt.setLong(6, UnitConverter.stringToLong(bnkSettingData.get("rocCashSendMoneyCharge")));
			pstmt.setLong(7, UnitConverter.stringToLong(bnkSettingData.get("rocCashCashOutAgentCharge")));
			pstmt.setLong(8, UnitConverter.stringToLong(bnkSettingData.get("rocCashCashOutBranchCharge")));
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}	
	
	
	public void saverocNo() {
		String sql = "DELETE FROM Methods_List WHERE activeMethods = ?";
		
		if (BankIssue.isRocketActivated()) {
			try (Connection conn = connector();
					PreparedStatement pstmt = conn.prepareStatement(sql)) {
					pstmt.setString(1, "Rocket");
					pstmt.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	
//	public static void main(String[] args) {
//		SettingBank access = new SettingBank();
//		Map<String, String> bnkSettingData = new HashMap<>();
//		
//		bnkSettingData.put("bkCashInCharge", "");
//		bnkSettingData.put("bkCashOutAgentCharge", "18.5");
//		bnkSettingData.put("bkSendMoneyCharge", "5");
//		bnkSettingData.put("bkATMCharge", "20");
//		
//		access.savebkYes(bnkSettingData);
//	}
} public class Source extends DashboardModel {

	public void createSource(String sourceName) {
		String sql = "INSERT INTO Source_List (sourceList) VALUES(?)";
		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sql)) {
			pstmt.setString(1, sourceName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void deleteSource(String sourceName) {
		String delete = "DELETE FROM Source_List WHERE sourceList = ?";

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(delete)) {
			pstmt.setString(1, sourceName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public void archiveSource(String sourceName) {
		String delete = "DELETE FROM Source_List WHERE sourceList = ?";
		String insert = "INSERT INTO Archived_Source_List (sourceArchiveList) VALUES(?)";

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(delete)) {
			pstmt.setString(1, sourceName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(insert)) {
			pstmt.setString(1, sourceName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void unarchiveSource(String sourceName) {
		String delete = "DELETE FROM Archived_Source_List WHERE sourceArchiveList = ?";
		String insert = "INSERT INTO Source_List (sourceList) VALUES(?)";

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(delete)) {
			pstmt.setString(1, sourceName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}

		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(insert)) {
			pstmt.setString(1, sourceName);
			pstmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public long getAmountBySourceFromGM(String monthName, String sourceName) {
		String sql = "SELECT gmAmount FROM Get_Money WHERE gmMonth = ? AND gmSource = ? ";
		long amount = 0;
		try (Connection conn = connector(); PreparedStatement pstmt = conn.prepareStatement(sql)) {
			pstmt.setString(1, monthName);
			pstmt.setString(2, sourceName);
			ResultSet result = pstmt.executeQuery();
			while (result.next()) {
				amount += stringToLong(removeThousandSeparator(result.getString("gmAmount")));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return amount;
	}

} public class TabAccess extends DatabaseConnection{

	public void setTabName(String tabName) {
		String sql = "UPDATE Current_Access SET tabName = ? ";
		
		try (Connection conn = connector();
                PreparedStatement pstmt = conn.prepareStatement(sql)) {
             pstmt.setString(1, tabName);
             pstmt.executeUpdate();
        } catch (SQLException e) {
        	e.printStackTrace();
        }
	}
	
	
	public String getTabName() {
		String tabName = null;
		String sql = "SELECT tabName \n"
				+ "FROM Current_Access \n"
				+ "WHERE ID = 1";
		
		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)) {
			if (result.next()) {
				tabName = result.getString("tabName");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return tabName;
	}
	
	
	public void setreRegistrationLodingStatus(String reRegistrationLodingStatus) {
		String sql = "UPDATE Current_Access SET reRegistrationLodingStatus = ? ";
		
		try (Connection conn = connector();
                PreparedStatement pstmt = conn.prepareStatement(sql)) {
             pstmt.setString(1, reRegistrationLodingStatus);
             pstmt.executeUpdate();
        } catch (SQLException e) {
        	e.printStackTrace();
        }
	}
	
	
	public String getreRegistrationLodingStatus() {
		String reRegistrationLodingStatus = null;
		String sql = "SELECT reRegistrationLodingStatus \n"
				+ "FROM Current_Access \n"
				+ "WHERE ID = 1";
		
		try (Connection conn = connector();
				Statement stmt = conn.createStatement();
				ResultSet result = stmt.executeQuery(sql)) {
			if (result.next()) {
				reRegistrationLodingStatus = result.getString("reRegistrationLodingStatus");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return reRegistrationLodingStatus;
	}
	
	
//	public static void main(String[] args) {
//		TabAccess access = new TabAccess();
//		access.setTabName("tabSector");
//		System.out.println(access.getTabName());
//	}
}
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.PasswordField;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Tooltip;
import javafx.stage.Stage;
import javafx.util.Duration;
import model.SettingsModel;
import operation.BankIssue;
import operation.ComboboxList;
import operation.GoToOperation;
import system.DateFormatManager;
import tab.AdvancedExpense;
import tab.Sector;
import tab.SettingBank;
import tab.Source;
import tab.TabAccess;
	@FXML
	private void tabBnkInitialize() {
		bkRbtn();
		rocRbtn();
	}
	
	@FXML
	private void bnktxtbkCashinAgent() {
		if (!validCharge(bnktxtbkCashinAgent.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtbkCashinAgent.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}
	
	@FXML
	private void bnktxtbkCashOutAgent() {
		if (!validCharge(bnktxtbkCashOutAgent.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtbkCashOutAgent.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}
	
	@FXML
	private void bnktxtbkSendMoney() {
		if (!validCharge(bnktxtbkSendMoney.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtbkSendMoney.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}

	@FXML
	private void bnktxtbkCashOutATM() {
		if (!validCharge(bnktxtbkCashOutATM.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtbkCashOutATM.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}

	@FXML
	private void bnktxtrocCashinAgent() {
		if (!validCharge(bnktxtrocCashinAgent.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtrocCashinAgent.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}

	@FXML
	private void bnktxtrocCashinBranch() {
		if (!validCharge(bnktxtrocCashinBranch.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtrocCashinBranch.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}

	@FXML
	private void bnktxtrocCashOutATM() {
		if (!validCharge(bnktxtrocCashOutATM.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtrocCashOutATM.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}

	@FXML
	private void bnktxtrocSendMoney() {
		if (!validCharge(bnktxtrocSendMoney.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtrocSendMoney.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}

	@FXML
	private void bnktxtrocCashOutAgent() {
		if (!validCharge(bnktxtrocCashOutAgent.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtrocCashOutAgent.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}

	@FXML
	private void bnktxtrocCashOutBranch() {
		if (!validCharge(bnktxtrocCashOutBranch.getText())) {
			bnkInvalidChargeMsg.setText(InvalidInput);
			bnktxtrocCashOutBranch.clear();
		} else {
			bnkInvalidChargeMsg.setText(" ");
		}
	}
	


//////////// bKash ///////////////
	@FXML
	private void bnkrbtnbkYes(ActionEvent event) {
		bkisActive();
	}
	
	@FXML
	private void bnkrbtnbkNo(ActionEvent event) {
		bkisInactive();
	}
	
	private void bkRbtn() {
		if (BankIssue.isbKashActivated()) {