private void btnAgregar_Click(object sender, EventArgs e) { errorProvider.Clear(); if (txtCod_Factura.Text == string.Empty) { errorProvider.SetError(txtCod_Factura, "Debe agregar un codigo"); } if (txtPrecio.Text == string.Empty) { errorProvider.SetError(txtPrecio, "Debe ingresar el precio"); } if (txtCantidad.Text == string.Empty) { errorProvider.SetError(txtCantidad, "Debe ingresar una cantidad"); } if (txtValor_Total.Text == string.Empty) { errorProvider.SetError(txtValor_Total, "Debe calcular el valor"); } else { DetalleFactura fac = new DetalleFactura(); fac.CodFactura = Convert.ToInt32(txtCod_Factura.Text); fac.NombreProducto = cbProducto.Text; fac.Precio = Convert.ToDecimal(txtPrecio.Text); fac.Cantidad = Convert.ToInt32(txtCantidad.Text); Productos.Add(fac); //int n = dgFactura.Rows.Add(); dgFactura.DataSource = null; dgFactura.DataSource = Productos; //dgFactura.Rows[n].Cells[4].Value = txtValor_Total.Text; dgFactura.Columns[0].Visible = false; txtCod_Factura.Text = ""; txtPrecio.Text = ""; txtCantidad.Text = ""; txtValor_Total.Text = ""; ////decimal total = 0; ////foreach (DataGridViewRow row in dgFactura.Rows) ////{ //// total += Convert.ToDecimal(row.Cells["ValorTotal"].Value); ////} ////txtTotal.Text = Convert.ToString(total); ////txtTotal.Refresh(); decimal total = 0; foreach (DataGridViewRow row in dgFactura.Rows) { //total += Convert.ToDecimal(row.Cells["ValorTotal"].Value); total += Convert.ToDecimal(row.Cells["Precio"].Value.ToString()) * Convert.ToDecimal(row.Cells["Cantidad"].Value.ToString()); } txtTotal.Text = Convert.ToString(total); } }
public DetalleFacturaExt(DetalleFactura detalleFactura) { this.detalleFactura = detalleFactura; }