⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 land.java

📁 java实现的工资管理系统 可以运行的源代码
💻 JAVA
字号:
package salary;
import java.awt.*;
import javax.swing.*;

import java.awt.event.*;
import java.sql.*;

class LandFrame extends JFrame
{
	
	JComboBox list;
	JLabel jLabel1;
	JLabel jLabel2;
	JTextField jtf1;
//	TextField jtf2;
	JPasswordField jpwf;
	
	JButton jbtn,jbtn1;
	LandFrame(String s)
	{
		super(s);
		setLayout(null);
		setBounds(100,100,500,400);
		list=new JComboBox();
		list.setBorder(BorderFactory.createTitledBorder("请选择登录"));
		list.addItem("管理员登录");
		list.addItem("用户登录");
		list.setBounds(175,50,150,50);
		jLabel1=new JLabel("用户名:");
		jLabel2=new JLabel("密码:");
		jbtn=new JButton("登录");
		jbtn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e)
			{
				testify();
			}
		});
		jbtn1=new JButton("退出");
		jbtn1.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				dispose();
			}
		});
		jtf1=new JTextField(10);
//		jtf2=new TextField(10);
//      jtf2.setEchoChar('*');
		jpwf=new JPasswordField(10);
		jpwf.setEchoChar('*');
		jLabel1.setBounds(155,150,50,30);
		jLabel2.setBounds(155,190,50,30);
		jtf1.setBounds(210,150,100,25);
//		jtf2.setBounds(230,190,100,25);
		jpwf.setBounds(210,190,100,25);
		jbtn.setBounds(120,250,80,40);
		jbtn1.setBounds(290,250,80,40);
		//jbtn.setBounds(110,110,50,50);
		Container con=getContentPane();
		
		con.add(list);
		con.add(jLabel1);
		con.add(jtf1);
		con.add(jLabel2);
//	    con.add(jtf2);
		con.add(jpwf);
		con.add(jbtn);
		con.add(jbtn1);
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		getRootPane().setDefaultButton(jbtn);
		setVisible(true);
		//validate();
		
	}
	void testify()
	{
		String str;
		str=(String)list.getSelectedItem();
		if(str=="管理员登录")
		{
			test_manage();
			//System.out.println("Hello");
		}
		else
		{
			test_employee();
		}
		//System.out.println(list.getSelectedItem());
	}
	void test_manage()
	{
		String str1,str2;
		
		
		str1=jtf1.getText();
		str2=new String(jpwf.getPassword());
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch(ClassNotFoundException e){}
		try
		{
			Connection con;
			con=DriverManager.getConnection("jdbc:odbc:salary","","");
			PreparedStatement psmt=con.prepareStatement("select m_password from manage where m_num='"+str1+"'");
			ResultSet res=psmt.executeQuery();
			//System.out.println(res.getString(1));
			
			if((!res.next()))
			{
				JOptionPane.showMessageDialog(this, "查无此人","错误",JOptionPane.ERROR_MESSAGE);
			}
			else
			{
				String pwd=res.getString(1);
				System.out.println(pwd);
				if(!(pwd.equals(str2)))
				{
					JOptionPane.showMessageDialog(this, "密码错误", "错误", JOptionPane.ERROR_MESSAGE);
				}
				else
				{
					loader1();
					dispose();
				}
				psmt.close();
				con.close();
				
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	void test_employee()
	{
		String str1,str2;
		str1=jtf1.getText();
		str2=new String(jpwf.getPassword());
		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch(ClassNotFoundException e){}
		try {
			Connection con;
			con=DriverManager.getConnection("jdbc:odbc:salary","","");
			PreparedStatement psmt=con.prepareStatement("select password from employee_info where  e_num='"+str1+"'");
			ResultSet res=psmt.executeQuery();
			if((!res.next()))
			{
				JOptionPane.showMessageDialog(this, "查无此人","错误",JOptionPane.ERROR_MESSAGE);
			}
			else
			{
				String pwd=res.getString(1);
				String pw=pwd.trim();
				//System.out.println(pwd);
	//			JOptionPane.showMessageDialog(this, pwd, "错误", JOptionPane.ERROR_MESSAGE);
	//			JOptionPane.showMessageDialog(this, str2, "错误", JOptionPane.ERROR_MESSAGE);
				if(!(pw.equals(str2)))
				{
					JOptionPane.showMessageDialog(this, "密码错误", "错误", JOptionPane.ERROR_MESSAGE);
				}
				else
				{
					loader2();
					dispose();
				}
				psmt.close();
				con.close();
				
			}	
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}
	void loader1()
    
	{
		try
		{
			ManageFrame me=new ManageFrame("工资管理系统");
		
		}
		catch(Exception ew)
		{
			System.out.println(ew.getMessage());
		}
		
	}
	void loader2()
	{
		land2 ld=new land2("用户查询");
	}
	class  land2 extends JFrame
	{
		
		JTable table;
		JLabel jLabel;
		JButton jbtn1,jbtn2,jbtn3;
		
		JComboBox jcb;
		Object a[][];
		Object name1[]={"员工号","奖金","扣除","基本工资(元)","实发工资(元)","月份"};
		
		land2(String s)
		{
			super(s);
			setBounds(100,100,350,200);
			setLayout(null);
			
			jLabel=new JLabel("请输入您要查询的月份:");
			jbtn1=new JButton("查询");
			jbtn1.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					user_query();
				}
			});
			jbtn2=new JButton("退出");
			jbtn2.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					dispose();
				}
			});
			jbtn3=new JButton("修改密码");
			jbtn3.addActionListener(new ActionListener()
					{
				         public void actionPerformed(ActionEvent e)
				         {
				        	change(); 
				         }
					});
			
			jcb=new JComboBox();
			jcb.setBorder(BorderFactory.createTitledBorder("请选择月份"));
			jcb.addItem("1");
			jcb.addItem("2");
			jcb.addItem("3");
			jcb.addItem("4");
			jcb.addItem("5");
			jcb.addItem("6");
			jcb.addItem("7");
			jcb.addItem("8");
			jcb.addItem("9");
			jcb.addItem("10");
			jcb.addItem("11");
			jcb.addItem("12");
			jLabel.setBounds(50,20,150,30);
			jcb.setBounds(205,20,80,50);
			jbtn1.setBounds(65,70,60,30);
			jbtn2.setBounds(140,70,60,30);
			jbtn3.setBounds(85,110,90,30);
			Container con=getContentPane();
			con.add(jLabel);
			con.add(jcb);
			con.add(jbtn1);
			con.add(jbtn2);
			con.add(jbtn3);
			setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			setVisible(true);
		}
		void change()
		{
			p_change pc=new p_change("修改密码");
		}
		class p_change extends JFrame
		{
			JLabel jLabel1,jLabel2,jLabel3;
			JPasswordField jpwf1,jpwf2,jpwf3;
			JButton jbtn,jbtn1;
			p_change(String s)
			{
				super(s);
				setBounds(100,100,330,250);
				setLayout(null);
				jLabel1=new JLabel("请输入旧密码:");
				jLabel2=new JLabel("请输入新密码:");
				jLabel3=new JLabel("请再次输入新密码:");
				jbtn=new JButton("确定");
				jbtn1=new JButton("退出");
				jbtn1.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent e)
					{
						dispose();
					}
				});
				jpwf1=new JPasswordField();
				jpwf2=new JPasswordField();
				jpwf3=new JPasswordField();
				jLabel1.setBounds(60,20,90,30);
				jLabel2.setBounds(60,60,90,30);
				jLabel3.setBounds(40,100,110,30);
				jpwf1.setBounds(155,25,110,20);
				jpwf2.setBounds(155,65,110,20);
				jpwf3.setBounds(155,105,110,20);
				jbtn.setBounds(70,160,60,30);
				jbtn1.setBounds(190,160,60,30);
				jbtn.addActionListener(new ActionListener()
						{
							public void actionPerformed(ActionEvent e)
							{
								check();
							}
						});
				Container con=getContentPane();
				con.add(jLabel1);
				con.add(jLabel2);
				con.add(jLabel3);
				con.add(jpwf1);
				con.add(jpwf2);
				con.add(jpwf3);
				con.add(jbtn);
				con.add(jbtn1);
				setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				setVisible(true);
			}
			void check()
			{
				String str1,str2,str3,str4;
				str1=new String(jpwf1.getPassword());
				str2=new String(jpwf2.getPassword());
				str3=new String(jpwf3.getPassword());
				try
				{
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				}
				catch(ClassNotFoundException e ){}
				try
				{
					
					str4=jtf1.getText();
					Connection con=DriverManager.getConnection("jdbc:odbc:salary","","");
					Statement stmt=con.createStatement();
					ResultSet rs=stmt.executeQuery("select password from employee_info where e_num='"+str4+"'");
					rs.next();
					String password=rs.getString(1);
					if(password.equals(str1))
					{
						if(!(str2.equals("")))
						{
							if(str2.equals(str3))
							{
								stmt.executeUpdate("update employee_info set password='"+str2+"' where e_num='"+str4+"'");
								JOptionPane.showMessageDialog(this, "密码修改成功","提示",JOptionPane.INFORMATION_MESSAGE);
								dispose();
								stmt.close();
								con.close();
							}
							else
							{
								JOptionPane.showMessageDialog(this, "两次密码输入不一致,请重新输入","提示",JOptionPane.INFORMATION_MESSAGE);
							}
						}
						else
						{
							JOptionPane.showMessageDialog(this, "请输入新密码","提示",JOptionPane.INFORMATION_MESSAGE);
						}
					}
					else
					{
						JOptionPane.showMessageDialog(this,"旧密码输入错误","错误",JOptionPane.ERROR_MESSAGE);
					}
				}
				catch(Exception e) {
					e.printStackTrace();
				}
			}
		}
/*		public class Land
		{
			public static void main(String[] args)
			{
				p_change pc=new p_change("ss");
			}
		}*/
	void user_query()
		{
			String str1,str2;
			final JFrame jf=new JFrame();
//			jf.setBounds(100,100,500,300);
//			jf.setSize(500,300);
			JButton jbtn;
			jbtn=new JButton("关闭");
			jbtn.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					jf.dispose();
				}
			});
			jf.setLayout(new BoxLayout(jf.getContentPane(),BoxLayout.Y_AXIS));
			jf.setBounds(100,100,400,200);
			str1=jtf1.getText();
			str2=(String)jcb.getSelectedItem();
			try {
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			} catch (ClassNotFoundException e) {
				// TODO: handle exception
			}
			try {
				Connection con=DriverManager.getConnection("jdbc:odbc:salary","","");
				Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
				ResultSet rs=stmt.executeQuery("select s_num,bonus,deduct,s_basicsalary,fact_salary,month" +
						" from salary where s_num='"+str1+"'and month='"+str2+"'");
				
				
//				JOptionPane.showMessageDialog(this, "hh","jj",JOptionPane.INFORMATION_MESSAGE);
				
				
				if(!(rs.next()))  JOptionPane.showMessageDialog(this, "此月工资尚未结算","提示",JOptionPane.INFORMATION_MESSAGE); 
				else
				{
					Object name[]={"员工号","奖金","扣除","基本工资","实发工资","月份"};
					a=new Object[1][6];
					String num=rs.getString(1);
					String bonus=rs.getString(2);
					String deduct=rs.getString(3);
					String basicsalary=rs.getString(4);
					String factsalary=rs.getString(5);
					String month=rs.getString(6);
					a[0][0]=num;
					a[0][1]=bonus;
					a[0][2]=deduct;
					a[0][3]=basicsalary;
					a[0][4]=factsalary;
					a[0][5]=month;
					table=new JTable(a,name);
					Container con1=jf.getContentPane();
					con1.add(new JScrollPane(table));
					con1.add(jbtn);
					jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
					jf.setVisible(true);
					
					
				}
				
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			
		}
	
    }


}
			
			
		

public class Land 
{
	public static void main(String[] args)
	{
		LandFrame lf=new LandFrame("登陆");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -