private void buttonAccept_Click(object sender, EventArgs e) { UsuarioDatos userData = this.getDataFromForm(); string rol = ""; if (userData != null) { if (txtPassword.Text != "" || edit) { if (!edit && UsuarioHelper.existUser(userData.username)) { MessageBox.Show("El nombre de usuario ingresado ya existe"); return; } if (rolesList.CheckedItems.Count > 0) { UsuarioHelper.disableAll(userData.username, VarGlobal.usuario.hotel); for (int i = 0; i <= rolesList.CheckedItems.Count - 1; i++) { rol = rolesList.GetItemText(rolesList.CheckedItems[i]); UsuarioDatosHelper.save(userData, VarGlobal.usuario.hotel, rol, txtPassword.Text); } if (edit) { MessageBox.Show("Modificacion de usuario realizada con exito"); } else { MessageBox.Show("Creacion de usuario realizada con exito"); } this.closeWindow(); } else { MessageBox.Show("Debe seleciconar algun rol"); } } } }
private void FormABMUsuarioModify_Load(object sender, EventArgs e) { this.ControlBox = false; this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; Roles.fillCheckedListBox(rolesList); Documentos.fillComboBox(comboBoxDocumentType); if (edit) { UsuarioDatos userData = UsuarioDatosHelper.getUserData(user); this.txtAddress.Text = userData.address; this.txtDocumentNumber.Text = userData.documentNumber.ToString(); this.txtMail.Text = userData.mail; this.txtNameLastname.Text = userData.nameLastname; this.txtPassword.Enabled = false; this.txtTelephone.Text = userData.telephone; this.txtUsername.Text = userData.username; this.txtUsername.Enabled = false; this.comboBoxDocumentType.SelectedIndex = this.comboBoxDocumentType.FindStringExact(userData.typeDocumentDescription); this.checkBoxEnable.Checked = userData.enabled; this.dtBirthDate.Value = userData.birthDate; List <string> roles = UsuarioHelper.getRolByUserHotel(user, VarGlobal.usuario.hotel); if (roles.Count > 0) { for (int i = 0; i <= rolesList.Items.Count - 1; i++) { if (roles.Contains(rolesList.GetItemText(rolesList.Items[i]))) { rolesList.SetItemChecked(i, true); } } } } }