Beispiel #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //  LoadingUtil.ShowImageLoading();
            try
            {
                UserVM user = null;
                if (GlobalObject.UserRoles.Any(p => p.RoleName == "admin"))
                {
                    if (string.IsNullOrEmpty(this.teAccount.Text.Trim()))
                    {
                        XtraMessageBox.Show("Account is empty!", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    if (string.IsNullOrEmpty(this.tePassword.Text.Trim()))
                    {
                        XtraMessageBox.Show("Password is empty!", "提示", MessageBoxButtons.OK);

                        return;
                    }
                    if (string.IsNullOrEmpty(this.teConfirmPassword.Text.Trim()))
                    {
                        XtraMessageBox.Show("ConfirmPassword is empty!", "提示", MessageBoxButtons.OK);
                        return;
                    }

                    if (this.teConfirmPassword.Text.Trim() != this.tePassword.Text.Trim())
                    {
                        XtraMessageBox.Show("Password is  not the  same  with ConfirmPassword!", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    user = new UserVM()
                    {
                        Account  = this.teAccount.Text.Trim(),
                        Password = this.tePassword.Text.Trim()
                    };
                }
                else
                {
                    string oldPassword = GetTextEdit("teAddOldPassword");
                    if (string.IsNullOrEmpty(oldPassword))
                    {
                        XtraMessageBox.Show("Old Password is empty!", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    if (oldPassword != GlobalObject.User.Password)
                    {
                        XtraMessageBox.Show("Old Password is not correct!", "提示", MessageBoxButtons.OK);
                        return;
                    }

                    string newPassword = GetTextEdit("teAddNewPassword");
                    if (string.IsNullOrEmpty(newPassword))
                    {
                        XtraMessageBox.Show("New Password is empty!", "提示", MessageBoxButtons.OK);
                        return;
                    }
                    string confirmPassword = GetTextEdit("teAddConfirmPassword");
                    if (string.IsNullOrEmpty(confirmPassword))
                    {
                        XtraMessageBox.Show("Confirm Password is empty!", "提示", MessageBoxButtons.OK);
                        return;
                    }

                    if (newPassword != confirmPassword)
                    {
                        XtraMessageBox.Show("Password is  not the  same  with ConfirmPassword!", "提示", MessageBoxButtons.OK);
                        return;
                    }


                    _operation = "EditUser";
                    user       = new UserVM()
                    {
                        Account  = GlobalObject.User.Account,
                        Password = confirmPassword
                    };
                }

                if (_operation == "EditUser")
                {
                    user.ID = (this.gvUser.GetRow(gvUser.FocusedRowHandle) as UserVM).ID;
                }


                var result = 0;
                if (_operation == "EditUser")
                {
                    result = _bll.EditUser(user);
                }
                else
                {
                    result = _bll.AddUser(user);
                }
                if (result > 0)
                {
                    XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK);
                    if (GlobalObject.UserRoles.Any(p => p.RoleName != "admin"))
                    {
                        GlobalObject.User.Password = GetTextEdit("teNewPassword");
                        RememberPassword();
                    }
                    ClearText();
                    RequestGridData();
                }
                else
                {
                    XtraMessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK);
            }
        }