| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- using Castle.ActiveRecord;
- using NHibernate.Criterion;
- using System;
- using System.Text;
- namespace BizCom
- {
- [ActiveRecord("X_User")]
- public class XUser : ComBase<XUser>
- {
- /// <summary>
- /// 内部编号
- /// </summary>
- [PrimaryKey(PrimaryKeyType.Native)]
- public int ID { get; set; }
- private int _roleID = 0;
- /// <summary>
- ///
- /// </summary>
- [Property]
- public int RoleID
- {
- get { return _roleID; }
- set { _roleID = value; }
- }
- private string _account = "";
- /// <summary>
- ///账号
- /// </summary>
- [Property]
- public string Account
- {
- get { return _account; }
- set { _account = value; }
- }
- private string _passWord = "";
- /// <summary>
- ///密码
- /// </summary>
- [Property]
- public string PassWord
- {
- get { return _passWord; }
- set { _passWord = value; }
- }
- /// <summary>
- ///创建时间
- /// </summary>
- [Property]
- public DateTime? CreateTime { get; set; }
- /// <summary>
- ///上一次登陆时间
- /// </summary>
- [Property]
- public DateTime? PreLoginTime { get; set; }
- /// <summary>
- ///最后一次登录时间
- /// </summary>
- [Property]
- public DateTime? CurLoginTime { get; set; }
- private string _loginIP = "";
- /// <summary>
- ///登录IP
- /// </summary>
- [Property]
- public string LoginIP
- {
- get { return _loginIP; }
- set { _loginIP = value; }
- }
- private string _ticket = "";
- /// <summary>
- ///登录票根
- /// </summary>
- [Property]
- public string Ticket
- {
- get { return _ticket; }
- set { _ticket = value; }
- }
- private int _state = 0;
- /// <summary>
- ///当前状态
- /// </summary>
- [Property]
- public int State
- {
- get { return _state; }
- set { _state = value; }
- }
- private string _station = "";
- /// <summary>
- ///站点
- /// </summary>
- [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)));
- }
- /// <summary>
- /// 查询cookie的票据是否符合
- /// </summary>
- /// <param name="userName"></param>
- /// <param name="ticket"></param>
- /// <returns></returns>
- 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());
- }
- }
- }
|