XUser.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using Castle.ActiveRecord;
  2. using NHibernate.Criterion;
  3. using System;
  4. using System.Text;
  5. namespace BizCom
  6. {
  7. [ActiveRecord("X_User")]
  8. public class XUser : ComBase<XUser>
  9. {
  10. /// <summary>
  11. /// 内部编号
  12. /// </summary>
  13. [PrimaryKey(PrimaryKeyType.Native)]
  14. public int ID { get; set; }
  15. private int _roleID = 0;
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. [Property]
  20. public int RoleID
  21. {
  22. get { return _roleID; }
  23. set { _roleID = value; }
  24. }
  25. private string _account = "";
  26. /// <summary>
  27. ///账号
  28. /// </summary>
  29. [Property]
  30. public string Account
  31. {
  32. get { return _account; }
  33. set { _account = value; }
  34. }
  35. private string _passWord = "";
  36. /// <summary>
  37. ///密码
  38. /// </summary>
  39. [Property]
  40. public string PassWord
  41. {
  42. get { return _passWord; }
  43. set { _passWord = value; }
  44. }
  45. /// <summary>
  46. ///创建时间
  47. /// </summary>
  48. [Property]
  49. public DateTime? CreateTime { get; set; }
  50. /// <summary>
  51. ///上一次登陆时间
  52. /// </summary>
  53. [Property]
  54. public DateTime? PreLoginTime { get; set; }
  55. /// <summary>
  56. ///最后一次登录时间
  57. /// </summary>
  58. [Property]
  59. public DateTime? CurLoginTime { get; set; }
  60. private string _loginIP = "";
  61. /// <summary>
  62. ///登录IP
  63. /// </summary>
  64. [Property]
  65. public string LoginIP
  66. {
  67. get { return _loginIP; }
  68. set { _loginIP = value; }
  69. }
  70. private string _ticket = "";
  71. /// <summary>
  72. ///登录票根
  73. /// </summary>
  74. [Property]
  75. public string Ticket
  76. {
  77. get { return _ticket; }
  78. set { _ticket = value; }
  79. }
  80. private int _state = 0;
  81. /// <summary>
  82. ///当前状态
  83. /// </summary>
  84. [Property]
  85. public int State
  86. {
  87. get { return _state; }
  88. set { _state = value; }
  89. }
  90. private string _station = "";
  91. /// <summary>
  92. ///站点
  93. /// </summary>
  94. [Property]
  95. public string Station
  96. {
  97. get { return _station; }
  98. set { _station = value; }
  99. }
  100. public static void Del(object id)
  101. {
  102. StringBuilder sql = new StringBuilder();
  103. sql.AppendFormat("delete from X_User where id=" + id);
  104. ExecuteNonQuery(sql.ToString());
  105. }
  106. public static XUser Get(int uId, string pwd)
  107. {
  108. Castle.ActiveRecord.Queries.SimpleQuery query = new Castle.ActiveRecord.Queries.SimpleQuery(typeof(XUser), @"from XUser user where user.ID = ? and user.PassWord = ?", uId, pwd);
  109. XUser[] users = (XUser[])ExecuteQuery(query);
  110. if (users.Length > 0) return users[0];
  111. return null;
  112. //return FindFirst(Expression.Sql(string.Format("ID={0} and Password='{1}'", uId, pwd)));
  113. }
  114. /// <summary>
  115. /// 查询cookie的票据是否符合
  116. /// </summary>
  117. /// <param name="userName"></param>
  118. /// <param name="ticket"></param>
  119. /// <returns></returns>
  120. public static XUser GetUserByCookie(string account, string ticket)
  121. {
  122. XUser lcUser = FindFirst(Expression.Sql(string.Format("Account='{0}' and Ticket='{1}'", account, ticket)));
  123. //FindFirst(Expression.And(Expression.Eq("Account", account), Expression.Eq("Ticket", ticket)));
  124. return lcUser;
  125. }
  126. public static XUser GetByLogin(string account, string pwd)
  127. {
  128. return FindFirst(Expression.Sql(string.Format("Account='{0}' and Password='{1}' ", account, pwd)));
  129. }
  130. public static void ResetPwd(int id, string pwd)
  131. {
  132. string sql = "update x_user set password='" + pwd + "' where id=" + id;
  133. ExecuteNonQuery(sql);
  134. }
  135. public static void ResetPersonPwd(int pId, string pwd)
  136. {
  137. string sql = "update x_user set password='" + pwd + "' where personid=" + pId;
  138. ExecuteNonQuery(sql);
  139. }
  140. public static int RealDel(int id, int pId)
  141. {
  142. StringBuilder str = new StringBuilder();
  143. str.AppendFormat("delete from x_user where id={0} and personId={1} ;", id, pId);
  144. return ExecuteNonQuery(str.ToString());
  145. }
  146. public static int OpenAccount(int id, int pId)
  147. {
  148. StringBuilder str = new StringBuilder();
  149. str.AppendFormat("update x_user set state=0 where ID={0} and PersonID={1};", id, pId);
  150. return ExecuteNonQuery(str.ToString());
  151. }
  152. public static int FreezeAccount(int id, int pId)
  153. {
  154. StringBuilder str = new StringBuilder();
  155. str.AppendFormat("update x_user set state=1 where id={0} and PersonID={1} ;", id, pId);
  156. return ExecuteNonQuery(str.ToString());
  157. }
  158. }
  159. }