예제 #1
0
        public CReport GetReport(CReport report)
        {
            string reportfullPath = Path.Combine(CReportConfig.Report_Url, report.ReportUrl);

            if (!File.Exists(reportfullPath))
            {
                report.Description = "Template not found.";
            }
            string htmlContent = File.ReadAllText(reportfullPath);

            htmlContent    = SetReportData(htmlContent, null);
            report.Content = ExportToPdf(htmlContent);
            return(report);
        }
예제 #2
0
파일: CReport.cs 프로젝트: phinamcn03/ttdk
        public CReport GetReportContent(int pUserID, string pReportSession, int pLanguageID, int ReportID)
        {
            CReport _report = new CReport();

            _report.Name       = this.Name;
            _report.Title      = this.Title;
            _report.ReportUrl  = this.ReportUrl;
            _report.ExportName = this.ExportName;
            _report.ExportType = this.ExportType;
            _report.Session    = pReportSession;

            try
            {
                //Neu file template la HTML
                if (_report.ReportUrl.EndsWith(".htm") || _report.ReportUrl.EndsWith(".html"))
                {
                    return(new CHTMLReport().GetReport(_report));
                }

                string _htmlFileName = "";
                if (_report.ReportUrl.Trim() != "" && _report.ReportUrl.ToLower().IndexOf("rpt") != -1)
                {
                    CLogManager.WritePL("CReport.GetReportContent", "Beg GetReportDocument ");
                    ReportDocument _reportDoc = GetReportDocument(_report.ReportUrl);
                    CLogManager.WritePL("CReport.GetReportContent", "End GetReportDocument ");
                    SetReportParameter(_reportDoc, pUserID, pReportSession, pLanguageID);
                    CLogManager.WritePL("CReport.GetReportContent", "End SetReportParameter ");
                    if (_reportDoc != null)
                    {
                        /*if (_reportDoc.ParameterFields.Count > 0)
                         * {
                         *  for (int i = 0; i < _reportDoc.ParameterFields.Count; i++)
                         *  {
                         *      switch (_reportDoc.ParameterFields[i].Name.ToLower())
                         *      {
                         *          case "@userid":
                         *              _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, pUserID);
                         *              break;
                         *          case "@session":
                         *              //su dung cho du lieu la Table, Store, Function
                         *              _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, "" + pReportSession.Replace("'", "") + "");
                         *              //Su dung cho du lieu la Command
                         *              //reportDoc.SetParameterValue(reportDoc.ParameterFields[i].Name, "'" + rpl.Session.Replace("'", "") + "'");
                         *              break;
                         *          case "@languageid":
                         *              _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, pLanguageID);
                         *              break;
                         *          default:
                         *              if (_reportDoc.ParameterFields[i].DefaultValues != null && _reportDoc.ParameterFields[i].DefaultValues.Count > 0)
                         *                  _reportDoc.SetParameterValue(_reportDoc.ParameterFields[i].Name, _reportDoc.ParameterFields[i].DefaultValues[0]);
                         *              break;
                         *      }
                         *  }
                         * }
                         * */

                        _reportDoc.PrintOptions.Dispose();
                        Stream _stream = null;
                        CLogManager.WritePL("CReport.GetReportContent", "Beg Export ");
                        switch (this.ExportName.ToLower())
                        {
                        case CExportName.Document:
                            _report.ExportName = CExportContentType.Document;
                            _stream            = _reportDoc.ExportToStream(ExportFormatType.WordForWindows);
                            _reportDoc.Close();
                            break;

                        case CExportName.Excel:
                            _report.ExportName = CExportContentType.Excel;
                            _stream            = _reportDoc.ExportToStream(ExportFormatType.Excel);

                            _reportDoc.Close();
                            break;

                        case CExportName.Html:
                            _report.ExportName = CExportContentType.Html;
                            _htmlFileName      = AppDomain.CurrentDomain.BaseDirectory + pReportSession + ".htm";
                            /*Export to HTML*/
                            _reportDoc.ExportToDisk(ExportFormatType.HTML40, _htmlFileName);     /*Sinh ra the DIV*/
                            //reportDoc.ExportToDisk(ExportFormatType.HTML32, filename); /*Sinh ra the Table*/
                            _reportDoc.Close();

                            /*Get HTML Content to byte array*/
                            _report.Content         = CReportFunction.GetBytesFromFile(_htmlFileName);
                            _report.ListReportImage = CReportFunction.GetListImagesBySession(pReportSession);
                            break;

                        case CExportName.Report:
                            _report.ExportName = CExportContentType.Document;
                            _stream            = _reportDoc.ExportToStream(ExportFormatType.CrystalReport);
                            _reportDoc.Close();
                            break;

                        default:     //PDF
                            _report.ExportName = CExportContentType.PDF;
                            _stream            = _reportDoc.ExportToStream(ExportFormatType.PortableDocFormat);
                            _reportDoc.Close();
                            break;
                        }
                        CLogManager.WritePL("CReport.GetReportContent", "End Export ");
                        if (_stream != null && _htmlFileName == "") //Not HTML
                        {
                            _report.Content = CReportFunction.StreamToByteArray(_stream);
                        }
                    }
                    else
                    {
                        _report.Description = "03 - Report file is not exits Or Load report data fail.";
                        CLogManager.WritePL("User:"******"ReportSession" + pReportSession + ", 03 - Report file is not exits Or Load report fail.");
                    }
                }
                else
                {
                    _report.Description = "01 - ReportFileName is null. Check database again!";
                    CLogManager.WritePL("User:"******"ReportID " + pReportSession + ", 01 - ReportFileName is null. Check database again!");
                }
            }
            catch (Exception ex)
            {
                CLogManager.WritePL("CReport.GetReportContent Ex", ex.ToString() + ex.StackTrace);
            }
            return(_report);
        }