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

📄 addemployeepanel.java

📁 本员工管理系统使公司员工能通过网络来查询信息、请假
💻 JAVA
字号:
package employeemanagersystem;

import java.awt.*;
import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import java.util.Date;
import java.text.SimpleDateFormat;
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 AddEmployeePanel
    extends JPanel
{
  //自定义的域变量
  SQLClass mySQL = new SQLClass();
  VectorVariable myVector = new VectorVariable();
  Date d=null;
  SimpleDateFormat sdf=new  SimpleDateFormat("yyyy-MM-dd HH:mm");
  JLabel nameLabel = new JLabel();
  JLabel depLabel = new JLabel();
  JLabel jobLabel = new JLabel();
  JLabel degreeLabel = new JLabel();
  JLabel isMarryLabel = new JLabel();
  JLabel telLabel = new JLabel();
  JLabel addressLabel = new JLabel();
  JLabel birthLabel = new JLabel();
  JLabel exhibitionLabel = new JLabel();
  JLabel idCardLabel = new JLabel();
  JLabel beginTimeLabel = new JLabel();
  JLabel timeLabel = new JLabel();
  JButton addButton = new JButton();
  JTextField nameTextField = new JTextField();
  JComboBox depComboBox = new JComboBox();
  JComboBox jobComboBox = new JComboBox();
  JComboBox degreeComboBox = new JComboBox();
  JRadioButton marryRadioButton = new JRadioButton();
  JRadioButton notMarryRadioButton = new JRadioButton();
  JComboBox yearComboBox = new JComboBox();
  JComboBox monthComboBox = new JComboBox();
  JComboBox dayComboBox = new JComboBox();
  JTextField addressTextField = new JTextField();
  JTextField idCardTextField = new JTextField();
  JTextField beginTimeTextField = new JTextField();
  JTextField timeTextField = new JTextField();
  JTextField telTextField = new JTextField();
  JRadioButton goodRadioButton = new JRadioButton();
  JLabel yearLabel = new JLabel();
  JLabel monthLabel = new JLabel();
  JLabel dayLabel = new JLabel();
  JRadioButton normalRadioButton = new JRadioButton();
  JRadioButton badRadioButton = new JRadioButton();
  ButtonGroup isMarryButtonGroup = new ButtonGroup();
  ButtonGroup exhibitionButtonGroup = new ButtonGroup();
  ButtonGroup exhibitionButtonGroup1 = new ButtonGroup();
  ButtonGroup isContinueButtonGroup = new ButtonGroup();
  JPasswordField PasswordField = new JPasswordField();
  JLabel passwordLabel = new JLabel();
  public AddEmployeePanel()
  {
    try
    {
      jbInit();
    }
    catch (Exception exception)
    {
      exception.printStackTrace();
    }
  }

  private void jbInit()
      throws Exception
  {
    this.setLayout(null);
    d=new Date();

    nameLabel.setText("姓名:");
    nameLabel.setBounds(new Rectangle(27, 37, 70, 22));
    depLabel.setText("部门:");
    depLabel.setBounds(new Rectangle(27, 68, 69, 24));
    jobLabel.setText("工种:");
    jobLabel.setBounds(new Rectangle(27, 101, 78, 24));
    degreeLabel.setText("学历:");
    degreeLabel.setBounds(new Rectangle(27, 137, 78, 21));
    isMarryLabel.setText("婚否:");
    isMarryLabel.setBounds(new Rectangle(27, 167, 77, 18));
    telLabel.setText("联系电话:");
    telLabel.setBounds(new Rectangle(27, 260, 60, 17));
    addressLabel.setText("地址:");
    addressLabel.setBounds(new Rectangle(27, 227, 59, 18));
    birthLabel.setText("出生年月:");
    birthLabel.setBounds(new Rectangle(27, 198, 60, 17));
    exhibitionLabel.setText("工作表现:(新员工默认为一般)");
    exhibitionLabel.setBounds(new Rectangle(333, 188, 182, 23));
    idCardLabel.setText("身份证号:");
    idCardLabel.setBounds(new Rectangle(333, 40, 70, 19));
    beginTimeLabel.setText("合同开始时间:");
    beginTimeLabel.setBounds(new Rectangle(333, 87, 90, 23));
    timeLabel.setText("合同期限:");
    timeLabel.setBounds(new Rectangle(333, 132, 74, 22));
    addButton.setBounds(new Rectangle(226, 332, 99, 25));
    addButton.setText("添加新员工");
    addButton.addActionListener(new AddEmployeePanel_addButton_actionAdapter(this));

    nameTextField.setBounds(new Rectangle(110, 40, 95, 21));
    depComboBox.setBounds(new Rectangle(110, 72, 98, 21));
    depComboBox.addItemListener(new AddEmployeePanel_depComboBox_itemAdapter(this));
    this.initDepComboBox();

    jobComboBox.setBounds(new Rectangle(110, 105, 101, 21));
    jobComboBox.addItemListener(new AddEmployeePanel_jobComboBox_itemAdapter(this));
    this.initJobComboBox();

    degreeComboBox.setBounds(new Rectangle(110, 137, 100, 22));

    for (int i = 0; i < myVector.degreeValues.length; i++)
    {
      degreeComboBox.addItem(myVector.degreeValues[i]);
    }
    //marryRadioButton.setBackground(SystemColor.control);
    marryRadioButton.setSelected(false);
    marryRadioButton.setText("是");
    marryRadioButton.setBounds(new Rectangle(110, 165, 47, 23));
    //notMarryRadioButton.setBackground(SystemColor.control);
    notMarryRadioButton.setText("否");
    PasswordField.setBounds(new Rectangle(425, 265, 110, 23));
    passwordLabel.setText("系统登录密码:");
    passwordLabel.setBounds(new Rectangle(334, 268, 81, 20));
   // goodRadioButton.setBackground(UIManager.getColor("control"));
    goodRadioButton.setSelected(false);
    //this.setBackground(SystemColor.control);
    //normalRadioButton.setBackground(SystemColor.control);
    normalRadioButton.setSelected(true); //badRadioButton.setBackground(SystemColor.control);
    isMarryButtonGroup.add(notMarryRadioButton);
    isMarryButtonGroup.add(marryRadioButton);
    notMarryRadioButton.setBounds(new Rectangle(165, 165, 48, 23));
    yearComboBox.setBounds(new Rectangle(111, 196, 49, 19));
    for (int i = 1900; i <= 2100; i++)
    {
      yearComboBox.addItem(i);
    }
    monthComboBox.setBounds(new Rectangle(186, 196, 47, 19));
    for (int i = 1; i <= 12; i++)
    {
      monthComboBox.addItem(i);
    }
    dayComboBox.setBounds(new Rectangle(256, 196, 47, 19));
    for (int i = 1; i <= 30; i++)
    {
      dayComboBox.addItem(i);
    }
    addressTextField.setBounds(new Rectangle(110, 226, 164, 23));
    idCardTextField.setBounds(new Rectangle(424, 41, 130, 21));
    beginTimeTextField.setBounds(new Rectangle(425, 87, 128, 21));
    beginTimeTextField.setText(sdf.format(d));
    timeTextField.setBounds(new Rectangle(424, 134, 72, 21));
    telTextField.setBounds(new Rectangle(110, 263, 131, 21));
    goodRadioButton.setText("出色");
    goodRadioButton.setBounds(new Rectangle(333, 233, 50, 23));
    yearLabel.setText("年");
    yearLabel.setBounds(new Rectangle(163, 197, 22, 19));
    monthLabel.setText("月");
    monthLabel.setBounds(new Rectangle(233, 195, 19, 20));
    dayLabel.setText("日");
    dayLabel.setBounds(new Rectangle(305, 196, 23, 19));
    normalRadioButton.setText("一般");
    normalRadioButton.setBounds(new Rectangle(393, 233, 56, 23));
    badRadioButton.setText("差劲");
    exhibitionButtonGroup.add(goodRadioButton);
    exhibitionButtonGroup.add(normalRadioButton);
    exhibitionButtonGroup.add(badRadioButton);
    badRadioButton.setBounds(new Rectangle(452, 233, 50, 23));
    this.add(idCardTextField);
    this.add(exhibitionLabel);
    this.add(idCardLabel);
    this.add(beginTimeLabel);
    this.add(notMarryRadioButton);
    this.add(yearComboBox);
    this.add(addressTextField);
    this.add(nameTextField);
    this.add(depComboBox);
    this.add(degreeComboBox);
    this.add(marryRadioButton);
    this.add(dayComboBox);
    this.add(monthComboBox);
    this.add(yearLabel);
    this.add(dayLabel);
    this.add(goodRadioButton);
    this.add(badRadioButton);
    this.add(normalRadioButton);
    this.add(telTextField);
    this.add(jobComboBox);
    this.add(monthLabel);
    this.add(PasswordField);
    this.add(passwordLabel);
    this.add(jobLabel);
    this.add(addressLabel);
    this.add(birthLabel);
    this.add(isMarryLabel);
    this.add(degreeLabel);
    this.add(depLabel);
    this.add(nameLabel);
    this.add(telLabel);
    this.add(timeLabel);
    this.add(timeTextField);
    this.add(beginTimeTextField);
    this.add(addButton);
  }

  public void initDepComboBox()
  {
    for (int i = 0; i < myVector.depIds.size(); i++)
    {
      depComboBox.addItem(myVector.depNames.elementAt(i).toString().trim());
    }
    depComboBox.addItem("");
  }

  public void initJobComboBox()
  {
    for (int i = 0; i < myVector.jobIds.size(); i++)
    {
      jobComboBox.addItem(myVector.jobNames.elementAt(i).toString().trim());
    }
    jobComboBox.addItem("");
  }

  public boolean getEmployeeInforValues(EmployeeDetailInformation edi)
  {
    boolean flag = false; //标明信息是否获取成功
    try
    {
      //给EmployeeDetailInformation类的成员变量赋值
      String depId = "";
      int depNo = depComboBox.getSelectedIndex();
      depId = myVector.depIds.elementAt(depNo).toString().trim();
      edi.depId = depId;

      //随机生成员工编号
      StringBuffer empIdtemp = new StringBuffer(depId);
      String empId = "";
      long randomId = Math.round(Math.random() * 90000) + 10000;
      String ID = "" + randomId; //生成随机数
      //System.out.println(ID);
      empIdtemp.append(ID);
      empId = empIdtemp.toString().trim();
      edi.empId = empId;

      String jobId = "";
      int jobNo = jobComboBox.getSelectedIndex();
      jobId = myVector.jobIds.elementAt(jobNo).toString().trim();
      edi.jobId = jobId;

      edi.name = nameTextField.getText().trim();

      edi.degree = degreeComboBox.getSelectedItem().toString().trim();

      if (marryRadioButton.isSelected())
      {
        edi.isMarry = 1;
      }
      edi.tel = telTextField.getText().trim();
      edi.address = addressTextField.getText().trim();
      String birth = yearComboBox.getSelectedItem().toString().trim() +
          "-" +
          monthComboBox.getSelectedItem().toString().trim() +
          "-" +
          dayComboBox.getSelectedItem().toString().trim();
      edi.birth = birth;

      edi.idCard = idCardTextField.getText().trim();

      edi.contractTime = Integer.parseInt(timeTextField.getText().trim());
      edi.beginTime = beginTimeTextField.getText().trim();
      edi.password = String.valueOf(PasswordField.getPassword()).trim();

      if (edi.name.equals("") || edi.degree.equals("") || edi.tel.equals("") ||
          edi.idCard.equals("") || edi.contractTime == 0)
      {
        JOptionPane.showMessageDialog(this, "姓名、联系电话、身份证号、合同期限 ,合同开始日期 不能为空!",
                                      "Error",
                                      JOptionPane.ERROR_MESSAGE);
        return false;
      }
      else
      {
        if (edi.password.equals(""))
        {
          int i = JOptionPane.showConfirmDialog(this,
                                                "您还没设置密码,是否设?(密码默认为111)",
                                                "Noticfy",
                                                JOptionPane.YES_NO_OPTION,
                                                JOptionPane.INFORMATION_MESSAGE);
          System.out.println(i);
          //0:Yes; 1:No; 2:Cancel;
          if (i == 0)
          {
            PasswordField.requestFocus();

            return false;
          }

          else
          {
            edi.password = "111";
          }
        }

        flag = true;

      }

    }
    catch (NumberFormatException nfe)
    {
      JOptionPane.showMessageDialog(this, "合同期限需为数字形式!", "Error",
                                    JOptionPane.ERROR_MESSAGE);
    }
    catch (Exception ee)
    {
      JOptionPane.showMessageDialog(this, "员工信息格式错误", "Error",
                                    JOptionPane.ERROR_MESSAGE);
    }
    return flag;

  }

  public void depComboBox_itemStateChanged(ItemEvent e)
  {
    if (depComboBox.getSelectedItem().toString().trim().equals(""))
    {
      JOptionPane.showMessageDialog(this, "请选择部门", "Error",
                                    JOptionPane.ERROR_MESSAGE);
      return;
    }
  }

  public void jobComboBox_itemStateChanged(ItemEvent e)
  {
    if (jobComboBox.getSelectedItem().toString().trim().equals(""))
    {
      JOptionPane.showMessageDialog(this, "请选择工种!", "Error",
                                    JOptionPane.ERROR_MESSAGE);
      return;
    }
  }

  public void addButton_actionPerformed(ActionEvent e)
  {
    EmployeeDetailInformation edi = new EmployeeDetailInformation();
    boolean flag1 = this.getEmployeeInforValues(edi); //获得有关信息的值;
    if (flag1)
    {
      boolean flag = false;

      flag = mySQL.addEmployee(edi);
      if (flag)
      {
        JOptionPane.showMessageDialog(this, "添加成功!", "Information",
                                      JOptionPane.INFORMATION_MESSAGE);
        nameTextField.setText("");
        idCardTextField.setText("");
        beginTimeTextField.setText("");
        timeTextField.setText(sdf.format(d));
        addressTextField.setText("");
        telTextField.setText("");
        PasswordField.setText("");
      }
      else
      {
        JOptionPane.showMessageDialog(this, "添加失败!", "Information",
                                      JOptionPane.INFORMATION_MESSAGE);
        return;
      }
    }
    else
    {
      JOptionPane.showMessageDialog(this, "获取信息失败!", "Error",
                                    JOptionPane.ERROR_MESSAGE);
      return;
    }

  }

}

class AddEmployeePanel_addButton_actionAdapter
    implements ActionListener
{
  private AddEmployeePanel adaptee;
  AddEmployeePanel_addButton_actionAdapter(AddEmployeePanel adaptee)
  {
    this.adaptee = adaptee;
  }

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

class AddEmployeePanel_jobComboBox_itemAdapter
    implements ItemListener
{
  private AddEmployeePanel adaptee;
  AddEmployeePanel_jobComboBox_itemAdapter(AddEmployeePanel adaptee)
  {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e)
  {
    adaptee.jobComboBox_itemStateChanged(e);
  }
}

class AddEmployeePanel_depComboBox_itemAdapter
    implements ItemListener
{
  private AddEmployeePanel adaptee;
  AddEmployeePanel_depComboBox_itemAdapter(AddEmployeePanel adaptee)
  {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e)
  {
    adaptee.depComboBox_itemStateChanged(e);
  }
}

⌨️ 快捷键说明

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