Example #1
0
        private void btnReporteValoracion_Click(object sender, RoutedEventArgs e)
        {
            if (!validarFechas())
            {
                MessageBox.Show("La fecha de inicio debe ser menor a la de termino\n Ingrese nuevamente", "Reporteria - Mis Ofertas");
                dpFechaInicio.Focus();
            }
            else
            {
                try
                {
                    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                    List <ReporteValoracion> listaRegistros = new List <ReporteValoracion>();

                    if (dpFechaInicio.SelectedDate == null && dpFechaTermino.SelectedDate == null)
                    {
                        listaRegistros = reporteValoracionNeg.listaRegistrosReporteValoracion(null, null);
                    }
                    else
                    {
                        listaRegistros = reporteValoracionNeg.listaRegistrosReporteValoracion(
                            dpFechaInicio.SelectedDate,
                            dpFechaTermino.SelectedDate);
                    }


                    String rutaDirectorioOferta             = "D:/MisOfertas/Reportes/";
                    List <ImagenOferta> listaImagenesOferta = new List <ImagenOferta>();
                    if (!Directory.Exists(rutaDirectorioOferta))
                    {
                        Directory.CreateDirectory(rutaDirectorioOferta);
                    }

                    DateTime fechaCreacionReporte = DateTime.Now;
                    String   rutaReporte          = rutaDirectorioOferta + "/ReporteValoracion" + fechaCreacionReporte.ToString("ddMMyyyyHHmm") + ".pdf";

                    PdfWriter   writer   = new PdfWriter(rutaReporte);
                    PdfDocument pdf      = new PdfDocument(writer);
                    Document    document = new Document(pdf, PageSize.A4);
                    PdfFont     font     = PdfFontFactory.CreateFont(FontConstants.TIMES_ROMAN);


                    string _filePath = System.IO.Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
                    _filePath  = Directory.GetParent(_filePath).FullName;
                    _filePath  = Directory.GetParent(_filePath).FullName;
                    _filePath += @"\img\MisOfertas-Letras.png";

                    //string ruta_imagen = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"img\MisOfertas-Letras.png");
                    //String ruta_imagen = "D:/Portafolio 2017/MisOfertasEscritorio/Seba/Satelite_MisOfertas/View/img/MisOfertas-Letras.png";
                    document.Add(new iText.Layout.Element.Image(ImageDataFactory.Create(_filePath)).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.RIGHT).SetWidth(40).SetHeight(40));


                    document.Add(new iText.Layout.Element.Paragraph("Reporte valoracion de ofertas").SetFont(font).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetFontSize(20));
                    document.Add(new iText.Layout.Element.Paragraph(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString()).SetFont(font).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetFontSize(18));

                    float[] columnWidths = { 1, 5, 6, 5, 5, 5, 5, 5, 5, 5 };//{1,1,10,10,5,5,1,1,1,1,1,1};

                    iText.Layout.Element.Table tableRegistros = new iText.Layout.Element.Table(10).SetFontSize(12);
                    tableRegistros.SetWidthPercent(100);
                    tableRegistros.SetFixedLayout();

                    float fontCell     = 11;
                    float fontCellData = 9;

                    Cell[] headerFooter = new Cell[] {
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("#").SetFontSize(fontCell).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Oferta").SetFontSize(fontCell),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Inicio").SetFontSize(fontCell),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Finalizacion").SetFontSize(fontCell),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Rubro").SetFontSize(fontCell),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Empresa").SetFontSize(fontCell),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Val. Negativas").SetFontSize(fontCell).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Val. Medias").SetFontSize(fontCell).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Val. Positivas").SetFontSize(fontCell).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER),
                        new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Total").SetFontSize(fontCell).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER)
                    };
                    //new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Productos").SetFontSize(fontCell),
                    //new Cell().SetBackgroundColor(new DeviceGray(0.75f)).Add("Imagenes").SetFontSize(fontCell)};


                    foreach (Cell hfCell in headerFooter)
                    {
                        tableRegistros.AddHeaderCell(hfCell);
                    }

                    for (int i = 0; i < listaRegistros.Count; i++)
                    {
                        ReporteValoracion reporte = listaRegistros[i];
                        Oferta            oferta  = reporte.Oferta;
                        Rubro             rubro   = reporte.Rubro;
                        Empresa           empresa = reporte.Empresa;
                        tableRegistros.AddCell(oferta.IdOferta.ToString()).SetFontSize(fontCellData).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        tableRegistros.AddCell(oferta.TituloOferta).SetFontSize(fontCellData);
                        tableRegistros.AddCell(oferta.FechaInicio.ToShortDateString()).SetFontSize(fontCellData);
                        tableRegistros.AddCell(oferta.FechaFinalizacion.ToShortDateString()).SetFontSize(fontCellData);
                        tableRegistros.AddCell(rubro.DescripcionRubro).SetFontSize(fontCellData);
                        tableRegistros.AddCell(empresa.NombreEmpresa).SetFontSize(fontCellData);
                        tableRegistros.AddCell(reporte.CantValoracionNegativas.ToString()).SetFontSize(fontCellData).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        tableRegistros.AddCell(reporte.CantValoracionMedia.ToString()).SetFontSize(fontCellData).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        tableRegistros.AddCell(reporte.CantValoracionPositiva.ToString()).SetFontSize(fontCellData).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                        tableRegistros.AddCell(reporte.CantValoracionTotal.ToString()).SetFontSize(fontCellData).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER);
                    }

                    //tableRegistros.AddCell(reporte.CantProductos.ToString()).SetFontSize(fontCellData);
                    //tableRegistros.AddCell(reporte.CantImagenes.ToString()).SetFontSize(fontCellData);
                    document.Add(tableRegistros);
                    document.Close();

                    Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
                    MessageBox.Show("Reporte generado correctamente \n en la ruta: " + rutaReporte, "Reporteria - Mis Ofertas");

                    //Uri test = new Uri(rutaReporte);
                    //WebBrowser.Navigate(rutaReporte);
                }
                catch (Exception err)
                {
                    MessageBox.Show("Se ha presentado un inconveniente al generar el reporet\nIntente nuevamente", "Reporteria - Mis Ofertas");
                }
            }
        }
