java考勤管理系统数据库实现.docx
《java考勤管理系统数据库实现.docx》由会员分享,可在线阅读,更多相关《java考勤管理系统数据库实现.docx(16页珍藏版)》请在冰豆网上搜索。
java考勤管理系统数据库实现
4.2设计代码
Java源程序:
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjava.awt.*;
importjava.sql.*;
importjava.lang.*;
importjava.util.*;
importjavax.swing.table.*;
importjava.math.*;
classDB_LSimplementsActionListener{
JFrameframe=newJFrame("欢迎进入LS工资管理系统");
JLabellabel=newJLabel("09网络2_54_李胜",JLabel.CENTER);
JButtonbutton1=newJButton("进入系统");
JButtonbutton2=newJButton("退出系统");
ImageIconim=newImageIcon("1.jpg");
JLabela1=newJLabel(im);
voidCreate(){
JPanelpcontentPane=(JPanel)frame.getContentPane();
JPanelpcontentPane1=newJPanel();
pcontentPane.add(label);
pcontentPane.setLayout(newFlowLayout());
pcontentPane.add(button1);
pcontentPane.add(button2);
pcontentPane.add(newLabel(""));
pcontentPane.add(a1);
pcontentPane.setBackground(Color.green);
pcontentPane.setVisible(true);
button1.addActionListener(this);
button2.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setBounds(200,100,550,600);
frame.setVisible(true);
}
publicstaticvoidmain(String[]args){
DB_LSdome=newDB_LS();
dome.Create();
}
publicvoidactionPerformed(ActionEvente){
if(button1.equals(e.getSource())){
DLdl=newDL();
dl.create();
}
if(button2.equals(e.getSource())){//退出
System.exit(0);
}
}
}
classDLimplementsActionListener{
JFrameframe=newJFrame("职工/管理员登陆");
JLabellabel1=newJLabel("用户名");
JLabellabel2=newJLabel("密码");
JButtonlogonButton1=newJButton("管理员登录");
JButtonlogonButton2=newJButton("职工登录");
JButtoncancelButton=newJButton("退出");
JTextFieldt1=newJTextField(0);
JTextFieldt2=newJTextField(0);
ImageIconim=newImageIcon("2.jpg");
JLabela2=newJLabel(im);
JTextFieldusername=newJTextField(9);
JPasswordFieldpassword=newJPasswordField(9);
voidcreate(){
JPanelp=(JPanel)frame.getContentPane();
JPanelp1=newJPanel();
p.setLayout(newFlowLayout());
p.add(label1);
p.setSize(5,5);
p.setLocation(4,8);
p.add(username);
p.setSize(100,200);
p.setLocation(800,800);
p.add(label2);
p.setSize(50,20);
p.setLocation(40,80);
p.add(password);
p.setSize(100,20);
p.setLocation(80,120);
p.add(logonButton1);
p.add(newJLabel(""));
p.add(logonButton2);
p.add(newJLabel(""));
p.add(cancelButton);
p.add(newJLabel(""));
p.add(a2);
p.add(t1);
p.add(t2);
p.setBackground(Color.blue);
p.setVisible(true);
logonButton1.addActionListener(this);
logonButton2.addActionListener(this);
cancelButton.addActionListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setBounds(200,100,750,550);
frame.setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(logonButton1.equals(e.getSource())&&(username.getText().equals("123")==true)&&(password.getText().equals("123")==true)){
GZGLZJMgz=newGZGLZJM();
gz.create();
}
else{JOptionPane.showMessageDialog(null,"对不起,你输入的密码错误!
");
};
if(logonButton2.equals(e.getSource())&&(username.getText().equals(t1.getText())==true)&&(password.getText().equals(t2.getText())==true)){
XKxk=newXK();
xk.create();
Connectioncon;
Statementsql;
ResultSetrs;
Vectorvector=newVector();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione1){
System.out.println(""+e1);
}
try{
con=DriverManager.getConnection("jdbc:
odbc:
123","","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql.executeQuery("SELECTGno,mmFROMYWHEREGno="+t1.getText()+"ANDmm="+t2.getText());
}catch(SQLExceptione1){
System.out.println(e1);
}
}
if(cancelButton.equals(e.getSource())){
System.exit(0);
}
}
}
classGZGLZJMextendsJFrameimplementsActionListener{
JFramef=newJFrame("工资管理系统");
JButtonb1=newJButton("津贴管理");
JButtonb2=newJButton("总查询");
JButtonb3=newJButton("工资管理");
JButtonb4=newJButton("后勤管理");
JButtonb6=newJButton("员工个人信息管理");
JButtonb5=newJButton("返回");
ImageIconim=newImageIcon("3.jpg");
JLabela3=newJLabel(im);
voidcreate(){
JPanelp=(JPanel)f.getContentPane();
JPanelp1=newJPanel();
p.setLayout(newFlowLayout());
p.add(b1);
p.add(newJLabel(""));
p.add(b6);
p.add(newJLabel(""));
p.add(b3);
p.add(newJLabel(""));
p.add(b4);
p.add(newJLabel(""));
p.add(b2);
p.add(newJLabel(""));
p.add(b5);
p.add(a3);
p.setBackground(Color.red);
p.setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
f.setBounds(200,100,800,600);
f.setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(b5.equals(e.getSource())){//返回
DLd=newDL();
f.dispose();
}
if(b1.equals(e.getSource())){//津贴管理
JTGLjt=newJTGL();
jt.create();
}
if(b6.equals(e.getSource())){//员工个人信息管理
YGGLyg=newYGGL();
yg.create();
}
if(b2.equals(e.getSource())){//查询
XKxk=newXK();
xk.create();
}
if(b4.equals(e.getSource())){//后勤管理
KQGLkq=newKQGL();
kq.create();
}
if(b3.equals(e.getSource())){//工资管理
GZGLgz=newGZGL();
gz.create();
}
}
}
classKQGLimplementsActionListener{
JFramef=newJFrame("录入修改删除考勤信息");
JButtonb1=newJButton("录入");
JButtonb2=newJButton("修改");
JButtonb3=newJButton("删除");
JButtonb4=newJButton("查询所有");
JButtonb5=newJButton("返回");
JTextFieldtf1=newJTextField(4);
JTextFieldtf2=newJTextField(4);
JTextFieldtf3=newJTextField(4);
JTextFieldtf4=newJTextField(4);
JTextFieldtf5=newJTextField(6);
JButtonb6=newJButton("查询单人考勤");
String[]cloum={"职工号","缺勤天数","缺勤类别","缺勤时间"};
Object[][]row=newObject[50][4];
JTabletable=newJTable(row,cloum);
JScrollPanescrollpane=newJScrollPane(table);
JSplitPanesplitpane=newJSplitPane(JSplitPane.VERTICAL_SPLIT);
voidcreate()
{
JPanelp=(JPanel)f.getContentPane();
p.setLayout(newFlowLayout());
//p.add(scrollpane);
p.add(splitpane);
JPanelp1=newJPanel();
p1.add(b1);
p1.add(b2);
p1.add(b3);
p1.add(b4);
p1.add(b6);
p1.add(b5);
JPanelp2=newJPanel();
p2.setBackground(Color.red);
p2.add(scrollpane);
JPanelp3=newJPanel();
p.setLayout(newFlowLayout());
p.add(newJLabel(""));
p.add(newJLabel("职工号"));
p.add(tf1);
p.add(newJLabel("缺勤天数"));
p.add(tf2);
p.add(newJLabel("缺勤类别"));
p.add(tf3);
p.add(newJLabel(""));
p.add(newJLabel("缺勤时间"));
p.add(tf4);
p.add(newJLabel("在此处输入职工号点击查询删除"));
p.add(tf5);
splitpane.add(p1,splitpane.TOP);
splitpane.add(p2,splitpane.BOTTOM);
splitpane.setDividerLocation(50);
p.setBackground(Color.CYAN);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
f.setBounds(200,100,500,600);
f.setResizable(true);//可以调整界面大小
f.setVisible(true);
}
publicvoidactionPerformed(ActionEvente){
if(b1.equals(e.getSource())){//添加
Connectioncon;
Statementsql;
ResultSetrs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione1){
System.out.println(""+e1);
}
try{
con=DriverManager.getConnection("jdbc:
odbc:
123","","");
sql=con.createStatement();
StringinsertStr="INSERTINTOKVALUES"+"("+"'"+tf1.getText()+"'"+","+tf2.getText()+","+"'"+tf3.getText()+"'"+","+tf4.getText()+")";
sql.executeUpdate(insertStr);
con.close();
}catch(SQLExceptione1){
System.out.println(e1);
}
}
if(b2.equals(e.getSource())){//修改
Connectioncon;
Statementsql;
ResultSetrs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione1){
System.out.println(""+e1);
}
try{
con=DriverManager.getConnection("jdbc:
odbc:
123","","");
sql=con.createStatement();
sql.executeUpdate("UPDATEKSETts="+tf2.getText()+"WHEREKno="+tf1.getText()+"");
sql.executeUpdate("UPDATEKSETlb="+tf3.getText()+"WHEREKno="+tf1.getText()+"");
sql.executeUpdate("UPDATEKSETsj="+tf4.getText()+"WHEREKno="+tf1.getText()+"");
con.close();
}catch(SQLExceptione1){
System.out.println(e1);
}
}
if(b3.equals(e.getSource())){//删除
Connectioncon;
Statementsql;
ResultSetrs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione1){
System.out.println(""+e1);
}
try{
con=DriverManager.getConnection("jdbc:
odbc:
123","","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
sql.executeUpdate("DELETEFROMKWHEREKno="+tf5.getText());
con.close();
}catch(SQLExceptione1){
System.out.println(e1);
}
}
if(b4.equals(e.getSource())){//查询全部
Connectioncon;
Statementsql;
ResultSetrs;
Vectorvector=newVector();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExceptione1){
System.out.println(""+e1);
}
try{
con=DriverManager.getConnection("jdbc:
odbc:
123","sa","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
if(b4.equals(e.getSource())){
for(inti=0;i<50;i++)
for(intj=0;j<4;j++)
table.setValueAt("",i,j);
rs=sql.executeQuery("SELECT*FROMKORD