?? subsystem.java
字號:
package com.everstar.usermanage;
import java.sql.*;
import java.io.*;
import java.util.ArrayList;
import com.everstar.database.*;
public class SubSystem {
private int subSystemID;
private String SystemName;
private SubSystemList sysList;
private Database dbConn;
private int managerID;
//constructor
public SubSystem(String SystemName,SubSystemList sysList,Database dbConn)
{
this.dbConn = dbConn;
this.SystemName = SystemName;
this.managerID = 0;
this.sysList = sysList;
this.subSystemID = getMaxId()+1;
inserttodb();
}
public SubSystem(int subSystemID,SubSystemList sysList,Database dbConn)
{
this.dbConn = dbConn;
this.sysList = sysList;
loadfromdb(subSystemID);
}
public int getmanagerID()
{
return managerID;
}
public void setmanagerID(int managerID)
{
this.managerID = managerID;
updatedb();
}
public int getsubSystemID()
{
return subSystemID;
}
public String getSystemName()
{
return SystemName;
}
public void setSystemName(String sysName)
{
this.SystemName = sysName;
updatedb();
}
//create a function belonged to the system
public Fun createFunction(String functionName,String operate)
{
return new Fun(functionName,operate,this,dbConn);
}
//get the function
public Fun getFunction(int functionID)
{
return new Fun(functionID,this,dbConn);
}
//remove a function
public void removeFunction(int functionID)
{
try
{
String DELETE_FUNCTION = "DELETE FROM FUN where systemid="+subSystemID+" and functionID="+functionID;
int i = dbConn.delete(DELETE_FUNCTION);
}
catch( Exception sqle )
{
sqle.printStackTrace();
}
}
//get all functionid from the subsystem
public int[] FunList()
{
ArrayList tempArrayList = new ArrayList();
try
{
String LIST_FUNCTION = "SELECT functionid FROM FUN where systemid="+subSystemID;
ResultSet rs =dbConn.select(LIST_FUNCTION);
while(rs.next())
{
tempArrayList.add(new Integer(rs.getInt(1)));
}
rs.close();
dbConn.close();
}
catch( Exception sqle )
{
sqle.printStackTrace();
}
int[] listFunctionArray = new int[tempArrayList.size()];
for (int i = 0;i < listFunctionArray.length; i++ )
{
listFunctionArray[i] = ((Integer)tempArrayList.get(i)).intValue();
}
return listFunctionArray;
}
private int getMaxId()
{
int temp = 0;
try
{
String GETMAXID = "SELECT MAX(SYSTEMID) FROM SUBSYSTEM";
ResultSet rs =dbConn.select(GETMAXID);
if(rs.next())
temp = rs.getInt(1);
rs.close();
dbConn.close();
}
catch( Exception sqle )
{
sqle.printStackTrace();
}
return temp;
}
private int inserttodb()
{
int i=0;
try
{
String INSERT_SYSTEM = "INSERT INTO SUBSYSTEM(systemid,name,managerid) values("+subSystemID+",'"+SystemName+"',"+managerID+")";
i = dbConn.insert(INSERT_SYSTEM);
}
catch( Exception sqle )
{
sqle.printStackTrace();
}
return i;
}
private void loadfromdb(int subSystemID)
{
String LOAD_SYSTEM = "SELECT SYSTEMID,NAME,managerid FROM SUBSYSTEM where systemid="+subSystemID;
try
{
ResultSet rs = dbConn.select(LOAD_SYSTEM);
if(rs.next())
{
this.subSystemID = rs.getInt(1);
this.SystemName = rs.getString(2);
this.managerID = rs.getInt(3);
}
rs.close();
dbConn.close();
}
catch( Exception sqle )
{
sqle.printStackTrace();
}
}
private int updatedb()
{
int i=0;
try
{
String UPDATE_SYSTEM = "UPDATE SUBSYSTEM SET NAME='"+SystemName+"',managerid="+managerID+" where systemid="+subSystemID;
i=dbConn.update(UPDATE_SYSTEM);
}
catch( Exception sqle )
{
sqle.printStackTrace();
}
return i;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -