예제 #1
0
        protected void CargasProductosEnPagina()
        {
            ServicioCompras.ServicioClient servicio         = new ServicioCompras.ServicioClient();
            Negocio.Producto[]             listadoProductos = servicio.ListarProductos();
            foreach (Negocio.Producto item in listadoProductos)
            {
                HtmlGenericControl colDiv = new HtmlGenericControl("div");
                colDiv.Attributes.Add("class", "col-sm-4 col-sm-4 col-sm-4");

                HtmlGenericControl thumb = new HtmlGenericControl("div");
                thumb.Attributes.Add("class", "thumbnail");

                HtmlImage imagen = new HtmlImage();
                imagen.Src = "http://placehold.it/320x150";

                HtmlGenericControl detalles = new HtmlGenericControl("div");
                detalles.Attributes.Add("class", "caption");

                HtmlGenericControl headerPrecio = new HtmlGenericControl("h4");
                headerPrecio.Attributes.Add("class", "pull-right");
                if (item.EnOferta.Equals("1"))
                {
                    headerPrecio.InnerText = item.PrecioOferta.ToString();
                }
                else
                {
                    headerPrecio.InnerText = item.PrecioNormal.ToString();
                }

                HtmlGenericControl headerNombre = new HtmlGenericControl("h4");
                HtmlAnchor         anclaInterna = new HtmlAnchor();
                //anclaInterna.HRef = "/MainPage.aspx?idProducto="+item.IdProducto;
                anclaInterna.InnerText = item.Nombre;
                anclaInterna.Attributes.Add("runat", "server");
                anclaInterna.Attributes.Add("onclick", "__doPostBack('" + item.IdProducto + "', 'ejecutar')");
                anclaInterna.ClientIDMode = ClientIDMode.Static;
                anclaInterna.Attributes.Add("id", item.IdProducto.ToString());
                anclaInterna.ServerClick += Ancla_click;
                headerNombre.Controls.Add(anclaInterna);


                HtmlGenericControl descripcion = new HtmlGenericControl("p");
                descripcion.InnerText = item.Descripcion;

                detalles.Controls.Add(headerPrecio);
                detalles.Controls.Add(headerNombre);
                detalles.Controls.Add(descripcion);

                thumb.Controls.Add(imagen);
                thumb.Controls.Add(detalles);

                colDiv.Controls.Add(thumb);

                filaElementos.Controls.Add(colDiv);
            }
        }
        protected void BtnComprar_Click(object sender, EventArgs e)
        {
            try
            {
                using (ServicioCompras.ServicioClient servicio = new ServicioCompras.ServicioClient())
                {
                    Negocio.CarroCompras carro = (Negocio.CarroCompras)Session["carrito"];

                    Negocio.Pedido nuevoPedido = new Negocio.Pedido();

                    nuevoPedido.RunCliente   = (string)Session["runCliente"];
                    nuevoPedido.FormaEntrega = this.dropFormaEntrega.SelectedItem.Text;
                    nuevoPedido.Comentario   = this.txbComentario.Text;

                    foreach (Negocio.DetalleProductoCarro item in carro.ProductosEnCarro)
                    {
                        nuevoPedido.TotalVenta += item.TotalDetalle;
                    }
                    ;

                    nuevoPedido.DetallePedido = new List <Negocio.DetallePedido>();
                    foreach (Negocio.DetalleProductoCarro item in carro.ProductosEnCarro)
                    {
                        Negocio.DetallePedido detalle = new Negocio.DetallePedido();

                        detalle.Producto = new Negocio.Producto {
                            IdProducto = item.Id
                        };
                        detalle.Cantidad = item.Cantidad;
                        nuevoPedido.DetallePedido.Add(detalle);
                    }

                    if (servicio.GenerarPedido(nuevoPedido))
                    {
                        this.estadoCompra.Text = "Pedido realizado con éxito";
                        Session["carrito"]     = null;
                        CargarTablaCarro();
                    }
                    else
                    {
                        this.estadoCompra.Text = "Falla al realizar pedido, intente más tarde";
                    }
                }
            }
            catch (Exception)
            {
                this.estadoCompra.Text = "Falla al realizar pedido, intente más tarde";
            }
        }
