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

📄 staff_edit_view.java

📁 javaGUI编写的人事管理系统(毕业学生答辩可参考)
💻 JAVA
字号:
package project;

import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.table.DefaultTableModel;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Staff_edit_view extends JPanel implements All_view {
  Staff_obj_M obj = new Staff_obj_M();
  Staff_C method = new Staff_C();
  String sql = null;
  String showMessage = null;
  JFrame mainframe = null;
  JLabel id = new JLabel();
  JLabel name = new JLabel();
  JTextField nameText = new JTextField();
  JLabel jLabel4 = new JLabel();
  JTextField birthText = new JTextField();
  JLabel jLabel1 = new JLabel();
  ButtonGroup buttonGroup1 = new ButtonGroup();
  JRadioButton male = new JRadioButton();
  JRadioButton female = new JRadioButton();
  JTextField idText = new JTextField();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JTextField telText = new JTextField();
  JLabel jLabel6 = new JLabel();
  JTextField addressText = new JTextField();
  JLabel jLabel7 = new JLabel();
  JTextField hire_dateText = new JTextField();
  JLabel jLabel8 = new JLabel();
  JTextField contract_expireText = new JTextField();
  JLabel jLabel9 = new JLabel();
  JTextField salaryText = new JTextField();
  JLabel jLabel10 = new JLabel();
  JTextField educationText = new JTextField();
  JButton okbtn = new JButton();
  JButton resetbtn = new JButton();
  JTextField partBox2 = new JTextField();
  JTextField positionBox2 = new JTextField();
  JLabel showMsg = new JLabel();
  JLabel jLabel11 = new JLabel();
  JTextField idtemp = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JLabel jLabel12 = new JLabel();
  JScrollPane jScrollPane1 = new JScrollPane();
  JTable jTable1;


  public Staff_edit_view(JFrame mainframe) {

    this.mainframe = mainframe;
    try {
      jbInit();
      setPanelPosOnDesktop(this.mainframe);
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }
    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {

      this.setLayout(null);
      setSize(new Dimension(627, 505));

      jLabel11.setText("工号:");
      jLabel11.setBounds(new Rectangle(240, 332, 44, 30));
      idtemp.setBounds(new Rectangle(324, 332, 91, 30));
      jButton1.setBounds(new Rectangle(200, 400, 67, 32));
      jButton1.setText("确定");
      jButton1.addActionListener(new Staff_edit_jButton1_actionAdapter(this));
      jButton2.setBounds(new Rectangle(373, 400, 67, 32));
      jButton2.setText("取消");
      jButton2.addActionListener(new Staff_edit_jButton2_actionAdapter(this));
      okbtn.addActionListener(new Staff_edit_okbtn_actionAdapter(this));
      resetbtn.addActionListener(new Staff_edit_resetbtn_actionAdapter(this));
      jLabel12.setFont(new java.awt.Font("幼圆", Font.BOLD, 20));
      jLabel12.setForeground(new Color(85, 45, 25));
      jLabel12.setText("员 工 信 息 修 改");
      jLabel12.setBounds(new Rectangle(228, 35, 211, 61));

    this.add(jScrollPane1);
    this.add(jButton2);
    this.add(jButton1);
    this.add(idtemp);
    this.add(jLabel11);
    this.add(jLabel12);
    this.st_tb();

  }

   public void st_tb(){
     jScrollPane1.setBounds(new Rectangle(69, 114, 500, 185));
     DataBase db3 = new DataBase();
     String sql1 =
         "select employee_id,name,dep_id,position_id from employee_table where useful=1";
     ResultSet rs = db3.executeQuery(sql1);
     DataMap mp = new DataMap(rs);
     Object[][] obj1 = mp.get_DataMap_Array();
     String[] colnames = {
         "工号", "姓名", "部门ID", "职位ID"};
     DefaultTableModel dm = new DefaultTableModel(obj1, colnames);
     jTable1 = new JTable(dm);
     jScrollPane1.getViewport().add(jTable1);

   }

  public void staff_editFrm(){
    this.setLayout(null);
    setSize(new Dimension(506, 409));
    id.setText("员工工号:");
    id.setBounds(new Rectangle(35, 28, 48, 24));
    name.setText("姓名:");
    name.setBounds(new Rectangle(179, 28, 39, 24));
    nameText.setText("");
    nameText.setBounds(new Rectangle(214, 28, 92, 24));
    jLabel4.setText("出生年月:");
    jLabel4.setBounds(new Rectangle(35, 72, 48, 24));
    birthText.setBounds(new Rectangle(94, 72, 154, 24));
    jLabel1.setText("性别:");
    jLabel1.setBounds(new Rectangle(332, 28, 32, 24));
    male.setText("男");
    male.setBounds(new Rectangle(378, 28, 38, 24));
    female.setText("女");
    female.setBounds(new Rectangle(425, 28, 42, 24));
    idText.setBounds(new Rectangle(94, 28, 70, 24));
    jLabel2.setText("部门 IID:");
    jLabel2.setBounds(new Rectangle(35, 116, 48, 24));
    jLabel3.setText("职务 ID:");
    jLabel3.setBounds(new Rectangle(278, 114, 45, 24));
    jLabel5.setText("联系电话:");
    jLabel5.setBounds(new Rectangle(35, 157, 48, 24));
    telText.setText("");
    telText.setBounds(new Rectangle(94, 157, 191, 24));
    jLabel6.setText("家庭住址:");
    jLabel6.setBounds(new Rectangle(35, 194, 48, 24));
    addressText.setText("");
    addressText.setBounds(new Rectangle(94, 194, 358, 24));
    jLabel7.setText("进司日期:");
    jLabel7.setBounds(new Rectangle(278, 72, 56, 24));
    hire_dateText.setBounds(new Rectangle(334, 72, 124, 24));
    jLabel8.setText("合同到期日:");
    jLabel8.setBounds(new Rectangle(35, 231, 59, 24));
    contract_expireText.setText("");
    contract_expireText.setBounds(new Rectangle(94, 231, 251, 24));
    jLabel9.setText("工资底薪:");
    jLabel9.setBounds(new Rectangle(35, 271, 48, 24));
    salaryText.setText("");
    salaryText.setBounds(new Rectangle(94, 271, 79, 24));
    jLabel10.setText("学历:");
    jLabel10.setBounds(new Rectangle(278, 271, 38, 24));
    educationText.setText("");
    educationText.setBounds(new Rectangle(334, 271, 72, 24));
    okbtn.setBounds(new Rectangle(97, 321, 76, 26));
    okbtn.setText("修改");
    resetbtn.setBounds(new Rectangle(286, 321, 76, 26));
    resetbtn.setText("取消");
    partBox2.setBounds(new Rectangle(94, 116, 91, 24));
    positionBox2.setBounds(new Rectangle(334, 114, 110, 24));
    showMsg.setText("");
    showMsg.setBounds(new Rectangle(93, 410, 212, 28));
    jLabel11.setText("请输入需修改员工的ID:");
    jLabel11.setBounds(new Rectangle(60, 95, 120, 36));

    this.add(id);
    this.add(idText);
    this.add(name);
    this.add(nameText);
    this.add(id);
    this.add(jLabel4);
    this.add(male);
    this.add(female);
    this.add(idText);
    this.add(birthText);
    this.add(jLabel1);
    this.add(jLabel2);
    this.add(jLabel3);
    this.add(jLabel5);
    this.add(jLabel6);
    this.add(addressText);
    this.add(jLabel7);
    this.add(hire_dateText);
    this.add(jLabel8);
    this.add(partBox2);
    this.add(positionBox2);
    this.add(contract_expireText);
    this.add(telText);
    this.add(jLabel9);
    this.add(salaryText);
    this.add(jLabel10);
    this.add(educationText);
    this.add(okbtn);
    this.add(resetbtn);
    this.add(showMsg);
    buttonGroup1.add(male);
    buttonGroup1.add(female);
  }

  public void setPanelPosOnDesktop(JFrame frame) {
   this.setLocation( (((Frame1)frame).get_Container_width()- this.getSize().width) / 2,
                     (((Frame1)frame).get_Container_height()- this.getSize().height) / 2);
    }

    public void closeCurrentPanel(JFrame frame) {
      ((Frame1)frame).remove_panel();
    frame.repaint();
    }

    public void set_focus() {
     idText.requestFocus();
    }
    public void requestFocus(){
        set_focus();
      }


  public void clear(){
    this.st_tb();
    nameText.setText("");
    birthText.setText("");
    addressText.setText("");
    hire_dateText.setText("");
    contract_expireText.setText("");
    telText.setText("");
    salaryText.setText("");
    educationText.setText("");
  }

  public void jButton2_actionPerformed(ActionEvent e) {
    this.removeAll();
    this.mainframe.repaint();
  }

  public void jButton1_actionPerformed(ActionEvent e) {
    int idtmp1 = Integer.parseInt(idtemp.getText());
    DataBase db = new DataBase();
    String sql = "select * from employee_table where employee_id="+idtmp1+"and useful=1";
    ResultSet rs = db.executeQuery(sql);
    try {
      if (rs.next()) {
        this.removeAll();
        this.mainframe.repaint();
        staff_editFrm();
        obj.setId(Integer.parseInt(idtemp.getText()));
        //从数据库中读取原数据到界面
        obj.setName(rs.getString(2));
        obj.setBirth(rs.getString(3));
          obj.setSex(rs.getInt(4));
          obj.setDep(rs.getInt(5));
          obj.setPosition(rs.getInt(6));
          obj.setTelephone(rs.getString(7));
          obj.setAddress(rs.getString(8));
          obj.setHiredate(rs.getString(9));
          obj.setContract(rs.getString(10));
          obj.setSalary(rs.getInt(11));
          obj.setEducation(rs.getString(12));
          idText.setText(idtemp.getText());
          nameText.setText(obj.getName());
          birthText.setText(obj.getBirth());
          if (obj.getSex()==1) {
            male.setSelected(true);
          }
          else {
            female.setSelected(true);
          }
          partBox2.setText(Integer.toString(obj.getDep()));
          positionBox2.setText(Integer.toString(obj.getPosition()));
          addressText.setText(obj.getAddress());
          hire_dateText.setText(obj.getHiredate());
          contract_expireText.setText(obj.getContract());
          telText.setText(obj.getTelephone());
          salaryText.setText(Integer.toString(obj.getSalary()));
          educationText.setText(obj.getEducation());


      }
        else {
          JOptionPane.showMessageDialog(this, "该员工的记录不存在", "OK", 1);
        }


    }
    catch (NumberFormatException ex) {
    }
    catch (SQLException ex) {
    }
  }

  public void okbtn_actionPerformed(ActionEvent e) {
    obj.setName(nameText.getText());
    obj.setBirth(birthText.getText());
    if (male.isSelected()) {
      obj.setSex(1);
    }
    else {
      obj.setSex(2);
    }
    obj.setDep(Integer.parseInt(partBox2.getText()));
    obj.setPosition(Integer.parseInt(positionBox2.getText()));
    obj.setTelephone(telText.getText());
    obj.setAddress(addressText.getText());
    obj.setHiredate(hire_dateText.getText());
    obj.setContract(contract_expireText.getText());
    obj.setSalary(Integer.parseInt(salaryText.getText()));
    obj.setEducation(educationText.getText());
    int r = method.staff_edit(obj);
    if (r == 0) {
      JOptionPane.showMessageDialog(this, "修改数据失败!!", "OK", 1);

     }
    else {
         JOptionPane.showMessageDialog(this, "修改数据成功!!", "OK", 1);
    }
    this.removeAll();
    this.mainframe.repaint();
    idtemp.setText("");
    try {
      jbInit();
    }
    catch (Exception ex) {
    }
  }

  public void resetbtn_actionPerformed(ActionEvent e) {
    this.removeAll();
    this.mainframe.repaint();
  }
}

class Staff_edit_resetbtn_actionAdapter
    implements ActionListener {
  private Staff_edit_view adaptee;
  Staff_edit_resetbtn_actionAdapter(Staff_edit_view adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.resetbtn_actionPerformed(e);
  }
}

class Staff_edit_okbtn_actionAdapter
    implements ActionListener {
  private Staff_edit_view adaptee;
  Staff_edit_okbtn_actionAdapter(Staff_edit_view adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.okbtn_actionPerformed(e);
  }
}

class Staff_edit_jButton1_actionAdapter
    implements ActionListener {
  private Staff_edit_view adaptee;
  Staff_edit_jButton1_actionAdapter(Staff_edit_view adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class Staff_edit_jButton2_actionAdapter
    implements ActionListener {
  private Staff_edit_view adaptee;
  Staff_edit_jButton2_actionAdapter(Staff_edit_view adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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