Ejemplo n.º 1
0
 public static int EliminarDetalleVenta(DetalleVenta detalle)
 {
     SqlParameter[] dbParams = new SqlParameter[]
         {
              DBHelper.MakeParam("@DetalleVentaId", SqlDbType.Int, 0, detalle.Id),
         };
     return Convert.ToInt32(DBHelper.ExecuteScalar("usp_EditDetalleVenta_EliminarDetalleVenta", dbParams));
 }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        public static int DisminuirStock(DetalleVenta detalle, SqlTransaction trx, SqlConnection cn)
        {
            SqlParameter[] dbParams = new SqlParameter[]
                {
                    // , , , , ,
                    DBHelper.MakeParam("@ProductoId", SqlDbType.Int, 0, detalle.Producto.Id),
                    DBHelper.MakeParam("@CantidadUnidades", SqlDbType.Int, 0, detalle.CantidadUnidades),

                };
            return Convert.ToInt32(DBHelper.ExecuteScalar("usp_AddVenta_DisminuirStock", dbParams, trx, cn));
        }
Ejemplo n.º 4
0
        public static int InsertarDetalle(DetalleVenta detalle, SqlTransaction trx, SqlConnection cn)
        {
            SqlParameter[] dbParams = new SqlParameter[]
                {
                    // , , , , ,
                    DBHelper.MakeParam("@ProductoId", SqlDbType.Int, 0, detalle.Producto.Id),
                    DBHelper.MakeParam("@CantidadUnidades", SqlDbType.Int, 0, detalle.CantidadUnidades),
                    DBHelper.MakeParam("@Descuento", SqlDbType.Decimal, 0, detalle.PorcDescuento),
                    DBHelper.MakeParam("@PrecioCosto", SqlDbType.Decimal, 0, detalle.PrecioCosto),
                    DBHelper.MakeParam("@PrecioVendido", SqlDbType.Decimal, 0, detalle.PrecioVendido),
                    DBHelper.MakeParam("@VentaId", SqlDbType.Int, 0, detalle.VentaId),
                };
            int DetalleVentaId = Convert.ToInt32(DBHelper.ExecuteScalar("usp_AddVenta_InsertarDetalle", dbParams, trx, cn));
            if (DetalleVentaId > 0)
            {
                if (DisminuirStock(detalle, trx, cn) == 0)
                {
                    throw new Exception("Hubo un error en la disminucion de stock " + detalle.Producto.Descripcion);
                }
            }

            return DetalleVentaId;
        }
Ejemplo n.º 5
0
        protected void gridDetalle_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
               if (e.CommandName == "EliminarDetalle")
                {
                    DetalleVenta detalle= new DetalleVenta();
                    detalle.Id = Convert.ToInt32(e.CommandArgument.ToString());

                    if (EditDetalleVenta.EliminarDetalleVenta(detalle) > 0)
                    {
                        CargarDetalleVenta(Convert.ToInt32(txtVentaId.Text));
                    }
                    else
                    {
                        messageBox.ShowMessage("No se pudo eliminar el detalle. Intente nuevamente.");
                    }
                }
            }
            catch (Exception ex)
            {
                messageBox.ShowMessage(ex.Message + ex.StackTrace);
            }
        }