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

📄 database.java

📁 Nike员工管理系统 一个nike员工管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    p1.add(new Label("工人工号:"));p1.add(工人工号);p1.add(new Label("姓名:"));p1.add(姓名);p1.add(new Label("车间或部门:"));p1.add(车间或部门);
    p2.add(new Label("工作工龄:"));p2.add(工作工龄);p2.add(new Label("年龄:"));p2.add(年龄);p2.add(new Label("性别:"));p2.add(性别);
    //p2.add(性别);p2.add(性别);
    add(p1,BorderLayout.NORTH);
    add(p2,BorderLayout.CENTER);
    p2.add(确定查询);p2.add(取消查询);
    确定查询.addActionListener(this);
    取消查询.addActionListener(this);
    setVisible(false);
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
    catch(ClassNotFoundException e){ }
    try{
         con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
         stmt=con.createStatement();
        }
    catch(SQLException ee) { }
    addWindowListener(new WindowAdapter()
                  { public void windowClosing(WindowEvent e)
                     {System.exit(0);}
                   });
   }

 public void actionPerformed(ActionEvent e)
  {if(e.getSource()==确定查询)
     {try{ find();}
     catch(SQLException ee){}
     String warning="查询成功!!!";
      JOptionPane.showMessageDialog(this,warning,"good!!!",JOptionPane.WARNING_MESSAGE);
        }

   else if(e.getSource()==取消查询)
       {String warning="没有该条记录";
        JOptionPane.showMessageDialog(this,warning,"good!!!",JOptionPane.WARNING_MESSAGE);
		工人工号.setText(null);
        姓名.setText(null);
        车间或部门.setText(null);
        工作工龄.setText(null);
        年龄.setText(null);
        //年龄.setText(null);
        性别.setText(null);
        }
   }
   public void find() throws SQLException
    { String s1;
      String s2;
      String s3;
      String s4;
      String s5;
      String s6;
      con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
      ResultSet rs=stmt.executeQuery("select *from 员工信息表 ");
      while (rs.next())
      {s1=rs.getString("工号"); s2=rs.getString("姓名");
       s3=rs.getString("车间或部门"); s4=rs.getString("工作工龄");
       s5=rs.getString("年龄"); s6=rs.getString("性别");
       if(s1.equals(工人工号.getText().trim()))
       { 姓名.setText(s2);车间或部门.setText(s3);工作工龄.setText(s4);年龄.setText(s5);性别.setText(s6);
         查询记录=1;break;
	    }
	}
	    con.close();
	    if(查询记录==0)
	    {工人工号.setText("没有该条记录");}
       //姓名.setText(s2);
    //工人工号,姓名,车间或部门,工作工龄,年龄,性别;
      //String temp="UPDATE 员工信息表 SET 姓名 ="+s2+",车间或部门 ="+s3+",工作工龄 ="+s4+",年龄 ="+s5+",性别 ="+s6+"WHERE 工号 = "+s1 ;
      //con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
      //stmt.executeUpdate(temp); con.close();



    }
}











//删除员工信息

class Delete extends Frame implements ActionListener
{TextField 工人工号;
 Label 工人号号;
 Button 删除,取消;
 Connection con =null;Statement stmt=null;
 Delete()
{ super("欢迎使用Nike员工管理系统");
    //setBackground(Color.blue);
    setBounds(10,10,600,600);
    //setVisible(true);
    //setVisble(false);
    //Nike=new NikeygManager();
    setVisible(false);
    validate();
    工人工号=new TextField(16);
	删除=new Button("删除");
    取消=new Button("取消");
    setLayout(new BorderLayout());
    Panel p1=new Panel();
    Panel p2=new Panel();
   // Panel p3=new Panel();
    p1.add(new Label("请要删除输入工人工号:"));p1.add(工人工号);//p1.add(new Label("姓名:"));p1.add(姓名);p1.add(new Label("车间或部门:"));p1.add(车间或部门);
    //p2.add(new Label("工作工龄:"));p2.add(工作工龄);p2.add(new Label("年龄:"));p2.add(年龄);p2.add(new Label("性别:"));p2.add(性别);
    //p2.add(性别);p2.add(性别);
    add(p1,BorderLayout.NORTH);
    add(p2,BorderLayout.CENTER);
    p2.add(删除);p2.add(取消);
    删除.addActionListener(this);
    取消.addActionListener(this);
    setVisible(false);
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
    catch(ClassNotFoundException e){ }
    try{
         con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
         stmt=con.createStatement();
        }
    catch(SQLException ee) { }
    addWindowListener(new WindowAdapter()
                  { public void windowClosing(WindowEvent e)
                     {System.exit(0);}
                   });
   }
   public void actionPerformed(ActionEvent e)
     {if(e.getSource()==删除)
        try{ sc();
        String warning="删除";
        JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

        }
        catch(SQLException ee){}
      else if(e.getSource()==取消)
          {工人工号.setText(null);
          //text2.setText(null);
          }
	  }
	  public void sc() throws SQLException
	        {
	  		  try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
	  		       catch(ClassNotFoundException e){}
	  		        try{
	  		  con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
	  		             stmt=con.createStatement();
	  		           }
	        catch(SQLException ee) {}
	  		  String s1="'"+工人工号.getText().trim()+"'";
	           //String s2="'"+text2.getText().trim()+"'";

	          String temp="delete from 员工信息表 where 工号 = ("+s1+") ";
	         con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
	         stmt.executeUpdate(temp);
	         con.close();
	        }
  }











//增加用户
class Useradd extends Frame implements ActionListener
 { TextField text1,text2,text3;
   Label label1,label2,label3,label4;
   Button button1,button2;
   Connection con =null;Statement stmt=null;
   Useradd( )
   { super("欢迎使用Nike员工管理系统→注册账号");
    //setBackground(Color.blue);
    setBounds(200,200,450,450);
    setVisible(true);
    //setVisble(false);
    //Nike=new NikeygManager();
    validate();
    text1=new TextField(10);
    text2=new TextField(10);
    text3=new TextField(10);
    label1=new Label("新用户名");
    label2=new Label("新密码");
    label3=new Label("欢迎使用此系统");
    button1=new Button("确定注册");
    button2=new Button("取消");
    setLayout(new BorderLayout());
    Panel p1=new Panel();
    Panel p2=new Panel();
    p1.add(label1);p1.add(text1);
    p1.add(label2);p1.add(text2);
    add(p1,BorderLayout.CENTER);
    p2.add(button1);p2.add(button2);
    add(p2,BorderLayout.SOUTH);
    //text1.setText("ysy");
    button1.addActionListener(this);
    button2.addActionListener(this);
    setVisible(false);
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
    catch(ClassNotFoundException e){ }
    try{
         con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
         stmt=con.createStatement();
         }
    catch(SQLException ee) { }
    addWindowListener(new WindowAdapter()
                  { public void windowClosing(WindowEvent e)
                     {System.exit(0);}
                     });
     }

public void actionPerformed(ActionEvent e)
  {if(e.getSource()==button1)
     try{ zcyh();
     String warning="确定要增加用户吗?";
     JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

     }
     catch(SQLException ee){}
   else if(e.getSource()==button2)
       {text1.setText(null);
        text2.setText(null);}
   }

public void zcyh() throws SQLException
      {
		  try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
		       catch(ClassNotFoundException e){}
		        try{
		  con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
		             stmt=con.createStatement();
		           }
      catch(SQLException ee) {}
		  String s1="'"+text1.getText().trim()+"'";
         String s2="'"+text2.getText().trim()+"'";
         //String s3="'"+车间或部门.getText().trim()+"'";
         //String s4="'"+工作工龄.getText().trim()+"'";
         //String s5="'"+年龄.getText().trim()+"'";
         String temp="INSERT INTO 账户 VALUES ("+s1+","+s2+")";
       con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
       stmt.executeUpdate(temp);
       con.close();
      }
  }


//密码登陆届面
class Dljm extends Frame implements ActionListener
 { TextField text1,text2;
   Label label1,label2,label3;
   Button button1,button2;
   Connection con =null;Statement stmt=null;
   NikeygManager Nike;
   Dljm( )
   { super("欢迎使用Nike员工管理系统");
    //setBackground(Color.blue);
    setBounds(200,200,300,200);
    setVisible(true);
    //setVisble(false);
    Nike=new NikeygManager();
    validate();
    text1=new TextField(10);
    text2=new TextField(10);
    label1=new Label("用户名");
    label2=new Label("密码");
    label3=new Label("欢迎使用此系统");
    button1=new Button("登陆");
    button2=new Button("取消");
    setLayout(new BorderLayout());
    Panel p1=new Panel();
    Panel p2=new Panel();
    p1.add(label1);p1.add(text1);
    p1.add(label2);p1.add(text2);
    add(p1,BorderLayout.CENTER);
    p2.add(button1);p2.add(button2);
    add(p2,BorderLayout.SOUTH);
    //text1.setText("ysy");
    button1.addActionListener(this);
    button2.addActionListener(this);
    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
    catch(ClassNotFoundException e){ }
    try{
         con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
         stmt=con.createStatement();
         }
    catch(SQLException ee) { }
    addWindowListener(new WindowAdapter()
                  { public void windowClosing(WindowEvent e)
                     {System.exit(0);}
                     });
                   }
  public void actionPerformed(ActionEvent e)
  {if(e.getSource()==button1)
     try{ dl();}
     catch(SQLException ee){}
   else if(e.getSource()==button2)
       {text1.setText(null);
        text2.setText(null);}
   }
   public void dl() throws SQLException
    { String name ,ma;
      con=DriverManager.getConnection("jdbc:odbc:nike","Nike","ookk");
      ResultSet rs=stmt.executeQuery("select * from 账户");
      while(rs.next())
        { name=rs.getString("用户名");
          ma=rs.getString("密码");
          if(name.equals(text1.getText())&&ma.equals(text2.getText()))
            { JOptionPane.showMessageDialog(this,"欢迎进入该系统!","警告",JOptionPane.WARNING_MESSAGE);
              setVisible(false);
              Nike.setVisible(true);
              //text1.setText("hello");
              }
          else if( !(name.equals(text1.getText())&&ma.equals(text2.getText())))
              { //JOptionPane.showMessageDialog(this,"输入错误","警告",JOptionPane.WARNING_MESSAGE);
                text1.setText(null);
                text2.setText(null);
              }
          }
          con.close();
      }
  }

   public class Database
  {public static void main(String args[])
   {
     Dljm window=new Dljm();window.pack();
     //NikeygManager  window1=new NikeygManager();window1.pack();

   }
  }

⌨️ 快捷键说明

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