Example #2
0
        public List <ReporteValoracion> listaRegistroValoracion(DateTime?fechaInicio, DateTime?fechaFin)
        {
            try
            {
                List <ReporteValoracion> listaRegistros = new List <ReporteValoracion>();
                OracleCommand            cmd            = new OracleCommand();
                ReporteValoracion        reporte;
                Oferta  oferta;
                Rubro   rubro;
                Local   local;
                Empresa empresa;



                cmd.Connection  = conexion.Obtener();
                cmd.CommandText = "SP_SELECT_REPORTE_VALORACIONES";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("p_FECHA_PUBLICACION_INICIO", OracleDbType.Date).Value             = fechaInicio;
                cmd.Parameters.Add("p_FECHA_PUBLICACION_TERMINO", OracleDbType.Date).Value            = fechaFin;
                cmd.Parameters.Add(new OracleParameter("p_CURSOR", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
                if (conexion.Obtener().State.Equals(ConnectionState.Closed))
                {
                    conexion.Obtener().Open();
                }
                OracleDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    reporte = new ReporteValoracion();

                    oferta                   = new Oferta();
                    oferta.IdOferta          = dr.GetInt32(0);
                    oferta.TituloOferta      = dr.GetString(1);
                    oferta.FechaInicio       = dr.GetDateTime(2);
                    oferta.FechaFinalizacion = dr.GetDateTime(3);
                    rubro                  = new Rubro();
                    rubro.IdRubro          = dr.GetInt32(4);
                    rubro.DescripcionRubro = dr.GetString(5);
                    local                  = new Local();
                    local.Direccion        = dr.GetString(6);
                    empresa                = new Empresa();
                    empresa.NombreEmpresa  = dr.GetString(7);

                    reporte.Oferta  = oferta;
                    reporte.Rubro   = rubro;
                    reporte.Local   = local;
                    reporte.Empresa = empresa;


                    reporte.CantValoracionNegativas = dr.GetInt32(8);
                    reporte.CantValoracionMedia     = dr.GetInt32(9);
                    reporte.CantValoracionPositiva  = dr.GetInt32(10);
                    reporte.CantValoracionTotal     = dr.GetInt32(11);
                    reporte.CantProductos           = dr.GetInt32(12);
                    reporte.CantImagenes            = dr.GetInt32(13);

                    listaRegistros.Add(reporte);
                }
                conexion.Obtener().Close();
                return(listaRegistros);
            }
            catch (Exception e)
            {
                conexion.Obtener().Close();
                return(null);
            }
        }