protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["consumidorEmail"] == null)
     {
         Response.Redirect("../Login/Login.aspx");
     }
     else
     {
         string consumidorEmail = (string)(Session["consumidorEmail"]);
         LogicaNegocio.LnUsuario objLnUsuario = new LogicaNegocio.LnUsuario();
         var      usuario     = objLnUsuario.BuscarUsuarioMail(consumidorEmail);
         string   nombre      = usuario.NOMBRE_USUARIO + " " + usuario.APEPA_USUARIO;
         decimal  puntos      = usuario.PUNTOS_USUARIO;
         DateTime fechaInicio = DateTime.Now;
         DateTime fechaFinal  = fechaInicio.AddMonths(1);
         lblNombre.Text      = nombre;
         lblPuntos.Text      = puntos.ToString();
         lblNombreCupon.Text = nombre;
         lblRutCupon.Text    = usuario.RUT_USUARIO;
         lblPuntosCupon.Text = usuario.PUNTOS_USUARIO.ToString();
         //recuperar descuento
         LogicaNegocio.LnTicket datosTicket = new LogicaNegocio.LnTicket();
         lblDescuentoCupon.Text = datosTicket.Descuento(puntos).ToString() + "%";
         lblRubroCupon.Text     = datosTicket.RubroDesct(puntos);
         lblMaxCupon.Text       = "$" + datosTicket.MaxDect(puntos).ToString();
         lblFechaCupon.Text     = fechaFinal.ToString("dd/MM/yyyy");
         //generar codigoQR
         BarcodeWriter barcode = new BarcodeWriter();                           //crea obj codigo
         barcode.Format = BarcodeFormat.QR_CODE;                                //formato codigo
         string datosQR = datosTicket.DatosQR(usuario);
         Bitmap bitmap  = new Bitmap(barcode.Write(datosQR), 300, 300);         //crea bitmap con el string y da tamaño
         bitmap.Save(Server.MapPath("./codigo.png"), ImageFormat.Png);          //salva bitmar en una ruta
         imgQr.ImageUrl = "./codigo.png";
     }
 }
示例#2
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            lblErrorRut.Visible   = false;
            LblErroCorreo.Visible = false;
            String activo       = ObtenerCheck();
            string passwordHash = Hash(txtPassword.Text);
            String comuna       = ddlComuna.SelectedValue;

            //Definir objeto usuario
            Modelo.Usuario obMoUsuario = new Modelo.Usuario
            {
                id_tipoUsuario    = 4,
                direccion_usuario = txtDireccion.Text,
                correoactivo      = activo,
                apepa_usuario     = txtApePaterno.Text,
                nombre_usuario    = txtNombreCliente.Text,
                rut_usuario       = txtRut.Text,
                correo_usuario    = txtCorreo.Text,
                apema_usuario     = txtApeMaterno.Text,
                puntos_usuario    = 0,
                telefono_usuario  = txtFono.Text,
                id_comuna         = int.Parse(comuna),
                password_usuario  = passwordHash
            };

            LogicaNegocio.LnUsuario objLnUsuario     = new LogicaNegocio.LnUsuario();
            List <Modelo.Usuario>   lstUsuariocorreo = objLnUsuario.GetBuscarUsuarioCorreo(obMoUsuario);
            List <Modelo.Usuario>   lstUsuarorut     = objLnUsuario.GetBuscarUsuarioRut(obMoUsuario);

            if (lstUsuariocorreo.Count > 1)
            {
                LblErroCorreo.Text    = "El correo ya existe en el sistema";
                LblErroCorreo.Visible = true;
            }
            if (lstUsuarorut.Count > 1)
            {
                lblErrorRut.Text    = "El rut usuario ya existe en el sistema";
                lblErrorRut.Visible = true;
            }
            if (lstUsuarorut.Count < 1 && lstUsuariocorreo.Count < 1)
            {
                List <Modelo.Usuario> lstUsuario = objLnUsuario.GetBuscarUsuario(obMoUsuario);
                objLnUsuario.InsertarUsuarioCliente(obMoUsuario);
                Response.Redirect("../Login/Login.aspx");
            }
        }
