schoolsystem.FeeModuleDialog.java Source code

Java tutorial

Introduction

Here is the source code for schoolsystem.FeeModuleDialog.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.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 *
 * @author codeGeek
 */
public class FeeModuleDialog extends javax.swing.JDialog {
    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 FeeModuleDialog
     */
    public FeeModuleDialog(JFrame frame, boolean modal) {
        super(frame, modal);
        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 FeeModuleDialog(JDialog frame, boolean modal, String admno, String year) {
        super(frame, modal);
        initComponents();

        try {
            combo_year.setSelectedItem(year);
            txt_fee_module.setText(admno);
            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 = btng_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() {

        btng_mode = new javax.swing.ButtonGroup();
        jButton1 = new javax.swing.JButton();
        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();
        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();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        combo_year = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        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();

        jButton1.setText("jButton1");

        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" }));

        btng_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);
            }
        });

        btng_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);
            }
        });

        btng_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" }));

        jLabel6.setText("Mode of payment");

        txt_fee_module_amt_paid.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
                new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0.00;(#,##0.00)"))));
        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);
            }
        });

        btn_view_balance.setText("ViewBalance");
        btn_view_balance.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_view_balanceActionPerformed(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)
                                .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
                                                                        .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)
                                                                                .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)
                                                                                .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)
                                                                                        .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,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        147,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                                .addGroup(panel_fee_moduleLayout
                                                                        .createSequentialGroup().addGap(10, 10, 10)
                                                                        .addComponent(btn_view_balance)
                                                                        .addGap(125, 125, 125)
                                                                        .addComponent(btn_fee_module_save))
                                                                .addGroup(panel_fee_moduleLayout
                                                                        .createSequentialGroup()
                                                                        .addComponent(jLabel6).addGap(60, 60, 60)
                                                                        .addComponent(radio_fee_module_receipt,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                70,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addComponent(radio_fee_module_cash,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                67,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addComponent(radio_fee_module_cheque,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                77,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                        .addGap(0, 0, Short.MAX_VALUE))
                                                .addComponent(jSeparator3,
                                                        javax.swing.GroupLayout.Alignment.TRAILING,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 413,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addContainerGap())
                                .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)))));
        panel_fee_moduleLayout.setVerticalGroup(panel_fee_moduleLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panel_fee_moduleLayout.createSequentialGroup().addContainerGap()
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txt_fee_module, 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(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)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(radio_fee_module_receipt).addComponent(radio_fee_module_cash)
                                .addComponent(radio_fee_module_cheque).addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lbl_receipt).addComponent(txt_fee_module_receipt,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(17, 17, 17)
                        .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)
                        .addGroup(panel_fee_moduleLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btn_fee_module_save).addComponent(btn_view_balance))));

        menu_fee_module_exit.setText("Exit");
        menu_fee_module_exit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menu_fee_module_exitActionPerformed(evt);
            }
        });
        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()
                        .addComponent(panel_fee_module, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .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.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap()));

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

    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_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 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 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 btn_fee_module_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_fee_module_saveActionPerformed
        Calendar calender = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("YYY-MM-dd");
        String insert_fee = "INSERT INTO fee (payment_mode,student_adm,Paid_amount,paiddate,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");
            //String phone=JOptionPane.showInputDialog(null,"")
        } 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, combo_year.getSelectedItem().toString());
                pst.executeUpdate();
                JOptionPane.showMessageDialog(null, "Fee details Saved");
                if (getParentPhoneNo() != null) {
                    System.out.println(getStudentName());
                    //sendSms("+254"+getParentPhoneNo());

                    //send an sms
                } else {
                    JOptionPane.showMessageDialog(null, "Could not send sms");
                    //String phone=JOptionPane.showInputDialog(null,"")
                }
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, ex);
                txt_fee_module.grabFocus();
            }

        }
    }//GEN-LAST:event_btn_fee_module_saveActionPerformed

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

        } else {
            evt.consume();
            Toolkit.getDefaultToolkit().beep();
        }
        //code here:
    }//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 
    }//GEN-LAST:event_txt_fee_moduleKeyTyped

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

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

    /**
     * @param args the command line arguments
     */

    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) {
            return phonenumber;
            //Logger.getLogger(FeeModule.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    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");
            for (int i = 0; i < results.length(); ++i) {
                JSONObject result = results.getJSONObject(i);
                System.out.print(result.getString("status") + ","); // status is either "Success" or "error message"
                System.out.print(result.getString("number") + ",");
                System.out.print(result.getString("messageId") + ",");
                System.out.println(result.getString("cost"));
            }
        }

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

    public String getStudentName() {
        String phonenumber = null;
        try {
            String parent = "select surname,firstname from student where student_adm='" + admno + "'";
            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;
    }

    // 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.ButtonGroup btng_mode;
    private javax.swing.JComboBox combo_fee_module_term;
    private javax.swing.JComboBox combo_year;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    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.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 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;
        }
    }
}