?? user.java
字號:
//系統用戶類
package device;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import devicecomm.*;
public class User {
private String UserId; // 用戶名
private String EmplName; // 員工姓名
private String PassWord; // 密碼
private int UserType; // 用戶類型;1-經理;2- 管理員
StringOper so = new StringOper();
// 獲得一個用戶的信息,如果存在此用戶返回true,否則false
public boolean getUser()throws Exception
{
int conditionNo = 0;
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
String sql = "Select * from dev_User";
System.out.println(sql);
String condition = " where ";
if(UserId != null)
{
condition += " UserId='"+UserId+"'";
conditionNo++;
}
if(PassWord != null)
{
if(conditionNo > 0)
{
condition += " and";
}
condition += " PassWord='"+PassWord+"'";
conditionNo++;
}
if(conditionNo > 0)
{
sql += condition;
}
try
{
rs = o_DBOper.getResultSet(sql);
if(rs.next())
{
setUserId(so.ReplaceNull(rs.getString("UserId")));
setEmplName(so.ReplaceNull(rs.getString("EmplName")));
setPassWord(so.ReplaceNull(rs.getString("PassWord")));
setUserType(rs.getInt("UserType"));
return true;
}
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
finally
{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
return false;
}
// 根據查詢條件獲得多個用戶信息
public Vector getMoreUser() throws Exception
{
Vector v_User = new Vector();
int conditionNo = 0;
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
String sql = "Select * from dev_User";
String condition = " where ";
try
{
if(UserId != null)
{
condition += " UserId='"+UserId+"'";
conditionNo++;
}
if(EmplName != null)
{
if(conditionNo > 0)
{
condition += " and ";
}
condition += " EmplName='"+EmplName+"'";
conditionNo++;
}
if(UserType != 0)
{
if(conditionNo > 0)
{
condition += " and ";
}
condition += " UserType="+UserType;
conditionNo++;
}
if(conditionNo > 0)
{
sql += condition;
}
sql += " order by UserId desc";
rs = o_DBOper.getResultSet(sql);
//System.out.println(sql);
while(rs.next())
{
User o_User2 = new User();
o_User2.setUserId(so.ReplaceNull(rs.getString("UserId")));
o_User2.setEmplName(so.ReplaceNull(rs.getString("EmplName")));
o_User2.setPassWord(so.ReplaceNull(rs.getString("PassWord")));
o_User2.setUserType(rs.getInt("UserType"));
v_User.add(o_User2);
}
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
finally
{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
return v_User;
}
//刪除用戶
public void DeleteUser(String UserId) throws Exception
{
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
String sql_dlt = "delete from dev_User where UserId ='" + UserId + "'";
try
{
o_DBOper.getResultSet(sql_dlt);
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
finally
{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
}
//插入用戶,密碼缺省為6個1
public void CreateUser() throws Exception
{
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
String sql = "Insert into dev_User(UserId,EmplName,UserType,PassWord) ";
sql =sql+"values('"+UserId+"','"+EmplName+"',"+UserType+",'111111')";
//System.out.println("INSERT SQL:"+sql);
try
{
o_DBOper.getResultSet(sql);
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
finally
{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
}
// 更新用戶信息,管理員更改用戶信息,不更改密碼
public void UpdateUser() throws Exception
{
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
String sql = "Update dev_User set EmplName='"+EmplName+"',UserType="+UserType;
sql = sql+" where UserId='"+UserId+"'";
// System.out.println("UPDATE SQL :"+sql);
try
{
o_DBOper.getResultSet(sql);
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
finally
{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
}
// 用戶更改自己密碼和管理員密碼重置為六個1
public void UpdatePassWord() throws Exception
{
DBOper o_DBOper = new DBOper();
ResultSet rs = null;
String sql = "Update dev_User set PassWord='"+PassWord+"' where UserId='"+UserId+"'";
try
{
o_DBOper.getResultSet(sql);
}
catch(Exception e)
{
throw new Exception(e.getMessage());
}
finally
{
try {o_DBOper.close();} catch (Exception e) { System.out.print(e.toString());}
}
}
// 設置、獲得用戶的信息
public void setUserId(String UserId){
this.UserId = UserId;
}
public String getUserId(){
return this.UserId;
}
public void setEmplName(String EmplName){
this.EmplName = EmplName;
}
public String getEmplName(){
return this.EmplName;
}
public void setPassWord(String PassWord){
this.PassWord = PassWord;
}
public String getPassWord(){
return this.PassWord;
}
public void setUserType(int UserType){
this.UserType = UserType;
}
public int getUserType(){
return this.UserType;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -