📄 deptservice.java
字号:
package hrm.dept;
import java.sql.*;
import java.util.*;
import java.text.*;
import commons.*;
public class DeptService extends ExecuteDB{
private String strSql;
//获取部门树信息,返回一个ArrayList类型对象
public ArrayList deptTree() {
this.strSql="select * from T_DEPT";
ResultSet rs=null;
ArrayList list=new ArrayList();
try
{
rs=super.exeQuery(this.strSql);
while(rs.next()){
DeptForm dept=new DeptForm();
dept.setDeptId(rs.getString("DEPTID"));
dept.setDeptCode(rs.getString("DEPTCODE"));
dept.setDeptName(rs.getString("DEPTNAME"));
dept.setAddress(rs.getString("ADDRESS"));
dept.setTelphone(rs.getString("TELPHONE"));
dept.setDesc(rs.getString("DESCS"));
list.add(dept);
}
}catch(Exception e)
{
System.out.println(e.toString());
}
return list;
}
//获取部门ID为deptID的信息
DeptForm getDept(String deptCode){
this.strSql="select * from T_DEPT where DEPTCODE='"+deptCode +"'";
System.out.println("strSql is "+this.strSql);
ResultSet rs=null;
ArrayList list=new ArrayList();
DeptForm dept=null;
try
{
rs=super.exeQuery(this.strSql);
if(rs.next()){
dept=new DeptForm();
dept.setDeptId(rs.getString("DEPTID"));
dept.setDeptCode(rs.getString("DEPTCODE"));
dept.setDeptName(rs.getString("DEPTNAME"));
dept.setAddress(rs.getString("ADDRESS"));
dept.setTelphone(rs.getString("TELPHONE"));
dept.setDesc(rs.getString("DESCS"));
}
rs.close();
}catch(Exception e)
{
System.out.println(e.toString());
}
return dept;
}
//向T_DEPT表中添加添加一条新记录
public boolean insertDept(DeptInfo dept)
{
this.strSql="insert into T_DEPT ";
this.strSql=this.strSql + "(DEPTCODE,DEPTNAME,ADDRESS,TELPHONE,DESCS)";
this.strSql=this.strSql + " values ('" + dept.getDeptCode() + "','" + dept.getDeptName() + "','"
+ dept.getAddress() + "','" + dept.getTelphone() + "','" + dept.getDesc() + "')";
System.out.println(this.strSql);
boolean isAdd=super.exeSql(this.strSql);
System.out.println("ok!");
System.out.println(isAdd);
return isAdd;
}
//修改类成员变量DEPTID对应的部门信息
public boolean updateDept(DeptInfo dept){
this.strSql="update T_DEPT set ";
this.strSql=this.strSql + " DEPTCODE=" + "'" + dept.getDeptCode() + "',";
this.strSql=this.strSql + " DEPTNAME=" + "'" + dept.getDeptName() + "',";
this.strSql=this.strSql + " ADDRESS=" + "'" + dept.getAddress() + "',";
this.strSql=this.strSql + " TELPHONE=" + "'" + dept.getTelphone() + "',";
this.strSql=this.strSql + " DESCS=" + "'" + dept.getDesc() + "'";
this.strSql=this.strSql+" where DEPTID=" + dept.getDeptId();
boolean isUpdate=super.exeSql(strSql);
return isUpdate;
}
//删除DEPTCODE中对应的部门信息
public boolean delete(DeptForm dept){
this.strSql="delete from T_DEPT where DEPTID =";
this.strSql=this.strSql + dept.getDeptId();
System.out.println(this.strSql);
boolean isDelete =super.exeSql(this.strSql);
return isDelete;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -