📄 informationmodel.java
字号:
/**接受转过来的参数*/
InformationForm informationform = ifm;
/** SQL语句执行变量 */
Statement sql = null;
/** SQL语句操作的结果集 */
ResultSet rs = null;
/**存放在查询界面获得的值以便在修改及删除界面显示出来*/
String str[] = { "null", "null", "null", "null", "null", "null" };
try
{
db=new DbConnection();
con=db.getCon();
sql = con.createStatement();
/**存放从form中得到的单选扭信息*/
String dep = informationform.getDep();
/**如果选中一个单选扭*/
if(dep!=null)
{
/**把dep转变成整形*/
int depnum= Integer.parseInt(dep);
rs = sql.executeQuery("select * from depart where depno="+depnum);
rs.first();
/** 把选中的信息放入数组当中去 */
String depno = rs.getString(1);
str[0] = depno;
String depname = rs.getString(2);
str[1] = depname;
String depleader = rs.getString(3);
str[2] = depleader;
String deptel = rs.getString(4);
str[3] = deptel;
String desalary = rs.getString(6);
str[4] = desalary;
return str;}else
{
return str;
}
}catch (SQLException e)
{
userError.error("userId: time: SessionId: 浏览器类型:"
+ "部门修改错误:修改的中间信息错误");
System.out.print(e.getMessage());
} finally {
try
{
if(sql != null)
{
sql.close();
}
if(con != null)
{
con.close();
}
} catch (Exception sqle)
{
userError.error("userId: time: SessionId: 浏览器类型:"
+ "部门修改错误:数据库释放错误");
}
AppMode.loginoutUser();
}
return str;
}
/**
* name: 部门信息修改
* describing: 修改部门表信息
*/
public int updateDep(InformationForm ifm2)
{
/**得到传过来的参数*/
InformationForm informationform=ifm2;
/** 根据t的返回值做不同页的跳转 */
int t;
/** SQL语句执行变量 */
Statement sql = null;
/** SQL语句操作的结果集 */
ResultSet rs = null;
/**存放得到的单选扭的值*/
String dep = informationform.getDepno();
/**转换为整数*/
int depnum= Integer.parseInt(dep);
/**存放得到的转换后的部门号*/
String depno;
/**存放得到的转换后的部门名*/
String depname;
/**存放得到的转换后的负责人*/
String depleader;
/**存放得到的转换后的部门电话*/
String deptel;
/**存放得到的转换后的部门工资*/
String depsalary;
/**避免出错转换一下*/
depno = informationform.getDepno();
depname = convert(informationform.getDepname());
depleader = convert(informationform.getDepleader());
deptel = informationform.getDeptel();
depsalary = informationform.getDepsalary();
try {
db=new DbConnection();
con=db.getCon();
sql = con.createStatement();
/**存放要执行的语句*/
String condition = "update depart set depleader=" + "'" + depleader + "'" + "," + "deptel="
+ "'"+ deptel + "'"+ "," + "depsalary=" + "'" + depsalary + "'" +","+"update_user_date="+"'"+update_date+"'" + "where depno="+ depnum;
System.out.println(condition);
if(informationform.getGroupNo()!=null){
ResultSet rstmp2 = null;
rstmp2=sql.executeQuery("select count(*) as mycount2 from deptable where depno="+depnum);
rstmp2.next();
int j=rstmp2.getInt("mycount2");
if(j!=0){
String condition2 = "delete from deptable where depno="+depnum;
}
String[]groupNo = informationform.getGroupNo();
int k = groupNo.length;
System.out.println(k);
for(int d =0;d < k;d++){
sql.executeUpdate("INSERT INTO deptable"
+ "(depno,tablename)"+"VALUES ( "+depnum+"," +"\""+groupNo[d]+"\""+")");
System.out.println(groupNo[d]);
}}
sql.executeUpdate(condition);
/** 记录用户操作日志:修改部门信息 */
userOperation.info("userId: time: 操作:修改部门信息 " + depno
+ "结果:成功");
t = 1;
return t;
} catch (SQLException e)
{
userError.error("userId: time: SessionId: 浏览器类型:"
+ "部门修改错误:数据库联接错误");
System.out.print(e.getMessage());
t = 2;
return t;
} finally {
try {
sql.close();
con.close();
} catch (SQLException sqle) {
userError.error("userId: time: SessionId: 浏览器类型:"
+ "部门修改错误:数据库释放错误");
System.out.print(sqle.getMessage());
}
}
}
/**
*
* @return boolean b 判断是否对数据库修改成功 (有待改进,返回类型最好为int型)
*/
public int ViewDelete(InformationForm cmf) {
/** 获得FORM里的参数 */
InformationForm informationform = cmf;
/**用于判断是否操作成功*/
Statement sql = null;
ResultSet rs = null;
ResultSet rstmp1 = null;
ResultSet rstmp2 = null;
String dep = informationform.getDepno();
int depnum= Integer.parseInt(dep);
System.out.println(depnum);
try {
db=new DbConnection();
con=db.getCon();
sql = con.createStatement();
rstmp1=sql.executeQuery("select count(*) as mycount1 from stuff where depno="+depnum);
rstmp1.next();
//记录查询出来的部门号的个数
int i=rstmp1.getInt("mycount1");
rstmp2=sql.executeQuery("select count(*) as mycount2 from deptable where depno="+depnum);
rstmp2.next();
int j=rstmp2.getInt("mycount2");
String condition1 = "delete from depart where depno="+depnum;
String condition2 = "delete from deptable where depno="+depnum;
if(i==0){
sql.executeUpdate(condition1);
if(j!=0){
sql.executeUpdate(condition2);
}
/** 记录用户操作日志:删除部门信息 */
userOperation.info("userId: time: 操作:删除部门信息 " + depnum
+ "结果:成功");
con.close();
return 1;}else{
return 2;
}
}catch (SQLException e) {
userError.error("userId: time: SessionId: 浏览器类型:"
+ "部门修改错误:数据库操作错误");
System.out.print("操作失败");
return 3;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -