Example #1
0
        /// <summary>
        /// 实例化ReportDocument
        /// </summary>
        /// <param name="strReportFileName">报表文件的名称</param>
        /// <param name="strSql">查询SQL语句</param>
        /// <param name="strTable">数据表</param>
        /// <returns>ReportDocument对象的引用</returns>
        public ReportDocument CrystalReports(string strReportFileName, string strSql, string strTable)
        {
            //获取报表路径
            string strReportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
                                                                                                          Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));

            strReportPath += @"\RP\" + strReportFileName;
            //得到dt数据源
            DataTable dt = db.GetDataTable(strSql, strTable);
            //ReportDocument对象加载rpt文件并绑定到数据源dt
            ReportDocument reportDoc = new ReportDocument();

            reportDoc.Load(strReportPath);
            reportDoc.SetDataSource(dt.DefaultView); //DataView是接口IEnumerable的实现子类,此处使用了“接口”的多态特性

            //水晶报表动态链接数据库
            TableLogOnInfo logOnInfo = new TableLogOnInfo();

            logOnInfo.ConnectionInfo.ServerName   = OperatorFile.GetIniFileString("DataBase", "Server", "", Application.StartupPath + "\\ERP.ini");
            logOnInfo.ConnectionInfo.DatabaseName = "db_ERP";
            logOnInfo.ConnectionInfo.UserID       = OperatorFile.GetIniFileString("DataBase", "UserID", "", Application.StartupPath + "\\ERP.ini");
            logOnInfo.ConnectionInfo.Password     = OperatorFile.GetIniFileString("DataBase", "Pwd", "", Application.StartupPath + "\\ERP.ini");

            // 对报表中的每个表依次循环(把连接信息存入每一个Table中)
            foreach (Table tb in reportDoc.Database.Tables)
            {
                tb.ApplyLogOnInfo(logOnInfo);
            }

            //返回ReportDocument对象
            return(reportDoc);
        }
Example #2
0
        /// <summary>
        /// 实例化ReportDocument
        /// </summary>
        /// <param name="strReportFileName">报表文件的名称</param>
        /// <param name="strSelectionFormula">记录的规则或公式</param>
        /// <returns>ReportDocument对象的引用</returns>
        public ReportDocument CrystalReports(string strReportFileName, string strSelectionFormula)
        {
            //获取报表路径
            string strReportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
                                                                                                          Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));

            strReportPath += @"\RP\" + strReportFileName;
            //加载报表并设置查询规则
            ReportDocument reportDoc = new ReportDocument();

            reportDoc.Load(strReportPath);
            reportDoc.DataDefinition.RecordSelectionFormula = strSelectionFormula;

            //水晶报表动态链接数据库
            TableLogOnInfo logOnInfo = new TableLogOnInfo();

            logOnInfo.ConnectionInfo.ServerName   = OperatorFile.GetIniFileString("DataBase", "Server", "", Application.StartupPath + "\\ERP.ini");
            logOnInfo.ConnectionInfo.DatabaseName = "db_ERP";
            logOnInfo.ConnectionInfo.UserID       = OperatorFile.GetIniFileString("DataBase", "UserID", "", Application.StartupPath + "\\ERP.ini");
            logOnInfo.ConnectionInfo.Password     = OperatorFile.GetIniFileString("DataBase", "Pwd", "", Application.StartupPath + "\\ERP.ini");

            // 对报表中的每个表依次循环(把连接信息存入每一个Table中)
            foreach (Table tb in reportDoc.Database.Tables)
            {
                tb.ApplyLogOnInfo(logOnInfo);
            }

            //返回ReportDocument对象
            return(reportDoc);
        }