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

📄 sqlclass.java~121~

📁 本员工管理系统使公司员工能通过网络来查询信息、请假
💻 JAVA~121~
📖 第 1 页 / 共 4 页
字号:
    try
    {
      CallableStatement cs = con.prepareCall(sqlCheck);

      cs.setString(1, infor[0]);
      cs.setString(2, empIdNow);
      int temp = 0;
      for (int i = 1; i < 4; i++)
      {
        temp = Integer.parseInt(infor[i].trim());
        cs.setInt(i + 2, temp);
      }
      cs.executeUpdate();

      cs.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);
  }

  //按新编号重新添加薪水表中相应信息
  public void insertSalary(String[] infor, String empIdNow)
  {
    String sqlSalary = "{call insertSalary(?,?,?)}";
    Connection con = this.getConnection();
    try
    {
      CallableStatement cs = con.prepareCall(sqlSalary);

      cs.setString(1, infor[0]);
      cs.setString(2, empIdNow);
      double salary = Double.parseDouble(infor[1].trim());
      cs.setDouble(3, salary);
      cs.executeUpdate();
      cs.close();

    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);
  }

  //将相应信息按新编号重新添加到年奖金表中
  public void insertBonus(String[] infor, String empIdNow)
  {
    String sqlBonus = "{call insertBonus(?,?,?)}";
    Connection con = this.getConnection();
    try
    {
      CallableStatement cs = con.prepareCall(sqlBonus);
      cs.setString(1, infor[0]);
      cs.setString(2, empIdNow);
      double bonus = Double.parseDouble(infor[1]);
      cs.setDouble(3, bonus);
      cs.executeUpdate();

      cs.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);
  }

  //更新调部门后的相应员工的ID号
  public void updateIds(String empIdAtFirst, String empIdNow)
  {
    String sqlId = "{call updateIds(?,?)}";
    Connection con = this.getConnection();
    try
    {
      CallableStatement cs = con.prepareCall(sqlId);
      cs.setString(1, empIdAtFirst);
      cs.setString(2, empIdNow);
      cs.executeUpdate();
      cs.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);
  }

  //删除别的相关联的表
  public void deleteOthers(String empId)
  {
    String sql = "{call deleteOthers(?)}";
    Connection con = this.getConnection();
    try
    {
      CallableStatement cs = con.prepareCall(sql);
      cs.setString(1, empId);
      cs.executeUpdate();
      cs.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);

  }

  //更新员工信息
  public boolean updateEmployee(Vector infor)
  {
    boolean flag = false;
    Connection con = this.getConnection();
    String employeeIdAtFirst = infor.elementAt(6).toString().trim();
    String empIdNow = infor.elementAt(0).toString().trim();

    String sql = "{call updateEmployeeInfor(?,?,?,?,?,?,?,?)}";
    //System.out.println(infor);
    try
    {
      CallableStatement cs = con.prepareCall(sql);
      for (int i = 0; i < 4; i++)
      {
        cs.setString(i + 1, infor.elementAt(i).toString().trim());
      }
      int m = 0;
      m = Integer.parseInt(infor.elementAt(4).toString().trim());
      cs.setInt(5, m);

      for (int i = 5; i < 8; i++)
      {
        cs.setString(i + 1, infor.elementAt(i).toString().trim());
      }
      int temp = cs.executeUpdate();
      if (temp > 0)
      {
        flag = true;
      }
      cs.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
      System.out.println("数据库更新失败!");
    }
    if (employeeIdAtFirst.equals(empIdNow) == false)
    {
      //收集ID更新后的所有此员工相关信息,并存入Vector
      String loginPassword = this.selectLogin(employeeIdAtFirst);
      Vector checkInfor = this.selectEmployeeCheck(employeeIdAtFirst);
      Vector salaryInfor = this.selectMonthSalary(employeeIdAtFirst);
      Vector bonusInfor = this.selectEmployeeBonus(employeeIdAtFirst);
      String[] check = new String[4];
      String[] salary = new String[2];
      String[] bonus = new String[2];
      //System.out.println(employeeIdAtFirst);
      //System.out.println(empIdNow);
      //System.out.println(checkInfor);
      //System.out.println(salaryInfor);
      //System.out.println(bonusInfor);
      //System.out.println(loginPassword);

      //删除此信息
      this.deleteOthers(employeeIdAtFirst);
      //更新员工表中的相关信息
      this.updateIds(employeeIdAtFirst, empIdNow);
      //向相应表中插入Vector所存的信息
      this.insertLogin(loginPassword, empIdNow);

      for (int i = 0; i < checkInfor.size(); i += 4)
      {
        for (int j = 0; j < 4; j++)
        {
          check[j] = checkInfor.elementAt(i + j).toString().trim();
        }
        this.insertCheck(check, empIdNow);
      }

      for (int i = 0; i < salaryInfor.size(); i += 2)
      {
        for (int j = 0; j < 2; j++)
        {
          salary[j] = salaryInfor.elementAt(i + j).toString().trim();
        }
        this.insertSalary(salary, empIdNow);
      }
      for (int i = 0; i < bonusInfor.size(); i += 2)
      {
        for (int j = 0; j < 2; j++)
        {
          bonus[j] = bonusInfor.elementAt(i + j).toString().trim();
        }
        this.insertBonus(bonus, empIdNow);
      }
    }
    this.closeConnection(con);

    return flag;
  }

  //返回员工信息,用以初始化管理员管理员工部分信息
  public Vector getEmployeeInfor(String empId)
  {
    String sql = "{call selectInfor(?)}";
    Vector infor = new Vector();
    Connection con = this.getConnection();
    try
    {
      CallableStatement cs = con.prepareCall(sql);
      cs.setString(1, empId);
      ResultSet rs = cs.executeQuery();
      if (rs.next())
      {
        infor.add(rs.getString(1).toString().trim());
        infor.add(rs.getString(2).toString().trim());
        infor.add(rs.getString(3).toString().trim());
        infor.add(rs.getString(4).toString().trim());
        infor.add(rs.getInt(5));
      }
      rs.close();
      cs.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);
    return infor;
  }

  //删除员工
  public boolean deleteEmployee(String empId)
  {
    boolean flag = false;
    String sql = "{call deleteEmployee(?)}";
    Connection con = this.getConnection();
    try
    {
      CallableStatement cs = con.prepareCall(sql);
      cs.setString(1, empId);
      int i = cs.executeUpdate();
      if (i > 0)
      {
        flag = true;
      }
      cs.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);
    return flag;
  }

  //返回一个员工的具体信息
  public void selectDetailInformation(String empId,
                                      EmployeeDetailInformation edi)
  {
    Connection con = this.getConnection();
    try
    {
      Statement s = con.createStatement();
      ResultSet rs = s.executeQuery("select dep_name,job_name,emp_name,emp_degree,emp_marryStatue,emp_tel,emp_address,emp_birth,emp_IDCard,emp_contractTime,emp_contractBeginTime,emp_exhibition,password,employee.dep_id,employee.job_id from employee,login,Department,JobType where Employee.dep_id=Department.dep_id and Employee.job_id=JobType.job_id and Employee.emp_id='" +
                                    empId + "' and log_id='" + empId + "'");
      if (rs.next())
      {
        edi.empId = empId;
        edi.depName = rs.getString(1).toString().trim();
        edi.jobName = rs.getString(2).toString().trim();
        edi.name = rs.getString(3).toString().trim();
        edi.degree = rs.getString(4).toString().trim();
        edi.isMarry = rs.getInt(5);
        edi.tel = rs.getString(6).toString().trim();
        edi.address = rs.getString(7).toString().trim();
        edi.birth = rs.getString(8).toString().trim();
        edi.idCard = rs.getString(9).toString().trim();
        edi.contractTime = rs.getInt(10);
        edi.beginTime = rs.getString(11).toString().trim();
        edi.exhibition = rs.getInt(12);
        edi.password = rs.getString(13).toString().trim();
        edi.depId = rs.getString(14).toString().trim();
        edi.jobId = rs.getString(15).toString().trim();
      }
      rs.close();
      s.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);
  }

  //更新个人具体信息
  public boolean updateDetailInformation(EmployeeDetailInformation edi,
                                         String employeeIdAtFirst)
  {
    boolean flag = false;
    Connection con = this.getConnection();
    String updateSql = "{call updateDetailInfor(?,?,?,?,?,?,?,?,?,?,?)}";
    System.out.println(edi.depId);
    try
    {
      CallableStatement cs = con.prepareCall(updateSql);
      cs.setString(1, employeeIdAtFirst);
      cs.setString(2, edi.depId);
      cs.setString(3, edi.jobId);
      cs.setString(4, edi.name);
      cs.setString(5, edi.degree);
      cs.setInt(6, edi.isMarry);
      cs.setString(7, edi.tel);
      cs.setString(8, edi.address);
      cs.setString(9, edi.birth);
      cs.setString(10, edi.idCard);
      cs.setString(11, edi.password);
      int i = cs.executeUpdate();
      if (i > 0)
      {
        flag = true;
      }
      cs.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }

    if (employeeIdAtFirst.trim().equals(edi.empId.trim()) == false)
    {
      String loginPassword = this.selectLogin(employeeIdAtFirst);
      Vector checkInfor = this.selectEmployeeCheck(employeeIdAtFirst);
      Vector salaryInfor = this.selectMonthSalary(employeeIdAtFirst);
      Vector bonusInfor = this.selectEmployeeBonus(employeeIdAtFirst);
      String[] check = new String[4];
      String[] salary = new String[2];
      String[] bonus = new String[2];
      //System.out.println(employeeIdAtFirst);
      //System.out.println(empIdNow);
      //System.out.println(checkInfor);
      //System.out.println(salaryInfor);
      //System.out.println(bonusInfor);
      //System.out.println(loginPassword);

      this.deleteOthers(employeeIdAtFirst);
      this.updateIds(employeeIdAtFirst, edi.empId);

      this.insertLogin(loginPassword, edi.empId);

      for (int i = 0; i < checkInfor.size(); i += 4)
      {
        for (int j = 0; j < 4; j++)
        {
          check[j] = checkInfor.elementAt(i + j).toString().trim();
        }
        this.insertCheck(check, edi.empId);
      }

      for (int i = 0; i < salaryInfor.size(); i += 2)
      {
        for (int j = 0; j < 2; j++)
        {
          salary[j] = salaryInfor.elementAt(i + j).toString().trim();
        }
        this.insertSalary(salary, edi.empId);
      }
      for (int i = 0; i < bonusInfor.size(); i += 2)
      {
        for (int j = 0; j < 2; j++)
        {
          bonus[j] = bonusInfor.elementAt(i + j).toString().trim();
        }
        this.insertBonus(bonus, edi.empId);
      }
    }
    this.closeConnection(con);

    return flag;
  }

  //用于返回登录者的姓名。
  public String getEmployeeNameByEmpId(String empId)
  {
    String empName = "";
    Connection con = this.getConnection();
    try
    {
      Statement s = con.createStatement();
      ResultSet rs = s.executeQuery(
          "select emp_name from employee where emp_id='" + empId + "'");
      if (rs.next())
      {
        empName = rs.getString(1).toString().trim();
      }
      rs.close();
      s.close();
    }
    catch (SQLException se)
    {
      se.printStackTrace();
    }
    this.closeConnection(con);
    return empName;

  }

  //统计考勤系统中的记录
  public void insertCheckItems()
  {
    VectorVariable vv = new VectorVariable();
    Vector empIds = vv.employeeIds;
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    String yearStr = sdf.format(date).substring(0, 4);
    String monthStr = sdf.format(date).substring(5, 7);
    int month = Integer.parseInt(monthStr);
    //System.out.println(sdf.format(date));
    String dateStr[] = new String[31];
    //System.out.println(yearStr);
    // System.out.println(monthStr);
    //System.out.println(month);
    switch (month)
    {
      case 1:
      case 3:
      case 5:
      case 7:
      case 8:
      case 10:
      case 12:
        dateStr = new String[31];
        for (int i = 0; i < 31; i++)
        {

⌨️ 快捷键说明

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