Esempio n. 1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            OrdenBLL ordBLL = new OrdenBLL();

            //ordBLL.creaOrden();
            if (Session["numero_boleta"] == null)
            {
            }
            else if (Session["numero_boleta"] != null && GridView1.Rows.Count > 0)
            {
                string faltaStock = "";
                foreach (GridViewRow row in GridView1.Rows)
                {
                    int    id  = int.Parse(row.Cells[1].Text);
                    string cat = row.Cells[3].Text;
                    if (cat != "bebible")
                    {
                        PlatoBLL plaBLL          = new PlatoBLL();
                        int      stockactual     = plaBLL.verificaStock(id);
                        int      stockSolicitado = int.Parse(((TextBox)row.Cells[5].FindControl("TextBox1")).Text);
                        if (stockactual < stockSolicitado)
                        {
                            faltaStock = faltaStock + row.Cells[2].Text + " Stock Actual: " + stockactual + "\\n ";
                        }
                    }
                    else if (cat == "bebible")
                    {
                        BebestibleBLL bebesBLL        = new BebestibleBLL();
                        int           stockactual     = bebesBLL.verificaStock(id);
                        int           stockSolicitado = int.Parse(((TextBox)row.Cells[5].FindControl("TextBox1")).Text);
                        if (stockactual < stockSolicitado)
                        {
                            faltaStock = faltaStock + row.Cells[2].Text + " Stock Actual: " + stockactual + "\\n ";
                        }
                    }
                }



                if (faltaStock.Length <= 0)
                {
                    bool check = ordBLL.creaOrden(int.Parse(Session["numero_boleta"].ToString()));
                    if (check)
                    {
                        foreach (GridViewRow row in GridView1.Rows)
                        {
                            int id       = int.Parse(row.Cells[1].Text);
                            int cantidad = int.Parse(((TextBox)row.Cells[5].FindControl("TextBox1")).Text);

                            if (row.Cells[3].Text != "bebible")
                            {
                                PlatoBLL plBLL = new PlatoBLL();
                                plBLL.ingresaRelacion(id, cantidad);
                                plBLL.reduceStock(id, cantidad);
                            }
                            else if (row.Cells[3].Text == "bebible")
                            {
                                BebestibleBLL bebBLL = new BebestibleBLL();
                                bebBLL.agregarRelacion(id, cantidad);
                                bebBLL.reduceStock(id, cantidad);
                            }
                        }
                        Session["pedido"] = null;
                        Response.Redirect("/CarroCompras.aspx");
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('No se pudo Generar la orden: \\n Insuficiente Stock de: \\n" + faltaStock + " ')", true);
                }
            }
        }