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

📄 departmentoperate.java

📁 java+sql2000企业人力管理系统
💻 JAVA
字号:
package managersystem.Dept;

import javax.swing.JOptionPane;
import java.sql.*;
import java.util.*;
import managersystem.DBGet;
import managersystem.user.Users;

public class DepartmentOperate {
    public DepartmentOperate() {
        try {
            jbInit();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    //插入
    public boolean DepartmentAdd(Department objD) {

        Connection con = null;
        PreparedStatement ptmt = null;
        String strSQL = "insert into Department values(?,?,?)";
        try {
            DBGet objG = new DBGet();
            con = objG.getConnection();
            ptmt = con.prepareStatement(strSQL);
            ptmt.setInt(1, objD.getDep_Id());
            ptmt.setString(2, objD.getDep_Name());
            ptmt.setString(3, objD.getDescribe());
            try {
                if (ptmt.executeUpdate() > 0) {
                    return true;
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "该部门已存在");
            }
            ptmt.close();
            con.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;
    }

    public Vector getAllDept() {
        Vector data = new Vector();
        Connection con = null;
        PreparedStatement ptmt = null;
        ResultSet rs = null;
        String strSQL = "select * from Department";
        try {
            DBGet objG = new DBGet();
            con = objG.getConnection();
            ptmt = con.prepareStatement(strSQL);
            rs = ptmt.executeQuery();
            while (rs.next()) {
                data.add(rs.getString(1));
                data.add(rs.getString(2));
                data.add(rs.getString(3));
            }
            rs.close();
            ptmt.close();
            con.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return data;
    }

    /*
     **删除部门信息
     */
    public boolean deleteDep_ID(int id) {
        DBGet objD = new DBGet();
        boolean success = false;
        Connection con = null;
        PreparedStatement ptmt = null;
        String strSQL = "delete from Department where Dep_ID=?";
        try {
            con = objD.getConnection();
            ptmt = con.prepareStatement(strSQL);
            ptmt.setInt(1, id);
            ptmt.executeUpdate();
            ptmt.close();
            con.close();
            success = true;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return success;
    }

//获取查询的结果
    public Vector getSearch(SearchBean objS) {
        Vector data = new Vector();
        // String strSQL = "select * from Department where Dep_ID= ? or dep_Name = ?";
        Connection con = null;
        PreparedStatement ptmt = null;
        ResultSet rs = null;
        String condition = "";
        int id = objS.getDep_Id();

            condition += "and Dep_Id = " + id + " ";

        String DeptName = objS.getDep_Name();
        if (!DeptName.equals("")) {
            condition += " or Dep_Name like '%" + DeptName + "%'";
        }
        String strSQL = "select * from Department where 1=1" + condition;

        try {
            DBGet objG = new DBGet();
            con = objG.getConnection();
            ptmt = con.prepareStatement(strSQL);
            rs = ptmt.executeQuery();
            while (rs.next()) {
                data.add(rs.getString(1));
                data.add(rs.getString(2));
                data.add(rs.getString(3));
            }
            rs.close();
            ptmt.close();
            con.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return data;
    }



    //更新
    public boolean updateName(Users objU) {
        boolean success = false;
        Connection con = null;
        PreparedStatement ptmt = null;
        String strSQL =
                "update Users set Usersname=?, Pwd=?, Emp_Id=?, User_Type=? ";
        try {
            DBGet objG = new DBGet();
            con = objG.getConnection();
            ptmt = con.prepareStatement(strSQL);
            ptmt.setString(1, objU.getUserName());
            ptmt.setString(2, objU.getPwd());
            ptmt.setInt(3, objU.getEmp_Id());
            ptmt.setInt(4, objU.getUser_Type());
            ptmt.executeUpdate();
            ptmt.close();
            con.close();
            success = true;

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return success;
    }

    //更新部门
    public boolean UpdateDepart(Department objD) {

        Connection con = null;
        PreparedStatement ptmt = null;
        String strSQL =
                "update Department set  Dep_Name=?, Describe=? where Dep_Id=?";
        try {
            DBGet objG = new DBGet();
            con = objG.getConnection();
            ptmt = con.prepareStatement(strSQL);
            ptmt.setString(1, objD.getDep_Name());
            ptmt.setString(2, objD.getDescribe());
            ptmt.setInt(3, objD.getDep_Id());
            ptmt.executeUpdate();
            ptmt.close();
            con.close();
            return true;

        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;

    }

    private void jbInit() throws Exception {
    }

}

⌨️ 快捷键说明

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