Exemple #1
0
        protected void generar_factura(object sender, EventArgs e)
        {
            if (user_loged == false)
            {
                Response.Redirect("registro.aspx");
            }
            else
            {
                ClienteEN  cliente = (ClienteEN)Session["cliente"];
                ClienteCEN cliCen  = new ClienteCEN();
                PedidoCEN  pedCen  = new PedidoCEN();
                if (RadioButtonList1.SelectedItem.ToString().ToLower() == "paypal")
                {
                    pedCen.CrearPedido(DateTime.Now, EstadoPedidoEnum.en_curso, TipoPagoEnum.paypal, "admin", cliente.NIF);
                }
                if (RadioButtonList1.SelectedItem.ToString().ToLower() == "visa")
                {
                    pedCen.CrearPedido(DateTime.Now, EstadoPedidoEnum.en_curso, TipoPagoEnum.visa, "admin", cliente.NIF);
                }


                IList <PedidoEN> pedEn = pedCen.ObtenerPorCliente(cliente.NIF);
                pedCen.Comprar(pedEn.ElementAt(pedEn.Count - 1).IdPedido, pedido);
                Session["cliente"] = cliente;
            }
            Document doc = new Document(PageSize.LETTER);
            // Indicamos donde vamos a guardar el documento
            PdfWriter writer = PdfWriter.GetInstance(doc,
                                                     new FileStream(@"D:\prueba.pdf", FileMode.Create));

            // Le colocamos el título y el autor
            // **Nota: Esto no será visible en el documento
            doc.AddTitle("Factura");
            doc.AddCreator("BalumaProject");

            // Abrimos el archivo
            doc.Open();

            iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(@"D:\logoweb.png");
            imagen.BorderWidth = 0;
            imagen.Alignment   = Element.ALIGN_RIGHT;
            float percentage = 0.0f;

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

            doc.Add(imagen);

            // Creamos el tipo de Font que vamos utilizar
            iTextSharp.text.Font _standardFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
            iTextSharp.text.Font _boldFont     = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK);

            DateTime hoy = DateTime.Today;
            DateTime fin = new DateTime(2015, 5, 18);

            ClienteEN cli = (ClienteEN)Session["cliente"];

            Paragraph linea1 = new Paragraph();

            // Escribimos el encabezamiento en el documento
            linea1.Add(new Chunk("FECHA DE EXPEDICIÓN: ", _boldFont));
            linea1.Add(new Chunk(hoy.ToString(), _standardFont));

            doc.Add(linea1);

            Paragraph linea2 = new Paragraph();

            doc.Add(new Chunk("FECHA DE VENCIMIENTO: ", _boldFont));
            doc.Add(new Chunk(fin.ToString(), _standardFont));

            doc.Add(linea2);

            Paragraph linea3 = new Paragraph();

            doc.Add(new Chunk("CLIENTE: ", _boldFont));
            doc.Add(new Chunk(cli.Nombre.ToString() + cli.Apellidos.ToString(), _standardFont));

            doc.Add(linea3);

            Paragraph linea4 = new Paragraph();

            doc.Add(new Chunk("NIF: ", _boldFont));
            doc.Add(new Chunk(cli.NIF, _standardFont));

            doc.Add(linea4);

            Paragraph linea5 = new Paragraph();

            doc.Add(new Chunk("DIRECCIÓN: ", _boldFont));
            doc.Add(new Chunk(cli.Localidad.ToString(), _standardFont));

            doc.Add(linea5);

            Paragraph linea6 = new Paragraph();

            doc.Add(new Chunk("E-MAIL: ", _boldFont));
            doc.Add(new Chunk(cli.Email.ToString(), _standardFont));

            doc.Add(linea6);

            doc.Add(Chunk.NEWLINE);


            // Creamos una tabla que contendrá el nombre, apellido y país
            // de nuestros visitante.
            PdfPTable tbl1 = new PdfPTable(3);

            tbl1.WidthPercentage = 100;

            // Configuramos el título de las columnas de la tabla
            PdfPCell clCantidad = new PdfPCell(new Phrase("CANTIDAD", _boldFont));

            clCantidad.BorderWidth       = 0;
            clCantidad.BorderWidthBottom = 0.75f;

            PdfPCell clDescrp = new PdfPCell(new Phrase("DESCRIPCIÓN", _boldFont));

            clDescrp.BorderWidth       = 0;
            clDescrp.BorderWidthBottom = 0.75f;

            PdfPCell clPrecio = new PdfPCell(new Phrase("PRECIO", _boldFont));

            clPrecio.BorderWidth       = 0;
            clPrecio.BorderWidthBottom = 0.75f;

            // Añadimos las celdas a la tabla
            tbl1.AddCell(clCantidad);
            tbl1.AddCell(clDescrp);
            tbl1.AddCell(clPrecio);



            foreach (ProductoEN producto in pedido)
            {
                // Llenamos la tabla con información
                clCantidad             = new PdfPCell(new Phrase(producto.Cantidad.ToString(), _standardFont));
                clCantidad.BorderWidth = 0;

                clDescrp             = new PdfPCell(new Phrase(producto.Nombre.ToString(), _standardFont));
                clDescrp.BorderWidth = 0;

                clPrecio             = new PdfPCell(new Phrase(producto.Precio.ToString(), _standardFont));
                clPrecio.BorderWidth = 0;

                // Añadimos las celdas a la tabla
                tbl1.AddCell(clCantidad);
                tbl1.AddCell(clDescrp);
                tbl1.AddCell(clPrecio);
            }

            doc.Add(tbl1);

            PdfPTable tbl2 = new PdfPTable(3);

            tbl2.WidthPercentage = 100;

            PdfPCell clb1 = new PdfPCell(new Phrase(" ", _standardFont));

            clb1.BorderWidth       = 0;
            clb1.BorderWidthBottom = 0.75f;

            PdfPCell clb2 = new PdfPCell(new Phrase(" ", _standardFont));

            clb2.BorderWidth       = 0;
            clb2.BorderWidthBottom = 0.75f;

            PdfPCell clTotal = new PdfPCell(new Phrase("TOTAL (+ IVA)", _boldFont));

            clTotal.BorderWidth       = 0;
            clTotal.BorderWidthBottom = 0.75f;

            // Añadimos las celdas a la tabla
            tbl2.AddCell(clb1);
            tbl2.AddCell(clb2);
            tbl2.AddCell(clTotal);

            /*FacturaCEN factura = new FacturaCEN();
             * factura.CrearFactura(0);*/
            clb1                = new PdfPCell(new Phrase(" ", _standardFont));
            clb1.BorderWidth    = 0;
            clb2                = new PdfPCell(new Phrase(" ", _standardFont));
            clb2.BorderWidth    = 0;
            clTotal             = new PdfPCell(new Phrase(calculoTotal(pedido).ToString(), _standardFont));
            clTotal.BorderWidth = 0;
            tbl2.AddCell(clb1);
            tbl2.AddCell(clb2);
            tbl2.AddCell(clTotal);

            doc.Add(tbl2);

            doc.Add(new Phrase("EMPRESA:" + "                   " + "RECIBÍ A CONFORMIDAD:", _standardFont));

            iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(@"C:\firma.jpg");
            imagen.BorderWidth = 0;
            imagen.Alignment   = Element.ALIGN_LEFT;
            float per = 0.0f;

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

            doc.Add(img);

            doc.Close();
            writer.Close();
        }
