Foros del Web » Programación para mayores de 30 ;) » .NET »

Reporte de Ejemplo

Estas en el tema de Reporte de Ejemplo en el foro de .NET en Foros del Web. Hola a Todos, nuevamente vengo a molestar con la clase Root.Reports, pero esta vez con buenas nuevas, aca les muestro un ejemplo para generar un ...
  #1 (permalink)  
Antiguo 27/03/2005, 11:45
Avatar de rodri  
Fecha de Ingreso: febrero-2005
Mensajes: 406
Antigüedad: 19 años, 2 meses
Puntos: 2
Sonrisa Reporte de Ejemplo

Hola a Todos, nuevamente vengo a molestar con la clase Root.Reports, pero esta vez con buenas nuevas, aca les muestro un ejemplo para generar un PDF que consta de una tabla resultado de una consulta a una Base de Datos, unos datos de hora y numero de paginas, ademas de una linea al final de cada hoja. Lo unico que tiene que hacer es hacer copy / paste en su parte de codigo, tener un boton que llame al PDF y obviamente tener registrada la dll de Root.Reports.

Pd. El usuario y password es el que tienen en su maquina obviamente.

Nos Vemos!!!, espero que sirva!


Ojo. este ejemplo lo adapté de los ejemplo que proporciona la clase que se descarga de:

http://sourceforge.net/project/showf...group_id=58374 (Recomendado por RootK en las Faqs)

Código:
public class Reporte_Customers:Report
            {
                    //definimos los campos de la definición de fuentes y bordes
                    private FontDef fd;
                    private double rPosLeft = 20;
                    private double rPosRight= 195;
                    private double rPosTop= 24;
                    private double rPosBottom= 278;
                    private string sConnectionString =@"Provider=SQLOLEDB;initial catalog=northwind;user id=sa;password='sa'";


              //protected override void Save(string nombre);

              protected override void Create()
              {

            fd = new FontDef(this, FontDef.StandardFont.Helvetica);
           FontProp fp = new FontPropMM(fd, 1.9);  // standard font
           FontProp fp_Header = new FontPropMM(fd, 1.9);  // font of the table header
           fp_Header.bBold = true;


            //using1
            using (TableLayoutManager tlm = new TableLayoutManager(fp_Header))
            {tlm.rContainerHeightMM = rPosBottom - rPosTop;  // set height of table
            tlm._tableHeight = TlmBase.TableHeight.AdjustLast;
             tlm.headerCellDef.rAlignV = RepObj.rAlignCenter;  // set vertical alignment of all header cells
             tlm.cellDef.pp_LineBottom = new PenProp(this, 0.05, Color.LightGray);  // set bottom line for all cells
             tlm.eNewContainer += new TableLayoutManager.NewContainerEventHandler(this.Tlm_NewContainer);

              TableLayoutManager.Column col;
             col = new TableLayoutManager.ColumnMM(tlm, "ID", 13);

             col = new TableLayoutManager.ColumnMM(tlm, "Company Name", 40);
             col.cellDef.textMode = TableLayoutManager.TextMode.MultiLine;

             col = new TableLayoutManager.ColumnMM(tlm, "Address", 36);

             col = new TableLayoutManager.ColumnMM(tlm, "City", 22);

             col = new TableLayoutManager.ColumnMM(tlm, "Postal Code", 16);

             col = new TableLayoutManager.ColumnMM(tlm, "Country", 18);
                // using2
             using (OleDbConnection oleDbConnection = new OleDbConnection(sConnectionString))
             {oleDbConnection.Open();
             OleDbCommand oleDbCommand = new OleDbCommand("SELECT CustomerID, CompanyName, Address, City, PostalCode, Country, Phone FROM Customers ORDER BY CompanyName", oleDbConnection);
                    //using3
                   using (OleDbDataReader oddr = oleDbCommand.ExecuteReader())
                   {
                         while (oddr.Read())
                        {
                        tlm.NewRow();
                   tlm.Add(0, new RepString(fp, oddr.GetString(0)));
                   tlm.Add(1, new RepString(fp, oddr.GetString(1)));
                   tlm.Add(2, new RepString(fp, oddr.GetString(2)));
                   tlm.Add(3, new RepString(fp, oddr.GetString(3)));
                   if (!oddr.IsDBNull(4)) {
                     tlm.Add(4, new RepString(fp, oddr.GetString(4)));
                   }
                   tlm.Add(5, new RepString(fp, oddr.GetString(5)));
                        }//while
                   }//using3
             }//using2

             }//using1



           // print page number and current date/time
          foreach (Root.Reports.Page page in enum_Page)
          {
             Double rY = rPosBottom + 1.5;
             page.AddLT_MM(rPosLeft, rY, new RepString(fp, DateTime.Now.ToShortDateString()  + "  " + DateTime.Now.ToShortTimeString()));
             page.AddRT_MM(rPosRight, rY, new RepString(fp, page.iPageNo + " / " + iPageCount));
             if (page.iPageNo==iPageCount)
             {
             page.AddCT_MM(50,200,new RepString(fp,"Hola"));
             }
              //intento hacer una linea
                      // con esta clase ajustamos a la linea -> el reporte en donde se genera,
                      // el grueso de la linea, el color de la linea
                    PenProp pprop = new PenProp(this,0.5,Color.Maroon);

                      // con esta creamos la linea en cuestion
                      // Parámetros -> el penprop, el largo de la linea en eje x (eje y en 0)
                    RepLineMM linea = new RepLineMM(pprop,175,0);
                      //con esta añadimos al reporte-> Posisicion en eje X, posicion en eje Y, el objeto de linea.
                    page.AddCT_MM(107,279,linea);
                    //linea hecha.

           }
            /**/
         }

                  private void Tlm_NewContainer(Object oSender, TableLayoutManager.NewContainerEventArgs ea)
         {  // only "public" for NDoc, should be "private"

new Root.Reports.Page(this);
           // first page with caption
           if (page_Cur.iPageNo == 1) {
             FontProp fp_Title = new FontPropMM(fd, 7);
             fp_Title.bBold = true;
             page_Cur.AddCT_MM(rPosLeft + (rPosRight - rPosLeft) / 2, rPosTop, new RepString(fp_Title, "Customer List"));
             ea.container.rHeightMM -= fp_Title.rLineFeedMM;  // reduce height of table container for the first page
            }


           // the new container must be added to the current page
           page_Cur.AddMM(rPosLeft, rPosBottom - ea.container.rHeightMM, ea.container);


         }

}

void Button1_Click(object sender, EventArgs e) {
RT.ResponsePDF(new Reporte_Customers(),this);
}
Chau!
__________________
0.o Rodri
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:23.