Exemplo n.º 1
0
        public static Result Load(DataTable dataTable, string reportFileName)
        {
            // is report file specified?
            if (string.IsNullOrEmpty(reportFileName))
            {
                return(new Result(false, "No report file specified in the Report Item"));
            }

            // is report file exist?
            var fullPathName = Path.Combine(ReportController.ReportFolder, reportFileName);

            if (!File.Exists(fullPathName))
            {
                return(new Result(false, "Report File not found."));
            }
            try
            {
                var reportDocument = new ReportDocument();
                reportDocument.Load(fullPathName);
                reportDocument.SetDataSource(dataTable);

                /****************************************
                * Load the CrystalReport using WPF Form
                ****************************************/
                var crystalReportsViewer = new CrystalReportsViewer();
                crystalReportsViewer.ViewerCore.ReportSource = reportDocument;

                var reportWindow = new MainReportWindow();
                reportWindow.AddControl(crystalReportsViewer);
                reportWindow.ShowDialog();

                return(new Result(true, "Report loaded successful."));
            }
            catch (Exception exception)
            {
                return(new Result(false, exception.Message));
            }
        }
Exemplo n.º 2
0
        public Result LoadReport(DateTime asOf, DataTable[] dataTables, string reportFile)
        {
            ReportFile = reportFile;
            // is report file specified?
            if (string.IsNullOrEmpty(ReportFile))
            {
                return(new Result(false, "No report file specified in the Report Item"));
            }

            // is report file exist?
            var fullPathName = Path.Combine(ReportController.ReportFolder, ReportFile);

            if (!File.Exists(fullPathName))
            {
                return(new Result(false, string.Format("Report File '{0}' not found.", reportFile)));
            }

            try
            {
                // query the database / run stored procedure
                if (!string.IsNullOrEmpty(reportFile))
                {
                    DataTable comp = Company.GetData();

                    // initialize report data
                    DataSource = new DataSet();
                    DataSource.Tables.Add(comp);
                    DataSource.Tables[0].TableName = "comp";

                    foreach (DataTable dataTable in dataTables)
                    {
                        DataSource.Tables.Add(dataTable);
                    }
                }

                /*******************************************************
                * define report document and set report file and data
                * *****************************************************/
                var reportDocument = new ReportDocument();
                reportDocument.Load(fullPathName);

                /*************************************************************************
                * Must loop through each DataTable to update the ReportDocument.Database
                *************************************************************************/
                foreach (DataTable table in DataSource.Tables)
                {
                    reportDocument.Database.Tables[table.TableName].SetDataSource(DataSource.Tables[table.TableName]);
                }

                /******************************************************************
                * Use ReportModel.ReportTitle as the report title of the rpt file
                ******************************************************************/
                foreach (FormulaFieldDefinition ff in reportDocument.DataDefinition.FormulaFields)
                {
                    if (ff.Kind == FieldKind.FormulaField)
                    {
                        if (ff.Name.Contains("report_title"))
                        {
                            ff.Text = "'" + Title + "'";
                            continue;
                        }
                        if (ff.Name.Contains("as_of"))
                        {
                            ff.Text = "'" + string.Format("As of {0:MMMM dd, yyyy}", asOf) + "'";
                        }
                    }
                }

                /****************************************
                * Load the CrystalReport using WPF Form
                ****************************************/
                var crystalReportsViewer = new CrystalReportsViewer();
                crystalReportsViewer.ViewerCore.ReportSource = reportDocument;

                var reportWindow = new MainReportWindow();
                reportWindow.AddControl(crystalReportsViewer);
                reportWindow.ShowDialog();

                return(new Result(true, "Report loaded successful."));
            }
            catch (Exception exception)
            {
                Logger.ExceptionLogger(GetType(), exception);
                return(new Result(false, exception.Message));
            }
        }
Exemplo n.º 3
0
        public Result LoadReport()
        {
            // is report file specified?
            if (string.IsNullOrEmpty(ReportFile))
            {
                return(new Result(false, "No report file specified in the Report Item"));
            }

            // is report file exist?
            var fullPathName = Path.Combine(ReportController.ReportFolder, ReportFile);

            if (!File.Exists(fullPathName))
            {
                return(new Result(false, "Report File not found."));
            }

            try
            {
                // query the database / run stored procedure
                if (!string.IsNullOrEmpty(StoredProcedure))
                {
                    DataTable comp = Company.GetData();
                    comp.TableName = "comp";

                    DataTable detail = HasStoredProcedureParameter
                                           ? DatabaseController.ExecuteStoredProcedure(StoredProcedure, StoredProcedureParameters)
                                           : DatabaseController.ExecuteStoredProcedure(StoredProcedure);

                    detail.TableName = Path.GetFileNameWithoutExtension(ReportFile);

                    // initialize report data
                    var dataSet = new DataSet();
                    dataSet.Tables.Add(comp);
                    dataSet.Tables.Add(detail);

                    DataSource = dataSet;
                }

                /*******************************************************
                * define report document and set report file and data
                * *****************************************************/
                var reportDocument = new ReportDocument();
                reportDocument.Load(fullPathName);

                /*************************************************************************
                * Must loop through each DataTable to update the ReportDocument.Database
                *************************************************************************/
                if (DataSource != null)
                {
                    foreach (DataTable table in DataSource.Tables)
                    {
                        reportDocument.Database.Tables[table.TableName].SetDataSource(DataSource.Tables[table.TableName]);
                    }
                }

                /******************************************************************
                * Use ReportModel.ReportTitle as the report title of the rpt file
                ******************************************************************/
                foreach (FormulaFieldDefinition ff in reportDocument.DataDefinition.FormulaFields)
                {
                    if (ff.Kind == FieldKind.FormulaField)
                    {
                        if (ff.Name.Contains("ReportTitle"))
                        {
                            ff.Text = "'" + Title + "'";
                            break;
                        }
                    }
                }

                /****************************************
                * Load the CrystalReport using WPF Form
                ****************************************/
                var crystalReportsViewer = new CrystalReportsViewer();
                crystalReportsViewer.ViewerCore.ReportSource = reportDocument;

                var reportWindow = new MainReportWindow();
                reportWindow.AddControl(crystalReportsViewer);
                reportWindow.ShowDialog();

                return(new Result(true, "Report loaded successful."));
            }
            catch (Exception exception)
            {
                Logger.ExceptionLogger(GetType(), exception);
                return(new Result(false, exception.Message));
            }
        }