payroll.FrmInsert.java Source code

Java tutorial

Introduction

Here is the source code for payroll.FrmInsert.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 payroll;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import java.awt.Color;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Gopinath
 */
public class FrmInsert extends javax.swing.JFrame {

    /**
     * Creates new form Insert
     */
    public FrmInsert() {
        initComponents();
        this.getContentPane().setBackground(Color.YELLOW);
        setDefaultCloseOperation(this.HIDE_ON_CLOSE);
    }

    /**
     * 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() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        rdbFemale = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        lblFname = new javax.swing.JLabel();
        lblGender = new javax.swing.JLabel();
        cmbDesig = new javax.swing.JComboBox();
        lblMobno = new javax.swing.JLabel();
        lblDOB = new javax.swing.JLabel();
        lblEmpreg = new javax.swing.JLabel();
        lblQual = new javax.swing.JLabel();
        txtFname = new javax.swing.JTextField();
        cmbQual = new javax.swing.JComboBox();
        txtLname = new javax.swing.JTextField();
        txtMobno = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtareaAddress = new javax.swing.JTextArea();
        lblEmail = new javax.swing.JLabel();
        lblAddress = new javax.swing.JLabel();
        lblDesig = new javax.swing.JLabel();
        btnSubmit = new javax.swing.JButton();
        lblLname = new javax.swing.JLabel();
        lblEmp_Id = new javax.swing.JLabel();
        rdbMale = new javax.swing.JRadioButton();
        lblDOJ = new javax.swing.JLabel();
        dtDOJ = new com.toedter.calendar.JDateChooser();
        dtDOB = new com.toedter.calendar.JDateChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("EMPLOYEE REGISTRATION");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 0));

        buttonGroup1.add(rdbFemale);
        rdbFemale.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        rdbFemale.setText("Female");

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        jLabel1.setText("Employee ID:");

        txtEmail.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N

        lblFname.setFont(new java.awt.Font("Times New Roman", 3, 12)); // NOI18N
        lblFname.setText("First Name:");

        lblGender.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblGender.setText("Gender:");

        cmbDesig.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        cmbDesig.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Clerk", "Peon", "Lab Assistant",
                "Assistant Proffesor", "Associate Proffesor", "Head Of Department" }));

        lblMobno.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblMobno.setText("Mobile Number:");

        lblDOB.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblDOB.setText("Date of birth:");

        lblEmpreg.setFont(new java.awt.Font("Algerian", 2, 18)); // NOI18N
        lblEmpreg.setForeground(new java.awt.Color(102, 51, 0));
        lblEmpreg.setText("Employee   Registration");

        lblQual.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblQual.setText("Qualification:");

        txtFname.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        txtFname.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtFnameMouseClicked(evt);
            }
        });
        txtFname.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtFnameKeyPressed(evt);
            }

            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtFnameKeyTyped(evt);
            }
        });

        cmbQual.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        cmbQual.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "HSC", "SSC", "DIPLOMA", "B.E/B.TECH", "M.E/M.TECH" }));

        txtLname.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        txtLname.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtLnameKeyPressed(evt);
            }
        });

        txtMobno.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        txtMobno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMobnoActionPerformed(evt);
            }
        });
        txtMobno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtMobnoKeyPressed(evt);
            }

            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtMobnoKeyTyped(evt);
            }
        });

        txtareaAddress.setColumns(20);
        txtareaAddress.setRows(5);
        jScrollPane1.setViewportView(txtareaAddress);

        lblEmail.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblEmail.setText("Email ID:");

        lblAddress.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblAddress.setText("Address:");

        lblDesig.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblDesig.setText("Designation:");

        btnSubmit.setBackground(new java.awt.Color(153, 153, 255));
        btnSubmit.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        btnSubmit.setText("SUBMIT");
        btnSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSubmitActionPerformed(evt);
            }
        });

        lblLname.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblLname.setText("Last Name:");

        lblEmp_Id.setFont(new java.awt.Font("Times New Roman", 3, 12)); // NOI18N
        lblEmp_Id.setText("Employee Id");
        lblEmp_Id.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblEmp_IdMouseClicked(evt);
            }
        });

        buttonGroup1.add(rdbMale);
        rdbMale.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        rdbMale.setText("Male");
        rdbMale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdbMaleActionPerformed(evt);
            }
        });

        lblDOJ.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N
        lblDOJ.setText("Date of joining:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGap(38, 38, 38)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblMobno).addComponent(lblEmail))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(rdbMale)
                                        .addGap(18, 18, 18).addComponent(rdbFemale))
                                .addComponent(txtLname, javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtFname, javax.swing.GroupLayout.PREFERRED_SIZE, 119,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 224,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(dtDOB, javax.swing.GroupLayout.Alignment.LEADING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                                        .addComponent(txtEmail, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtMobno, javax.swing.GroupLayout.Alignment.LEADING)))
                        .addContainerGap(302, Short.MAX_VALUE))
                .addGroup(
                        javax.swing.GroupLayout.Alignment.TRAILING,
                        jPanel1Layout
                                .createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(
                                        lblEmpreg, javax.swing.GroupLayout.PREFERRED_SIZE, 232,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(224, 224, 224))
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(27, 27, 27).addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(lblFname).addComponent(jLabel1)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lblGender).addComponent(lblLname)))
                                        .addGap(18, 18, 18).addComponent(lblEmp_Id,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 110,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(11, 11, 11)
                                        .addComponent(lblDOB))))
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(35, 35, 35).addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout
                                        .createSequentialGroup().addGap(279, 279, 279).addComponent(btnSubmit))
                                .addComponent(lblAddress)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(jPanel1Layout.createSequentialGroup().addComponent(lblDesig)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(cmbDesig, javax.swing.GroupLayout.PREFERRED_SIZE, 189,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel1Layout.createSequentialGroup().addComponent(lblQual)
                                                .addGap(18, 18, 18).addComponent(cmbQual,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 189,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(lblDOJ)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(dtDOJ, javax.swing.GroupLayout.PREFERRED_SIZE, 132,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addComponent(lblEmpreg, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1).addComponent(lblEmp_Id,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 14,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(32, 32, 32)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(38, 38, 38)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(lblLname).addComponent(txtLname,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(lblGender).addComponent(rdbMale)
                                                .addComponent(rdbFemale)))
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lblFname).addComponent(txtFname,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(dtDOB, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblDOB))
                        .addGap(12, 12, 12)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtMobno, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lblMobno)).addGap(18, 18, 18)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(lblEmail).addComponent(txtEmail,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(33, 33, 33)
                                                        .addComponent(lblAddress))
                                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(18, 18, 18)
                                                        .addComponent(jScrollPane1,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 75,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(cmbQual, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lblQual))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(cmbDesig, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(lblDesig))
                                        .addGap(31, 31, 31).addComponent(lblDOJ))
                                .addComponent(dtDOJ, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                        .addComponent(btnSubmit).addContainerGap()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap().addComponent(jPanel1,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE));

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

    private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed
        // TODO add your handling code here:
        int i = 0;
        String nu = "";

        if (txtFname.getText().equals(nu)) {
            JOptionPane.showMessageDialog(null, "First name cannot remain empty", "FAILED",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (txtLname.getText().equals(nu)) {
            JOptionPane.showMessageDialog(null, "Last name cannot remain empty", "FAILED",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (txtEmail.getText().equals(nu)) {
            JOptionPane.showMessageDialog(null, "Email cannot remain empty", "FAILED", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (txtareaAddress.getText().equals(nu)) {
            JOptionPane.showMessageDialog(null, "Address cannot remain empty", "FAILED", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (txtMobno.getText().equals(nu)) {
            JOptionPane.showMessageDialog(null, "Mobile number cannot remain empty", "FAILED",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (txtMobno.getText().length() != 10) {
            JOptionPane.showMessageDialog(null, "Enter valid mobile number", "FAILED", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (cmbDesig.getSelectedItem().equals(nu)) {
            JOptionPane.showMessageDialog(null, "Select a gender", "FAILED", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (cmbQual.getSelectedItem().equals(nu)) {
            JOptionPane.showMessageDialog(null, "Select your qualification", "FAILED", JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (dtDOB.getDate().equals(nu)) {
            JOptionPane.showMessageDialog(null, "Date of birth cannot remain empty", "FAILED",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
        if (dtDOJ.getDate().equals(nu)) {
            JOptionPane.showMessageDialog(null, "Date of joining cannot remain empty", "FAILED",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        try {
            java.util.Date d1 = dtDOB.getDate();
            java.util.Date d2 = dtDOJ.getDate();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String date = sdf.format(dtDOB.getDate());
            String gender = null;
            ButtonGroup group = new ButtonGroup();

            if (rdbMale.isSelected()) {
                gender = rdbMale.getText();

            } else {
                gender = rdbFemale.getText();

            }
            final JPanel p2 = new JPanel();
            final JOptionPane jo = new JOptionPane();

            Connect1 j = new Connect1();
            DBCollection dbc = j.connect("Emp_Records");
            DBCursor cursor = dbc.find();
            while (cursor.hasNext() == true) {
                DBObject obj = cursor.next();
                i++;
            }

            String ID = "";
            if (i < 10)
                ID = "EMP00" + i;
            else
                ID = "EMP0" + i;
            String emailID = txtEmail.getText();
            String emailRE = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$";

            Boolean flag = emailID.matches(emailRE);
            BasicDBObject bdb = new BasicDBObject();
            bdb.put("ID", ID);

            bdb.put("First Name", txtFname.getText());
            bdb.put("Last Name", txtLname.getText());
            if (flag != null)
                bdb.put("Email", txtEmail.getText());
            else {
                JOptionPane.showMessageDialog(p2, "Invalid Email Id", "Enter a valid email address",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            bdb.put("Address", txtareaAddress.getText());
            bdb.put("Mobile Number", txtMobno.getText());
            bdb.put("Qualification", cmbQual.getSelectedItem());
            bdb.put("Designation", cmbDesig.getSelectedItem());
            Calendar c = new GregorianCalendar();
            int year = c.get(Calendar.YEAR);

            /*  if(year-d1.getYear()-1900>60)
              {
            JOptionPane.showMessageDialog(p2,"Only employees between 21 to 60 years can work ","failure",JOptionPane.ERROR_MESSAGE); 
              return;
                  
              }
              if(year-d1.getYear()<20)
              {
            JOptionPane.showMessageDialog(p2,"Only employees between 21 to 60 years can work ","failure",JOptionPane.ERROR_MESSAGE); 
              return;
                  
              }*/
            bdb.put("DOB", d1);
            bdb.put("Gender", gender);
            bdb.put("DOJ", d2);
            dbc.insert(bdb);

            JOptionPane.showMessageDialog(p2, "Registered successfully", "Registration success",
                    JOptionPane.INFORMATION_MESSAGE);
            clear();
            this.setVisible(false);
            FrmPassword u1 = new FrmPassword();

            new FrmPassword().setVisible(true);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "ONE OR MORE FIELDS ARE EMPTY", "FAILURE",
                    JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_btnSubmitActionPerformed

    public void clear() {
        txtFname.setText(null);
        txtLname.setText(null);
        cmbDesig.setSelectedItem(null);
        cmbQual.setSelectedItem(null);
        txtMobno.setText(null);
        rdbMale.setSelected(false);
        rdbFemale.setSelected(false);
        dtDOB.setDate(null);
        dtDOJ.setDate(null);
    }

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

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

    private void txtFnameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFnameKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtFnameKeyTyped

    private void txtFnameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFnameKeyPressed
        // TODO add your handling code here:
        final KeyEvent k = evt;

        txtFname.addKeyListener(new KeyAdapter() {

            public void keyTyped(KeyEvent e) {
                //  if (!Character.isDigit(e.getKeyChar()))
                final char c = k.getKeyChar();
                if (Character.isDigit(c) || (Character.isWhitespace(c))) {
                    txtFname.setEditable(false);
                } else {

                    txtFname.setEditable(true);
                }
            }
        });
    }//GEN-LAST:event_txtFnameKeyPressed

    private void txtLnameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtLnameKeyPressed
        // TODO add your handling code here:
        final KeyEvent k = evt;

        txtLname.addKeyListener(new KeyAdapter() {

            public void keyTyped(KeyEvent e) {
                //  if (!Character.isDigit(e.getKeyChar()))
                final char c = k.getKeyChar();
                if (Character.isDigit(c) || (Character.isWhitespace(c))) {
                    txtLname.setEditable(false);
                } else {

                    txtLname.setEditable(true);
                }
            }
        });
    }//GEN-LAST:event_txtLnameKeyPressed

    private void txtMobnoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMobnoKeyPressed
        // TODO add your handling code here:
        final KeyEvent k = evt;

        txtMobno.addKeyListener(new KeyAdapter() {

            public void keyTyped(KeyEvent e) {
                //  if (!Character.isDigit(e.getKeyChar()))
                final char c = k.getKeyChar();
                if (Character.isLetter(c) || (Character.isWhitespace(c))) {
                    txtMobno.setEditable(false);
                } else {

                    txtMobno.setEditable(true);
                }
            }
        });
    }//GEN-LAST:event_txtMobnoKeyPressed

    private void txtMobnoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtMobnoKeyTyped
        // TODO add your handling code here:
        /* int length=txtMobno.getText().length();
            
         if(length==9)
        lblStatus.setText("Valid");
         else {
        lblStatus.setText("Invalid");
         }*/
    }//GEN-LAST:event_txtMobnoKeyTyped

    private void lblEmp_IdMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblEmp_IdMouseClicked
        // TODO add your handling code here:

    }//GEN-LAST:event_lblEmp_IdMouseClicked

    private void txtFnameMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtFnameMouseClicked
        // TODO add your handling code here:

    }//GEN-LAST:event_txtFnameMouseClicked

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:

        int i = 0, emp_id = 0;
        Connect1 j = new Connect1();
        DBCollection dbc = j.connect("Emp_Records");
        DBCursor cursor = dbc.find();
        while (cursor.hasNext()) {
            i++;
            DBObject obj = cursor.next();
        }

        emp_id = i;
        String ID = "";
        if (i < 10)
            ID = "EMP00" + i;
        else
            ID = "EMP0" + i;

        lblEmp_Id.setText(ID);

    }//GEN-LAST:event_formWindowActivated

    /**
     * @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(FrmInsert.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmInsert.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmInsert.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmInsert.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>
        //</editor-fold>

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSubmit;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cmbDesig;
    private javax.swing.JComboBox cmbQual;
    private com.toedter.calendar.JDateChooser dtDOB;
    private com.toedter.calendar.JDateChooser dtDOJ;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblDOB;
    private javax.swing.JLabel lblDOJ;
    private javax.swing.JLabel lblDesig;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblEmp_Id;
    private javax.swing.JLabel lblEmpreg;
    private javax.swing.JLabel lblFname;
    private javax.swing.JLabel lblGender;
    private javax.swing.JLabel lblLname;
    private javax.swing.JLabel lblMobno;
    private javax.swing.JLabel lblQual;
    private javax.swing.JRadioButton rdbFemale;
    private javax.swing.JRadioButton rdbMale;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFname;
    private javax.swing.JTextField txtLname;
    private javax.swing.JTextField txtMobno;
    private javax.swing.JTextArea txtareaAddress;
    // End of variables declaration//GEN-END:variables
}