Ejemplo n.º 1
0
        protected void btnAgregar_Click(object sender, EventArgs e)
        {
            if (Correo == null)
            {
                Response.Write("<script>alert('" + "Debe de inicar sesion para poder annadir productos a su carrito. " + "');</script>");
                //Response.Redirect("/portadaCliente.aspx");
            }
            else
            {
                if (txtCantidad.Text != "")
                {
                    if (Convert.ToInt32(txtCantidad.Text) <= 0)
                    {
                        lblError.Text = "La cantidad debe ser mayor que 0.";
                    }
                    else
                    {
                        double desc = 0;
                        double totaldesc;
                        double resta = 0;
                        lblError.Text = "";
                        //inicializar DetalleBL y le psasamos como parametro la sesion
                        DetalleBL  tabla   = new DetalleBL((DataTable)Session["carrito"]);
                        SqlCommand comando = new SqlCommand("Select Descuento from Medicamentos where Nom_med='" + lblNombre.Text + "'", c.getcn);
                        c.getcn.Open();
                        SqlDataReader leer = comando.ExecuteReader();
                        if (leer.Read())
                        {
                            desc = leer.GetDouble(0);
                        }
                        c.getcn.Close();
                        //ejecuto y muestro el mensaje
                        if (desc == 0)
                        {
                            Pago.DatosCarrito.descuento = desc;
                        }
                        else
                        {
                            Pago.DatosCarrito.descuento = desc;
                            totaldesc = desc * double.Parse(lblPrecio.Text);
                            resta     = double.Parse(lblPrecio.Text) - totaldesc;
                        }
                        string mensaje = tabla.agregar(int.Parse(lblcodigo.Text), lblNombre.Text, decimal.Parse(lblPrecio.Text), int.Parse(txtCantidad.Text), resta);
                        lblMensaje.Text = mensaje;
                        // ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language=JavaScript>alert('" + (mensaje) + "');</script");

                        //actualizamos la sesion
                        Session["carrito"] = tabla.getRegistro;
                    }
                }
                else
                {
                    lblError.Text = "Debe ingresar la cantidad.";
                }
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Correo = (string)(Session["Correo"]);
            if (!IsPostBack)
            {
                //instancia DetalleBL
                DetalleBL tabla = new DetalleBL((DataTable)Session["carrito"]);

                //listar
                GridView1.DataSource = tabla.getRegistro;
                GridView1.DataBind();

                //mostrar el total
                sub                     = Convert.ToDouble(tabla.totaliza());
                itb                     = sub * 0.18;
                total                   = sub + itb;
                lblSubtotal.Text        = sub.ToString();
                lblItbis.Text           = itb.ToString();
                lblTotal.Text           = total.ToString();
                Pago.DatosCarrito.monto = total;
                Label2.Text             = Pago.DatosCarrito.nombre;
                //Label1.Text = Correo;
            }
        }