schoolsystem.FeeModule.java Source code

Java tutorial

Introduction

Here is the source code for schoolsystem.FeeModule.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package schoolsystem;

import java.awt.Toolkit;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 *
 * @author codeGeek
 */
public class FeeModule extends javax.swing.JFrame {
    String admno;
    String paidamount;
    String mode;
    String receiptno;
    String chequeno;
    String term;
    //sms sending variables
    String apiKey = "2166fa37bf20e3f60212d188aa57cb3809763d95ce9df3bacc4ab8f0e20f6ce2";
    String receiver;
    String message;
    String username = "petermug";
    Connection conn;
    DatabaseConnect dbconn;
    PreparedStatement pst;
    private String transactionNo;
    private ResultSet rs;
    private String studentname;

    /**
     * Creates new form FeeModule
     */
    public FeeModule() {
        initComponents();
        try {

            lbl_cheque.setVisible(false);
            txt_fee_module_cheque_no.setVisible(false);
            lbl_receipt.setVisible(false);
            txt_fee_module_receipt.setVisible(false);
            radio_fee_module_cash.setActionCommand("Cash");
            radio_fee_module_cash.setSelected(true);
            radio_fee_module_cheque.setActionCommand("Cheque");
            radio_fee_module_receipt.setActionCommand("Receipt");
            dbconn = new DatabaseConnect();
            conn = dbconn.dbConnect();

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FeeModule.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(FeeModule.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void getTextFieldValues() {
        if (txt_fee_module_cheque_no.isVisible()) {
            transactionNo = txt_fee_module_cheque_no.getText();
        }
        if (txt_fee_module_receipt.isVisible()) {
            transactionNo = txt_fee_module_receipt.getText();
        }
        admno = txt_fee_module.getText();
        paidamount = txt_fee_module_amt_paid.getText();
        chequeno = txt_fee_module_cheque_no.getText();
        receiptno = txt_fee_module_receipt.getText();
        mode = radio_group_mode.getSelection().getActionCommand();
        term = combo_fee_module_term.getSelectedItem().toString();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        radio_group_mode = new javax.swing.ButtonGroup();
        panel_fee_module = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txt_fee_module = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        combo_fee_module_term = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        radio_fee_module_cash = new javax.swing.JRadioButton();
        radio_fee_module_cheque = new javax.swing.JRadioButton();
        radio_fee_module_receipt = new javax.swing.JRadioButton();
        lbl_receipt = new javax.swing.JLabel();
        txt_fee_module_receipt = new javax.swing.JTextField();
        lbl_cheque = new javax.swing.JLabel();
        txt_fee_module_cheque_no = new javax.swing.JTextField();
        btn_fee_module_save = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        combo_year = new javax.swing.JComboBox();
        txt_fee_module_amt_paid = new javax.swing.JFormattedTextField();
        btn_view_balance = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        menu_fee_module_exit = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Fee payment module");
        setResizable(false);

        panel_fee_module.setBorder(javax.swing.BorderFactory.createTitledBorder("Fee Payment module"));

        jLabel1.setText("Admin no");

        txt_fee_module.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_fee_moduleKeyTyped(evt);
            }
        });

        jLabel2.setText("Amount paid");

        jLabel3.setText("Term");

        combo_fee_module_term
                .setModel(new javax.swing.DefaultComboBoxModel(new String[] { "TERM 1", "TERM 2", "TERM 3" }));

        jLabel4.setText("Mode of Payment");

        radio_group_mode.add(radio_fee_module_cash);
        radio_fee_module_cash.setText("Cash");
        radio_fee_module_cash.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                radio_fee_module_cashItemStateChanged(evt);
            }
        });

        radio_group_mode.add(radio_fee_module_cheque);
        radio_fee_module_cheque.setText("Cheque");
        radio_fee_module_cheque.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                radio_fee_module_chequeItemStateChanged(evt);
            }
        });
        radio_fee_module_cheque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radio_fee_module_chequeActionPerformed(evt);
            }
        });

        radio_group_mode.add(radio_fee_module_receipt);
        radio_fee_module_receipt.setText("Receipt");
        radio_fee_module_receipt.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                radio_fee_module_receiptItemStateChanged(evt);
            }
        });

        lbl_receipt.setText("Enter Receipt number");

        txt_fee_module_receipt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_fee_module_receiptKeyTyped(evt);
            }
        });

        lbl_cheque.setText("Enter cheque number");

        txt_fee_module_cheque_no.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_fee_module_cheque_noKeyTyped(evt);
            }
        });

        btn_fee_module_save.setText("Save & Send sms");
        btn_fee_module_save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_fee_module_saveActionPerformed(evt);
            }
        });

        jLabel5.setText("Year");

        combo_year.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4" }));

        txt_fee_module_amt_paid.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat(""))));
        txt_fee_module_amt_paid.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_fee_module_amt_paidKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout panel_fee_moduleLayout = new javax.swing.GroupLayout(panel_fee_module);
        panel_fee_module.setLayout(panel_fee_moduleLayout);
        panel_fee_moduleLayout.setHorizontalGroup(panel_fee_moduleLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panel_fee_moduleLayout.createSequentialGroup().addContainerGap()
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jSeparator1)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel_fee_moduleLayout
                                        .createSequentialGroup()
                                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 120,
                                                Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(radio_fee_module_receipt,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 70,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(16, 16, 16)
                                        .addComponent(radio_fee_module_cash, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(radio_fee_module_cheque,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 77,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(117, 117, 117))
                                .addGroup(panel_fee_moduleLayout.createSequentialGroup()
                                        .addComponent(lbl_cheque, javax.swing.GroupLayout.PREFERRED_SIZE, 133,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(0, 0, Short.MAX_VALUE))))
                .addGroup(panel_fee_moduleLayout.createSequentialGroup().addGap(218, 218, 218)
                        .addComponent(btn_fee_module_save).addGap(0, 0, Short.MAX_VALUE))
                .addGroup(panel_fee_moduleLayout.createSequentialGroup().addGroup(panel_fee_moduleLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jSeparator2)
                        .addGroup(panel_fee_moduleLayout.createSequentialGroup().addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(panel_fee_moduleLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 143,
                                                Short.MAX_VALUE))
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 133,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(panel_fee_moduleLayout.createSequentialGroup().addContainerGap()
                                        .addComponent(lbl_receipt, javax.swing.GroupLayout.PREFERRED_SIZE, 133,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel5)).addGap(18, 18, 18)
                                .addGroup(panel_fee_moduleLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(combo_fee_module_term, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txt_fee_module)
                                        .addComponent(txt_fee_module_receipt, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                173, Short.MAX_VALUE)
                                        .addComponent(txt_fee_module_cheque_no)
                                        .addComponent(combo_year, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txt_fee_module_amt_paid))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addContainerGap()));
        panel_fee_moduleLayout.setVerticalGroup(panel_fee_moduleLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panel_fee_moduleLayout.createSequentialGroup().addContainerGap(17, Short.MAX_VALUE)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txt_fee_module))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2).addComponent(txt_fee_module_amt_paid,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5).addComponent(combo_year,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3).addComponent(combo_fee_module_term,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 5,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(panel_fee_moduleLayout.createSequentialGroup()
                                        .addGroup(panel_fee_moduleLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(radio_fee_module_cash)
                                                .addComponent(radio_fee_module_cheque)
                                                .addComponent(radio_fee_module_receipt))
                                        .addGap(25, 25, 25))
                                .addGroup(panel_fee_moduleLayout.createSequentialGroup().addComponent(jLabel4)
                                        .addGap(29, 29, 29)))
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lbl_receipt)
                                .addComponent(txt_fee_module_receipt, javax.swing.GroupLayout.PREFERRED_SIZE, 26,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lbl_cheque).addComponent(txt_fee_module_cheque_no,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_fee_module_save)));

        btn_view_balance.setText("view balance");
        btn_view_balance.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_view_balanceActionPerformed(evt);
            }
        });

        jMenu1.setText("File");

        menu_fee_module_exit.setText("Exit");
        jMenu1.add(menu_fee_module_exit);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(panel_fee_module, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btn_view_balance))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addComponent(panel_fee_module, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_view_balance).addGap(0, 0, Short.MAX_VALUE)));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void txt_fee_module_receiptKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_fee_module_receiptKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            Toolkit.getDefaultToolkit().beep();
            evt.consume();
        }
    }//GEN-LAST:event_txt_fee_module_receiptKeyTyped

    private void txt_fee_module_cheque_noKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_fee_module_cheque_noKeyTyped
        if (evt.getKeyChar() < '0' || evt.getKeyChar() > '9') {
            Toolkit.getDefaultToolkit().beep();
            evt.consume();
        } // TODO add your handling code here:
    }//GEN-LAST:event_txt_fee_module_cheque_noKeyTyped

    private void radio_fee_module_chequeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radio_fee_module_chequeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_radio_fee_module_chequeActionPerformed

    private void btn_fee_module_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_fee_module_saveActionPerformed
        saveFee(combo_fee_module_term.getSelectedItem().toString(), combo_year.getSelectedItem().toString());

    }//GEN-LAST:event_btn_fee_module_saveActionPerformed

    private void radio_fee_module_cashItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_radio_fee_module_cashItemStateChanged
        int change = evt.getStateChange();
        if (change == ItemEvent.SELECTED) {
            transactionNo = String.valueOf(0);
        }
    }//GEN-LAST:event_radio_fee_module_cashItemStateChanged

    private void radio_fee_module_chequeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_radio_fee_module_chequeItemStateChanged
        int change = evt.getStateChange();
        if (change == ItemEvent.SELECTED) {
            lbl_cheque.setVisible(true);
            txt_fee_module_cheque_no.setVisible(true);
        } else {
            lbl_cheque.setVisible(false);
            txt_fee_module_cheque_no.setVisible(false);
        }

    }//GEN-LAST:event_radio_fee_module_chequeItemStateChanged

    private void radio_fee_module_receiptItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_radio_fee_module_receiptItemStateChanged
        int change = evt.getStateChange();
        if (change == ItemEvent.SELECTED) {
            lbl_receipt.setVisible(true);
            txt_fee_module_receipt.setVisible(true);
        } else {
            lbl_receipt.setVisible(false);
            txt_fee_module_receipt.setVisible(false);
        }
    }//GEN-LAST:event_radio_fee_module_receiptItemStateChanged

    private void btn_view_balanceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_view_balanceActionPerformed
        new ViewBalance(null).setVisible(true);

    }//GEN-LAST:event_btn_view_balanceActionPerformed

    private void txt_fee_module_amt_paidKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_fee_module_amt_paidKeyTyped
        // TODO add your handling code here:

        if (evt.getKeyChar() >= '0' && evt.getKeyChar() <= '9') {

        } else {
            evt.consume();
            Toolkit.getDefaultToolkit().beep();
        }
    }//GEN-LAST:event_txt_fee_module_amt_paidKeyTyped

    private void txt_fee_moduleKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_fee_moduleKeyTyped
        if (evt.getKeyChar() >= '0' && evt.getKeyChar() <= '9') {

        } else {
            if (evt.getKeyChar() == KeyEvent.VK_SLASH) {

            } else {
                evt.consume();
                Toolkit.getDefaultToolkit().beep();
            }

        } // TODO add your handling code here:
    }//GEN-LAST:event_txt_fee_moduleKeyTyped

    public JTextField getVisibleTextField() {
        if (txt_fee_module_cheque_no.isVisible()) {
            return txt_fee_module_cheque_no;
        }
        if (txt_fee_module_receipt.isVisible()) {
            return txt_fee_module_receipt;
        }
        return null;
    }

    public String getParentPhoneNo() {
        String phonenumber = null;
        try {
            String parent = "select mobilenumber from guardian where student_adm='" + admno + "'";
            pst = conn.prepareStatement(parent);
            rs = pst.executeQuery();
            if (rs.next()) {
                return rs.getString(1);
            } else
                return phonenumber;
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex);
            //String phone=JOptionPane.showInputDialog(null,"")
            return phonenumber;
            //Logger.getLogger(FeeModule.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public String getStudentName() {
        String phonenumber = null;
        try {
            String parent = "select surname,firstname from student where student_adm='" + admno + "' and year='"
                    + combo_year.getSelectedItem() + "'";
            pst = conn.prepareStatement(parent);
            rs = pst.executeQuery();
            while (rs.next()) {
                String surname = rs.getString("surname");
                String firstname = rs.getString("firstname");
                studentname = surname + " " + firstname;
            }

        } catch (SQLException ex) {

            Logger.getLogger(FeeModule.class.getName()).log(Level.SEVERE, null, ex);
        }
        return studentname;
    }

    /**
     * @param args 
     * the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FeeModule.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FeeModule.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FeeModule.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FeeModule.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FeeModule().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_fee_module_save;
    private javax.swing.JButton btn_view_balance;
    private javax.swing.JComboBox combo_fee_module_term;
    private javax.swing.JComboBox combo_year;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel lbl_cheque;
    private javax.swing.JLabel lbl_receipt;
    private javax.swing.JMenuItem menu_fee_module_exit;
    private javax.swing.JPanel panel_fee_module;
    private javax.swing.JRadioButton radio_fee_module_cash;
    private javax.swing.JRadioButton radio_fee_module_cheque;
    private javax.swing.JRadioButton radio_fee_module_receipt;
    private javax.swing.ButtonGroup radio_group_mode;
    private javax.swing.JTextField txt_fee_module;
    private javax.swing.JFormattedTextField txt_fee_module_amt_paid;
    private javax.swing.JTextField txt_fee_module_cheque_no;
    private javax.swing.JTextField txt_fee_module_receipt;
    // End of variables declaration//GEN-END:variables

    private boolean emptyFiedls() {
        if (getVisibleTextField() == null) {
            if (admno.isEmpty() || paidamount.isEmpty()) {
                return true;
            } else
                return false;
            //To change body of generated methods, choose Tools | Templates.
        } else {
            if (admno.isEmpty() || getVisibleTextField().getText().isEmpty() || paidamount.isEmpty()) {
                return true;
            } else
                return false;
        }
    }

    private void sendSms(String phone) {
        AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apiKey);

        // Thats it, hit send and we'll take care of the rest. Any errors will
        // be captured in the Exception class below
        receiver = phone;
        message = "Student " + getStudentName() + " Paid : " + paidamount + " TO our school on this date "
                + new SimpleDateFormat("YYYY/MM/dd").format(new Date()) + " by " + mode;
        try {
            JSONArray results = gateway.sendMessage(receiver, message);
            JOptionPane.showMessageDialog(null, "Parent notified of fee payment");

        }

        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Message Could not be sent Check internet connection");
        }
        //To change body of generated methods, choose Tools | Templates.
    }

    private boolean admnoValid(String admno) {

        try {
            String parent = "select student_adm from student where student_adm='" + admno + "' and year='"
                    + combo_year.getSelectedItem() + "'";
            pst = conn.prepareStatement(parent);
            rs = pst.executeQuery();
            if (rs.next())
                return true;
            else
                return false;

        } catch (SQLException ex) {
            Logger.getLogger(FeeModule.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }

    private void saveFee(String term, String year) {
        Calendar calender = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("YYY-MM-dd");
        String insert_fee = "INSERT INTO fee (payment_mode,student_adm,Paid_amount,paid_date,term,transaction_no,year)VALUES(?,?,?,?,?,?,?)";
        getTextFieldValues();
        if (emptyFiedls()) {
            JOptionPane.showMessageDialog(null, "Please fill in the Fields");
        } else if (!admnoValid(admno)) {
            JOptionPane.showMessageDialog(null, "Invalid admission");

        } else if (Double.parseDouble(paidamount.replace(",", "")) > 20000) {
            JOptionPane.showMessageDialog(null, "Invalid Fee entry");
        } else {
            try {
                pst = conn.prepareStatement(insert_fee);
                pst.setString(1, mode);
                pst.setString(2, admno);
                pst.setString(3, paidamount.replace(",", ""));
                pst.setString(4, format.format(calender.getTime()));
                pst.setString(5, term);
                pst.setString(6, transactionNo);
                pst.setString(7, year);
                pst.executeUpdate();
                JOptionPane.showMessageDialog(null, "Fee details Saved");
                if (getParentPhoneNo() != null) {
                    //sendSms("+254"+getParentPhoneNo());

                } else {
                    JOptionPane.showMessageDialog(null, "Could not send sms");
                    //String phone=JOptionPane.showInputDialog(null,"")
                }
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, ex);
                txt_fee_module.grabFocus();
            }
        } //To change body of generated methods, choose Tools | Templates.
    }
}