private void btnGuardar_Click(object sender, EventArgs e) { try { string rpta = ""; if (this.txtnombre.Text == string.Empty) { MensajeError("Falta Ingresar algunos datos, serán remarcados"); erroricono.SetError(txtnombre, "Ingrese un Nombre"); } if (this.txtidcarrera.Text == string.Empty) { MensajeError("Falta Ingresar algunos datos, serán remarcados"); erroricono.SetError(txtidcarrera, "Ingrese el codigo de la carrera"); } else { if (this.IsNuevo) { rpta = LCarrera.insertar(this.txtidcarrera.Text.Trim().ToUpper(), this.txtnombre.Text.Trim().ToUpper()); } if (this.IsEditar) { rpta = LCarrera.editar(this.txtidcarrera.Text.Trim().ToUpper(), this.txtnombre.Text.Trim().ToUpper()); } // validar si se inserto correctamente el registro if (rpta.Equals("OK")) { if (this.IsNuevo) { MensajeOk("Se insertó de forma correcta el registro"); } else { MensajeOk("Se actualizó de forma correcta el registro"); } } // si es error else { this.MensajeError(rpta); } this.IsNuevo = false; this.IsEditar = false; this.Botones(); this.Limpiar(); this.Mostrar(); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void btnEliminar_Click(object sender, EventArgs e) { try { DialogResult Opcion; Opcion = MessageBox.Show("¿Realmente desea eliminar los registros?", "Sistema de Ventas", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (Opcion == DialogResult.OK) { string Rpta = ""; string codigo; int cont_eliminados = 0; foreach (DataGridViewRow row in dataListado.Rows) { if (Convert.ToBoolean(row.Cells[0].Value)) { codigo = Convert.ToString(row.Cells[1].Value); Rpta = LCarrera.eliminar(codigo); if (Rpta.Equals("OK")) { cont_eliminados++; } else { this.MensajeError(Rpta); } } } // show messages deletes if (cont_eliminados > 0) { if (cont_eliminados == 1) { this.MensajeOk("Se elimino un registro"); } else { this.MensajeOk("Se eliminaron " + cont_eliminados + " registros"); } } this.chkeliminar.Checked = false; this.Mostrar(); } } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }
private void llenar_combo() { this.cbcarrera.DataSource = LCarrera.mostrar(); this.cbcarrera.DisplayMember = "idcarrera"; this.cbcarrera.ValueMember = "idcarrera"; }
// Método mostrar private void Mostrar() { this.dataListado.DataSource = LCarrera.mostrar(); this.OcultarColumnas(); lblTotal.Text = "Total de Registros : " + Convert.ToString(dataListado.Rows.Count); }
private void BuscarNombre() { this.dataListado.DataSource = LCarrera.buscar_nombre(this.txtBuscar.Text); this.OcultarColumnas(); lblTotal.Text = "Total de Registros : " + Convert.ToString(dataListado.Rows.Count); }