工資系統代碼JAVA版_第1頁
工資系統代碼JAVA版_第2頁
工資系統代碼JAVA版_第3頁
工資系統代碼JAVA版_第4頁
工資系統代碼JAVA版_第5頁
已閱讀5頁,還剩52頁未讀, 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、標準文案工資系統代碼/*系統歡迎界面*/import java.awt.FlowLayout;import java.awt.event.*; import javax.swing.*; SuppressWarnings("serial")class WagesSystem extends JFrame implements ActionListener JFrame frame = new JFrame("歡迎進入工資管理系統"); JButton button1 = new JButton("進入系統"); JButton but

2、ton2 = new JButton("退出系統"); ImageIcon im = new ImageIcon("1.jpg"); JLabel a1 = new JLabel(im); void Create() JPanel pcontentPane = (JPanel) frame.getContentPane();pcontentPane.add(a1); pcontentPane.setLayout(new FlowLayout();pcontentPane.add(button1); pcontentPane.add(button2); p

3、contentPane.setVisible(true); button1.addActionListener(this); button2.addActionListener(this); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null);frame.setVisible(true); public static void main(String args) WagesSystem dome = new WagesSystem(); dom

4、e.Create(); public void actionPerformed(ActionEvent e) if (button1.equals(e.getSource() DL dl = new DL(); dl.create(); frame.dispose(); if (button2.equals(e.getSource()System.exit(0); /*登錄界面*/import java.awt.HeadlessException;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;imp

5、ort java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JT

6、extField;import .*;import java.sql.*;SuppressWarnings("serial")class DL extends JFrame implements ActionListener NetConn sql;Statement sqll;ResultSet rs;JFrame frame = new JFrame("職工/管理員登陸");JLabel label1 = new JLabel("用戶名");JLabel label2 = new JLabel("密 碼");J

7、Button logonButton1 = new JButton("系統管理員登錄");JButton logonButton2 = new JButton("教職工登錄");JButton logonButton3 = new JButton("財務管理員登錄");JButton cancelButton = new JButton("退出");JTextField username = new JTextField(9);JPasswordField password = new JPasswordField

8、(9);static String t1;static String t2;void create() frame.setLayout(null);label1.setBounds(60,20,50,20);frame.add(label1);username.setBounds(130,20,150,20);frame.add(username);label2.setBounds(60,50,50,20);frame.add(label2);password.setBounds(130,50,150,20);frame.add(password);logonButton1.setBounds

9、(100,90,150,20);frame.add(logonButton1);logonButton2.setBounds(100,120,150,20);frame.add(logonButton2);logonButton3.setBounds(100,150,150,20);frame.add(logonButton3);cancelButton.setBounds(100,180,150,20);frame.add(cancelButton);logonButton1.addActionListener(this);logonButton2.addActionListener(thi

10、s);logonButton3.addActionListener(this);cancelButton.addActionListener(this);sql=new NetConn();/建立數據庫連接frame.setSize(350,250);frame.setLocationRelativeTo(null);frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);SuppressWarnings("deprecation")public void actionPerfo

11、rmed(ActionEvent e) t1 = username.getText();t2 = password.getText();/系統管理員登錄if(e.getSource()=logonButton1)if( username.getText().equals("admin") = true&& (password.getText().equals("admin") = true) JOptionPane.showMessageDialog(this, " 登錄成功!");xtgly a=new xtgly(

12、);frame.dispose(); else JOptionPane.showMessageDialog(null, "輸入用戶名或密碼錯誤!");/教職工登陸if(e.getSource()=logonButton2)sqll=sql.connect(); try rs=sqll.executeQuery("SELECT * FROM user_teacher where name="+"'"+username.getText()+"'");String sname,spass;if(rs.ne

13、xt()sname=rs.getString(2); spass=rs.getString(3);if(password.getText().trim().equals(spass)&&(username.getText().trim().equals(sname) JOptionPane.showMessageDialog(this, " 登錄成功!");Teacher_P a=new Teacher_P();a.creat(rs.getString(1);frame.dispose(); elseJOptionPane.showMessageDialog

14、(null, "輸入用戶名或密碼錯誤!");elseJOptionPane.showMessageDialog(null, " 用戶不存在!"); catch (SQLException e2) / TODO 自動生成的 catch 塊e2.printStackTrace();/財務登陸if (e.getSource()=logonButton3)sqll=sql.connect(); try rs=sqll.executeQuery("SELECT * FROM user_cw where name="+"'&qu

15、ot;+username.getText()+"'");String sname,spass;if(rs.next()sname=rs.getString(2); spass=rs.getString(3);if(password.getText().trim().equals(spass)&&(username.getText().trim().equals(sname) JOptionPane.showMessageDialog(this, " 登錄成功!");CW a=new CW();a.create(rs.getStri

16、ng(1);frame.dispose(); elseJOptionPane.showMessageDialog(null, "輸入用戶名或密碼錯誤!");elseJOptionPane.showMessageDialog(null, " 用戶不存在!"); catch (SQLException e2) / TODO 自動生成的 catch 塊e2.printStackTrace();/ 退出if (cancelButton.equals(e.getSource() System.exit(0);/*數據庫鏈接*/import java.sql.*;/

17、數據庫聯接類public class NetConn Connection con;Statement sql;public Statement connect()try /載入驅動程序字符串 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); catch(ClassNotFoundException e1) try /通過JDBC URL得到Connetction對象 con=DriverManager.getConnection("jdbc:sqlserver:/localhost:14

18、33;DatabaseName=gzxt","sa","123456"); /通過Connection對象創建Statement對象 sql=con.createStatement(); catch(SQLException e2) return sql;/*系統管理員界面*/import java.awt.BorderLayout;import java.awt.Container;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import jav

19、a.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPasswordField;import javax.swing.JScrollPane;import javax.swing.JTabbedPane;import javax.swing.JTable;i

20、mport javax.swing.JTextField;SuppressWarnings("serial")class xtgly extends JFrame implements ActionListenerJFrame frame = new JFrame("教職工信息查詢及密碼修改");Object a,b; Object colname="工號","姓名","密碼"NetConn sql;Statement sqll;ResultSet rs;JTable table,table2;

21、JButton Button1 = new JButton("添加教職工");JButton Button2 = new JButton("添加財務管理員");JButton Button3 = new JButton("修改密碼");JButton Button4 = new JButton("刷新");JTabbedPane tab = new JTabbedPane(JTabbedPane.TOP); int i=0;xtgly()frame.setLayout(null);sql=new NetConn()

22、;sqll=sql.connect();a=new Object303;b=new Object303;try String temp="select * from user_cw"rs=sqll.executeQuery(temp);while(rs.next()ai0=rs.getString(1);ai1=rs.getString(2);ai2=rs.getString(3);i+;i=0;String temp2="select * from user_teacher"rs=sqll.executeQuery(temp2);while(rs.ne

23、xt()bi0=rs.getString(1);bi1=rs.getString(2);bi2=rs.getString(3);i+; catch (SQLException e) / TODO 自動生成的 catch 塊e.printStackTrace();table=new JTable(a,colname);table.setEnabled(false);table2=new JTable(b,colname);table2.setEnabled(false);JScrollPane JSP= new JScrollPane(table);JScrollPane JSP2= new J

24、ScrollPane(table2);tab.add(JSP,"財務管理員");tab.add(JSP2,"教職工");tab.setBounds(0,0,350,180);Button1.setBounds(1,185,110,20);Button1.addActionListener(this);Button2.setBounds(115,185,125,20);Button2.addActionListener(this);Button3.setBounds(245,185,89,20);Button3.addActionListener(this

25、);Button4.setBounds(260,0,75,20);Button4.addActionListener(this);frame.add(Button1);frame.add(Button2);frame.add(Button3);frame.add(Button4);frame.add(tab);frame.setSize(350,250);frame.setLocationRelativeTo(null);frame.setVisible(true);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);public void

26、 actionPerformed(ActionEvent e)/添加教職工if(e.getSource()=Button1)Add_teacher add1=new Add_teacher();/添加財務管理員if(e.getSource()=Button2)Add_cw add2=new Add_cw();/修改密碼if(e.getSource()=Button3)Change_mima change=new Change_mima();if(e.getSource()=Button4)i=0;try String temp="select * from user_cw"

27、rs=sqll.executeQuery(temp);while(rs.next()ai0=rs.getString(1);ai1=rs.getString(2);ai2=rs.getString(3);i+;i=0;String temp2="select * from user_teacher"rs=sqll.executeQuery(temp2);while(rs.next()bi0=rs.getString(1);bi1=rs.getString(2);bi2=rs.getString(3);i+; catch (SQLException e1) / TODO 自動

28、生成的 catch 塊e1.printStackTrace();table.removeAll();table2.removeAll();table=new JTable(a,colname);table.setEnabled(false);table2=new JTable(b,colname);table2.setEnabled(false);tab.updateUI();/*添加財務管理人員*/import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;i

29、mport java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Add_cw implements ActionListenerJDialog user_cw=new JDialo

30、g();JLabel no,name,key,re_key;JTextField user_no,user_name;JPasswordField pass,aenter;JButton button1,button2;NetConn sql;Statement sqll;ResultSet rs;Add_cw()user_cw.setTitle("添加財務管理員");user_cw.setLayout(null);no=new JLabel(" 工 號:");user_no=new JTextField("",10);user_no

31、.setBounds(115,5,120,20);no.setBounds(20,5,80,20);name=new JLabel(" 姓 名:");user_name=new JTextField("",10);user_name.setBounds(115,30,120,20);name.setBounds(20,30,80,20);key=new JLabel(" 密 碼:");pass=new JPasswordField("",10);pass.setEchoChar('*');pass.

32、setBounds(115,55,120,20);key.setBounds(20,55,80,20);re_key=new JLabel("確認密碼:");aenter=new JPasswordField("",10);aenter.setEchoChar('*');aenter.setBounds(115,80,120,20);re_key.setBounds(20,80,80,20);button1=new JButton("確認");button1.setBounds(50,110,80,20);button

33、1.addActionListener(this);button2=new JButton("取消");button2.setBounds(170,110,80,20);button2.addActionListener(this);user_cw.add(no);user_cw.add(name);user_cw.add(key);user_cw.add(re_key);user_cw.add(user_no);user_cw.add(user_name);user_cw.add(pass);user_cw.add(aenter);user_cw.add(button1)

34、;user_cw.add(button2);user_cw.setSize(300,180);user_cw.setModal(true);user_cw.setLocationRelativeTo(null);user_cw.setVisible(true);public void actionPerformed(ActionEvent e)if(e.getSource()=button1)String s=aenter.getText().trim();if(!(pass.getText().trim().equals(s)JOptionPane.showMessageDialog(nul

35、l, "兩次輸入的密碼不一致!");else if(pass.getText().trim().equals("")|user_no.getText().trim().equals("")|user_name.getText().trim().equals("")JOptionPane.showMessageDialog(null, "輸入的信息不全,請填寫完整!");elsetry sql=new NetConn(); sqll=sql.connect();/根據用戶添加的用戶名進行選擇rs=

36、sqll.executeQuery("SELECT * FROM user_cw where no="+"'"+user_no.getText()+"'");/如果已經存在同名的用戶,則顯示錯誤提示if(rs.next()JOptionPane.showMessageDialog(null,"用戶已經存在,添加失敗!");/如果不存在用戶名,則將用戶新添加信息添加到數據庫中else/int s1=Integer.parseInt(user_no.getText().trim();String s1=

37、"'"+user_no.getText().trim()+"'"String s2="'"+user_name.getText().trim()+"'"String s3="'"+pass.getText().trim()+"'"String temp="INSERT INTO user_cw VALUES ("+s1+","+s2+","+s3+")&quo

38、t;sqll.executeUpdate(temp);JOptionPane.showMessageDialog(null,"用戶添加成功!"); catch (SQLException e1) e1.printStackTrace();if(e.getSource()=button2)user_cw.dispose();/*添加教職工用戶*/import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLE

39、xception;import java.sql.Statement;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Add_teacher implements ActionListenerJDialog user_teacher=new JDialog();JLabe

40、l no,name,key,re_key,yhk_num,zhiwu;JTextField user_no,user_name,user_yhk_num,user_zhiwu;JPasswordField pass,aenter;JButton button1,button2;NetConn sql;Statement sqll;ResultSet rs;Add_teacher()user_teacher.setTitle("添加教職工");user_teacher.setLayout(null);no=new JLabel(" 工 號:");user_

41、no=new JTextField("",10);user_no.setBounds(115,5,120,20);no.setBounds(20,5,80,20);name=new JLabel(" 姓 名:");user_name=new JTextField("",10);user_name.setBounds(115,30,120,20);name.setBounds(20,30,80,20);key=new JLabel(" 密 碼:");pass=new JPasswordField("&quo

42、t;,10);pass.setEchoChar('*');pass.setBounds(115,55,120,20);key.setBounds(20,55,80,20);re_key=new JLabel("確認密碼:");aenter=new JPasswordField("",10);aenter.setEchoChar('*');aenter.setBounds(115,80,120,20);re_key.setBounds(20,80,80,20);yhk_num=new JLabel("銀行卡號:&q

43、uot;);user_yhk_num=new JTextField("",10);user_yhk_num.setBounds(115,105,120,20);yhk_num.setBounds(20,105,80,20);zhiwu=new JLabel(" 職 務:");user_zhiwu=new JTextField("",10);user_zhiwu.setBounds(115,130,120,20);zhiwu.setBounds(20,130,80,20);button1=new JButton("確認&quo

44、t;);button1.setBounds(50,160,80,20);button1.addActionListener(this);button2=new JButton("取消");button2.setBounds(170,160,80,20);button2.addActionListener(this);user_teacher.add(no);user_teacher.add(name);user_teacher.add(key);user_teacher.add(re_key);user_teacher.add(yhk_num);user_teacher.a

45、dd(zhiwu);user_teacher.add(user_no);user_teacher.add(user_name);user_teacher.add(pass);user_teacher.add(aenter);user_teacher.add(user_yhk_num);user_teacher.add(user_zhiwu);user_teacher.add(button1);user_teacher.add(button2);user_teacher.setSize(300,230);user_teacher.setModal(true);user_teacher.setLo

46、cationRelativeTo(null);user_teacher.setVisible(true);public void actionPerformed(ActionEvent e)if(e.getSource()=button1)String s=aenter.getText().trim();if(!(pass.getText().trim().equals(s)JOptionPane.showMessageDialog(null, "兩次輸入的密碼不一致!");else if(pass.getText().trim().equals("")

47、|user_no.getText().trim().equals("")|user_name.getText().trim().equals("")|user_yhk_num.getText().trim().equals("")|user_zhiwu.getText().trim().equals("")JOptionPane.showMessageDialog(null, "輸入的信息不全,請填寫完整!");elsetry sql=new NetConn(); sqll=sql.connec

48、t();/根據用戶添加的用戶名進行選擇rs=sqll.executeQuery("SELECT * FROM user_teacher where no="+"'"+user_no.getText()+"'");/如果已經存在同名的用戶,則顯示錯誤提示if(rs.next()JOptionPane.showMessageDialog(null,"用戶已經存在,添加失敗!");/如果不存在用戶名,則將用戶新添加信息添加到數據庫中else/int s1=Integer.parseInt(user_no.

49、getText().trim();String s1="'"+user_no.getText().trim()+"'"String s2="'"+user_name.getText().trim()+"'"String s3="'"+pass.getText().trim()+"'"String s4="'"+user_yhk_num.getText().trim()+"'"

50、;String s5="'"+user_zhiwu.getText().trim()+"'"String temp="INSERT INTO user_teacher VALUES ("+s1+","+s2+","+s3+","+s4+","+s5+")"sqll.executeUpdate(temp);JOptionPane.showMessageDialog(null,"用戶添加成功!"); ca

51、tch (SQLException e1) e1.printStackTrace();if(e.getSource()=button2)user_teacher.dispose();/*通過管理員密碼修改*/import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import javax.swing.JButton;import javax.swin

52、g.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JTextField;public class Change_mima implements ActionListenerJDialog change=new JDialog();JLabel no,name,key,re_key;JTextField user_no,user_name;JPasswordField pass,aenter;JButton

53、button1,button2;NetConn sql;Statement sqll;ResultSet rs,rs2;Change_mima()change.setTitle("添加財務管理員");change.setLayout(null);no=new JLabel(" 工 號:");user_no=new JTextField("",10);user_no.setBounds(115,5,120,20);no.setBounds(20,5,80,20);name=new JLabel(" 姓 名:");user_name=new JTextField("",10);user_name.setBounds(115,30,120,20);name.setBounds(20,30,80,20);key=new JLabel(" 密 碼:");pass=new

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論