📄 sysmanbean.java
字号:
package oa.bean;
import java.text.*;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.sql.*;
import oa.main.*;
public class SysmanBean extends ParentBean
{
int type = 0;
String id = "-1";
String dictname = "";
//设置系统管理类型
public void setType(int t)
{
type = t;
}
//设置记录唯一编号
public void setID(String i)
{
id = i;
}
//设置字典名称
public void setDictname(String d)
{
dictname = d;
}
public int revert()
{
String sql="";
String sqlxh="";
String strSYZT="0";
switch (type)
{
case 1: sql = "update news.CODE_ZDB set SYZT = "+strSYZT+" where ZDMC='"+dictname
+"' and XMBH="+id+"";
break;
default:break;
}
if(!sql.equals(""))
{
return deleteRecord(sql);
}
return 0;
}
//取得数据表内容
public Vector getData()
{
Vector vect = new Vector();
String sql = "";
switch (type)
{//SYZT,
case 1: sql = " select * from news.CODE_ZDB order by ZDMC,JBXH ";break;
default:break;
}
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
//取得列数和列名
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
while(rs.next())
{
Hashtable hash = new Hashtable();
for(int i=1;i<=cols;i++)
{
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
hash.put(field,value);
}
vect.add(hash);
}
}catch(Exception e){System.out.println("运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
return vect;
}
//取得数据表中的某一条记录
public Hashtable getOneData()
{
Hashtable hash = new Hashtable();
String sql = "";
switch (type)
{
case 1: sql = " select * from news.CODE_ZDB where ZDMC = '"+dictname+"' and XMBH = "+id;break;
default:break;
}
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
if (rs.next())
{
for(int i=1;i<=cols;i++)
{
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
hash.put(field,value);
}
}
}catch(Exception e){System.out.println("运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
return hash;
}
//增加字典数据记录
public int addDict(Hashtable hash)
{
String strZDMC = ds.toString((String)hash.get("ZDMC"));
int intXMBH = db.makeID("CODE_ZDB","ZDMC","XMBH",strZDMC,false);
String strXMMC = ds.toString((String)hash.get("XMMC"));
String strSYZT = ds.toString((String)hash.get("SYZT"));
String strJBXH = ds.toString((String)hash.get("JBXH"));
//检验是否已经存在
ResultSet rs = selectRecord("select * from news.CODE_ZDB where ZDMC='"+strZDMC+"' and XMMC='"+strXMMC+"'");
Statement stmt = null;
try{
if(rs.next())
return 1;
}catch(Exception e){System.out.println("运行时出错:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
/////////////////
int maxjbNo=makeID("CODE_ZDB","ZDMC","JBXH",strZDMC,false);
int jbxh=0;
if(!strJBXH.equals(""))
jbxh=Integer.parseInt(strJBXH);
if(jbxh==0||jbxh>maxjbNo)
{ jbxh=maxjbNo;strJBXH=""+jbxh;}
////////////////////// and SYZT=0
String sql="update news.CODE_ZDB set jbxh=jbxh+1 where ZDMC='"+ strZDMC + "' and JBXH >=" + jbxh ;
deleteRecord(sql);
//////////////////////
Vector vect =new Vector();
vect.add("CODE_ZDB");
vect.add(addVector("ZDMC",strZDMC,"CHAR"));
vect.add(addVector("XMBH",String.valueOf(intXMBH),"NUM"));
vect.add(addVector("XMMC",strXMMC,"CHAR"));
vect.add(addVector("SYZT",strSYZT,"NUM"));
vect.add(addVector("JBXH",strJBXH,"NUM"));
return insertRecord(vect);
}
//修改字典数据记录
public int modDict(Hashtable hash)
{
String strXMMC = ds.toString((String)hash.get("XMMC"));
String strSYZT = ds.toString((String)hash.get("SYZT"));
String strJBXH = ds.toString((String)hash.get("JBXH"));
// id = ds.toString((String)hash.get("XMBH"));
// dictname = ds.toString((String)hash.get("ZDMC"));
//////////////// and SYZT=0
ResultSet rs1 = selectRecord(
"select JBXH from news.CODE_ZDB where XMBH='"
+ id
+ "' and ZDMC='"
+ dictname
+ "'");
int yjbxh=999;
Statement stmt = null;
try{
if(rs1.next())
yjbxh=Integer.parseInt(rs1.getString("JBXH"));///////////////
}catch(Exception e){System.out.println("运行时出错:"+e);}
finally{
if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
int jbxh=Integer.parseInt(strJBXH);
int maxjbNo=makeID("CODE_ZDB","ZDMC","JBXH",dictname,false);
if(jbxh==0||jbxh>=maxjbNo)
{ jbxh=maxjbNo-1;strJBXH=""+jbxh;}
if(jbxh < yjbxh){
String sql="update news.CODE_ZDB set jbxh=jbxh+1 where ZDMC='"
+ dictname
+ "' and JBXH >="
+ jbxh
+ " and JBXH<"
+ yjbxh;
deleteRecord(sql);
}
else if(jbxh > yjbxh && yjbxh!=0){
String sql="update news.CODE_ZDB set jbxh=jbxh-1 where ZDMC='"
+ dictname
+ "' and JBXH <="
+ jbxh
+ " and JBXH>"
+ yjbxh;
deleteRecord(sql);
}
///////////////////////
Vector vect = new Vector();
vect.add("CODE_ZDB");
vect.add(addVector("XMMC",strXMMC,"CHAR"));
vect.add(addVector("SYZT",strSYZT,"NUM"));
vect.add(addVector("JBXH",strJBXH,"NUM"));
vect.add("ZDMC='"+dictname+"' and XMBH="+id+"");
return updateRecord(vect);
}
//删除数据记录
public int delData()
{
String sql="";
String sqlxh="";
String strSYZT="1";
switch (type)
{
case 1: sql = "update news.CODE_ZDB set SYZT = "+strSYZT+" where ZDMC='"+dictname
+"' and XMBH="+id+"";
break;
case 11: sql = "delete from news.CODE_ZDB where SYZT=1 and ZDMC='"+dictname
+"' and XMBH="+id+"";
executeUpdate("update news.CODE_ZDB set JBXH=JBXH-1 where ZDMC='"
+dictname+"' and JBXH > (select JBXH from CODE_ZDB where SYZT=1 and ZDMC='"
+dictname+"' and XMBH="+id+")");
break;
default:break;
}
if(!sql.equals(""))
{
deleteRecord(sql);
}
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -