using Castle.ActiveRecord; using NHibernate.Criterion; using System; using System.Text; namespace BizCom { [ActiveRecord("X_User")] public class XUser : ComBase { /// /// 内部编号 /// [PrimaryKey(PrimaryKeyType.Native)] public int ID { get; set; } private int _roleID = 0; /// /// /// [Property] public int RoleID { get { return _roleID; } set { _roleID = value; } } private string _account = ""; /// ///账号 /// [Property] public string Account { get { return _account; } set { _account = value; } } private string _passWord = ""; /// ///密码 /// [Property] public string PassWord { get { return _passWord; } set { _passWord = value; } } /// ///创建时间 /// [Property] public DateTime? CreateTime { get; set; } /// ///上一次登陆时间 /// [Property] public DateTime? PreLoginTime { get; set; } /// ///最后一次登录时间 /// [Property] public DateTime? CurLoginTime { get; set; } private string _loginIP = ""; /// ///登录IP /// [Property] public string LoginIP { get { return _loginIP; } set { _loginIP = value; } } private string _ticket = ""; /// ///登录票根 /// [Property] public string Ticket { get { return _ticket; } set { _ticket = value; } } private int _state = 0; /// ///当前状态 /// [Property] public int State { get { return _state; } set { _state = value; } } private string _station = ""; /// ///站点 /// [Property] public string Station { get { return _station; } set { _station = value; } } public static void Del(object id) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("delete from X_User where id=" + id); ExecuteNonQuery(sql.ToString()); } public static XUser Get(int uId, string pwd) { Castle.ActiveRecord.Queries.SimpleQuery query = new Castle.ActiveRecord.Queries.SimpleQuery(typeof(XUser), @"from XUser user where user.ID = ? and user.PassWord = ?", uId, pwd); XUser[] users = (XUser[])ExecuteQuery(query); if (users.Length > 0) return users[0]; return null; //return FindFirst(Expression.Sql(string.Format("ID={0} and Password='{1}'", uId, pwd))); } /// /// 查询cookie的票据是否符合 /// /// /// /// public static XUser GetUserByCookie(string account, string ticket) { XUser lcUser = FindFirst(Expression.Sql(string.Format("Account='{0}' and Ticket='{1}'", account, ticket))); //FindFirst(Expression.And(Expression.Eq("Account", account), Expression.Eq("Ticket", ticket))); return lcUser; } public static XUser GetByLogin(string account, string pwd) { return FindFirst(Expression.Sql(string.Format("Account='{0}' and Password='{1}' ", account, pwd))); } public static void ResetPwd(int id, string pwd) { string sql = "update x_user set password='" + pwd + "' where id=" + id; ExecuteNonQuery(sql); } public static void ResetPersonPwd(int pId, string pwd) { string sql = "update x_user set password='" + pwd + "' where personid=" + pId; ExecuteNonQuery(sql); } public static int RealDel(int id, int pId) { StringBuilder str = new StringBuilder(); str.AppendFormat("delete from x_user where id={0} and personId={1} ;", id, pId); return ExecuteNonQuery(str.ToString()); } public static int OpenAccount(int id, int pId) { StringBuilder str = new StringBuilder(); str.AppendFormat("update x_user set state=0 where ID={0} and PersonID={1};", id, pId); return ExecuteNonQuery(str.ToString()); } public static int FreezeAccount(int id, int pId) { StringBuilder str = new StringBuilder(); str.AppendFormat("update x_user set state=1 where id={0} and PersonID={1} ;", id, pId); return ExecuteNonQuery(str.ToString()); } } }