?? user.cs
字號(hào):
using System;
using System.Web;
using System.Data;
using System.Data.OleDb;
//using COMPlusServicesExample ;
//using System.EnterpriseServices ;
namespace PMS.Components
{
/// <summary>
/// User 的摘要說(shuō)明。
/// </summary>
public class User
{
public static readonly int USERTYPENORMAL = 0;
public static readonly int USERTYPEADMIN = 1;
public static readonly int USERTYPESUPERADMIN = 2;
/// <summary>
/// 顯示所有的用戶信息
/// </summary>
/// <returns></returns>
public DataTable GetUser()
{
try
{
PMS.Common.DataAccess DataAs = new PMS.Common.DataAccess() ;
DataTable DT = DataAs.CreateDataTable("select UserID from [User]") ;
return(DT) ;
}
catch(Exception ex)
{
PMS.Common.SystemError.SystemLog(ex.Message) ;
throw new Exception(ex.Message,ex) ;
}
}
/// <summary>
///
/// </summary>
/// <param name="UserID"></param>
/// <returns></returns>
public DataTable GetUser(string UserID)
{
try
{
PMS.Common.DataAccess DataAs = new PMS.Common.DataAccess() ;
DataTable DT = DataAs.CreateDataTable("select * from [User] where UserID='"+UserID+"'") ;
return(DT) ;
}
catch(Exception ex)
{
PMS.Common.SystemError.SystemLog(ex.Message) ;
throw new Exception(ex.Message,ex) ;
}
}
/// <summary>
/// 通過(guò)用戶名得到密碼
/// </summary>
/// <param name="UserID"></param>
/// <returns></returns>
public string GetPwd(string UserID)
{
try
{
PMS.Common.DataAccess DataAs = new PMS.Common.DataAccess() ;
DataTable DT = DataAs.CreateDataTable("select Password from [User] where UserID = '"+UserID+"'") ;
string pwd = DT.Rows[0][0].ToString().Trim() ;
return(pwd) ;
}
catch(Exception ex)
{
PMS.Common.SystemError.SystemLog(ex.Message) ;
throw new Exception(ex.Message,ex) ;
}
}
/// <summary>
/// 添加用戶,往用戶表中插入一條記錄
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public bool AddUser(string strSql)
{
try
{
PMS.Common.DataAccess DataAs = new PMS.Common.DataAccess() ;
bool bResult = DataAs.ExecSql(strSql) ;
return(bResult) ;
}
catch(Exception ex)
{
PMS.Common.SystemError.SystemLog(ex.Message) ;
throw new Exception(ex.Message,ex) ;
}
}
/// <summary>
/// 根據(jù)用戶名刪除一條記錄
/// </summary>
/// <param name="UserID"></param>
/// <returns></returns>
public bool DeleteUser(string UserID)
{
try
{
PMS.Common.DataAccess DataAs = new PMS.Common.DataAccess() ;
bool bResult = DataAs.ExecSql("delete from [User] where UserID = '"+UserID+"'") ;
return(bResult) ;
}
catch(Exception ex)
{
PMS.Common.SystemError.SystemLog(ex.Message) ;
throw new Exception(ex.Message,ex) ;
}
}
/// <summary>
/// 更改指定用戶名的密碼
/// </summary>
/// <param name="UserID"></param>
/// <param name="sPwd"></param>
/// <returns></returns>
public bool UpdateUserPwd(string UserID,string sPwd)
{
try
{
PMS.Common.DataAccess DataAs = new PMS.Common.DataAccess() ;
bool bResult = DataAs.ExecSql("update [User] set Password = '" + sPwd + "' where UserID = '"+UserID+"'") ;
return(bResult) ;
}
catch(Exception ex)
{
PMS.Common.SystemError.SystemLog(ex.Message) ;
throw new Exception(ex.Message,ex) ;
}
}
/// <summary>
/// 判斷用戶名和密碼是否有效
/// </summary>
/// <param name="UserID"></param>
/// <param name="Pwd"></param>
/// <returns></returns>
public bool Login(string UserID,string Pwd)
{
try
{
PMS.Common.DataAccess DataAs = new PMS.Common.DataAccess() ;
DataTable DT = DataAs.CreateDataTable("select 1 from [User] where UserID='"+UserID+"' and Password = '" + Pwd + "'") ;
if(DT.Rows.Count > 0)
{
DT.Dispose() ;
return true ;
}
else
{
DT.Dispose() ;
return false ;
}
}
catch(Exception ex)
{
PMS.Common.SystemError.SystemLog(ex.Message) ;
throw new Exception(ex.Message,ex) ;
}
}
public static int IsAuthority(string UserID)
{
///用戶ID為空
if(UserID == null || UserID == "")
{
return(int.MaxValue);
}
///獲取用戶所屬的類型
PMS.Components.User User = new User();
DataTable DT = User.GetUser(UserID);
if(DT.Rows.Count > 0)
{
if(int.Parse(DT.Rows[0]["State"].ToString()) == 1)
{
int UserType = int.Parse(DT.Rows[0]["UserType"].ToString());
return UserType;
}
else
{
return(int.MaxValue);
}
}
else
{
return(int.MaxValue);
}
}
/// <summary>
///
/// </summary>
/// <param name="UserID"></param>
/// <returns></returns>
public bool IsUnique(string UserID)
{
DataTable DT = GetUser(UserID);
if(DT.Rows.Count == 0)
{
return true ;
}
else
{
return false ;
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -