Signup Page For Payroll Application
Code for this Sign Up Page
Main Class
--------------------
public class SignUp extends javax.swing.JFrame {
/**
* Creates new form SignUp
*/
Connection con=new DBConnection().paydbconnect(); /*creating database connection*/
Statement st;
ResultSet rs;
int uid=100;
String gender="",martial="",dep="",mode="",lang="";
String userid="";
public SignUp() {
initComponents();
}
Database Connection
-----------------------
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnection
{
Connection con;
public Connection paydbconnect()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/paydb","root","123");
}
catch(Exception e)
{
System.out.print("Exception from database connectivity"+ e.getMessage()+"\n"+e.getStackTrace());
}
return con;
}
}
Inserting values into Database
-------------------------------
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.hide();
Login l=new Login();
l.setVisible(true);
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String msg="Please ensure that your entries are correct this will not be editable in future Do you want to proceed ? ";
int i=JOptionPane.showConfirmDialog(this,msg);
String dbuid="";
uid++;
userid="emp"+fullnamefield.getText().trim().substring(0,3).trim()+uid;
if(i==0)
{
try
{
st=con.createStatement();
st.executeUpdate("insert into login values('"+userid+"','123')");
st.executeUpdate("insert into personal values('"+userid+"','"+fullnamefield.getText()+"','"+addressfield.getText()+"','"+
nationalityfield.getSelectedItem()+"','"+emailfield.getText()+"','"+
phonefield.getText()+"','"+gender+"','"+martial+"','"+bloodfield.getText()+"')");
st.executeUpdate("insert into family values('"+userid+"','"+namefield.getText()+"','"+relationfield.getText()+"','"+
occupationfield.getText()+"','"+familydobfield.getDate().toLocaleString()+"','"+dep+"')");
st.executeUpdate("insert into education values('"+userid+"','"+qualificationfield.getText()+"','"+institutefield.getText()+"','"
+universityfield.getText()+"','"+yearofpassedfield.getText()+"',"+Float.parseFloat(totalmarkfield.getText())+")");
st.executeUpdate("insert into skill values('"+userid+"','"+skillfield.getText()+"','"+skilllevelfield.getSelectedItem()+"','"+experiencefield.getText()+"','"+lang+"')");
st.executeUpdate("insert into official values('"+userid+"','"+dojfield.getDate().toLocaleString()+"','"+probationfield.getText()+"','"+companyfield.getText()+"','"+designationfield.getText()+"','"+gradefield.getText()+"','"
+employeetypefield.getSelectedItem()+"','"+mode+"','"+
accountfield.getText()+"','"+banknamefield.getText()+"')");
this.hide();
Successfull s=new Successfull(userid);
s.setVisible(true);
}
catch(SQLException e)
{
System.out.println(e);
}
}
//System.out.println(userid);
}
Here i used createStatement() instead of it you can use PreparedStatement() for faster database operations
Other codings
--------------------
private void chequeItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
if(cheque.isSelected())
mode="Cheque";
else if(jCheckBox6.isSelected())
mode="Cash";
else
mode="Bank Transfer";
}
private void dependantyesfieldItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
if(dependantyesfield.isSelected())
dep="Yes";
else
dep="No";
}
private void nationalityfieldItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
}
private void singlefieldItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
if(singlefield.isSelected())
martial="single";
else
martial="married";
}
private void malefieldItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
if(malefield.isSelected())
gender="male";
else
gender="female";
}
private void languagefieldValueChanged(javax.swing.event.ListSelectionEvent evt) {
// TODO add your handling code here:
lang=(String)languagefield.getSelectedValue();
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(this,"All fields are mandatory try to fill all fields...");
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
JOptionPane.showMessageDialog(this,"Press home button to exit");
}
For designing the front end i used the tabbed pane
you can add this calendar in your program as jar file called JCalendar you can download it from internet and add the jar file on tools->pallette->add jar..


No comments:
Post a Comment