// Add fee method private void addFees() { try { float feesadded = Float.parseFloat(addfeestextfield.getText()); int id = table.getSelectionModel().getMinSelectionIndex(); long studentid = (long) table.getValueAt(id, 0); int index = feestable.getSelectionModel().getMinSelectionIndex(); String coursename = (String) feestable.getValueAt(index, 0); Database db = new Database(); db.addFees(feesadded, studentid, coursename); updateFeesData(studentid); addfeestextfield.setText(""); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE); } }
// Method to update Table and related components private void update() { Database db = new Database(); String column[] = { "ID", "NAME", "GENDER", "GUARDIAN_ROLE", "GUARDIAN_NAME", "PRESENT_ADDRESS", "PRESENT_CITY", "PRESENT_PHONE" }; try { // Update table if (searchcombobox.getSelectedIndex() == 0 && allfieldcheckbox.isSelected()) { mytablemodel = new MyTableModel(db.getAllStudent(), db.getColumnNameFromStudent()); } else if (searchcombobox.getSelectedIndex() == 0 && !allfieldcheckbox.isSelected()) { mytablemodel = new MyTableModel(db.getSomeFieldsFromStudent(), column); } else if (searchcombobox.getSelectedIndex() == 1 && allfieldcheckbox.isSelected()) { String query = "SELECT * FROM Student WHERE NAME = \'" + searchtextfield.getText().trim() + "\'"; mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent()); } else if (searchcombobox.getSelectedIndex() == 1 && !allfieldcheckbox.isSelected()) { String query = "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE NAME = \'" + searchtextfield.getText().trim() + "\'"; mytablemodel = new MyTableModel(db.getData(query), column); } else if (searchcombobox.getSelectedIndex() == 2 && allfieldcheckbox.isSelected()) { String query = "SELECT * FROM Student WHERE GUARDIAN_NAME = \'" + searchtextfield.getText().trim() + "\'"; mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent()); } else if (searchcombobox.getSelectedIndex() == 2 && !allfieldcheckbox.isSelected()) { String query = "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE GUARDIAN_NAME = \'" + searchtextfield.getText().trim() + "\'"; mytablemodel = new MyTableModel(db.getData(query), column); } else if (searchcombobox.getSelectedIndex() == 3 && allfieldcheckbox.isSelected()) { String query = "SELECT * FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE CID = ANY(SELECT ID FROM CourseInfo WHERE NAME = \'" + searchtextfield.getText().trim() + "\'))"; mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent()); } else if (searchcombobox.getSelectedIndex() == 3 && !allfieldcheckbox.isSelected()) { String query = "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE CID = ANY(SELECT ID FROM CourseInfo WHERE NAME = \'" + searchtextfield.getText().trim() + "\'))"; mytablemodel = new MyTableModel(db.getData(query), column); } else if (searchcombobox.getSelectedIndex() == 4 && allfieldcheckbox.isSelected()) { String query = "SELECT * FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE TOTAL_FEES - FEES_PAYED >= 0)"; mytablemodel = new MyTableModel(db.getData(query), db.getColumnNameFromStudent()); } else { String query = "SELECT ID, NAME, GENDER, GUARDIAN_ROLE, GUARDIAN_NAME, PRESENT_ADDRESS, PRESENT_CITY, PRESENT_PHONE FROM Student WHERE ID = ANY(SELECT SID FROM Fee WHERE TOTAL_FEES - FEES_PAYED >= 0)"; mytablemodel = new MyTableModel(db.getData(query), column); } table = new JTable(mytablemodel); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // Add list selection listener to table table.getSelectionModel().addListSelectionListener(this); TableColumn col = null; for (int i = 3; i < table.getColumnCount(); i++) { col = table.getColumnModel().getColumn(i); col.setPreferredWidth(200); } scrollpane = new JScrollPane(table); panel_3.removeAll(); panel_3.add(scrollpane); // Update total student label int total = db.getTotalStudent(); totalstudentlabel.setText("Total Student = " + total); // Clear search combo box searchtextfield.setText(""); this.revalidate(); } catch (Exception e) { JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }