コード例 #1
0
    protected void SaveButton_Click(object sender, EventArgs e)
    {
        PanelError.Visible = false;
        try
        {
            decimal precio = Convert.ToDecimal(PrecioTextBox.Text, CultureInfo.InvariantCulture);
            int     stock  = Convert.ToInt32(StockTextBox.Text);

            int      productoId = this.ProductoId;
            Producto obj        = new Producto()
            {
                ProductoId = productoId,
                Nombre     = NombreTextBox.Text,
                Precio     = precio,
                Stock      = stock
            };

            if (productoId > 0)
            {
                ProductoBRL.UpdateProducto(obj);
            }
            else
            {
                ProductoBRL.InsertProducto(obj);
            }
        }
        catch (Exception ex)
        {
            MsgLiteral.Text    = "Error al guardar el producto";
            PanelError.Visible = true;
            return;
        }

        Response.Redirect("ListProductos.aspx");
    }
コード例 #2
0
    protected void ProductosGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int productoId = 0;

        try
        {
            productoId = Convert.ToInt32(e.CommandArgument);
        }
        catch (Exception ex)
        {
        }
        if (productoId <= 0)
        {
            return;
        }
        if (e.CommandName == "Editar")
        {
            Response.Redirect("DetalleProducto.aspx?ProductoId=" + productoId);
            return;
        }
        if (e.CommandName == "Eliminar")
        {
            try
            {
                ProductoBRL.DeleteProducto(productoId);
                CargarProductos();
            }
            catch (Exception ex)
            {
            }
        }
    }
コード例 #3
0
 private void CargarProductos()
 {
     try
     {
         List <Producto> productos = ProductoBRL.GetProductos();
         ProductosGridView.DataSource = productos;
         ProductosGridView.DataBind();
     }
     catch (Exception ex)
     {
     }
 }
コード例 #4
0
 private void CargarDatos(int productoId)
 {
     try
     {
         Producto obj = ProductoBRL.GetProductoById(productoId);
         NombreTextBox.Text = obj.Nombre;
         PrecioTextBox.Text = obj.Precio.ToString(CultureInfo.InvariantCulture);
         StockTextBox.Text  = obj.Stock.ToString();
     }
     catch (Exception ex)
     {
         MsgLiteral.Text    = "Error al obtener el Producto";
         PanelError.Visible = true;
     }
 }