Exemple #1
0
    protected void btnAgregar_Click(object sender, EventArgs e)
    {
        PruebaLINQ linq = new PruebaLINQ();

        int filas = linq.agregarProducto(
            ProductName.Text,
            int.Parse(SupplierID.SelectedValue.ToString()),
            int.Parse(CategoryID.SelectedValue.ToString()),
            QuantityPerUnit.Text,
            Decimal.Parse(UnitPrice.Text.ToString()),
            short.Parse(UnitsInStock.Text.ToString()),
            short.Parse(UnitsOnOrder.Text.ToString())
            );

        if (filas != 0)
        {
            Response.Redirect("Default.aspx");
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert", "alert('Error al guardar los datos');", true);
        }
    }
    protected void btnModificar_Click(object sender, EventArgs e)
    {
        PruebaLINQ linq = new PruebaLINQ();

        bool estado = linq.actualizarProducto(
            int.Parse(ProductID.Value),
            ProductName.Text,
            int.Parse(SupplierID.SelectedValue.ToString()),
            int.Parse(CategoryID.SelectedValue.ToString()),
            QuantityPerUnit.Text,
            Decimal.Parse(UnitPrice.Text.ToString()),
            short.Parse(UnitsInStock.Text.ToString()),
            short.Parse(UnitsOnOrder.Text.ToString())
            );

        if (estado)
        {
            Response.Redirect("Default.aspx");
        }
        else
        {
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "error_msg", "alert('Error al modificar el producto');", true);
        }
    }