예제 #3
0
 protected void controlLogin_Authenticate(object sender, EventArgs e)
 {
     ServicioCompras.ServicioClient seguridad = new ServicioCompras.ServicioClient();
     if (seguridad.AutenticarCliente(controlLogin.UserName.ToLower(), controlLogin.Password))
     {
         string run = seguridad.RecuperarRUNCliente(controlLogin.UserName);
         if (!run.Equals(""))
         {
             Session["runCliente"] = run;
         }
         FormsAuthentication.SetAuthCookie(controlLogin.UserName, true);
         Response.Redirect("MainPage.aspx", true);
     }
     else
     {
         lblEstadoIngreso.Text = "Error al autenticar, intente nuevamente";
     }
 }
예제 #4
0
        protected void CargarHistorial()
        {
            string runCliente = (string)Session["runCliente"];

            try
            {
                using (ServicioCompras.ServicioClient servicio = new ServicioCompras.ServicioClient())
                {
                    Negocio.Pedido[] listado = servicio.ListarHistorial(runCliente);
                    grillaHistorial.DataSource = listado;
                    grillaHistorial.DataBind();
                }
            }
            catch (Exception)
            {
                estadoGrilla.Text    = "No se pudieron encontrar datos";
                estadoGrilla.Visible = true;
            }
        }
예제 #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Negocio.Cliente nuevoCliente = new Negocio.Cliente();
                nuevoCliente.Run              = HttpUtility.HtmlEncode(Request.Form["txbRutRegister"]);
                nuevoCliente.NombreCompleto   = HttpUtility.HtmlEncode(Request.Form["txbNombreRegister"]);
                nuevoCliente.Genero           = HttpUtility.HtmlEncode(Request.Form["cmbGenero"]);
                nuevoCliente.Email            = HttpUtility.HtmlEncode(Request.Form["txbEmailRegister"]).ToLower();
                nuevoCliente.Password         = HttpUtility.HtmlEncode(Request.Form["txbContraseñaRegister"]);
                nuevoCliente.FechaNacimiento  = DateTime.Parse(HttpUtility.HtmlEncode(Request.Form["txbFechaRegister"]));
                nuevoCliente.Region           = HttpUtility.HtmlEncode(Request.Form["txbRegionRegister"]);
                nuevoCliente.Provincia        = HttpUtility.HtmlEncode(Request.Form["txbProvinciaRegister"]);
                nuevoCliente.Comuna           = HttpUtility.HtmlEncode(Request.Form["txbComunaRegister"]);
                nuevoCliente.Direccion        = HttpUtility.HtmlEncode(Request.Form["txbDireccionRegister"]);
                nuevoCliente.NumeroTelefonico = HttpUtility.HtmlEncode(Request.Form["txbTelRegister"]);

                ServicioCompras.ServicioClient servicio = new ServicioCompras.ServicioClient();
                if (servicio.RegistrarUsuario(nuevoCliente))
                {
                    lblResult.Text = "registrado con éxito";
                }
                else
                {
                    lblResult.Text = "falla al registrar, intente nuevamente ";
                    HtmlAnchor linkRegistro = new HtmlAnchor();
                    linkRegistro.InnerText = "Volver a página de registro";
                    linkRegistro.HRef      = "login.aspx";
                    lblResult.Parent.Controls.Add(linkRegistro);
                }
            }
            catch (Exception exc)
            {
                lblResult.Text = "falla en el registro: " + exc.Message;
                HtmlAnchor linkRegistro = new HtmlAnchor();
                linkRegistro.InnerText = "Volver a página de registro";
                linkRegistro.HRef      = "login.aspx";
                lblResult.Parent.Controls.Add(linkRegistro);
            }
        }
