Example #1
0
        protected override void PostBack()
        {
            user = UserBLL.ReadUser(userID);

            int oldCompanyID   = user.CompanyID;
            int oldStudyPostID = user.StudyPostID;

            user.CompanyID = RequestHelper.GetForm <int>("CompanyID");
            if (user.CompanyID < 0)
            {
                user.CompanyID = oldCompanyID == int.MinValue ? base.UserCompanyID : oldCompanyID;
            }

            user.Department = RequestHelper.GetForm <int>("Department");
            if (user.Department < 0)
            {
                ScriptHelper.Alert("请选择部门");
            }

            user.WorkingPostID = RequestHelper.GetForm <int>("WorkingPostID");
            if (user.WorkingPostID < 0)
            {
                ScriptHelper.Alert("请选择岗位");
            }

            user.PostName = StringHelper.AddSafe(RequestHelper.GetForm <string>("WorkingPostName"));
            if (user.WorkingPostID < 0 && string.IsNullOrEmpty(user.PostName))
            {
                ScriptHelper.Alert("请填写店内岗位名称");
            }

            user.StudyPostID = RequestHelper.GetForm <int>("StudyPostID");
            if (user.StudyPostID < 0)
            {
                ScriptHelper.Alert("请选择学习岗位");
            }

            user.Email  = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email"));
            user.Sex    = RequestHelper.GetForm <int>("Sex");
            user.QQ     = StringHelper.AddSafe(RequestHelper.GetForm <string>("QQ"));
            user.Status = RequestHelper.GetForm <int>("Status");
            if (user.Status < 0)
            {
                ScriptHelper.Alert("请选择状态");
            }

            //新增会员或有更改姓名的权限
            if (userID <= 0 || base.CompareUserPower("UpdateRealName", PowerCheckType.Single))
            {
                user.RealName = StringHelper.AddSafe(RequestHelper.GetForm <string>("RealName"));
            }

            //新增会员或有更改手机号码的权限
            if (userID <= 0 || base.CompareUserPower("UpdateMobile", PowerCheckType.Single))
            {
                user.Mobile = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile"));
                if (string.IsNullOrEmpty(user.Mobile))
                {
                    ScriptHelper.Alert("请正确填写手机号码!");
                }
            }

            //验证手机号码是否存在
            //if (UserBLL.IsExistMobile(user.Mobile, user.ID))
            //    ScriptHelper.Alert("手机号码已存在");

            if (base.CompareUserPower("ShowIDCard", PowerCheckType.Single))
            {
                user.IDCard = StringHelper.AddSafe(RequestHelper.GetForm <string>("IDCard"));
            }

            if (base.CompareUserPower("ShowIDCard", PowerCheckType.Single) && !string.IsNullOrEmpty(RequestHelper.GetForm <string>("EntryDate")))
            {
                user.EntryDate = RequestHelper.GetForm <DateTime>("EntryDate");
            }

            string alertMessage = ShopLanguage.ReadLanguage("AddOK");

            if (userID < 0)
            {
                base.CheckUserPower("AddUser", PowerCheckType.Single);
                user.Status = (int)UserState.Normal;

                if (UserBLL.IsUserNumOverflow(user.CompanyID))
                {
                    ScriptHelper.Alert("超过用户数量,暂不能添加!");
                }

                user.UserName = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserName"));
                Regex regex = new Regex("^([a-zA-Z0-9_一-龥])+$");
                if (!regex.IsMatch(user.UserName))
                {
                    ScriptHelper.Alert("用户名只能包含字母、数字、下划线、中文");
                }

                if (UserBLL.CheckUserName(user.UserName) > 0)
                {
                    ScriptHelper.Alert("用户名已存在,请更换用户名!");
                }

                string userPassword  = RequestHelper.GetForm <string>("UserPassword");
                string userPassword2 = RequestHelper.GetForm <string>("UserPassword2");
                if (string.IsNullOrEmpty(userPassword) || string.IsNullOrEmpty(userPassword2) || userPassword != userPassword2)
                {
                    ScriptHelper.Alert("两次密码不一致");
                }
                regex = new Regex("(?=^[0-9a-zA-Z._@#]{6,16}$)((?=.*[0-9])(?=.*[^0-9])|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))");
                if (!regex.IsMatch(userPassword))
                {
                    ScriptHelper.Alert("密码为6-16位数字与字母的组合!");
                }
                user.UserPassword = StringHelper.Password(userPassword, (PasswordType)ShopConfig.ReadConfigInfo().PasswordType);

                user.GroupID = RequestHelper.GetForm <int>("GroupID");
                if (user.GroupID < 0)
                {
                    user.GroupID = 36;
                }

                int id = UserBLL.AddUser(user);
                AdminLogBLL.AddAdminLog(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("User"), id);
            }
            else
            {
                base.CheckUserPower("UpdateUser", PowerCheckType.Single);

                //变换学习岗位,如果岗位已通过则更新注册时间,以便岗位计划按新时间重新计数,否则不更改原有岗位计划统计时间
                PostInfo studyPost    = PostBLL.ReadPost(user.StudyPostID);
                PostInfo oldStudyPost = PostBLL.ReadPost(oldStudyPostID);
                if (oldCompanyID != user.CompanyID || (user.StudyPostID != oldStudyPostID && (studyPost.ParentId == 3 || oldStudyPost.ParentId == 3) && studyPost.ParentId != oldStudyPost.ParentId))
                {
                    user.PostStartDate = DateTime.Today;
                }

                UserBLL.UpdateUser(user);

                //如果公司ID更改,相应修改成绩列表
                if (oldCompanyID != user.CompanyID)
                {
                    TestPaperBLL.UpdatePaperCompanyId(user.ID, user.CompanyID);
                }

                AdminLogBLL.AddAdminLog(ShopLanguage.ReadLanguage("UpdateRecord"), ShopLanguage.ReadLanguage("User"), user.ID);
                alertMessage = ShopLanguage.ReadLanguage("UpdateOK");
            }
            string returnURL = ServerHelper.UrlDecode(RequestHelper.GetQueryString <string>("ReturnURL"));

            if (string.IsNullOrEmpty(returnURL))
            {
                ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl);
            }
            else
            {
                ScriptHelper.Alert(alertMessage, returnURL);
            }
        }