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

📄 staff_dele_c.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.*;
import javax.swing.table.DefaultTableModel;
import java.awt.Rectangle;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Staff_dele_C
extends JPanel implements All_view {
  JFrame mainframe = null;
  JLabel jLabel1 = new JLabel();
  JTextField idText = new JTextField();
  JButton staffokbtn = new JButton();
  JButton staffcancel = new JButton();
  JLabel jLabel2 = new JLabel();
  JScrollPane jScrollPane1 = new JScrollPane();
  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);
  JTable jTable1 = new JTable(dm);

  public Staff_dele_C(JFrame mainframe) {
    this.mainframe = mainframe;
    try {
      jbInit();
        setPanelPosOnDesktop(this.mainframe);
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    this.setLayout(null);
    setSize(new Dimension(597, 516));
    jLabel1.setForeground(UIManager.getColor("Button.disabledForeground"));
    jLabel1.setText("请输入需要删除的员工ID:");
    jLabel1.setBounds(new Rectangle(150, 400, 150, 31));
    idText.setBounds(new Rectangle(313, 400, 117, 30));
    staffokbtn.setBounds(new Rectangle(202, 462, 82, 23));
    staffokbtn.setForeground(SystemColor.windowBorder);
    staffokbtn.setActionCommand("确定");
    staffokbtn.setText("确定");
    staffokbtn.addActionListener(new Staff_dele_staffokbtn_actionAdapter(this));
    staffcancel.setBounds(new Rectangle(325, 462, 82, 23));
    staffcancel.setForeground(SystemColor.windowText);
    staffcancel.setText("取消");
    staffcancel.addActionListener(new Staff_dele_staffcancel_actionAdapter(this));
    jLabel2.setFont(new java.awt.Font("幼圆", Font.BOLD, 20));
    jLabel2.setForeground(new Color(85, 45, 25));
    jLabel2.setText("删 除 员 工 信 息");
    jLabel2.setBounds(new Rectangle(205, 34, 188, 51));
    jScrollPane1.setBounds(new Rectangle(79, 128, 450, 250));
    this.add(jScrollPane1);
    this.add(jLabel2);
    this.add(jLabel1);
    this.add(idText);
    this.add(staffokbtn);
    this.add(staffcancel);
    jScrollPane1.getViewport().add(jTable1);
  }


   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 staffokbtn_actionPerformed(ActionEvent e) {
    int aaa=Integer.parseInt(idText.getText());
      DataBase db= new DataBase();
      String sql="select * from employee_table where employee_id="+aaa+" and useful=1 ";
      ResultSet rs=db.executeQuery(sql);

      try {
        if (rs.next()) {
          sql = "update employee_table set useful=0 where employee_id="+aaa;
          db.executeUpdate(sql);
          JOptionPane.showMessageDialog(this, "该员工的记录已成功删除", "OK", 1);

          //重新加载
          DataBase db4 = new DataBase();
          String sql2 =
              "select employee_id,name,dep_id,position_id from employee_table where useful=1";
          ResultSet rs1 = db4.executeQuery(sql2);
          DataMap mp = new DataMap(rs1);
          Object[][] obj2 = mp.get_DataMap_Array();
          String[] colnames = {
              "工号", "姓名", "部门ID", "职位ID"};
          DefaultTableModel dm = new DefaultTableModel(obj2, colnames);
          JTable jTable2 = new JTable(dm);
          jScrollPane1.getViewport().add(jTable2);
          idText.setText(null);
//重新加载

        }
        else {
          JOptionPane.showMessageDialog(this, "无此员工的记录", "OK", 1);
        }
      }
      catch (SQLException ex) {
      }
  }

  public void staffcancel_actionPerformed(ActionEvent e) {
     idText.setText("");
     return;
  }

}

class Staff_dele_staffcancel_actionAdapter
    implements ActionListener {
  private Staff_dele_C adaptee;
  Staff_dele_staffcancel_actionAdapter(Staff_dele_C adaptee) {
    this.adaptee = adaptee;
  }

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

class Staff_dele_staffokbtn_actionAdapter
    implements ActionListener {
  private Staff_dele_C adaptee;
  Staff_dele_staffokbtn_actionAdapter(Staff_dele_C adaptee) {
    this.adaptee = adaptee;
  }

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

⌨️ 快捷键说明

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