Leave Report(Employee Payroll Project)
package leave;
import database.ConnectionSetting;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.print.*;
import java.awt.*;
public class LeaveReport extends JInternalFrame
{
/*Declaring Object Name of Lables and Panel*/
JLabel headinglbl,oplbl;
JPanel head, MainPanel;
JButton printBtn;
Connection con = null;
public LeaveReport()
{
/*Creating Connection between Back End and Front End*/
try
{
ConnectionSetting conn = new ConnectionSetting();
con = conn.getConnection();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,e,”DataSource Error”,1);
}
/*Declaring Properties of Frame*/
this.setTitle(“Leave Report”);
this.setResizable(true);
this.setFrameIcon(new ImageIcon(“Images/leave.jpg”));
this.setLocation(0,25);
this.setSize(1010,685);
this.setClosable(true);
this.setVisible(true);
this.setLayout(null);
/*Initializing all Panels*/
head = new JPanel();
MainPanel = new JPanel();
/*Initializing all Labels*/
headinglbl = new JLabel(“Pay System”);
oplbl = new JLabel(“Leave Report”);
/*Declaring Array to hold Records of Employee in Table Format*/
String[][] data= new String[1000][8];
try
{
/*Retrieving Creating connection between Front End and Back End
Records from All Leave Table of Specified Employee*/
PreparedStatement ps = con.prepareStatement(“select Emp_Table.EmpID,Emp_Table.Emp_Name,Emp_Table.Design,Emp_Table.Depart,AbsentLeave_Table.total,BreakLeave_Table.total,CausalLeave_Table.total,SicknessLeave_Table.total from Emp_Table,AbsentLeave_Table,BreakLeave_Table,CausalLeave_Table,SicknessLeave_Table where Emp_Table.EmpID=AbsentLeave_Table.EmpID and Emp_Table.EmpID=BreakLeave_Table.EmpID and Emp_Table.EmpID=CausalLeave_Table.EmpID and Emp_Table.EmpID=SicknessLeave_Table.EmpID”);
ResultSet rs = ps.executeQuery();
int i=0;
while(rs.next())
{
data[i][0] = rs.getString(1);
data[i][1] = rs.getString(2);
data[i][2] = rs.getString(3);
data[i][3] = rs.getString(4);
data[i][4] = String.valueOf(rs.getInt(5));
data[i][5] = String.valueOf(rs.getInt(6));
data[i][6] = String.valueOf(rs.getInt(7));
data[i][7] = String.valueOf(rs.getInt(8));
i++;
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,e,”Data Retrieving Error”,1);
}
/*Declaring and defining Array to store Field Name of Table*/
String[] heading = {“EmpID”,”Name”,”Designation”,”Department”,”Total Absent”,”Total Break”,”Total Casual”,”Total Sickness”};
JTable jt = new JTable(data, heading);
JScrollPane pane = new JScrollPane(jt);
pane.setBounds(5,5,980,490);
/*setting size of panels*/
head.setBounds(5,5,990,100);
MainPanel.setBounds(5,110,990,500);
MainPanel.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
/*Setting size of all Labels*/
headinglbl.setBounds(350,20,300,40);
oplbl.setBounds(400,60,300,40);
/*Setting Background Color of Panels*/
head.setBackground(Color.LIGHT_GRAY);
MainPanel.setBackground(Color.CYAN);
/*Adding Heading label on Head Panel*/
head.add(headinglbl);
head.add(oplbl);
/*Adding Print Button on Frame*/
this.add(printBtn = new JButton(“Print”));
printBtn.setBounds(450,610,100,25);
/*Perfroming Print Opertion here*/
printBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
Object ob = ae.getSource();
if(ob==printBtn)
{
PrinterJob print = PrinterJob.getPrinterJob();
print.setPrintable(null);
if(print.printDialog())
{
try
{
print.print();
}
catch(Exception e)
{}
}
}
}
});//print Operation ends here
/*Setting null layout of panel*/
head.setLayout(null);
MainPanel.setLayout(null);
/*Adding panels on Frame*/
this.add(head);
this.add(MainPanel);
/*Adding Table on MainPanel*/
MainPanel.add(pane);
/*Specifying Font and Height of Heading Label*/
headinglbl.setFont(new Font(“Algerian”,Font.BOLD,40));
oplbl.setFont(new Font(“Castellar”,Font.PLAIN,20));
}
}