📄 user.cs
字号:
using System;
using System.Web;
using System.Data;
using System.Data.OleDb;
//using COMPlusServicesExample ;
//using System.EnterpriseServices ;
namespace PMS.Components
{
/// <summary>
/// User 的摘要说明。
/// </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>
/// 通过用户名得到密码
/// </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>
/// 根据用户名删除一条记录
/// </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 ;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -