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

📄 manager.java

📁 本系统适合中小规模宾馆使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.Hashtable;//数据类型类

//主窗口
public class Manager extends Frame implements ActionListener
{   MenuBar bar;
    Menu fileMenu,fileMenu1,fileMenu2,fileMenu3,fileMenu0,m;
    MenuItem 登陆,录入,修改,查询,删除,mi;
    Container Con=null;
    CardLayout card=null;
    JLabel label=null;
    TextField 工号,姓名;
    TextField 工龄;
    TextField 年龄,性别;

    Button 增加用户,取消,删除按钮;
    Update dd; //声明一个修改窗口的对象
    Useradd aa;
    Userfind bb;
    Delete cc;
    Connection con=null;Statement Stmt=null;

    Manager(){
    	
    	super("欢迎使用WWW员工信息管理系统");
    	setBackground(Color.blue);
 
    int 查询记录=0;
    Connection Con=null;Statement Stmt=null;
    dd=new Update();
    aa=new Useradd();
    bb=new Userfind();
    cc=new Delete();
    //setBounds(150,150,300,300);
    setVisible(true);setLayout(new GridLayout(6,3));

    try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
    catch(ClassNotFoundException e){}

    try{
	    con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
           Stmt=con.createStatement();
        }
    catch(SQLException ee) {}

    工号=new TextField(16);
    姓名=new TextField(16);
    性别=new TextField(16);
    工龄=new TextField(16);
    年龄=new TextField(16);

    增加用户=new Button("增加");
    取消=new Button("取消");
    删除按钮=new Button("删除");

    Panel p1=new Panel(),p2=new 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(年龄);

      p3.add(增加用户);
      p3.add(取消);
      p3.add(删除按钮);

      setLayout(new GridLayout(12,10));
      add(p1);add(p2);add(p3);

     登陆=new MenuItem("注册账号");
     录入=new MenuItem("录入员工基本信息");
     修改=new MenuItem("修改员工基本信息");
     查询=new MenuItem("查询员工基本信息");
     删除=new MenuItem("删除员工基本信息");
     mi=new MenuItem("责任表duty");

     bar=new MenuBar();
     fileMenu0=new Menu("注册用户");
     fileMenu=new Menu("增加员工信息");
     fileMenu1=new Menu("修改信息");
     fileMenu2=new Menu("查询员工信息");
     fileMenu3=new Menu("删除员工信息");
     m=new Menu("链接");
     fileMenu0.add(登陆);
     fileMenu.add(录入);
     fileMenu1.add(修改);
     fileMenu2.add(查询);
     fileMenu3.add(删除);
     m.add(mi);
     bar.add(fileMenu0);
     bar.add(fileMenu);
     bar.add(fileMenu1);
     bar.add(fileMenu2);
     bar.add(fileMenu3);
     bar.add(m);
     setMenuBar(bar);

     //label=new JLabel("请先登陆系统后使用该系统!",JLabel.SOUTH);
     label=new JLabel("欢迎使用WWW公司员工基信息管理系统",JLabel.CENTER);
     label.setFont(new Font("TimesRoman",Font.BOLD,24));
     label.setForeground(Color.red);
     add (label);
     //add (label1);
     //工人工号=s1;

     增加用户.addActionListener(this);
	 取消.addActionListener(this);
     删除按钮.addActionListener(this);
     //设置按钮的不可用
     //取消.setEnabled(false);
     //增加按钮.setEnabled(false);
     //删除按钮.setEnabled(false);
     登陆.addActionListener(this);
     录入.addActionListener(this);
     修改.addActionListener(this);
     查询.addActionListener(this);
     删除.addActionListener(this);
      mi.addActionListener(this);

     setVisible(false);
     addWindowListener(new WindowAdapter()
                    { public void windowClosing(WindowEvent e)
                       {
                          System.exit(0);
      	               }
                    });
    //setVisible(true);
    setBounds(100,50,800,400);
    validate();
   }


  //按钮事件
  public void actionPerformed(ActionEvent e)
   {
     if(e.getSource()==登陆)
       {   setVisible(false);
           aa.setVisible(true);
        }
     else if(e.getSource()==录入)
       {
        try{ 录入();}
		catch(SQLException ee) {}

		String warning="确定要增加员工信息吗?";
        JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);

       }
      else if(e.getSource()==查询)
      {
         setVisible(false);
	     bb.setVisible(true);
      }
      else if(e.getSource()==删除)
	        {
	           setVisible(false);
	  	     cc.setVisible(true);
      }
      else if(e.getSource()==修改)
	        {  setVisible(false);
	           dd.setVisible(true);
      }
      else if(e.getSource()==mi)
	        {  setVisible(false);
	           Duty d = new Duty();
	           d.setVisible(true);
      }
    else if(e.getSource()==取消)
      { 工号.setText(null);
        姓名.setText(null);
        性别.setText(null);
        工龄.setText(null);
        年龄.setText(null);
         }

   }
   
  public void 录入() throws SQLException
      {
		  try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
		       catch(ClassNotFoundException e){}
  
          try{
		  con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
		             Stmt=con.createStatement();
		           }
          catch(SQLException ee) {}

         String s1="'"+工号.getText().trim()+"'";
         String s2="'"+姓名.getText().trim()+"'";
         String s4="'"+工龄.getText().trim()+"'";
         String s5="'"+年龄.getText().trim()+"'";
         String s6="'"+性别.getText().trim()+"'";
         String temp="INSERT INTO info VALUES ("+s1+","+s2+","+s4+","+s5+","+s6+")";
       con=DriverManager.getConnection("jdbc:odbc:hotel","sa","");
       Stmt.executeUpdate(temp);
       con.close();
      }
}









//修改员工信息窗口
class Update extends Frame implements ActionListener
 { TextField 工号,姓名;
   TextField 工龄;
   TextField 年龄,性别;
   Button 确定修改,取消修改;
   Connection con =null;Statement stmt=null;

   Update( )
   { super("欢迎使用WWW员工管理系统");
    //setBackground(Color.blue);
    setBounds(10,10,1000,300);
    setVisible(false);
    validate();
 
    工号=new TextField(16);
	姓名=new TextField(16);
	工龄=new TextField(16);
	年龄=new TextField(16);
	性别=new TextField(16);
	确定修改=new Button("确定修改");
    取消修改=new Button("取消修改");


    确定修改=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(姓名);
    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:hotel","sa","");
         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{ xg();}
     catch(SQLException ee){}
     String warning="确定要修改员工信息吗?";
        JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);}

   else if(e.getSource()==取消修改)
       {工号.setText(null);
        姓名.setText(null);
        工龄.setText(null);
        年龄.setText(null);
        性别.setText(null);
        }
   }

   public void xg() throws SQLException
    { String s1="'"+工号.getText().trim()+"'";
      String s4="'"+工龄.getText().trim()+"'";

⌨️ 快捷键说明

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