using Castle.ActiveRecord; using NHibernate.Criterion; using System; using System.Text; namespace BizCom { [ActiveRecord("CE_ErpUser")] public class CeErpUser : ComBase { /// /// 内部编号 /// [PrimaryKey(PrimaryKeyType.Native)] public int ID { get; set; } private CeErpUserInfo _person; [BelongsTo("InfoID", Insert = false, NotFoundBehaviour = NotFoundBehaviour.Ignore, Cascade = CascadeEnum.None, Update = false)] public CeErpUserInfo Person { get { return _person; } set { _person = value; } } private int _infoID = 0; /// ///人员编号 /// [Property] public int InfoID { get { return _infoID; } set { _infoID = 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; } } private string _Name = ""; /// /// /// [Property] public string Name { get { return _Name; } set { _Name = value; } } private int _isApp = 0; /// /// /// [Property] public int isApp { get { return _isApp; } set { _isApp = value; } } private string _Code = ""; /// /// /// [Property] public string Code { get { return _Code; } set { _Code = value; } } private bool _isOpen = false; /// /// /// [Property] public bool isOpen { get { return _isOpen; } set { _isOpen = value; } } private string _pemShop = ""; /// /// /// [Property] public string pemShop { get { return _pemShop; } set { _pemShop = value; } } private string _pemDesign = ""; /// /// /// [Property] public string pemDesign { get { return _pemDesign; } set { _pemDesign = value; } } private string _pemVend = ""; /// /// /// [Property] public string pemVend { get { return _pemVend; } set { _pemVend = value; } } private string _pemLogistics = ""; /// /// /// [Property] public string pemLogistics { get { return _pemLogistics; } set { _pemLogistics = value; } } private int _isMultiLogin = 0; /// ///是否可以多台登录 /// [Property] public int IsMultiLogin { get { return _isMultiLogin; } set { _isMultiLogin = value; } } /// ///设计点上班时间 /// [Property] public DateTime? OnDutyTime { get; set; } private string _teamIds = ""; /// ///小组id /// [Property] public string TeamIds { get { return _teamIds; } set { _teamIds = value; } } private string _teamNames = ""; /// ///小组人名 /// [Property] public string TeamNames { get { return _teamNames; } set { _teamNames = value; } } /// ///下班时间 /// [Property] public DateTime? OffDutyTime { get; set; } private string _pemExpress = ""; /// ///可以使用的快递 /// [Property] public string pemExpress { get { return _pemExpress; } set { _pemExpress = value; } } private string _manageOrgIds = ""; /// /// 管理组织 /// [Property] public string ManageOrgIds { get { return _manageOrgIds; } set { _manageOrgIds = value; } } public static CeErpUser GetByUserName(string username) { CeErpUser lcUser = FindFirst(Expression.Sql(string.Format("Name='{0}' ", username))); return lcUser; } public static CeErpUser Get(int uId, string pwd) { Castle.ActiveRecord.Queries.SimpleQuery query = new Castle.ActiveRecord.Queries.SimpleQuery(typeof(CeErpUser), @"from CeErpUser user where user.ID = ? and user.PassWord = ?", uId, pwd); CeErpUser[] users = (CeErpUser[])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 CeErpUser GetUserByCookie(string account, string ticket) { CeErpUser 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 CeErpUser 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 ce_erpuser set password='" + pwd + "' where id=" + id; ExecuteNonQuery(sql); } public static void ResetPersonPwd(int pId, string pwd) { string sql = "update ce_erpuser set password='" + pwd + "' where infoid=" + pId; ExecuteNonQuery(sql); } public static void OpenAccount(int uid, string pwd) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("if (select count(0) from ce_erpuser where id={0} and password='')>0 begin ", uid); sql.AppendFormat(" update ce_erpuser set isopen=1,state=0,password='{1}' where id={0} ", uid, pwd); sql.Append(" end else begin "); sql.AppendFormat(" update ce_erpuser set isopen=1,state=0 where id={0} ", uid, pwd); sql.Append(" end "); ExecuteNonQuery(sql.ToString()); } public static void FreezeAccount(int uid) { string sql = "update ce_erpuser set isopen=0,state=1 where id=" + uid; ExecuteNonQuery(sql); } public static int RealDel(int id) { StringBuilder str = new StringBuilder(); str.AppendFormat("delete ce_erpuserinfo where id in(select infoid from ce_erpuser where id={0});", id); str.AppendFormat("delete from ce_erpuser where id={0};", id); return ExecuteNonQuery(str.ToString()); } public static int IsOnDuty(int id) { StringBuilder str = new StringBuilder(); str.AppendFormat("select OnDuty from view_ErpUser where id = {0};", id); return ExecuteNonQuery(str.ToString()); } } }