예제 #6
0
        protected void Ancla_click(object sender, EventArgs e)
        {
            int id = Int32.Parse(((HtmlAnchor)sender).ID);

            Negocio.CarroCompras carrito = (Negocio.CarroCompras)Session["carrito"];
            //consulto si existe en el carrito de compras
            if (carrito.ProductosEnCarro.Exists(obj => obj.Id == id))
            {
                Negocio.DetalleProductoCarro detalle = carrito.ProductosEnCarro.First(obj => obj.Id == id);
                carrito.ProductosEnCarro.First(obj => obj.Id == id).Cantidad++;
                carrito.ProductosEnCarro.First(obj => obj.Id == id).TotalDetalle = (detalle.Cantidad + 1) * detalle.PrecioUnidad;
            }
            //si no existe en el carrito, se busca en la bd, se mapea, y se agrega al carrito con cantidad 1
            else
            {
                using (ServicioCompras.ServicioClient servicio = new ServicioCompras.ServicioClient())
                {
                    Negocio.DetalleProductoCarro nuevoDetalle      = new Negocio.DetalleProductoCarro();
                    Negocio.Producto             productoClickeado = servicio.BuscarProductoID(id);
                    nuevoDetalle.Id       = id;
                    nuevoDetalle.Nombre   = productoClickeado.Nombre;
                    nuevoDetalle.Cantidad = 1;
                    if (productoClickeado.EnOferta.Equals("1"))
                    {
                        nuevoDetalle.PrecioUnidad = productoClickeado.PrecioOferta;
                    }
                    else
                    {
                        nuevoDetalle.PrecioUnidad = productoClickeado.PrecioNormal;
                    }
                    nuevoDetalle.TotalDetalle = nuevoDetalle.PrecioUnidad;
                    carrito.ProductosEnCarro.Add(nuevoDetalle);
                }
            }
            Session["carrito"] = carrito;
        }
예제 #7
0
        protected void CargarProductosAlCarrito()
        {
            int id = Int32.Parse(Request.Params.Get("__EVENTTARGET"));

            Negocio.CarroCompras carrito = (Negocio.CarroCompras)Session["carrito"];
            //consulto si existe en el carrito de compras
            if (carrito.ProductosEnCarro.Exists(obj => obj.Id == id))
            {
                Negocio.DetalleProductoCarro detalle = carrito.ProductosEnCarro.First(obj => obj.Id == id);
                carrito.ProductosEnCarro.First(obj => obj.Id == id).Cantidad++;
                carrito.ProductosEnCarro.First(obj => obj.Id == id).TotalDetalle = detalle.Cantidad * detalle.PrecioUnidad;
            }
            //si no existe en el carrito, se busca en la bd, se mapea, y se agrega al carrito con cantidad 1
            else
            {
                using (ServicioCompras.ServicioClient servicio = new ServicioCompras.ServicioClient())
                {
                    Negocio.DetalleProductoCarro nuevoDetalle      = new Negocio.DetalleProductoCarro();
                    Negocio.Producto             productoClickeado = servicio.BuscarProductoID(id);
                    nuevoDetalle.Id       = id;
                    nuevoDetalle.Nombre   = productoClickeado.Nombre;
                    nuevoDetalle.Cantidad = 1;
                    if (productoClickeado.EnOferta.Equals("1"))
                    {
                        nuevoDetalle.PrecioUnidad = productoClickeado.PrecioOferta;
                    }
                    else
                    {
                        nuevoDetalle.PrecioUnidad = productoClickeado.PrecioNormal;
                    }
                    nuevoDetalle.TotalDetalle = nuevoDetalle.PrecioUnidad;
                    carrito.ProductosEnCarro.Add(nuevoDetalle);
                }
            }
            Session["carrito"] = carrito;
        }