protected void btnAgregarproducto_Click(object sender, EventArgs e) { string sRes = ValidarDatos(); if (sRes == "") { SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings.Get("connectionString")); cn.Open(); SqlTransaction trx = cn.BeginTransaction(); try { DetalleVenta detalle = new DetalleVenta(); Producto producto = new Producto(); producto.Id = Convert.ToInt32(hdnProductoId.Value); DataSet dsProducto = EditProducto.GetProducto(producto); detalle.Producto = producto; detalle.VentaId = Convert.ToInt32(txtVentaId.Text); detalle.PrecioCosto = Convert.ToDouble(dsProducto.Tables[0].Rows[0]["PrecioCosto"]); detalle.PrecioVendido = Convert.ToDouble(dsProducto.Tables[0].Rows[0]["PrecioVenta"]); detalle.CantidadUnidades = Convert.ToInt32(txtCantidad.Text); int detalleVentaId = EditDetalleVenta.InsertarDetalle(detalle, trx, cn); if (detalleVentaId > 0) { trx.Commit(); CargarDetalleVenta(Convert.ToInt32(txtVentaId.Text)); txtStock.Text = ""; txtCantidad.Text = ""; txtProducto.Text = ""; hdnProductoId.Value = ""; } else { trx.Rollback(); messageBox.ShowMessage("No se pudo insertar el detalle, intente nuevamente"); } } catch (Exception ex) { trx.Rollback(); messageBox.ShowMessage(ex.Message + ex.StackTrace); } finally { if (null != cn) { cn.Close(); } } } else { messageBox.ShowMessage(sRes); } }
private void CargarDatos(int ProductoId) { Producto producto = new Producto(); producto.Id = ProductoId; DataSet ds = EditProducto.GetProducto(producto); DataRow dr = ds.Tables[0].Rows[0]; txtId.Text = ProductoId.ToString(); // txtCodigo.Text = dr["Codigo"].ToString(); txtDescripcion.Text = dr["Descripcion"].ToString(); ddlTipo.SelectedValue = dr["TipoId"].ToString(); //txtColor.Text = dr["ColorDescripcion"].ToString(); //ddlTalle.SelectedValue = dr["TalleId"].ToString(); txtPrecioCosto.Text = dr["PrecioCosto"].ToString(); txtPorcGanancia.Text = dr["PorcGanancia"].ToString(); txtPrecioVenta.Text = dr["PrecioVenta"].ToString(); txtStockActual.Text = dr["StockActual"].ToString(); txtPorcDescuento.Text = dr["PorcDescuento"].ToString(); txtCompra.Text = dr["CompraDescripcion"].ToString(); hdnCompraId.Value = dr["CompraId"].ToString(); }