[Original] Crystal Report Data Filled (a push mode, two pull mode) class library

xiaoxiao2021-03-06  40

#Region statement // --------------------------------------------- ------------------------- ////// author: Li Miao (Nick.Lee) //// crystal reports data population (a Push mode, two pull modes) class library ///// Boyorgril@msn.com/////---------------------- ---------------------------------------------- # endregion # region Data fill crystal report function collection

///

/// Use Engine.Database to populate CRYSTALREPORT, use it for OLEDB, ODBC, this example is SQL Server, pull mode /// /// server name / param> /// Database name /// User ID /// user password /// Crystal Report CrystalReport object / * Note: Use engine.Database population must be set in the Crystal Report * / Public Void Crydbfill (String Severname) , string DatabaseName, string UserID, string Password, ReportClass sender) {TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo (); ConnectionInfo crConnectionInfo = new ConnectionInfo (); CrystalDecisions.CrystalReports.Engine.Database crDatabase; CrystalDecisions.CrystalReports.Engine.Tables crTables; // CrystalDecisions.CrystalReports.Engine.Table crTable; // object definition crConnectionInfo.ServerName = severName; crConnectionInfo.DatabaseName = DatabaseName; crConnectionInfo.UserID = UserID; crConnectionInfo.Password = Password; crDatabase = sender.Database; crTables = crDatabase.Tables; // Crystal Reports database connection foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables) {crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; crTable.ApplyLogOnInfo (crTableLogOnInfo);} // loop table and Fill} /// /// Use Dataset to populate CrystalReport and ReportDocument, for SQL Server, push mode, can populate multiple table names in one data set /// /// /// < Param name = "sqltext"> Database query field //// database connection field ///

"DataTableName"> virtual cube Title public void crySetFill (string sqlText, string cnString, string DataTableName) {// build the data set (local variables) System.Data.SqlClient.SqlConnection connection1 = new System.Data.SqlClient . SqlConnection; system.data.sqlclient.sqldataadapter COM = new system.data.sqlclient.sqldataadapter (SqlText, Connection1); // Assign memory space // to the data collection allocate memory space com.fill (SET1 , DATATABLENAME);} ///

/// Implement multiple datasets set fills CrystalReport /// /// Crystal report CrystalReport object public void rptReportClassFill (ReportClass sender) {// data filling sender.SetDataSource (Set1); // first use crySetFill //print1.cryDSetFill("select * from Customers "," server = localhost; uid = sa; pwd = sa; database = Northwind "," customers "); // State public type, for example: // public printclass print1 = new printclass (); // public crystalReport2 rep1 = new crystalReport2 (); // then call // rPTREPORTCLASSFILL (REP1); //Crystalreportviewer1.reportsource = rep1; //crystalreportViewer1.database (); // string sqltext = "select * from customers"; // string cnstring = "server = localhost; uid = sa; pwd = sa; data = northwind;"; / * Note: Use DataSet pads must first create a visual DataSet.xsd, add Element, and display related data fields in the crystal report * /}

///

/// Implement multiple data sets Fill CRYSTALREPORT /// /// Crystal Report ReportDocument Object Public Void RPTREPORTDocumentFill (ReportDocument Sender ) {// Data fill sender.setDataSource (SET1); // First use CrysetFill //print1.crydsetFill ("Select * from customers "," Server = localhost; uid = sa; pwd = sa; database = northwind "," Customers "); // declare common type, for example: // public printClass print1 = new printClass (); // public ReportDocument RD1 = new ReportDocument (); // then call // rptReportDocumentFill (RD1); //CrystalReportViewer1.ReportSource = Rd1; //crystalreportViewer1.database = "select * from customers"; // string cnstring = "server = localhost; uid = sa; pwd = sa; data = northwind;"; / * pay attention : Use the DataSet padding must first create a visual dataset.xsd, add Element, and display the relevant data fields in the crystal report * /}

///

/// Use ReportDocument to populate CRYSTALREPORT, use OLEDB, ODBC, this example is SQL Server, pull mode /// /// server name /// Database name /// User ID /// user password /// Get the name of the crystal report file for the specified path /// Crystal report ReportDocument object public void CryDocumentFill (String Severname String DatabaseName, String Userid, String Password, String FileName, ReportDocument Sender) {string path = system.web.httpContext.current.server.mappath (filename); Sender.Load (PATH);

TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo (); crTableLogOnInfo.ConnectionInfo.ServerName = SeverName; crTableLogOnInfo.ConnectionInfo.Password = Password; crTableLogOnInfo.ConnectionInfo.DatabaseName = DatabaseName; crTableLogOnInfo.ConnectionInfo.UserID = UserID; // set the connection path to load parameters // ReportDocument Sender.database.tables [0] .applylogonInfo (CRTABLOGONIINFO); // Settings the corresponding table connection parameter // Use Namespace // USING CRYSTALDECISIONS.CRYSTALREPORTS.EENGINE; // USING CRYSTALDECSIONS.SHARED; / * Note: Using Engine.Database Plip must first set the relevant data field * / / / / / declaration in the crystal report, for example: // public printclass print1 = new printClass (); // public reportDocument rd1 = new reportDocument (); // then call // print1 . CryDocumentfill ("10.141.165.136", "northwind", "sa", "sa", "customers", "*. RPT", RD1); //crystalreportviewer1.reportsource = rd1; //crystalreportviewer1.database (); }

#ndregion

转载请注明原文地址:https://www.9cbs.com/read-59589.html

New Post(0)