private void btnAceptar_Click(object sender, EventArgs e) { if (operacion == 1) // Modificar { // U = new Usuario(); if (this.LeerControles() == false) { return; } UsuarioNegocio UsuarioNegocio = new UsuarioNegocio(); if (UsuarioNegocio.Escribir(U) == false) { MessageBox.Show("Error al modificar"); return; } MessageBox.Show("Modificación exitosa"); int idu = U.id; this.cbxUsuario.DataSource = UsuarioNegocio.Leer_Todos(); for (int i = 0; i < cbxUsuario.Items.Count; i++) { Usuario aux = (Usuario)cbxUsuario.Items[i]; if (aux.id == idu) { cbxUsuario.SelectedIndex = i; break; } } this.btnBuscar.Enabled = true; if (id == 2) { this.btnAgregar.Enabled = true; } this.btnAceptar.Visible = false; this.btnCancelar.Visible = false; this.cbxTipoUsuario.Enabled = false; this.tbxClave.Enabled = false; this.tbxNombre.Enabled = false; this.chbBaja.Enabled = false; } if (operacion == 2) // Baja usuario { UsuarioNegocio UsuarioNegocio = new UsuarioNegocio(); if (UsuarioNegocio.Eliminar(U) == false) { MessageBox.Show("Error al eliminar"); } else { MessageBox.Show("Eliminación exitosa"); this.cbxUsuario.DataSource = UsuarioNegocio.Leer_Todos(); if (this.cbxUsuario.Items.Count > 0) { this.cbxUsuario.SelectedIndex = 0; } } this.btnCancelar.Visible = false; this.btnAceptar.Visible = false; this.btnBuscar.Enabled = true; this.btnAgregar.Enabled = true; } if (operacion == 3) // Alta Usuario { if (this.Existe(this.tbxNombre.Text.Trim()) == true) { MessageBox.Show("El usuario existe"); this.btnCancelar.Visible = false; this.btnAceptar.Visible = false; this.btnBuscar.Enabled = true; this.btnAgregar.Enabled = true; this.tbxClave.Enabled = false; this.tbxNombre.Enabled = false; this.cbxTipoUsuario.Enabled = false; this.cbxUsuario.Enabled = false; this.chbBaja.Enabled = false; return; } U = new Usuario(); if (this.LeerControlesAlta(ref U) == false) { return; } UsuarioNegocio UsuarioNegocio = new UsuarioNegocio(); if (UsuarioNegocio.Agregar(U) == false) { MessageBox.Show("Error al agregar"); this.btnCancelar.Visible = false; this.btnAceptar.Visible = false; this.btnBuscar.Enabled = true; this.btnAgregar.Enabled = true; this.tbxClave.Enabled = false; this.tbxNombre.Enabled = false; this.cbxTipoUsuario.Enabled = false; this.cbxUsuario.Enabled = false; this.chbBaja.Enabled = false; return; } string n = U.nombre; this.cbxUsuario.DataSource = UsuarioNegocio.Leer_Activos(); for (int i = 0; i < cbxUsuario.Items.Count; i++) { Usuario aux = (Usuario)cbxUsuario.Items[i]; if (aux.nombre.CompareTo(n) == 0) { cbxUsuario.SelectedIndex = i; break; } } this.btnCancelar.Visible = false; this.btnAceptar.Visible = false; this.btnBuscar.Enabled = true; this.btnAgregar.Enabled = true; this.tbxClave.Enabled = false; this.tbxNombre.Enabled = false; this.cbxTipoUsuario.Enabled = false; this.cbxUsuario.Enabled = false; this.chbBaja.Enabled = false; } }