Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            List <Libro> librosCesta = new List <Libro>();

            //List<Libro> librosCesta;
            __controlFichero = new Controlador_Acceso_Ficheros();
            __controlCesta   = new ControladorCesta();

            try
            {
                librosCesta = __controlCesta.getLibrosPorISBN(readCookie(), rutaFichero);
            }
            catch (Exception)
            {
                //hostion
            }



            __controlTablas = new ControladorTablas(this.Page);
            string subTotal = __controlTablas.rellenaItems(librosCesta, this.tablaItems);

            this.labelSubtotal.Text = subTotal;
            //this.labelTotalCompra.Text = ( Convert.ToDecimal(subTotal) ).ToString() + " euros";
            //rellena la tabla con items y ademas me devuelve el precio total;
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            #region "sesionUser"
            Label LabelUser = (Label)this.Master.FindControl("LabelUser");

            if (this.Session["Usuario"] != null)
            {
                LabelUser.Text = (string)Session["Usuario"];
            }
            else
            {
                LabelUser.Text = "Parece que el nombre no se almacena bien";
            }

            ///---llamada a procedimiento interno para ver variables post

            #endregion
            __controlTablas = new ControladorTablas(this.Page);
            __controlInit   = new Controlador_Acceso_Ficheros();
            TreeView myTreeView = (TreeView)this.Master.FindControl("myTreeView");
            listaRecuperada = __controlInit.infoLibros("./Ficheros/libros.txt");

            string parametroISBN = this.Request.Params["isbn"];

            var resultado = from libro in listaRecuperada
                            where libro.ISBN10 == parametroISBN
                            select libro;

            Libro l = (Libro)resultado.Single();
            __controlTablas.rellenaControlDetallado(this.tablaDetallesLibro, l);

            if (this.IsPostBack)
            {
                foreach (string clave in this.Request.Params.AllKeys)
                {
                    string claveRequest = this.Request.Params[clave];

                    switch (clave)
                    {
                    case "__EVENTTARGET":

                        if (claveRequest.Contains(myTreeView.ID))
                        {
                            this.tablaDetallesLibro.Controls.Clear();
                            char[] separador          = new char[] { '\\' };
                            string __categoriaPulsada = this.Request.Params["__EVENTARGUMENT"].ToString().Split(separador)[0].Substring(1);

                            if (__categoriaPulsada == "Todos")
                            {
                                __controlTablas.rellenaTablaLibros(this.tablaDetallesLibro, listaRecuperada, false);
                            }
                            //rellenaTabla(librosFichero, false);

                            List <Libro> categoryList = __controlInit.findByCategory(listaRecuperada, __categoriaPulsada);

                            __controlTablas.rellenaTablaLibros(this.tablaDetallesLibro, categoryList, true);
                            //rellenaTabla(categoryList, true);
                        }
                        break;

                    default:
                        break;
                    }
                    if (clave.Contains("btncomprarDetalle"))
                    {
                        string isbnLibro = parametroISBN;
                        //ya tengo el ISBN porq me lo mando con la url.
                        if (Request.Cookies["cesta"] != null)
                        {
                            HttpCookie miCookie = Request.Cookies["cesta"];
                            miCookie.Values["libros"] += isbnLibro + ":";
                            Response.Cookies.Add(miCookie);
                        }

                        Response.Redirect("VistaCesta.aspx");
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            #region "controles de la Master"
            ImageButton        ButtonCompra = (ImageButton)this.Master.FindControl("ButtonCompra");
            Label              LabelUser    = (Label)this.Master.FindControl("LabelUser");
            TreeView           myTreeView   = (TreeView)this.Master.FindControl("myTreeView");
            ContentPlaceHolder holder       = (ContentPlaceHolder)this.Master.FindControl("placeHolderControl");
            #endregion
            MiniCesta __controlCesta = (MiniCesta)Page.LoadControl(__rutaControlCesta);
            holder.Controls.Add(__controlCesta);

            __controlFichero = new Controlador_Acceso_Ficheros();
            __controlTabla   = new ControladorTablas(this.Page);

            librosFichero = __controlFichero.infoLibros("./Ficheros/libros.txt");

            #region "sesionUser"
            if (this.Session["Usuario"] != null)
            {
                LabelUser.Text = (string)Session["Usuario"];
            }
            else
            {
                LabelUser.Text = "Parece que el nombre no se almacena bien";
            }

            ///---llamada a procedimiento interno para ver variables post

            #endregion

            mostrar();

            #region "isPostback"
            if (this.IsPostBack)
            {
                foreach (string clave in this.Request.Params.AllKeys)
                {
                    string claveRequest = this.Request.Params[clave];
                    switch (clave)
                    {
                    case "__EVENTTARGET":

                        if (claveRequest.Contains(myTreeView.ID))
                        {
                            char[] separador = new char[] { '\\' };
                            __categoriaPulsada = this.Request.Params["__EVENTARGUMENT"].ToString().Split(separador)[0].Substring(1);
                            LabelUser.Text     = "has seleccionado el nodo treeview: " + __categoriaPulsada;
                            //metodo que devuelve libros con categorías....

                            if (__categoriaPulsada == "Todos")
                            {
                                __controlTabla.rellenaTablaLibros(this.tablaLibros, librosFichero, false);
                            }

                            List <Libro> categoryList = __controlFichero.findByCategory(librosFichero, __categoriaPulsada);

                            __controlTabla.rellenaTablaLibros(this.tablaLibros, categoryList, true);
                        }

                        else if (claveRequest.Contains("linkButtonTitulo"))
                        {
                            string isbnLibro = ((string)claveRequest).Substring(((string)claveRequest).Length - 10, 10);
                            Response.Redirect("VistaDetallesLibro.aspx?isbn=" + isbnLibro);
                        }


                        break;

                    default:
                        break;
                    }
                    if (clave.Contains("botonCompra"))
                    {
                        string isbnLibro = ((string)clave).Substring(((string)clave).Length - 10, 10);

                        if (Request.Cookies["cesta"] != null)
                        {
                            HttpCookie miCookie = Request.Cookies["cesta"];
                            miCookie.Values["libros"] += isbnLibro + ":";
                            Response.Cookies.Add(miCookie);
                        }

                        __controlCesta.addItem();
                        __controlTabla.rellenaTablaLibros(this.tablaLibros, librosFichero, false);
                    }
                    else if (clave.Contains("botonVerCesta"))
                    {
                        Response.Redirect("VistaCesta.aspx");
                    }
                }
            }
            #endregion
            else
            {
                Response.Cookies["cesta"]["owner"]  = (string)this.Session["Usuario"];
                Response.Cookies["cesta"]["libros"] = "";
                Response.Cookies["cesta"].Expires   = DateTime.Now.AddDays(1);
                __controlTabla.rellenaTablaLibros(this.tablaLibros, librosFichero, false);
            }
        }