//MOSTRAR public void Mostrar() { dgvListado.DataSource = NegocioIngreso.Mostrar(); if (dgvListado.Rows.Count > 0) { lblSinIngresos.Visible = false; } OcultarColumnas(); NombreColumnas(); }
private void btnEliminar_Click(object sender, EventArgs e) { int idIngreso; string respuesta = ""; DialogResult Opcion; frmIngresarCliente formIngresarCliente = new frmIngresarCliente(); try { //SELECCION DE VARIOS REGISTROS if (chkEliminarVarios.Checked) { Opcion = MessageBox.Show( "¿Realmente desea anular los registros seleccionados?. Tenga en cuenta que al anular este ingreso el stock actual de los productos relacionados se restará", "Anulando registro. ¡Advertencia!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (Opcion == DialogResult.Yes) { foreach (DataGridViewRow row in dgvListado.Rows) { if (Convert.ToBoolean(row.Cells[0].Value)) { idIngreso = Convert.ToInt32(row.Cells[1].Value); respuesta = NegocioIngreso.Anular(idIngreso); //DataTable Detalle = new DataTable(); DataTable Detalle = NegocioIngreso.Mostrar(idIngreso); foreach (DataRow det in Detalle.Rows) { int idArticulo = Convert.ToInt32(det["IdArticulo"]); decimal cantidad = Convert.ToDecimal(det["Cantidad"]); respuesta = NegocioArticulo.DisminuirStock(idArticulo, cantidad); } } } if (respuesta.Equals("OK")) { formIngresarCliente.NotificacionOk("Los registros se anularon correctamente.", "Anulando"); } else { formIngresarCliente.NotificacionError("Los registros no se anularon.", "Error"); } Mostrar(); } } else { //SELECCION DE UN REGISTRO Opcion = MessageBox.Show( "¿Realmente desea anular los registros seleccionados?. Tenga en cuenta que al anular este ingreso el stock actual de los productos relacionados se restará", "Anulando registro. ¡Advertencia!", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (Opcion == DialogResult.Yes) { idIngreso = Convert.ToInt32(dgvListado.CurrentRow.Cells[1].Value); respuesta = NegocioIngreso.Anular(Convert.ToInt32(idIngreso)); DataTable Detalle = NegocioIngreso.Mostrar(idIngreso); foreach (DataRow det in Detalle.Rows) { int idArticulo = Convert.ToInt32(det["IdArticulo"]); decimal cantidad = Convert.ToDecimal(det["Cantidad"]); respuesta = NegocioArticulo.DisminuirStock(idArticulo, cantidad); } if (respuesta.Equals("OK")) { formIngresarCliente.NotificacionOk("El registro se anuló correctamente", "Anulando"); } else { formIngresarCliente.NotificacionError("El registro no se anuló", "Error"); } Mostrar(); } } chkEliminarVarios.Checked = false; } catch (Exception ex) { MessageBox.Show(ex.Message + ex.StackTrace); } }