private void button1_Click(object sender, EventArgs e) { Agregar_productos_a_factura agregar = new Agregar_productos_a_factura(); agregar.ShowDialog(); detalleAgregado = Vista.iniciador.detalle; if (detalleAgregado != null) { foreach (DetalleFactura det in detalleAgregado) { Boolean result = false; int comparar = det.producto.idProducto; for (int c = 0; c < dgv_detalle.RowCount; c++) { if (comparar == (int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value) { result = true; break; } } if (result == false) { int idPro = det.producto.idProducto; int cod = det.producto.CODProducto; string nom = det.producto.Nombre; string uni = det.producto.Unidad.Nombre; double can = det.cantidad; double pre = det.producto.precio; double subTot = can * pre; if ((int)cmb_iva.SelectedValue == 1) { double iva=det.producto.precio*0.21; dgv_detalle.Rows.Add(cod, nom, uni, can, pre-iva, subTot, idPro, iva * det.cantidad,1); } else { dgv_detalle.Rows.Add(cod, nom, uni, can, pre, subTot, idPro, 0,1); } calcularMontoTotal(); } else { if ((int)cmb_iva.SelectedValue == 1) { for (int c = 0; c < dgv_detalle.RowCount; c++) { if ((int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value == det.producto.idProducto) { double can = (double)dgv_detalle.Rows[c].Cells["cantidad"].Value + det.cantidad; dgv_detalle.Rows[c].Cells["cantidad"].Value = can; double pre = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value; dgv_detalle.Rows[c].Cells["sub"].Value = can * det.producto.precio; double iva = det.producto.precio * 0.21; dgv_detalle.Rows[c].Cells["sinIva"].Value = can * iva; calcularMontoTotal(); } } } else { for (int c = 0; c < dgv_detalle.RowCount; c++) { if ((int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value == det.producto.idProducto) { double can = (double)dgv_detalle.Rows[c].Cells["cantidad"].Value + det.cantidad; dgv_detalle.Rows[c].Cells["cantidad"].Value = can; double pre = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value; dgv_detalle.Rows[c].Cells["sub"].Value = can * det.producto.precio; dgv_detalle.Rows[c].Cells["sinIva"].Value = 0; calcularMontoTotal(); } } } } } btn_agregar_a_factura.Enabled = false; } }
private void button1_Click(object sender, EventArgs e) { Agregar_productos_a_factura agregar = new Agregar_productos_a_factura(); agregar.ShowDialog(); detalleAgregado = Vista.iniciador.detalle; if (detalleAgregado != null) { foreach (DetalleFactura det in detalleAgregado) { Boolean result = false; int comparar = det.producto.idProducto; for (int c = 0; c < dgv_detalle.RowCount; c++) { if (comparar == (int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value) { result = true; break; } } if (result == false) { int idPro = det.producto.idProducto; int cod = det.producto.CODProducto; string nom = det.producto.Nombre; string uni = det.producto.Unidad.Nombre; double can = det.cantidad; double pre = det.producto.precio; double subTot = can * pre; if ((int)cmb_iva.SelectedValue == 1) { double iva = det.producto.precio * 0.21; dgv_detalle.Rows.Add(cod, nom, uni, can, pre - iva, subTot, idPro, iva * det.cantidad, 1); } else { dgv_detalle.Rows.Add(cod, nom, uni, can, pre, subTot, idPro, 0, 1); } calcularMontoTotal(); } else { if ((int)cmb_iva.SelectedValue == 1) { for (int c = 0; c < dgv_detalle.RowCount; c++) { if ((int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value == det.producto.idProducto) { double can = (double)dgv_detalle.Rows[c].Cells["cantidad"].Value + det.cantidad; dgv_detalle.Rows[c].Cells["cantidad"].Value = can; double pre = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value; dgv_detalle.Rows[c].Cells["sub"].Value = can * det.producto.precio; double iva = det.producto.precio * 0.21; dgv_detalle.Rows[c].Cells["sinIva"].Value = can * iva; calcularMontoTotal(); } } } else { for (int c = 0; c < dgv_detalle.RowCount; c++) { if ((int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value == det.producto.idProducto) { double can = (double)dgv_detalle.Rows[c].Cells["cantidad"].Value + det.cantidad; dgv_detalle.Rows[c].Cells["cantidad"].Value = can; double pre = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value; dgv_detalle.Rows[c].Cells["sub"].Value = can * det.producto.precio; dgv_detalle.Rows[c].Cells["sinIva"].Value = 0; calcularMontoTotal(); } } } } } btn_agregar_a_factura.Enabled = false; } }