Wednesday 13 March 2013

DBMS Employee payroll


SQL> REM Emp_Details ( eid, ename, dob, sex, designation, address,
phone, email, REM REM department
)
SQL> REM Payroll ( eid, basic, da, hra, pf, mc, gross, tot_deduc,
net_pay ) eid REM REM references E
mp_Details(eid)
SQL>
SQL>
SQL> drop table Payroll;
Table dropped.
SQL> drop table Emp_Details;
Table dropped.
SQL>
SQL> create table Emp_Details(
2 eid number(5) CONSTRAINT pk_eid PRIMARY KEY,
3 ename varchar2(25),
4 dob date,
5 sex varchar2(7),
6 designation varchar2(25),
7 address varchar2(25),
8 phone number(10),
9 email varchar2(20),
10 department varchar2(10)
11 );
Table created.
SQL>
SQL> create table payroll(
2 Eid number(5) CONSTRAINT pk_Eid PRIMARY KEY,
3 basic number(7) CONSTRAINT not_basic NOT NULL,
4 da number(5),
5 hra number(5),
6 pf number(5),
7 mc number(5),
8 gross number(5),
9 tot_deduc number(7),
10 net_pay number(7),
11 CONSTRAINT fk_eid FOREIGN KEY(Eid) REFERENCES
Emp_Details(eid)
12 );
Table created.
SQL>
SQL> create or replace procedure calc(peid in payroll.Eid%type,
2 pbasic in Payroll.basic%type)
3 is
4 p payroll%rowtype;
5 temp number;
6 begin
7 temp:=0;
8 p.da:=(60/100)*pbasic;
9 p.hra:=(11/100)*pbasic;
10 p.pf:=(4/100)*pbasic;
11 p.mc:=(3/100)*pbasic;
12 p.gross:=(pbasic+p.da+p.hra);
13 p.tot_deduc:=(p.pf+p.mc);
14 p.net_pay:=(p.gross - p.tot_deduc);
15 select 1 into temp
16 from payroll
17 where Eid=peid;
18 EXCEPTION when no_data_found then
19 insert into Payroll values
20
(peid,pbasic,p.da,p.hra,p.pf,p.mc,p.gross,p.tot_deduc,p.net_pay);
21 end;
22 /
Procedure created.
SQL>
package Employee;
import java.sql.*;
import javax.swing.JOptionPane;
import javax.swing.ButtonGroup;
/**
*
* @author Ananthi
*/
public class Employee extends javax.swing.JFrame {
Connection con;
Statement stmt;
PreparedStatement pstmt;
ResultSet rs;
public Employee()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
JOptionPane.showMessageDialog(this,"Driver Loaded");
try
{
con=DriverManager.getConnection("jdbc:odbc:ananthi",
"system","ssn");
JOptionPane.showMessageDialog(this,"Connection
Established");
}
catch(SQLException ex)
{
JOptionPane.showMessageDialog(this,ex.getMessage());
}
}
catch(ClassNotFoundException ex){
JOptionPane.showMessageDialog(this,"Not loaded");
}
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated
Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
employee = new javax.swing.JTabbedPane();
EXIT = new javax.swing.JPanel();
ADDRESS = new javax.swing.JLabel();
SEX = new javax.swing.JLabel();
design = new javax.swing.JTextField();
DOB = new javax.swing.JLabel();
EMP_ID = new javax.swing.JLabel();
EMP_NAME = new javax.swing.JLabel();
department = new javax.swing.JTextField();
phone = new javax.swing.JTextField();
DEPT = new javax.swing.JLabel();
ename = new javax.swing.JTextField();
eid = new javax.swing.JTextField();
DESIGN = new javax.swing.JLabel();
EMAIL = new javax.swing.JLabel();
F = new javax.swing.JRadioButton();
M = new javax.swing.JRadioButton();
PHONE = new javax.swing.JLabel();
email = new javax.swing.JTextField();
dob = new javax.swing.JTextField();
INSERT = new javax.swing.JButton();
UPDATE = new javax.swing.JButton();
DELETE = new javax.swing.JButton();
SEARCH = new javax.swing.JButton();
FIRST = new javax.swing.JButton();
LAST = new javax.swing.JButton();
sex = new javax.swing.JTextField();
PREVIOUS = new javax.swing.JButton();
NEXT = new javax.swing.JButton();
CLEAR = new javax.swing.JButton();
exit = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
address = new javax.swing.JTextArea();
payroll = new javax.swing.JPanel();
employee_id = new javax.swing.JLabel();
Basic = new javax.swing.JLabel();
Da = new javax.swing.JLabel();
Hra = new javax.swing.JLabel();
Pf = new javax.swing.JLabel();
Mc = new javax.swing.JLabel();
Gross = new javax.swing.JLabel();
Total_ded = new javax.swing.JLabel();
Net_pay = new javax.swing.JLabel();
eid1 = new javax.swing.JTextField();
basic = new javax.swing.JTextField();
da = new javax.swing.JTextField();
hra = new javax.swing.JTextField();
pf = new javax.swing.JTextField();
mc = new javax.swing.JTextField();
gross = new javax.swing.JTextField();
total_ded = new javax.swing.JTextField();
net_pay = new javax.swing.JTextField();
calc = new javax.swing.JButton();
DISPLAY = new javax.swing.JButton();
Clear = new javax.swing.JButton();
EXIT1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_
ON_CLOSE);
ADDRESS.setText("Address");
SEX.setText("Sex");
DOB.setText("Date of Birth");
EMP_ID.setText("Employee Id");
EMP_NAME.setText("Employee Name");
DEPT.setText("Department");
eid.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent
evt) {
eidActionPerformed(evt);
}
});
DESIGN.setText("Designation");
EMAIL.setText("E-Mail");
buttonGroup1.add(F);
F.setText("Female");
F.setActionCommand("Male");
F.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
FActionPerformed(evt);
}
});
buttonGroup1.add(M);
M.setText("Male");
M.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
MActionPerformed(evt);
}
});
PHONE.setText("Phone");
email.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
emailActionPerformed(evt);
}
});
INSERT.setText("INSERT");
INSERT.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
INSERTActionPerformed(evt);
}
});
UPDATE.setText("UPDATE");
UPDATE.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
UPDATEActionPerformed(evt);
}
});
DELETE.setText("DELETE");
DELETE.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
DELETEActionPerformed(evt);
}
});
SEARCH.setText("SEARCH");
SEARCH.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
SEARCHActionPerformed(evt);
}
});
FIRST.setText("FIRST");
FIRST.setActionCommand("First");
FIRST.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
FIRSTActionPerformed(evt);
}
});
LAST.setText("LAST");
LAST.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent
evt) {
LASTActionPerformed(evt);
}
});
sex.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent
evt) {
sexActionPerformed(evt);
}
});
PREVIOUS.setText("PREVIOUS");
PREVIOUS.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
PREVIOUSActionPerformed(evt);
}
});
NEXT.setText("NEXT");
NEXT.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent
evt) {
NEXTActionPerformed(evt);
}
});
CLEAR.setText("CLEAR");
CLEAR.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
CLEARActionPerformed(evt);
}
});
exit.setText("EXIT");
exit.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent
evt) {
exitActionPerformed(evt);
}
});
address.setColumns(20);
address.setRows(5);
jScrollPane1.setViewportView(address);
javax.swing.GroupLayout EXITLayout = new
javax.swing.GroupLayout(EXIT);
EXIT.setLayout(EXITLayout);
EXITLayout.setHorizontalGroup(
EXITLayout.createParallelGroup(javax.swing.GroupLayout
.Alignment.LEADING)
.addGroup(EXITLayout.createSequentialGroup()
.addGap(50, 50, 50)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.LEADING)
.addGroup(EXITLayout.createSequentialGroup()
.addGroup(EXITLayout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(FIRST,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(INSERT,
javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE))
.addGap(90, 174, Short.MAX_VALUE)
.addGroup(EXITLayout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(PREVIOUS,
javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
.addComponent(DELETE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(37, 37, 37)
.addGroup(EXITLayout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(LAST,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(SEARCH,
javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE))
.addGap(43, 43, 43)
.addGroup(EXITLayout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(CLEAR,
javax.swing.GroupLayout.PREFERRED_SIZE, 78,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(exit,
javax.swing.GroupLayout.PREFERRED_SIZE, 78,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(63, 63, 63))
.addGroup(EXITLayout.createSequentialGroup()
.addGroup(EXITLayout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.LEADING)
.addGroup(EXITLayout.createSequentialG
roup()
.addGroup(EXITLayout.createParalle
lGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLay
out.Alignment.TRAILING, EXITLayout.createSequentialGroup()
.addComponent(EMP_ID,
javax.swing.GroupLayout.PREFERRED_SIZE, 82,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(52, 52, 52))
.addGroup(EXITLayout.createSeq
uentialGroup()
.addGroup(EXITLayout.creat
eParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(DOB,
javax.swing.GroupLayout.PREFERRED_SIZE, 72,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(SEX,
javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(EMAIL)
.addComponent(PHONE)
.addComponent(DESIGN)
.addComponent(ADDRESS)
.addComponent(EMP_NAME
, javax.swing.GroupLayout.PREFERRED_SIZE, 120,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(14, 14, 14)))
.addGroup(EXITLayout.createParalle
lGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(design,
javax.swing.GroupLayout.PREFERRED_SIZE, 225,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(EXITLayout.createPar
allelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(eid)
.addComponent(ename)
.addComponent(dob)
.addComponent(email)
.addGroup(EXITLayout.creat
eSequentialGroup()
.addComponent(M)
.addGap(18, 18, 18)
.addComponent(F)
.addPreferredGap(javax
.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(sex))
.addComponent(department)
.addComponent(phone,
javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1
, javax.swing.GroupLayout.PREFERRED_SIZE, 225,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(EXITLayout.createPar
allelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(UPDATE,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(NEXT,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE))))
.addComponent(DEPT,
javax.swing.GroupLayout.PREFERRED_SIZE, 96,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())))
);
EXITLayout.setVerticalGroup(
EXITLayout.createParallelGroup(javax.swing.GroupLayout
.Alignment.LEADING)
.addGroup(EXITLayout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.TRAILING, false)
.addGroup(EXITLayout.createSequentialGroup()
.addComponent(eid,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.C
omponentPlacement.UNRELATED)
.addComponent(ename,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.C
omponentPlacement.UNRELATED)
.addComponent(dob,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(EXITLayout.createSequentialGroup()
.addComponent(EMP_ID,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(EMP_NAME,
javax.swing.GroupLayout.PREFERRED_SIZE, 14,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(DOB,
javax.swing.GroupLayout.PREFERRED_SIZE, 18,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.TRAILING)
.addGroup(EXITLayout.createParallelGroup(javax
.swing.GroupLayout.Alignment.BASELINE)
.addComponent(M)
.addComponent(F)
.addComponent(SEX))
.addComponent(sex,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.LEADING, false)
.addComponent(design)
.addComponent(DESIGN,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(19, 19, 19)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.LEADING)
.addGroup(EXITLayout.createSequentialGroup()
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 71,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18))
.addGroup(javax.swing.GroupLayout.Alignment.TR
AILING, EXITLayout.createSequentialGroup()
.addComponent(ADDRESS)
.addGap(54, 54, 54)))
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.LEADING, false)
.addComponent(phone)
.addComponent(PHONE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED, 18, Short.MAX_VALUE)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.LEADING, false)
.addComponent(email)
.addComponent(EMAIL,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.LEADING, false)
.addComponent(department)
.addComponent(DEPT,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(44, 44, 44)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.BASELINE)
.addComponent(INSERT)
.addComponent(UPDATE)
.addComponent(DELETE)
.addComponent(SEARCH)
.addComponent(CLEAR))
.addGap(18, 18, 18)
.addGroup(EXITLayout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.BASELINE)
.addComponent(FIRST)
.addComponent(LAST)
.addComponent(PREVIOUS)
.addComponent(NEXT)
.addComponent(exit))
.addGap(21, 21, 21))
);
employee.addTab("EMPLOYEE", EXIT);
employee_id.setText("Employee ID");
Basic.setText("Basic");
Da.setText("DA");
Hra.setText("HRA");
Pf.setText("PF");
Mc.setText("MC");
Gross.setText("GROSS");
Total_ded.setText("Total Deduction");
Net_pay.setText("Net Pay");
eid1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent
evt) {
eid1ActionPerformed(evt);
}
});
da.setBackground(new java.awt.Color(240, 240, 240));
da.setDisabledTextColor(new java.awt.Color(172, 168,
153));
hra.setBackground(new java.awt.Color(240, 240, 240));
pf.setBackground(new java.awt.Color(240, 240, 240));
pf.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
pfActionPerformed(evt);
}
});
mc.setBackground(new java.awt.Color(240, 240, 240));
gross.setBackground(new java.awt.Color(240, 240, 240));
total_ded.setBackground(new java.awt.Color(240, 240,
240));
net_pay.setBackground(new java.awt.Color(240, 240, 240));
calc.setText("CALCULATE");
calc.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent
evt) {
calcActionPerformed(evt);
}
});
DISPLAY.setText("DISPLAY");
DISPLAY.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
DISPLAYActionPerformed(evt);
}
});
Clear.setText("CLEAR");
Clear.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
ClearActionPerformed(evt);
}
});
EXIT1.setText("EXIT");
EXIT1.addActionListener(new
java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
evt) {
EXIT1ActionPerformed(evt);
}
});
javax.swing.GroupLayout payrollLayout = new
javax.swing.GroupLayout(payroll);
payroll.setLayout(payrollLayout);
payrollLayout.setHorizontalGroup(
payrollLayout.createParallelGroup(javax.swing.GroupLay
out.Alignment.LEADING)
.addGroup(payrollLayout.createSequentialGroup()
.addGap(34, 34, 34)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
.addComponent(employee_id)
.addComponent(Basic)
.addComponent(Da)
.addComponent(Hra)
.addComponent(Pf)
.addComponent(Mc)
.addComponent(Gross)
.addComponent(Total_ded)
.addComponent(Net_pay)
.addComponent(calc))
.addGap(59, 59, 59)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
.addGroup(payrollLayout.createParallelGroup(ja
vax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(basic,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
.addComponent(da,
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(hra,
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(eid1)
.addComponent(pf)
.addComponent(mc)
.addComponent(gross)
.addComponent(total_ded)
.addComponent(net_pay))
.addGroup(payrollLayout.createSequentialGroup(
)
.addComponent(DISPLAY)
.addGap(61, 61, 61)
.addComponent(Clear)
.addGap(54, 54, 54)
.addComponent(EXIT1)))
.addContainerGap(209, Short.MAX_VALUE))
);
payrollLayout.setVerticalGroup(
payrollLayout.createParallelGroup(javax.swing.GroupLay
out.Alignment.LEADING)
.addGroup(payrollLayout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.BASELINE)
.addComponent(employee_id)
.addComponent(eid1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.BASELINE)
.addComponent(Basic)
.addComponent(basic,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.BASELINE)
.addComponent(Da)
.addComponent(da,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING)
.addComponent(hra,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(payrollLayout.createSequentialGroup(
)
.addGap(3, 3, 3)
.addComponent(Hra,
javax.swing.GroupLayout.PREFERRED_SIZE, 20,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING, false)
.addComponent(pf,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(payrollLayout.createSequentialGroup(
)
.addGap(3, 3, 3)
.addComponent(Pf,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(18, 18, 18)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING, false)
.addGroup(payrollLayout.createSequentialGroup(
)
.addComponent(mc,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(gross,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(total_ded,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(payrollLayout.createSequentialGroup(
)
.addComponent(Mc,
javax.swing.GroupLayout.PREFERRED_SIZE, 22,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(Gross,
javax.swing.GroupLayout.PREFERRED_SIZE, 21,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.C
omponentPlacement.UNRELATED)
.addComponent(Total_ded,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(18, 18, 18)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.LEADING, false)
.addComponent(Net_pay,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(net_pay))
.addPreferredGap(javax.swing.LayoutStyle.Component
Placement.RELATED, 64, Short.MAX_VALUE)
.addGroup(payrollLayout.createParallelGroup(javax.
swing.GroupLayout.Alignment.BASELINE)
.addComponent(calc)
.addComponent(DISPLAY)
.addComponent(Clear)
.addComponent(EXIT1))
.addGap(82, 82, 82))
);
employee.addTab("PAYROLL", payroll);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addComponent(employee)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addComponent(employee)
);
pack();
}// </editor-fold>
private void INSERTActionPerformed(java.awt.event.ActionEvent
evt) {
try {
String sql = ("insert into emp_details
values(?,?,?,?,?,?,?,?,?)");
pstmt = con.prepareStatement(sql);
pstmt.setString(1, eid.getText());
pstmt.setString(2, ename.getText());
pstmt.setString(3, dob.getText());
if (M.isSelected()) {
pstmt.setString(4, "M");
}
if (F.isSelected()) {
pstmt.setString(4, "F");
}
pstmt.setString(5, design.getText());
pstmt.setString(6, address.getText());
pstmt.setString(7, phone.getText());
pstmt.setString(8, email.getText());
pstmt.setString(9, department.getText());
pstmt.executeUpdate();
JOptionPane.showMessageDialog(this, "Inserted
Successfully!!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
private void UPDATEActionPerformed(java.awt.event.ActionEvent
evt) {
String id, name, dep, des, em, ph, add, s, dat;
int e_id;
try
{
stmt = con.createStatement();
} catch (SQLException e)
{
JOptionPane.showMessageDialog(null, "statement not
created");
}
try {
id = new String();
name = new String();
s = new String();
add = new String();
ph = new String();
em = new String();
dat = new String();
id = eid.getText();
name = ename.getText();
dep = department.getText();
des = design.getText();
ph = phone.getText();
s = sex.getText();
em=email.getText();
add = address.getText();
dat=dob.getText();
e_id = Integer.parseInt(id);
if (name.isEmpty() == false) {
stmt.executeUpdate("update emp_details set
ename='" + name + "' where eid=" + e_id + "" + "");
}
if (dep.isEmpty() == false) {
stmt.executeUpdate("update emp_details set
department='" + dep + "' where eid=" + e_id + "" + "");
}
if (des.isEmpty() == false) {
stmt.executeUpdate("update emp_details set
designation='" + des + "' where eid=" + e_id + "" + "");
}
if (ph.isEmpty() == false) {
stmt.executeUpdate("update emp_details set
phone='" + ph + "' where eid=" + e_id + "" + "");
}
if (add.isEmpty() == false) {
stmt.executeUpdate("update emp_details set
address='" + add + "' where eid=" + e_id + "" + "");
}
if (em.isEmpty() == false) {
stmt.executeUpdate("update emp_details set
email='" + em + "' where eid=" + e_id + "" + "");
}
if (s.isEmpty() == false) {
stmt.executeUpdate("update emp_details set sex='"
+ s + "' where eid=" + e_id + "" + "");
}
if (dat.isEmpty() == false) {
stmt.executeUpdate("update emp_details set dob='"
+ dat + "' where eid=" + e_id + "" + "");
}
JOptionPane.showMessageDialog(this, "Upadated
Succesfully");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
private void DELETEActionPerformed(java.awt.event.ActionEvent
evt) {
try {
String sql1 = ("delete from payroll where eid=?");
PreparedStatement pstmt1 = con.prepareStatement(sql1);
pstmt1.setString(1, eid.getText());
pstmt1.executeUpdate();
String sql = ("delete from emp_details where eid=?");
pstmt = con.prepareStatement(sql);
pstmt.setString(1, eid.getText());
pstmt.executeUpdate();
JOptionPane.showMessageDialog(this," DELETED
Successfully!!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
private void SEARCHActionPerformed(java.awt.event.ActionEvent
evt) {
try {
String sql = " select *from emp_details where eid=?";
PreparedStatement pstmt1 = con.prepareStatement(sql);
pstmt1.setString(1, eid.getText());
rs = pstmt1.executeQuery();
rs.next();
ename.setText(rs.getString(2));
dob.setText(rs.getString(3));
sex.setText(rs.getString(4));
design.setText(rs.getString(5));
address.setText(rs.getString(6));
phone.setText(rs.getString(7));
email.setText(rs.getString(8));
department.setText(rs.getString(9));
JOptionPane.showMessageDialog(this, "Successfully
searched!!!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, "No Record
Found!");
}
}
private void FIRSTActionPerformed(java.awt.event.ActionEvent
evt) {
try {
stmt =
con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery("select * from emp_details");
rs.first();
eid.setText(rs.getString(1));
ename.setText(rs.getString(2));
dob.setText(rs.getString(3));
sex.setText(rs.getString(4));
design.setText(rs.getString(5));
address.setText(rs.getString(6));
phone.setText(rs.getString(7));
email.setText(rs.getString(8));
department.setText(rs.getString(9));
JOptionPane.showMessageDialog(this, "First Record
Displayed Successfully!!");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
private void LASTActionPerformed(java.awt.event.ActionEvent
evt) {
try {
stmt =
con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery("select * from emp_details");
rs.last();
eid.setText(rs.getString(1));
ename.setText(rs.getString(2));
dob.setText(rs.getString(3));
sex.setText(rs.getString(4));
design.setText(rs.getString(5));
address.setText(rs.getString(6));
phone.setText(rs.getString(7));
email.setText(rs.getString(8));
department.setText(rs.getString(9));
JOptionPane.showMessageDialog(null, "Last Record
Displayed Successfully!!!");
} catch (SQLException e) {
System.out.println(e);
JOptionPane.showMessageDialog(null, "EOF is
Encountered..");
}
}
private void
PREVIOUSActionPerformed(java.awt.event.ActionEvent evt) {
/*try {
//
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet
.CONCUR_READ_ONLY);
// rs=stmt.executeQuery("select * from emp_details");
rs.previous();
eid.setText(rs.getString(1));
ename.setText(rs.getString(2));
dob.setText(rs.getString(3));
sex.setText(rs.getString(4));
design.setText(rs.getString(5));
address.setText(rs.getString(6));
phone.setText(rs.getString(7));
email.setText(rs.getString(8));
department.setText(rs.getString(9));
} catch (SQLException e) {
System.out.println(e);
JOptionPane.showMessageDialog(null, "eof is
encountered..");
}*/
String sql = "SELECT * from emp_details";
try {
con.createStatement(rs.TYPE_SCROLL_INSENSITIVE,
rs.CONCUR_READ_ONLY);
PreparedStatement psmt = con.prepareStatement(sql,
rs.TYPE_SCROLL_INSENSITIVE, rs.CONCUR_READ_ONLY);
rs = psmt.executeQuery();
boolean nxt = rs.next();
while (nxt) {
if (rs.getString(1).equals(eid.getText())) {
boolean nx1 = rs.previous();
if (nx1) {
eid.setText(rs.getString(1));
ename.setText(rs.getString(2));
dob.setText(rs.getString(3));
sex.setText(rs.getString(4));
design.setText(rs.getString(5));
address.setText(rs.getString(9));
phone.setText(rs.getString(7));
email.setText(rs.getString(6));
department.setText(rs.getString(8));
} else {
JOptionPane.showMessageDialog(this,
"PREVIOUS RECORD NOT AVAILABLE!");
}
}
boolean next1 = rs.next();
nxt = next1;
if (rs.isFirst()) {
break;
}
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
private void NEXTActionPerformed(java.awt.event.ActionEvent
evt) {
String sql = "SELECT * from emp_details";
try {
PreparedStatement psmt = con.prepareStatement(sql,
rs.TYPE_SCROLL_INSENSITIVE, rs.CONCUR_READ_ONLY);
rs = psmt.executeQuery();
con.createStatement(rs.TYPE_SCROLL_INSENSITIVE,
rs.CONCUR_READ_ONLY);
boolean nxt = rs.next();
while (nxt) {
if (rs.getString(1).equals(eid.getText())) {
boolean nx1 = rs.next();
if (nx1) {
eid.setText(rs.getString(1));
ename.setText(rs.getString(2));
dob.setText(rs.getString(3));
sex.setText(rs.getString(4));
design.setText(rs.getString(5));
address.setText(rs.getString(9));
phone.setText(rs.getString(7));
email.setText(rs.getString(6));
department.setText(rs.getString(8));
}
}
if (rs.isLast()) {
break;
}
boolean next1 = rs.next();
nxt = next1;
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(this, "NEXT RECORD NOT
AVAILABLE!");
}
}
private void CLEARActionPerformed(java.awt.event.ActionEvent
evt) {
eid.setText("");
ename.setText("");
dob.setText("");
sex.setText("");
design.setText("");
address.setText("");
phone.setText("");
email.setText("");
department.setText("");
}
private void calcActionPerformed(java.awt.event.ActionEvent
evt) {
try
{
String sql1 = ("select * from payroll where eid=" +
eid1.getText() + "");
PreparedStatement psmt1 = con.prepareStatement(sql1);
rs = psmt1.executeQuery();
eid1.setText(rs.getString(1));
basic.setText(rs.getString(2));
da.setText(rs.getString(3));
hra.setText(rs.getString(4));
pf.setText(rs.getString(5));
mc.setText(rs.getString(6));
gross.setText(rs.getString(7));
total_ded.setText(rs.getString(8));
net_pay.setText(rs.getString(9));
JOptionPane.showMessageDialog(this, "PAYROLL DETAILS
ALREADY CALCULATED!");
}
catch (SQLException ex)
{
try {
String str = "{call calc(?,?)}";
CallableStatement pstmt = con.prepareCall(str);
pstmt.setString(1, eid1.getText());
pstmt.setString(2, basic.getText());
pstmt.execute();
String sql1 = ("select * from payroll where eid="
+ eid1.getText() + "");
PreparedStatement stmt1 =
con.prepareStatement(sql1);
rs = stmt1.executeQuery();
rs.next();
eid.setText(rs.getString(1));
basic.setText(rs.getString(2));
da.setText(rs.getString(3));
hra.setText(rs.getString(4));
pf.setText(rs.getString(5));
mc.setText(rs.getString(6));
gross.setText(rs.getString(7));
total_ded.setText(rs.getString(8));
net_pay.setText(rs.getString(9));
JOptionPane.showMessageDialog(this, "PAYROLL
DETAILS CALCULATED SUCCESSFULLY!");
} catch (SQLException e) {
JOptionPane.showMessageDialog(this, "Enter a Valid
Input!!!!");
}
}
}
private void DISPLAYActionPerformed(java.awt.event.ActionEvent
evt) {
try {
String sql = " select *from payroll where eid=?";
PreparedStatement pstmt1 = con.prepareStatement(sql);
pstmt1.setString(1, eid1.getText());
rs = pstmt1.executeQuery();
rs.next();
basic.setText(rs.getString(2));
da.setText(rs.getString(3));
hra.setText(rs.getString(4));
pf.setText(rs.getString(5));
mc.setText(rs.getString(6));
gross.setText(rs.getString(7));
total_ded.setText(rs.getString(8));
net_pay.setText(rs.getString(9));
JOptionPane.showMessageDialog(this, "Record
Found!!!");
}
catch (SQLException ex)
{
JOptionPane.showMessageDialog(this, "No Record
Found!!!");
}
}
private void ClearActionPerformed(java.awt.event.ActionEvent
evt) {
eid1.setText("");
basic.setText("");
da.setText("");
hra.setText("");
pf.setText("");
mc.setText("");
total_ded.setText("");
gross.setText("");
net_pay.setText("");
}
private void EXIT1ActionPerformed(java.awt.event.ActionEvent
evt) {
System.exit(1);
}
private void eidActionPerformed(java.awt.event.ActionEvent
evt) {
}
private void emailActionPerformed(java.awt.event.ActionEvent
evt) {
}
private void MActionPerformed(java.awt.event.ActionEvent evt)
{
}
private void FActionPerformed(java.awt.event.ActionEvent evt)
{
}
private void sexActionPerformed(java.awt.event.ActionEvent
evt) {
}
private void eid1ActionPerformed(java.awt.event.ActionEvent
evt) {
}
private void pfActionPerformed(java.awt.event.ActionEvent evt)
{
}
private void exitActionPerformed(java.awt.event.ActionEvent
evt) {
System.exit(1);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Employee().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel ADDRESS;
private javax.swing.JLabel Basic;
private javax.swing.JButton CLEAR;
private javax.swing.JButton Clear;
private javax.swing.JButton DELETE;
private javax.swing.JLabel DEPT;
private javax.swing.JLabel DESIGN;
private javax.swing.JButton DISPLAY;
private javax.swing.JLabel DOB;
private javax.swing.JLabel Da;
private javax.swing.JLabel EMAIL;
private javax.swing.JLabel EMP_ID;
private javax.swing.JLabel EMP_NAME;
private javax.swing.JPanel EXIT;
private javax.swing.JButton EXIT1;
private javax.swing.JRadioButton F;
private javax.swing.JButton FIRST;
private javax.swing.JLabel Gross;
private javax.swing.JLabel Hra;
private javax.swing.JButton INSERT;
private javax.swing.JButton LAST;
private javax.swing.JRadioButton M;
private javax.swing.JLabel Mc;
private javax.swing.JButton NEXT;
private javax.swing.JLabel Net_pay;
private javax.swing.JLabel PHONE;
private javax.swing.JButton PREVIOUS;
private javax.swing.JLabel Pf;
private javax.swing.JButton SEARCH;
private javax.swing.JLabel SEX;
private javax.swing.JLabel Total_ded;
private javax.swing.JButton UPDATE;
private javax.swing.JTextArea address;
private javax.swing.JTextField basic;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton calc;
private javax.swing.JTextField da;
private javax.swing.JTextField department;
private javax.swing.JTextField design;
private javax.swing.JTextField dob;
private javax.swing.JTextField eid;
private javax.swing.JTextField eid1;
private javax.swing.JTextField email;
private javax.swing.JTabbedPane employee;
private javax.swing.JLabel employee_id;
private javax.swing.JTextField ename;
private javax.swing.JButton exit;
private javax.swing.JTextField gross;
private javax.swing.JTextField hra;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField mc;
private javax.swing.JTextField net_pay;
private javax.swing.JPanel payroll;
private javax.swing.JTextField pf;
private javax.swing.JTextField phone;
private javax.swing.JTextField sex;
private javax.swing.JTextField total_ded;
// End of variables declaration
}
INSERTION:
UPDATION:
DELETE:
SEARCH:
FIRST:
NEXT:
PREVIOUS:
LAST:
CALCULATE:
DISPLAY:

No comments:

Post a Comment