示例#1
0
        private bool Login(string userID, string pwd, bool IsNeedPwd)
        {
            try
            {
                bool OK = false;
                UserStrategyBuilder sb = new UserStrategyBuilder();
                sb.AddStrategy(new Strategy(UserStrategyName.UserID, userID));
                string sql = sb.BuildMainQueryString();

                Rms.ORMap.QueryAgent qa     = new QueryAgent();
                EntityData           entity = qa.FillEntityData("SystemUser", sql);
                qa.Dispose();
                string workNO = "";


                if (!entity.HasRecord())
                {
                }
                else
                {
                    string RealPwd = entity.GetString("Password");
                    if (RealPwd != pwd)
                    {
                        OK = false;
                    }
                    else
                    {
                        int status = entity.GetInt("Status");
                        // 0-正常,1 禁用
                        if (status == 0)
                        {
                            string userCode = entity.GetString("UserCode");
                            User   user     = new User(userCode);
                            //						user.ResetUser("P1010");
                            Session["User"]       = user;
                            ViewState["UserName"] = userID;
                            ViewState["Password"] = pwd;
                            workNO = user.WorkNO;
                            OK     = true;

                            /********************** 在线用户统计 ***************************/
                            Application.Lock();
                            Hashtable UserTable = (Hashtable)Application["UserTable"];
                            if (!UserTable.Contains(user.UserCode + "," + Session.SessionID))
                            {
                                UserTable.Add(user.UserCode + "," + Session.SessionID, user.UserName);
                                Application["UserTable"] = UserTable;
                            }

                            //单一用户登录控制
                            if (BLL.ConvertRule.ToString(Application["SingleUserLogin"]) == "1")
                            {
                                Hashtable KilledUserTable = (Hashtable)Application["KilledUserTable"];
                                PageBase.KillUser(user, UserTable, KilledUserTable, Session);
                            }

                            Application.UnLock();
                            /***************************************************************/
                        }
                    }
                }
                entity.Dispose();

                if (OK)
                {
                    //记录最后操作时间
                    Session["LastOperTime"] = DateTime.Now;
                }
                return(OK);
            }
            catch (Exception ex)
            {
                ApplicationLog.WriteLog(this.ToString(), ex, "用户登录失败");
                Response.Write(Rms.Web.JavaScript.Alert(true, "用户登录失败:" + ex.Message));
                return(false);
            }
        }