Example #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         string        carveIds = SysContext.CurrentCarveIDs;
         MessageHelper manager  = new MessageHelper();
         if (DataPrivilegeRule.IsAdministrator())
         {
             rptMessage.DataSource = manager.GetAllMessages();
         }
         else
         {
             rptMessage.DataSource = manager.GetMessageByPoliceStation();
         }
         rptMessage.DataBind();
     }
 }
Example #2
0
    /// <summary>
    /// 用户登录
    /// </summary>
    /// <returns></returns>
    public static bool UserLogin(string username, string password)
    {
        string tempPass     = Encrypt.DESEncrypt(password);
        var    loginSuccess = DB.From <CFUser>().Where(CFUser._.LoginName == username && CFUser._.LoginPassword == tempPass).Any();

        if (loginSuccess)
        {
            var user = DB.From <CFUser>().Where(CFUser._.LoginName == username && CFUser._.LoginPassword == tempPass).ToFirst();


            var roles = DB.From <CFUserRole>().Where(CFUserRole._.UserID == user.UserID).ToList();

            var roleids = Array.ConvertAll <int, string>(roles.Select(c => c.RoleID).ToArray(), c => c.ToStr());

            string regDeptIds   = string.Empty;
            string carveCorpIds = string.Empty;

            //UserInfoHelper helper = new UserInfoHelper();

            DataTable dt = null;


            SysContext.CurrentUserID = user.UserID;

            SysContext.CurrentDeptID = user.DeptID;

            SysContext.CurrentEmployeeID = user.EmployeeID;

            SysContext.CurrentSupplierID = user.SupplierID;

            if (user.LastLoginTime.HasValue)
            {
                SysContext.CurrentUserLastLoginTime = user.LastLoginTime.Value.ToString();
            }

            if (user.LoginName.HasValue())
            {
                SysContext.CurrentUserName = user.LoginName;
            }

            SysContext.CurrentUserTitle = user.Title;

            SysContext.CurrentRealName = user.RealName;

            SysContext.CurrentRoleID = string.Join(",", roleids);

            UserInfoHelper helper = new UserInfoHelper();
            if (DataPrivilegeRule.IsAdministrator(user.UserID, roleids))
            {
                dt = helper.GetRegDeptList();
                foreach (DataRow row in dt.Rows)
                {
                    regDeptIds += ",'" + row["PSID"].ToString() + "'";
                }

                dt = helper.GetCummunityList();
                foreach (DataRow row in dt.Rows)
                {
                    carveCorpIds += ",'" + row["LSID"].ToString() + "'";
                }
            }
            else
            {
                dt = helper.GetUserRegRelationList(user.UserID.ToString());
                foreach (DataRow row in dt.Rows)
                {
                    regDeptIds += ",'" + row["t_ad_reg_dept_id"].ToString() + "'";
                }

                dt = helper.GetCummunityListByUser(user.UserID.ToString());
                foreach (DataRow row in dt.Rows)
                {
                    carveCorpIds += ",'" + row["t_ad_reg_dept_id"].ToString() + "'";
                }
            }

            if (!string.IsNullOrEmpty(regDeptIds))
            {
                regDeptIds = regDeptIds.Substring(1);
                SysContext.CurrentAreaIDs = regDeptIds;
            }
            else
            {
                regDeptIds = "'undefined'";
                SysContext.CurrentAreaIDs = regDeptIds;
            }

            if (!string.IsNullOrEmpty(carveCorpIds))
            {
                carveCorpIds = carveCorpIds.Substring(1);
                SysContext.CurrentCarveIDs = carveCorpIds;
            }
            else
            {
                carveCorpIds = "'undefined'";
                SysContext.CurrentCarveIDs = carveCorpIds;
            }

            LogManager.WriteLog("USER", user.RealName + " 登录系统");

            user.Attach();
            user.LastLoginTime = DateTime.Now;
            DB.Update <CFUser>(user);

            string  currentIp = LigerRM.Common.Global.GlobalHelper.GetIPAddress();
            DataSet ds        = DB.ExecuteDataSet("select * from CF_UserLoginStatus where UserID=" + SysContext.CurrentUserID.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                DB.ExecuteDataSet("Update CF_UserLoginStatus set LoginTime='" + DateTime.Now.ToString() + "', LoginIP='" + currentIp + "', IsOnline=1 where UserID=" + SysContext.CurrentUserID.ToString());
            }
            else
            {
                DB.ExecuteDataSet("insert into CF_UserLoginStatus values (" + SysContext.CurrentUserID.ToString() + ",'" + DateTime.Now.ToString() + "','" + currentIp + "',1) ");
            }
        }
        return(loginSuccess);
    }