Exemple #2
0
        public static void InitializeData()
        {
            /*PROTECTED REGION ID(initializeDataMethod) ENABLED START*/

            /*
             * Inicializaci�n de datos previos a la demo.
             * La creaci�n de algunas entidades son necesarias antes de poder proceder
             * con la ejecuci�n del programa.
             * */
            AdministradorCEN admin = new AdministradorCEN();

            admin.CrearAdministrador("admin", "admin", "admin", "admin", "admin");
            CategoriaCEN categoria = new CategoriaCEN();

            categoria.CrearCategoria("cuadra", "vela");
            categoria.CrearCategoria("latina", "vela");
            categoria.CrearCategoria("de cuchillo", "vela");

            ClienteCEN cliente = new ClienteCEN();

            cliente.CrearCliente("a a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a");
            cliente.CrearCliente("cliente1 cliente1", "cliente1", "cliente1", "cliente1",
                                 "cliente1", "cliente1", "cliente1", "cliente1",
                                 "cliente1", "cliente1", "cliente1");
            cliente.CrearCliente("cliente2 cliente2", "cliente2", "cliente2", "cliente2",
                                 "cliente2", "cliente2", "cliente2", "cliente2",
                                 "cliente2", "cliente2", "cliente2");
            cliente.CrearCliente("cliente3 cliente3", "cliente3", "cliente3", "cliente3",
                                 "cliente3", "cliente3", "cliente3", "cliente3",
                                 "cliente3", "cliente3", "cliente3");
            cliente.CrearCliente("Manuel Manuel", "Manuel", "Manuel", "Manuel",
                                 "Manuel", "Manuel", "Manuel", "Manuel",
                                 "Manuel", "Manuel", "Manuel");

            var pedido = new PedidoCEN();

            pedido.CrearPedido(DateTime.Now, EstadoPedidoEnum.en_curso, TipoPagoEnum.paypal, "admin", "cliente1");
            pedido.CrearPedido(DateTime.Now, EstadoPedidoEnum.cancelado, TipoPagoEnum.visa, "admin", "cliente1");
            pedido.CrearPedido(DateTime.Now, EstadoPedidoEnum.entregado, TipoPagoEnum.paypal, "admin", "cliente1");

            pedido.CrearPedido(DateTime.Now, EstadoPedidoEnum.en_curso, TipoPagoEnum.paypal, "admin", "Manuel");
            pedido.CrearPedido(DateTime.Now, EstadoPedidoEnum.cancelado, TipoPagoEnum.visa, "admin", "Manuel");
            pedido.CrearPedido(DateTime.Now, EstadoPedidoEnum.entregado, TipoPagoEnum.paypal, "admin", "Manuel");


            ProductoCEN prod  = new ProductoCEN();
            ProductoCEN prod2 = new ProductoCEN();

            prod.CrearProducto(1, 300f, "admin", "latina", "latina clasica", 1);
            prod2.CrearProducto(2, 200f, "admin", "latina", "latina regata", 1);
            prod2.CrearProducto(3, 200f, "admin", "cuadra", "cuadra competicion", 1);
            prod2.CrearProducto(4, 200f, "admin", "de cuchillo", "cuchillo clasica", 1);

            /*   IList<ProductoEN> productos = new List<ProductoEN>();
             * productos = prod.DameTodosLosProductos(0, 100);
             * carrito.AnyadirProducto(1, productos);*/



            try
            {
                /*List<BalumaProjectGenNHibernate.EN.Mediaplayer.MusicTrackEN> musicTracks = new List<BalumaProjectGenNHibernate.EN.Mediaplayer.MusicTrackEN>();
                 * BalumaProjectGenNHibernate.EN.Mediaplayer.UserEN userEN = new BalumaProjectGenNHibernate.EN.Mediaplayer.UserEN();
                 * BalumaProjectGenNHibernate.EN.Mediaplayer.ArtistEN artistEN = new BalumaProjectGenNHibernate.EN.Mediaplayer.ArtistEN();
                 * BalumaProjectGenNHibernate.EN.Mediaplayer.MusicTrackEN musicTrackEN = new BalumaProjectGenNHibernate.EN.Mediaplayer.MusicTrackEN();
                 * BalumaProjectGenNHibernate.CEN.Mediaplayer.ArtistCEN artistCEN = new BalumaProjectGenNHibernate.CEN.Mediaplayer.ArtistCEN();
                 * BalumaProjectGenNHibernate.CEN.Mediaplayer.UserCEN userCEN = new BalumaProjectGenNHibernate.CEN.Mediaplayer.UserCEN();
                 * BalumaProjectGenNHibernate.CEN.Mediaplayer.MusicTrackCEN musicTrackCEN = new BalumaProjectGenNHibernate.CEN.Mediaplayer.MusicTrackCEN();
                 * BalumaProjectGenNHibernate.CEN.Mediaplayer.PlayListCEN playListCEN = new BalumaProjectGenNHibernate.CEN.Mediaplayer.PlayListCEN();
                 *
                 *              //Add Users
                 * userEN.Email = "*****@*****.**";
                 * userEN.Name = "user";
                 * userEN.Surname = "userSurname";
                 * userEN.Password = "******";
                 * userCEN.New_(userEN.Name, userEN.Surname, userEN.Email, userEN.Password);
                 *
                 * //Add Music Track1
                 * musicTrackEN.Id = "http://www2.b3ta.com/mp3/Beer Beer Beer (YOB mix).mp3";
                 * musicTrackEN.Format = "mp3";
                 * musicTrackEN.Lyrics = "Beer Beer Beer Beer Beer Beer ..";
                 * musicTrackEN.Name = "Beer Beer Beer";
                 * musicTrackEN.Company = "Company";
                 * musicTrackEN.Cover = "http://www.tomasabraham.com.ar/cajadig/2007/images/nro18-2/beer1.jpg";
                 * musicTrackEN.Price = 20;
                 * musicTrackEN.Rating = 5;
                 * musicTrackEN.CommunityRating = 5;
                 * musicTrackEN.Duration = 200;
                 * musicTrackCEN.New_(musicTrackEN.Id, musicTrackEN.Format, musicTrackEN.Lyrics, musicTrackEN.Name,
                 *  musicTrackEN.Company, musicTrackEN.Cover, musicTrackEN.CommunityRating, musicTrackEN.Rating,
                 *  musicTrackEN.Price, musicTrackEN.Duration);
                 * musicTracks.Add(musicTrackEN);
                 * musicTrackCEN.AsignUser(musicTrackEN.Id,userEN.Email);
                 *
                 * //Define Album
                 * //BalumaProjectGenNHibernate.CEN.Mediaplayer.AlbumCEN albumCEN = new BalumaProjectGenNHibernate.CEN.Mediaplayer.AlbumCEN();
                 * //albumCEN.New_("Album 1", "This is a Album 1", artists, musicTracks);*/
                /*PROTECTED REGION END*/
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.InnerException);
                throw ex;
            }
        }