public int InsertarDFactura(CEDetalleFactura objDf) { int resultado; SqlCommand cmd = new SqlCommand("Sp_InsertarDFactura", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@IdFactura", SqlDbType.NVarChar).Value = objDf.IdFactura; cmd.Parameters.AddWithValue("@IdProducto", SqlDbType.NVarChar).Value = objDf.IdProducto; cmd.Parameters.AddWithValue("@Cantidad", SqlDbType.VarChar).Value = objDf.Cantidad; try { ConectarBD(); resultado = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Error al tratar de almacenar", ex); } finally { DesconectarBD(); cmd.Dispose(); } return(resultado); }
private void agregarDgv() { for (int i = 0; i < 16; i++) { if (chkArray[i].Checked) { int sent = 0, pos = 0; btnFactura.Enabled = true; CEDetalleFactura det = new CEDetalleFactura(); CEProducto prod = new CEProducto(); CNProducto get = new CNProducto(); //asignar id a objeto producto, recuperar valores de la BD prod.IdProducto = i + 1; prod.Nombre = get.NombreProducto(prod.IdProducto); prod.Precio = get.PrecioProducto(prod.IdProducto); //Agregar fila a detalle factura det.IdProducto = prod.IdProducto; det.Cantidad = int.Parse(nudArray[i].Value.ToString()); DataGridViewRow row = (DataGridViewRow)dgvDetalleFactura.Rows[0].Clone(); row.Cells[0].Value = prod.Nombre; row.Cells[1].Value = nudArray[i].Value; row.Cells[2].Value = prod.Precio; row.Cells[3].Value = prod.Precio * nudArray[i].Value; dgvDetalleFactura.Rows.Add(row); for (int j = 0; j < detallesFactura.Count; j++) { if (detallesFactura[j].IdProducto == det.IdProducto) { sent = 1; pos = j; } } if (sent == 1) { detallesFactura[pos].Cantidad += det.Cantidad; } else { detallesFactura.Add(det); } } } }
public int InsertarDFactura(CEDetalleFactura objDf) { return(objDf1.InsertarDFactura(objDf)); }