示例#3
0
        protected void btnAceptar_Click(object sender, EventArgs e)
        {
            try
            {
                string stMensaje = string.Empty;
                if (string.IsNullOrEmpty(txtEmail.Text))
                {
                    stMensaje += "Ingresar email -";
                }
                if (string.IsNullOrEmpty(txtPassword.Text))
                {
                    stMensaje += "Ingresar password,";
                }
                if (!string.IsNullOrEmpty(stMensaje))
                {
                    throw new Exception(stMensaje.TrimEnd(','));
                }
                //se implementa el hasheo de la password
                string passwordHash = Hash(txtPassword.Text);
                //Definir objeto usuario
                Modelo.Usuario obMoUsuario = new Modelo.Usuario
                {
                    correo_usuario   = txtEmail.Text,
                    password_usuario = passwordHash
                };

                //Instanciar objeto que traerá los datos del usuario que realiza login
                LogicaNegocio.LnUsuario objLnUsuario = new LogicaNegocio.LnUsuario();
                List <Modelo.Usuario>   lstUsuario   = objLnUsuario.GetBuscarUsuario(obMoUsuario);

                if (lstUsuario.Count > 0)
                {
                    Session["consumidorEmail"] = txtEmail.Text;
                    Response.Redirect("../Index/Index.aspx");
                }
                else
                {
                    throw new Exception("Usuario o password incorrectos");
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script>swal('Error!'," +
                                                   " '" + ex.Message + "!', 'error')</script>");
            }
        }
        protected void btnDescargar_Click(object sender, EventArgs e)
        {
            string consumidorEmail = (string)(Session["consumidorEmail"]);

            LogicaNegocio.LnUsuario objLnUsuario = new LogicaNegocio.LnUsuario();
            var     usuario = objLnUsuario.BuscarUsuarioMail(consumidorEmail);
            string  nombre  = usuario.NOMBRE_USUARIO + " " + usuario.APEPA_USUARIO;
            decimal puntos  = usuario.PUNTOS_USUARIO;

            LogicaNegocio.LnTicket datosTicket = new LogicaNegocio.LnTicket();
            DateTime fechaInicio = DateTime.Now;
            DateTime fechaFinal  = fechaInicio.AddMonths(1);


            //preparacion documento
            Document document = new Document();
            string   path     = Server.MapPath(".");

            PdfWriter.GetInstance(document, new FileStream(path + "/cupon.pdf", FileMode.Create));

            //Abrir el Documento
            document.Open();

            //preparando imagen
            string pathImg = Server.MapPath("./codigo.png");

            iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(pathImg);
            imagen.BorderWidth = 0;
            imagen.Alignment   = Element.ALIGN_LEFT;
            float percentage = 0.0f;

            percentage = 150 / imagen.Width;
            imagen.ScalePercent(percentage * 100);

            PdfPTable tablaPdf = new PdfPTable(3);
            PdfPCell  titulo   = new PdfPCell(new Phrase("Cupón de Descuento"));

            titulo.Colspan             = 3;
            titulo.HorizontalAlignment = 1;
            titulo.BorderWidthTop      = 1; titulo.BorderWidthLeft = 1; titulo.BorderWidthRight = 1; titulo.BorderWidthBottom = 0;
            tablaPdf.AddCell(titulo);

            PdfPCell celdaimagen = new PdfPCell();

            celdaimagen.AddElement(imagen);
            celdaimagen.Rowspan             = 7;
            celdaimagen.HorizontalAlignment = 1;
            celdaimagen.VerticalAlignment   = 1;
            celdaimagen.BorderWidthLeft     = 1; celdaimagen.BorderWidthBottom = 1; celdaimagen.BorderWidthRight = 0; celdaimagen.BorderWidthTop = 0;
            tablaPdf.AddCell(celdaimagen);

            PdfPCell cellNombre = new PdfPCell(new Phrase("Nombre:"));

            cellNombre.BorderWidth = 0;
            tablaPdf.AddCell(cellNombre);

            PdfPCell cellNombreUsu = new PdfPCell(new Phrase(nombre));

            cellNombreUsu.BorderWidth      = 0;
            cellNombreUsu.BorderWidthRight = 1;
            tablaPdf.AddCell(cellNombreUsu);

            PdfPCell cellRut = new PdfPCell(new Phrase("RUT:"));

            cellRut.BorderWidth = 0;
            tablaPdf.AddCell(cellRut);

            PdfPCell cellRutUsu = new PdfPCell(new Phrase(usuario.RUT_USUARIO));

            cellRutUsu.BorderWidth      = 0;
            cellRutUsu.BorderWidthRight = 1;
            tablaPdf.AddCell(cellRutUsu);

            PdfPCell cellPuntos = new PdfPCell(new Phrase("Puntos:"));

            cellPuntos.BorderWidth = 0;
            tablaPdf.AddCell(cellPuntos);

            PdfPCell cellPuntosUsu = new PdfPCell(new Phrase(usuario.PUNTOS_USUARIO.ToString()));

            cellPuntosUsu.BorderWidth      = 0;
            cellPuntosUsu.BorderWidthRight = 1;
            tablaPdf.AddCell(cellPuntosUsu);

            PdfPCell cellDescto = new PdfPCell(new Phrase("Descuento:"));

            cellDescto.BorderWidth = 0;
            tablaPdf.AddCell(cellDescto);

            PdfPCell cellDesctoUsu = new PdfPCell(new Phrase(datosTicket.Descuento(puntos).ToString() + "%"));

            cellDesctoUsu.BorderWidth      = 0;
            cellDesctoUsu.BorderWidthRight = 1;
            tablaPdf.AddCell(cellDesctoUsu);

            PdfPCell cellRubro = new PdfPCell(new Phrase("Rubro:"));

            cellRubro.BorderWidth = 0;
            tablaPdf.AddCell(cellRubro);

            PdfPCell cellRubroUsu = new PdfPCell(new Phrase(datosTicket.RubroDesct(puntos)));

            cellRubroUsu.BorderWidth      = 0;
            cellRubroUsu.BorderWidthRight = 1;
            tablaPdf.AddCell(cellRubroUsu);

            PdfPCell cellMax = new PdfPCell(new Phrase("Máximo Descuento:"));

            cellMax.BorderWidth = 0;
            tablaPdf.AddCell(cellMax);

            PdfPCell cellMaxUsu = new PdfPCell(new Phrase("$" + datosTicket.MaxDect(puntos).ToString()));

            cellMaxUsu.BorderWidth      = 0;
            cellMaxUsu.BorderWidthRight = 1;
            tablaPdf.AddCell(cellMaxUsu);

            PdfPCell cellFecha = new PdfPCell(new Phrase("Fecha Expiración:"));

            cellFecha.BorderWidth       = 0;
            cellFecha.BorderWidthBottom = 1;
            tablaPdf.AddCell(cellFecha);

            PdfPCell cellFechaUsu = new PdfPCell(new Phrase(fechaFinal.ToString("dd/MM/yyyy")));

            cellFechaUsu.BorderWidth       = 0;
            cellFechaUsu.BorderWidthRight  = 1;
            cellFechaUsu.BorderWidthBottom = 1;
            tablaPdf.AddCell(cellFechaUsu);


            Entities        obEntitiesOfertas = new Entities();
            TICKETDESCUENTO ticket            = new TICKETDESCUENTO();

            //convertir imagen a byte[] para gardarlo en la base de datos
            FileStream stream = File.OpenRead(Server.MapPath("./codigo.png"));

            byte[] fileBytes = new byte[stream.Length];
            stream.Read(fileBytes, 0, fileBytes.Length);
            stream.Close();

            /*proceso inverso
             * using (Stream file = File.OpenWrite(Server.MapPath("./codigo.png")))
             *   {
             *       file.Write(fileBytes, 0, fileBytes.Length);
             *   }
             */

            /*
             * ticket.ID_TICKET = datosTicket.BuscarUltimoIDTicket() + 1;
             * ticket.CODIGOBARRA = fileBytes;
             * ticket.DESCUENTO_OTORGADO = datosTicket.Descuento(puntos);
             * ticket.FECHA_INICIO = fechaInicio;
             * ticket.FECHA_TERMINO = fechaFinal;
             * ticket.RUT_USUARIO = usuario.RUT_USUARIO;
             * ticket.TOPE = datosTicket.MaxDect(puntos);
             */
            obEntitiesOfertas.InsertarTicket(fechaFinal, datosTicket.MaxDect(puntos), usuario.RUT_USUARIO, fileBytes, fechaInicio, datosTicket.BuscarUltimoIDTicket() + 1, datosTicket.Descuento(puntos));
            obEntitiesOfertas.SaveChanges();

            document.Add(tablaPdf);
            //cerrar Documento
            document.Close();

            //Descargar el archivo
            // Limpiamos la salida
            Response.Clear();
            // Con esto le decimos al browser que la salida sera descargable
            Response.ContentType = "application/octet-stream";
            // esta linea es opcional, en donde podemos cambiar el nombre del fichero a descargar (para que sea diferente al original)
            Response.AddHeader("Content-Disposition", "attachment; filename=cupon.pdf");
            // Escribimos el fichero a enviar
            Response.WriteFile("./cupon.pdf");
            // volcamos el stream
            Response.Flush();
            // Enviamos todo el encabezado ahora
            Response.End();
        }
        protected void btnAceptar_Click(object sender, EventArgs e)
        {
            try
            {
                string stMensaje = string.Empty;
                if (string.IsNullOrEmpty(txtEmail.Text))
                {
                    stMensaje += "Ingresar email -";
                }

                if (!string.IsNullOrEmpty(stMensaje))
                {
                    throw new Exception(stMensaje.TrimEnd(','));
                }

                LogicaNegocio.LnUsuario objLnUsuario = new LogicaNegocio.LnUsuario();
                Modelo.Usuario          objUser      = new Modelo.Usuario
                {
                    correo_usuario = txtEmail.Text,
                    rut_usuario    = txtRut.Text
                };

                List <Modelo.Usuario> lsConsulta = objLnUsuario.GetBuscarUsuarioCorreoRut(objUser);
                string nombre = null;
                string pass   = null;
                string rut    = null;
                string correo = null;
                if (lsConsulta.Count > 0)
                {
                    foreach (var item in lsConsulta)
                    {
                        nombre = item.nombre_usuario;
                        rut    = item.rut_usuario;
                        correo = item.correo_usuario;
                        pass   = item.password_usuario;
                    }

                    string[] stLogin = nombre.ToString().Split('@');

                    string stCuerpoHTML = "<!DOCTYPE html>";
                    stCuerpoHTML += "<html lang='es'>";
                    stCuerpoHTML += "<head>";
                    stCuerpoHTML += "<meta charset='utf - 8'>";
                    stCuerpoHTML += "<title>Recuperacion de correo</title>";
                    stCuerpoHTML += "</head>";
                    stCuerpoHTML += "<body style='background - color: black '>";
                    stCuerpoHTML += "<table style='max - width: 600px; padding: 10px; margin: 0 auto; border - collapse: collapse; '>	";
                    stCuerpoHTML += "<tr>";
                    stCuerpoHTML += "<td style='padding: 0'>";
                    stCuerpoHTML += "<img style='padding: 0; display: block' src='cid:Fondo' width='100%' height='10%'>";
                    stCuerpoHTML += "</td>";
                    stCuerpoHTML += "</tr>";
                    stCuerpoHTML += "<tr>";
                    stCuerpoHTML += "<td style='background - color: #ecf0f1'>";
                    stCuerpoHTML += "<div style='color: #34495e; margin: 4% 10% 2%; text-align: justify;font-family: sans-serif'>";
                    stCuerpoHTML += "<h2 style='color: #e67e22; margin: 0 0 7px'>Hola " + stLogin[0] + "</h2>";
                    stCuerpoHTML += "<p style='margin: 2px; font - size: 15px'>";
                    stCuerpoHTML += "Hemos recibido una solicitud para restablecer el password de su cuenta asociada con ";
                    stCuerpoHTML += "esta dirección de correo electrónico. Si no ha realizado esta solicitud, puede ignorar este ";
                    stCuerpoHTML += "correo electrónico y le garantizamos que su cuenta es completamente segura.";
                    stCuerpoHTML += "<br/>";
                    stCuerpoHTML += "<br/>";// nombredelvalor = valor & nombredelvalor2 = valor2
                    stCuerpoHTML += "Ingrese al siguiente link: " + "http://*****:*****@"\Imagenes\descuentos4.jpg",
                        idImagen       = "fondo",
                        mensaje        = stCuerpoHTML
                    };

                    LogicaNegocio.LnRecuperarPassword lnRecuperar = new LogicaNegocio.LnRecuperarPassword();
                    lnRecuperar.setEmailLn(objCorreo);
                    ClientScript.RegisterStartupScript(this.GetType(), "mensaje", "<script>swal('Correo enviado!'," +
                                                       " 'Hemos enviado un email a su direccion de correo', 'success')</script>");
                }
                else
                {
                    throw new Exception("No se encontró información asociada a esa dirección de correo");
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "No se pudo enviar el email", "<script>swal('Error!'," +
                                                   " '" + ex.Message + "!', 'error')</script>");
            }
        }