📄 user.java
字号:
/*
* Created on 2004-4-12
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.cmmi2pms.sa.user;
/**
* @author lxj
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import com.cmmi2pms.common.comdb.*;
import com.cmmi2pms.common.*;
import org.apache.log4j.Logger;
public class User {
// --------------------------------------------------------- Instance Variables
private int userID;
private String userName;
private String password;
private String a_permission;
private String name;
private int departID;
private String DepartName;
private String position;
private String email;
private String phone;
private String mobile;
private int isAvailable;
private static Logger logger = Logger.getLogger ("User") ;
private SqlDB dbf;
private ResultSet rs;
//增加一个关闭resultset与SqlDB的方法
private void close()
{
try
{
if(rs!=null) rs.close();
logger.debug("close the resultset");
if(dbf!=null) dbf.close();
logger.debug("close the sqldb");
}
catch(SQLException sqle)
{
logger.error("Close SqlDB error: "+sqle.getMessage());
}
}
//private AddUserForm theUserForm;
// --------------------------------------------------------- Methods
public void createUser(UserForm theUserForm) {
try{
//PooledConnectionMgr.getInstance().initialize(30,"192.168.15.150",3306,"CMMI2PM");
//Get an instance reference to the DbFacade object
dbf = new SqlDB();
int newUserID = CommonFuncs.getCurrentID("userID","employee");
//String pmID = getAField("employee","userID","Name='" + theUserForm.getPM() +"'");
//String departmentID = getAField("department","departID ","departName='" + theUserForm.getDepartID() +"'");
dbf.setSql("INSERT INTO `employee` VALUES (?,?,?,?,?,?,?,?,?,?,?)");
dbf.setInt(1,newUserID);
dbf.setString(2,theUserForm.getUsername());
dbf.setString(3,theUserForm.getPassword());
dbf.setString(4,theUserForm.getPermission());
dbf.setString(5,theUserForm.getName());
dbf.setInt(6,theUserForm.getDepartID());
dbf.setString(7,theUserForm.getPosition());
dbf.setString(8,theUserForm.getEmail());
dbf.setString(9,theUserForm.getPhone());
dbf.setString(10,theUserForm.getMobile());
dbf.setInt(11,1);
//dbf.setString(5,"R&D");
dbf.execute();
//List results of changes.
logger.info("user" + theUserForm.getUsername() + "is created");
}
catch (Exception e)
{
logger.error("Exception in createUser:" + e.getMessage());
}finally
{
close();
}
}
public void getUserInfor(int userID) {
try{
//PooledConnectionMgr.getInstance().initialize(30,"192.168.15.150",3306,"CMMI2PM");
//Get an instance reference to the DbFacade object
dbf = new SqlDB();
String sql = "SELECT * from employee where userID='" + userID + "'";
rs=dbf.executeQuery(sql);
logger.info("executeQuery" + sql + "in getUserInfor");
if (rs.next())
{
this.userID = userID;
this.userName = rs.getString("userName");
this.password = rs.getString("password");
this.a_permission = rs.getString("permission");
this.name = rs.getString("name");
this.departID = rs.getInt("departID");
this.position = rs.getString("position");
this.email = rs.getString("email");
this.phone = rs.getString("phone");
this.mobile = rs.getString("mobile");
this.isAvailable = rs.getInt("isAvailable");
}
}
catch (Exception e)
{
logger.error("Exception in getUserInfor:" + e.getMessage());
}finally
{
close();
}
}
public void delUser(int userID) {
try{
//PooledConnectionMgr.getInstance().initialize(30,"192.168.15.150",3306,"CMMI2PM");
//Get an instance reference to the DbFacade object
dbf = new SqlDB();
System.out.println("before executeQuery");
String sql = "update employee set isAvailable=0 where userID = " + userID ;
dbf.setSql(sql);
dbf.execute();
logger.info("execute" + sql + "in delUser");
}
catch (Exception e)
{
logger.error("Exception in getUserInfor:" + e.getMessage());
}finally
{
close();
}
}
public void updateUser(UserForm theUserForm) {
try{
//PooledConnectionMgr.getInstance().initialize(30,"192.168.15.150",3306,"CMMI2PM");
//Get an instance reference to the DbFacade object
dbf = new SqlDB();
String sql = "update employee set userName = '"+ theUserForm.getUsername() + "',";
sql += "permission = '" + theUserForm.getPermission() + "',";
sql += "name = '" + theUserForm.getName() + "',";
sql += "departID = '" + theUserForm.getDepartID() + "',";
sql += "position = '" + theUserForm.getPosition() + "',";
sql += "email = '" + theUserForm.getEmail() + "',";
sql += "phone = '" + theUserForm.getPhone() + "',";
sql += "mobile = '" + theUserForm.getMobile() + "' ";
sql += " where userID = " + theUserForm.getUserID();
logger.info("------before execute:" + sql + "in updateUser");
dbf.setSql(sql);
dbf.execute();
logger.info("-----after execute:" + sql + "in updateUser");
}
catch (Exception e)
{
logger.error("Exception in getUserInfor:" + e.getMessage());
}finally
{
close();
}
}
public void passwordChange(UserForm theUserForm) {
try{
//PooledConnectionMgr.getInstance().initialize(30,"192.168.15.150",3306,"CMMI2PM");
//Get an instance reference to the DbFacade object
dbf = new SqlDB();
String sql = "update employee set password = '" + theUserForm.getPassword() + "'";
sql += " where userID = " + theUserForm.getUserID();
logger.info("------before execute:" + sql + "in passwordChange");
dbf.setSql(sql);
dbf.execute();
logger.info("-----after execute:" + sql + "in passwordChange");
}
catch (Exception e)
{
logger.error("Exception in getUserInfor:" + e.getMessage());
}finally
{
close();
}
}
public int getUserID() {
return userID;
}
public void setUserID(int userID) {
this.userID = userID;
}
public String getUsername() {
return userName;
}
public void setUsername(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPermission() {
return a_permission;
}
public void setPermission(String a_permission) {
this.a_permission = a_permission;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getDepartID() {
return departID;
}
public void setDepartID(int departID) {
this.departID = departID;
}
public String getDepartName() {
return DepartName;
}
public void setDepartName(String DepartName) {
this.DepartName = DepartName;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public int getIsAvailable() {
return isAvailable;
}
public void setIsAvailable(int isAvailable) {
this.isAvailable = isAvailable;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -