/// <summary> /// 确定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonOK_Click(object sender, EventArgs e) { //登录名 string loginname = _txtLoginName.Text; //密码 string password = _txtPassWord.Text; //所属用户组 string groupname = _cboGroup.Text; //权限 string permission = _cboPermission.Text; //备注 string remarks = _rtxtRemark.Text; //用户登录名不能包含特殊字符且不能为空 //查空、特殊字符 if (LibCommon.Validator.checkSpecialCharacters(_txtLoginName.Text.ToString()) || LibCommon.Validator.IsEmpty(_txtLoginName.Text.ToString())) { Alert.alert(LibCommon.Const.LOGIN_NAME_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning); _txtLoginName.Focus(); return; } //添加时查重 if (_strIsAddOrModify == "add") { UserLogin entAdd = UserLogin.FindOneByLoginName(_txtLoginName.Text.ToString().Trim()); if (entAdd != null) { if (entAdd.LoginName == _txtLoginName.Text.ToString()) { Alert.alert(LibCommon.Const.LOGIN_NAME_EXIST, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning); _txtLoginName.Focus(); return; } } } //修改 else if (_strIsAddOrModify == "modify") { UserLogin entModify = UserLogin.Find(_needModifyEnt.Id); if (entModify != null) { Alert.alert(LibCommon.Const.LOGIN_NAME_EXIST, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning); _txtLoginName.Focus(); return; } } //密码不能包含特殊字符且不能为空 if (LibCommon.Validator.checkSpecialCharacters(password) || LibCommon.Validator.IsEmptyOrBlank(password)) { Alert.alert(LibCommon.Const.PASS_WORD_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning); _txtPassWord.Focus(); return; } //确认密码不能为空且必须与密码值相同 if (_txtConfirmPassword.Text != _txtPassWord.Text) { Alert.alert(LibCommon.Const.CONFIRM_PASSWORD_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning); _txtConfirmPassword.Focus(); return; } //权限选择不能为空 if (_cboPermission.SelectedItem == null) { Alert.alert(LibCommon.Const.PERMISSION_IS_WRONG, LibCommon.Const.NOTES, MessageBoxButtons.OK, MessageBoxIcon.Warning); _cboPermission.Focus(); return; } //定义用户实体 UserLogin ent = new UserLogin(); //登录名 ent.LoginName = loginname; //密码 ent.PassWord = password; //权限 ent.Permission = permission; //所属用户组 ent.GroupName = groupname; //备注 ent.Remarks = remarks; //尚未登录系统,在插入新值时,默认为True ent.IsLogined = 0; //记住密码,在插入新值时,默认为False ent.IsSavePassWord = 0; //添加 if (_strIsAddOrModify == "add") { //数据库插值 ent.Save(); UserGroupInformationManagementBLL.UpdateUserCountFromUserGroup(ent.GroupName); } //修改 if (_strIsAddOrModify == "modify") { //数据库更新,ent代表修改的实体,参数2代表LoginName UserLogin.FindOneByLoginName(UserLoginInformationManagement._userSel[0]); ent.LoginName = loginname; ent.PassWord = password; ent.Permission = permission; ent.GroupName = groupname; ent.Remarks = remarks; ent.IsLogined = 0; ent.IsSavePassWord = 0; ent.Save(); } //初次登录系统时,需要添加新用户。记录初次登录的用户名与密码,并直接输入到LoginForm中 if (LibCommon.Const.FIRST_TIME_LOGIN) { LibCommon.Const.FIRST_LOGIN_NAME = ent.LoginName; LibCommon.Const.FIRST_LOGIN_PASSWORD = ent.PassWord; LibCommon.Const.FIRST_LOGIN_PERMISSION = ent.Permission; this.Close(); return; } this.Close(); }