private void BtnQuitarProducto_Click(object sender, EventArgs e) { if (DtvFactura.Rows.Count > 0) { try { if (DtvFactura.SelectedRows.Count > 0) { V_IDDetalleVenta = DtvFactura.CurrentRow.Cells["ID_DetalleVenta"].Value.ToString(); V_IDProductoDetalle = DtvFactura.CurrentRow.Cells["ID_Producto"].Value.ToString(); V_CantidadProductoDetalle = DtvFactura.CurrentRow.Cells["Cantidad"].Value.ToString(); INST_EliminarProductoDetalleVenta.MET_EliminarProductoDetalleVenta(V_IDDetalleVenta, V_IDProductoDetalle, V_CantidadProductoDetalle); MessageBox.Show("SE ELIMINO EL PRODUCTO DE LA FACTURA"); MET_MostrarProductos(); MET_MostrarDetalleVenta(); TotalITBIS = 0; TotalSUBTOTAL = 0; TotalVenta = 0; MET_CalcularITBIS_SUBTOTAL(); if (DtvFactura.Rows.Count <= 0) { TxtITBIS.Clear(); TxtSUBTOTAL.Clear(); TxtTotal.Clear(); } } else { MessageBox.Show("SELECCIONE EL PRODUCTO QUE DESEA ELIMINAR DE LA FACTURA"); } } catch (Exception) { MessageBox.Show("Hay Un error en los datos introducidos.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (DtvFactura.Rows.Count <= 0) { MessageBox.Show("NO HAY NINGUN PRODUCTO QUE ELIMINAR"); return; } }
private void BtnDevolver_Click(object sender, EventArgs e) { BtnBuscar.Visible = false; BtnListo.Visible = true; TxtIDFactura.ReadOnly = true; if (DtvDetallesVenta.SelectedRows.Count > 0) { V_IDDetalleVenta = DtvDetallesVenta.CurrentRow.Cells["ID_DetalleVenta"].Value.ToString(); V_IDProducto = DtvDetallesVenta.CurrentRow.Cells["ID_Producto"].Value.ToString(); V_CantidadProductoDetalle = DtvDetallesVenta.CurrentRow.Cells["Cantidad"].Value.ToString(); V_PrecioProducto = DtvDetallesVenta.CurrentRow.Cells["Precio"].Value.ToString(); if (Convert.ToInt32(TxtCantidadADevolver.Text) == Convert.ToInt32(V_CantidadProductoDetalle)) { //ELIMINA EL PRODUCTO DE LOS DETALLES DE VENTA SI SE DEVUELVE TODO CN_Acciones INST_DevolverTodoProductoDetalleVenta = new CN_Acciones(); INST_DevolverTodoProductoDetalleVenta.MET_EliminarProductoDetalleVenta(V_IDDetalleVenta, V_IDProducto, V_CantidadProductoDetalle); try { CN_Acciones INST_Insertar_Detalle_Devolucion = new CN_Acciones(); INST_Insertar_Detalle_Devolucion.MET_InsertarDetalleDevolucion(Convert.ToInt32(V_ID_Devolucion), Convert.ToInt32(TxtIDFactura.Text), Convert.ToInt32(V_IDDetalleVenta), Convert.ToInt32(V_IDProducto), Convert.ToDouble(V_PrecioProducto), Convert.ToInt32(TxtCantidadADevolver.Text)); MET_MostrarDetalleVenta(); MET_CalcularITBIS_SUBTOTAL(); } catch (Exception Error) { MessageBox.Show("OCURRIO UN ERROR " + Error); } try { //EDITA LA FACTURA SI SE ELIMINA SI SE DEVUELDE UN EL PRODUCTO CN_Acciones INST_EditarFacturaDevolucion = new CN_Acciones(); INST_EditarFacturaDevolucion.MET_EditarFacturaDevolucion( Convert.ToDouble(TxtITBIS.Text), Convert.ToDouble(TxtSUBTOTAL.Text), Convert.ToDouble(TxtTotal.Text), TxtIDFactura.Text); MessageBox.Show("SE EDITO LA FACTURA"); } catch (Exception Error) { MessageBox.Show("OCURRIO UN ERROR " + Error); } TotalCredito += (Convert.ToDouble(V_PrecioProducto) * Convert.ToInt32(TxtCantidadADevolver.Text)); TxtCredito.Text = Convert.ToString(TotalCredito); try { CN_Acciones INST_EditarDevolucionAgregarCredito = new CN_Acciones(); INST_EditarDevolucionAgregarCredito.MET_EditarDevolucionAgregarCredito( Convert.ToDouble(TxtCredito.Text), Convert.ToInt32(V_ID_Devolucion)); } catch (Exception Error) { MessageBox.Show("OCURRIO UN ERROR " + Error); } } else if (Convert.ToInt32(TxtCantidadADevolver.Text) > Convert.ToInt32(V_CantidadProductoDetalle)) { MessageBox.Show("LA ANTIDAD A DEVOLVER NO PUEDE SER MAYOR QUE LA CANTIDAD DE PRODUCTO VENDIDA"); return; } else if (Convert.ToInt32(TxtCantidadADevolver.Text) < Convert.ToInt32(V_CantidadProductoDetalle)) { try { CN_Acciones INST_DevolverMenosProductoDetalleVenta = new CN_Acciones(); INST_DevolverMenosProductoDetalleVenta.MET_InsertarDetalleDevolucionCuandoNoSeDevuelveTodo( Convert.ToInt32(V_ID_Devolucion), Convert.ToInt32(TxtIDFactura.Text), Convert.ToInt32(V_IDDetalleVenta), Convert.ToInt32(V_IDProducto), Convert.ToDouble(V_PrecioProducto), Convert.ToInt32(TxtCantidadADevolver.Text)); MET_MostrarDetalleVenta(); MET_CalcularITBIS_SUBTOTAL(); } catch (Exception Error) { MessageBox.Show("OCURRIO UN ERROR " + Error); } try { //EDITA LA FACTURA SI SE ELIMINA SI SE DEVUELDE UN EL PRODUCTO CN_Acciones INST_EditarFacturaDevolucion = new CN_Acciones(); INST_EditarFacturaDevolucion.MET_EditarFacturaDevolucion( Convert.ToDouble(TxtITBIS.Text), Convert.ToDouble(TxtSUBTOTAL.Text), Convert.ToDouble(TxtTotal.Text), TxtIDFactura.Text); MessageBox.Show("SE EDITO LA FACTURA"); } catch (Exception Error) { MessageBox.Show("OCURRIO UN ERROR " + Error); } } TotalCredito += (Convert.ToDouble(V_PrecioProducto) * Convert.ToInt32(TxtCantidadADevolver.Text)); TxtCredito.Text = Convert.ToString(TotalCredito); try { CN_Acciones INST_EditarDevolucionAgregarCredito = new CN_Acciones(); INST_EditarDevolucionAgregarCredito.MET_EditarDevolucionAgregarCredito( Convert.ToDouble(TxtCredito.Text), Convert.ToInt32(V_ID_Devolucion)); } catch (Exception Error) { MessageBox.Show("OCURRIO UN ERROR " + Error); } MessageBox.Show("SE DEVOLVIO EL PRODUCTO"); //MET_MostrarDetalleVenta(); //MET_CalcularITBIS_SUBTOTAL(); } else { MessageBox.Show("SELECCIONE EL PRODUCTO QUE DESEA ELIMINAR DE LA FACTURA"); } MET_MostrarDevolucionImpresa(); }