private void btSaveUser_Click(object sender, EventArgs e) { if (!xValidateInputUser()) { return; } var mUser = new MUser(); mUser.UserName = txtUserName.Text.Trim(); mUser.Password = txtPassword.Text; mUser.FullName = txtFullName.Text; mUser.Email = txtEmail.Text; mUser.Role = cboRole.SelectedItem.ToString() == LanguageHelper.GetValueOf("USERS_CBOROLE_ADMIN") ? (int)emModeApp.Admin : (int)emModeApp.User; mUser.UpdateTime = DateTime.Now; this.SetModeWaiting(); try { using (var objDB = AppManager.GetConnection()) { if (_mode == emModeForm.CreateNewUser) { if (!objDB.InserUser(mUser)) { ShowMsg(MessageBoxIcon.Error, LanguageHelper.GetValueOf("MSG_INSERT_ERR")); return; } } else { mUser.UserId = _userId; if (!objDB.UpdateUser(mUser)) { ShowMsg(MessageBoxIcon.Error, LanguageHelper.GetValueOf("MSG_UPDATE_ERR")); return; } } _mode = emModeForm.UpdateUser; InitDataUserToGrvUser(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { this.SetModeWaiting(false); } }
private void xModeUser(emModeForm mode) { _mode = mode; if (_mode == emModeForm.CreateNewUser) { txtUserName.Text = string.Empty; txtPassword.Text = string.Empty; txtFullName.Text = string.Empty; txtEmail.Text = string.Empty; cboRole.SelectedIndex = 0; txtUserName.ReadOnly = false; cboRole.Enabled = true; } else { txtUserName.ReadOnly = true; } }