예제 #1
0
        public void ExportReport(ReportDocument oReport, string cFileName, ExportTypes oExportTypes, int nFirstPage, int nLastPage)
        {
            ExportOptions              oExportOptions      = new ExportOptions();
            PdfRtfWordFormatOptions    oFormatOptions      = ExportOptions.CreatePdfRtfWordFormatOptions();
            DiskFileDestinationOptions oDestinationOptions = ExportOptions.CreateDiskFileDestinationOptions();

            switch (oExportTypes)
            {
            case ExportTypes.PDF:
            case ExportTypes.MSWord:
                oExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                PdfRtfWordFormatOptions oPDFFormatOptions = ExportOptions.CreatePdfRtfWordFormatOptions();

                if (nFirstPage > 0 && nLastPage > 0)
                {
                    oPDFFormatOptions.FirstPageNumber = nFirstPage;
                    oPDFFormatOptions.LastPageNumber  = nLastPage;
                    oPDFFormatOptions.UsePageRange    = true;
                }
                oExportOptions.ExportFormatOptions = oPDFFormatOptions;
                break;

            case ExportTypes.MSExcel:
                oExportOptions.ExportFormatType = ExportFormatType.Excel;
                ExcelFormatOptions oExcelFormatOptions = ExportOptions.CreateExcelFormatOptions();

                if (nFirstPage > 0 && nLastPage > 0)
                {
                    oExcelFormatOptions.FirstPageNumber = nFirstPage;
                    oExcelFormatOptions.LastPageNumber  = nLastPage;
                    oExcelFormatOptions.UsePageRange    = true;
                }
                oExcelFormatOptions.ExcelUseConstantColumnWidth = false;
                oExportOptions.ExportFormatOptions = oExcelFormatOptions;
                break;

            case ExportTypes.HTML:
                oExportOptions.ExportFormatType = ExportFormatType.HTML40;
                HTMLFormatOptions oHTMLFormatOptions = ExportOptions.CreateHTMLFormatOptions();
                if (nFirstPage > 0 && nLastPage > 0)
                {
                    oHTMLFormatOptions.FirstPageNumber = nFirstPage;
                    oHTMLFormatOptions.LastPageNumber  = nLastPage;
                    oHTMLFormatOptions.UsePageRange    = true;
                }
                // can set additional HTML export options here

                oExportOptions.ExportFormatOptions = oHTMLFormatOptions;
                break;
            }


            oDestinationOptions.DiskFileName        = cFileName;
            oExportOptions.ExportDestinationOptions = oDestinationOptions;
            oExportOptions.ExportDestinationType    = ExportDestinationType.DiskFile;

            oReport.Export(oExportOptions);
        }
예제 #2
0
        private void GenerateHTML()
        {
            ReportDocument rpt = new ReportDocument();

            switch (cboView.SelectedItem.Value)
            {
            case "0":
                rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/ChartOfAccountsDetails.rpt"));
                break;

            case "1":
                rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/ChartOfAccountsSummary.rpt"));
                break;
            }

            HTMLFormatOptions htmlOpts = new HTMLFormatOptions();

            ExportOptions exportop          = new ExportOptions();
            DiskFileDestinationOptions dest = new DiskFileDestinationOptions();

            string strPath = Server.MapPath(@"\RetailPlus\temp\html\");
//			DeleteTempDirectory(strPath);

            string strFileName = "chartofacc_" + Session["UserName"].ToString() + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".htm";

            if (System.IO.File.Exists(strPath + strFileName))
            {
                System.IO.File.Delete(strPath + strFileName);
            }

            htmlOpts.HTMLFileName             = strFileName;
            htmlOpts.HTMLEnableSeparatedPages = true;;
            htmlOpts.HTMLHasPageNavigator     = true;
            htmlOpts.HTMLBaseFolderName       = strPath;
            rpt.ExportOptions.FormatOptions   = htmlOpts;

            exportop = rpt.ExportOptions;

            exportop.ExportDestinationType = ExportDestinationType.DiskFile;
            exportop.ExportFormatType      = ExportFormatType.HTML40;

            dest.DiskFileName           = strFileName.ToString();
            exportop.DestinationOptions = dest;

            SetDataSource(rpt);

            rpt.Export();   rpt.Close();    rpt.Dispose();

            strFileName = "//" + Request.ServerVariables["SERVER_NAME"].ToString() + FindHTMLFile(strPath, strFileName);

            fraViewer.Attributes.Add("src", strFileName);
        }
예제 #3
0
        private void GenerateHTML()
        {
            ReportDocument rpt = new ReportDocument();

            rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/_ProductBranchInventoryReport.rpt"));

            HTMLFormatOptions htmlOpts = new HTMLFormatOptions();

            ExportOptions exportop          = new ExportOptions();
            DiskFileDestinationOptions dest = new DiskFileDestinationOptions();

            string strPath = Server.MapPath(@"\retailplus\temp\html\");

            string strFileName = "products_" + Session["UserName"].ToString() + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".htm";

            if (System.IO.File.Exists(strPath + strFileName))
            {
                System.IO.File.Delete(strPath + strFileName);
            }

            htmlOpts.HTMLFileName             = strFileName;
            htmlOpts.HTMLEnableSeparatedPages = true;;
            htmlOpts.HTMLHasPageNavigator     = true;
            htmlOpts.HTMLBaseFolderName       = strPath;
            rpt.ExportOptions.FormatOptions   = htmlOpts;

            exportop = rpt.ExportOptions;

            exportop.ExportDestinationType = ExportDestinationType.DiskFile;
            exportop.ExportFormatType      = ExportFormatType.HTML40;

            dest.DiskFileName           = strFileName.ToString();
            exportop.DestinationOptions = dest;

            SetDataSource(rpt);

            Session["ReportDocument"] = rpt;

            rpt.Export();   rpt.Close();    rpt.Dispose();

            strFileName = "//" + Request.ServerVariables["SERVER_NAME"].ToString() + FindHTMLFile(strPath, strFileName);

            fraViewer.Attributes.Add("src", strFileName);
        }
예제 #4
0
		private void GenerateHTML()
		{
			ReportDocument rpt = new ReportDocument();

			switch (cboReportType.SelectedItem.Text)
			{
				case "Posted PO":
                    rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/PostedPO.rpt"));
					break;
				case "Posted PO Returns":
                    rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/PostedPOReturns.rpt"));
					break;
				case "Posted Debit Memo":
                    rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/PostedDebitMemo.rpt"));
					break;
				case "By Vendor":
                    rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/PurchaseAnalysis.rpt"));
					break;
				default:
					return;
					
			}

			HTMLFormatOptions htmlOpts = new HTMLFormatOptions();
 
			ExportOptions exportop = new ExportOptions();
			DiskFileDestinationOptions dest = new DiskFileDestinationOptions();
			
			string strPath = Server.MapPath(@"\retailplus\temp\html\");

			string strFileName = cboReportType.SelectedItem.Text.Replace(" ", "").ToLower() + "_" + Session["UserName"].ToString() + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".htm";
			if (System.IO.File.Exists(strPath + strFileName))
				System.IO.File.Delete(strPath + strFileName);

			htmlOpts.HTMLFileName = strFileName;
			htmlOpts.HTMLEnableSeparatedPages = true;;
			htmlOpts.HTMLHasPageNavigator = true;
			htmlOpts.HTMLBaseFolderName = strPath;
			rpt.ExportOptions.FormatOptions = htmlOpts;

			exportop = rpt.ExportOptions;

			exportop.ExportDestinationType = ExportDestinationType.DiskFile;
			exportop.ExportFormatType = ExportFormatType.HTML40;
			
			dest.DiskFileName = strFileName.ToString();
			exportop.DestinationOptions = dest;

			SetDataSource(rpt);

            Session["ReportDocument"] = rpt;

			rpt.Export();   rpt.Close();    rpt.Dispose();

			strFileName = "//" + Request.ServerVariables["SERVER_NAME"].ToString() + FindHTMLFile(strPath,strFileName);	
			
			fraViewer.Attributes.Add("src",strFileName);
		}
예제 #5
0
        /// <summary>
        /// Set export file type or printer to Report Document object.
        /// </summary>
        private void ApplyReportOutput()
        {
            if (_printToPrinter)
            {
                var printerName = ReportArguments.PrinterName != null?ReportArguments.PrinterName.Trim() : "";

                _logger.Write(string.Format("The default printer set in the Report is '{0}'", _reportDoc.PrintOptions.PrinterName));
                if (printerName.Length > 0 && printerName.ToUpper() != "DFLT")
                //Print to the Specified Printer
                {
                    _reportDoc.PrintOptions.NoPrinter   = false; //Changes the report option "No Printer: Optimized for Screen"
                    _reportDoc.PrintOptions.PrinterName = printerName;
                    _logger.Write(string.Format("The Specified PrinterName '{0}' is set by Parameter will be used", printerName));
                }
                else if (_reportDoc.PrintOptions.PrinterName.Length > 0 && printerName.ToUpper() == "DFLT")
                //Print to the reports default Printer
                {
                    _reportDoc.PrintOptions.NoPrinter = false; //Changes the report option "No Printer: Optimized for Screen"
                    _logger.Write(string.Format("The Specified PrinterName '{0}' is set in the report and DFLT flag will be used", _reportDoc.PrintOptions.PrinterName));
                }
                else
                //Print to the Windows default Printer
                {
                    System.Drawing.Printing.PrinterSettings prinSet = new System.Drawing.Printing.PrinterSettings();
                    _logger.Write(string.Format("Printer is not specified - The Windows Default Printer '{0}' will be used", prinSet.PrinterName));
                    if (prinSet.PrinterName.Trim().Length > 0)
                    {
                        _reportDoc.PrintOptions.NoPrinter   = false;   //Changes the report option "No Printer: Optimized for Screen"
                        _reportDoc.PrintOptions.PrinterName = prinSet.PrinterName;
                    }
                    else
                    {
                        throw new Exception("No printer name is specified");
                    }
                }
            }
            else
            {
                if (_outputFormat.ToUpper() == "RTF")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.RichText;
                }
                else if (_outputFormat.ToUpper() == "TXT")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.Text;
                }
                else if (_outputFormat.ToUpper() == "TAB")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.TabSeperatedText;
                }
                else if (_outputFormat.ToUpper() == "CSV")
                {
                    CharacterSeparatedValuesFormatOptions csvExpOpts = new CharacterSeparatedValuesFormatOptions();
                    csvExpOpts.ExportMode                     = CsvExportMode.Standard;
                    csvExpOpts.GroupSectionsOption            = CsvExportSectionsOption.Export;
                    csvExpOpts.ReportSectionsOption           = CsvExportSectionsOption.Export;
                    csvExpOpts.GroupSectionsOption            = CsvExportSectionsOption.ExportIsolated;
                    csvExpOpts.ReportSectionsOption           = CsvExportSectionsOption.ExportIsolated;
                    csvExpOpts.SeparatorText                  = ",";
                    csvExpOpts.Delimiter                      = "\"";
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.CharacterSeparatedValues;
                    _reportDoc.ExportOptions.FormatOptions    = csvExpOpts;
                }
                else if (_outputFormat.ToUpper() == "PDF")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

                    var grpCnt = _reportDoc.DataDefinition.Groups.Count;

                    if (grpCnt > 0)
                    {
                        _reportDoc.ExportOptions.ExportFormatOptions = new PdfFormatOptions {
                            CreateBookmarksFromGroupTree = true
                        }
                    }
                    ;
                }
                else if (_outputFormat.ToUpper() == "RPT")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.CrystalReport;
                }
                else if (_outputFormat.ToUpper() == "DOC")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows;
                }
                else if (_outputFormat.ToUpper() == "XLS")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.Excel;
                }
                else if (_outputFormat.ToUpper() == "XLSDATA")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.ExcelRecord;
                }
                else if (_outputFormat.ToUpper() == "XLSX")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.ExcelWorkbook;
                }
                else if (_outputFormat.ToUpper() == "ERTF")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.EditableRTF;
                }
                else if (_outputFormat.ToUpper() == "XML")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.Xml;
                }
                else if (_outputFormat.ToUpper() == "HTM" || _outputFormat.ToUpper() == "HTML")
                {
                    HTMLFormatOptions htmlFormatOptions = new HTMLFormatOptions();

                    if (_outputFilename.LastIndexOf("\\") > 0) //if absolute output path is specified
                    {
                        htmlFormatOptions.HTMLBaseFolderName = _outputFilename.Substring(0, _outputFilename.LastIndexOf("\\"));
                    }

                    htmlFormatOptions.HTMLFileName             = _outputFilename;
                    htmlFormatOptions.HTMLEnableSeparatedPages = false;
                    htmlFormatOptions.HTMLHasPageNavigator     = true;
                    htmlFormatOptions.FirstPageNumber          = 1;
                    _reportDoc.ExportOptions.ExportFormatType  = ExportFormatType.HTML40;
                    _reportDoc.ExportOptions.FormatOptions     = htmlFormatOptions;
                }
            }
        }
예제 #6
0
		private void GenerateHTML()
		{
            ReportDocument rpt = new ReportDocument();
            rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/GeneralLedger.rpt"));

			HTMLFormatOptions htmlOpts = new HTMLFormatOptions();
 
			ExportOptions exportop = new ExportOptions();
			DiskFileDestinationOptions dest = new DiskFileDestinationOptions();
			
			string strPath = Server.MapPath(@"\RetailPlus\temp\html\");
//			DeleteTempDirectory(strPath);

			string strFileName = "generalledger_" + Session["UserName"].ToString() + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".htm";
			if (System.IO.File.Exists(strPath + strFileName))
				System.IO.File.Delete(strPath + strFileName);

			htmlOpts.HTMLFileName = strFileName;
			htmlOpts.HTMLEnableSeparatedPages = true;;
			htmlOpts.HTMLHasPageNavigator = true;
			htmlOpts.HTMLBaseFolderName = strPath;
			rpt.ExportOptions.FormatOptions = htmlOpts;

			exportop = rpt.ExportOptions;

			exportop.ExportDestinationType = ExportDestinationType.DiskFile;
			exportop.ExportFormatType = ExportFormatType.HTML40;
			
			dest.DiskFileName = strFileName.ToString();
			exportop.DestinationOptions = dest;

			SetDataSource(rpt);

			rpt.Export();   rpt.Close();    rpt.Dispose();

			strFileName = "//" + Request.ServerVariables["SERVER_NAME"].ToString() + FindHTMLFile(strPath,strFileName);	
			
			fraViewer.Attributes.Add("src",strFileName);
		}
예제 #7
0
        /// <summary>
        /// Export report to file
        /// </summary>
        /// <param name="crReportDocument">ReportDocument</param>
        /// <param name="ExpType">Export Type (pdf, xls, doc, rpt, htm)</param>
        /// <param name="ExportPath">Export Path (physical path on the disk were exported document will be stored on)</param>
        /// <param name="filename">File name (file name without extension f.e. "MyReport1")</param>
        /// <returns>returns true if export was succesfull</returns>
        public static bool ExportReport(ReportDocument crReportDocument, string ExpType, string ExportPath, string filename)
        {
            //creating full report file name for example if the filename was "MyReport1"
            //and ExpType was "pdf", full file name will be "MyReport1.pdf"
            filename = filename + "." + ExpType;

            //creating storage directory if not exists
            if (!Directory.Exists(ExportPath))
            {
                Directory.CreateDirectory(ExportPath);
            }

            //creating new instance representing disk file destination options such as filename, export type etc.
            DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();
            ExportOptions crExportOptions = crReportDocument.ExportOptions;


            switch (ExpType)
            {
            case "rtf":
            {
                //setting disk file name
                crDiskFileDestinationOptions.DiskFileName = ExportPath + filename;
                //setting destination type in our case disk file
                crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                //setuing export format type
                crExportOptions.ExportFormatType = ExportFormatType.RichText;
                //setting previously defined destination opions to our input report document
                crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
                break;
            }

            //NOTE following code is similar to previous, so I want comment it again
            case "pdf":
            {
                crDiskFileDestinationOptions.DiskFileName = ExportPath + filename;
                crExportOptions.DestinationOptions        = crDiskFileDestinationOptions;
                crExportOptions.ExportDestinationType     = ExportDestinationType.DiskFile;
                crExportOptions.ExportFormatType          = ExportFormatType.PortableDocFormat;
                break;
            }

            case "doc":
            {
                crDiskFileDestinationOptions.DiskFileName = ExportPath + filename;
                crExportOptions.ExportDestinationType     = ExportDestinationType.DiskFile;
                crExportOptions.ExportFormatType          = ExportFormatType.WordForWindows;
                crExportOptions.DestinationOptions        = crDiskFileDestinationOptions;
                break;
            }

            case "xls":
            {
                crDiskFileDestinationOptions.DiskFileName = ExportPath + filename;
                crExportOptions.ExportDestinationType     = ExportDestinationType.DiskFile;
                crExportOptions.ExportFormatType          = ExportFormatType.Excel;
                crExportOptions.DestinationOptions        = crDiskFileDestinationOptions;
                break;
            }

            case "rpt":
            {
                crDiskFileDestinationOptions.DiskFileName = ExportPath + filename;
                crExportOptions.ExportDestinationType     = ExportDestinationType.DiskFile;
                crExportOptions.ExportFormatType          = ExportFormatType.CrystalReport;
                crExportOptions.DestinationOptions        = crDiskFileDestinationOptions;
                break;
            }

            case "htm":
            {
                HTMLFormatOptions HTML40Formatopts = new HTMLFormatOptions();
                crExportOptions.ExportDestinationType     = ExportDestinationType.DiskFile;
                crExportOptions.ExportFormatType          = ExportFormatType.HTML40;
                HTML40Formatopts.HTMLBaseFolderName       = ExportPath + filename;
                HTML40Formatopts.HTMLFileName             = "HTML40.html";
                HTML40Formatopts.HTMLEnableSeparatedPages = true;
                HTML40Formatopts.HTMLHasPageNavigator     = true;
                HTML40Formatopts.FirstPageNumber          = 1;
                HTML40Formatopts.LastPageNumber           = 3;
                crExportOptions.FormatOptions             = HTML40Formatopts;
                break;
            }
            }
            try
            {
                //trying to export input report document, and if success returns true
                crReportDocument.Export();
                return(true);
            }
            catch (Exception err)
            {
                return(false);
            }
        }
예제 #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // since we are using Crystal to do everything, the web page is built here
        if (!IsPostBack)
        {
            Session["dtPrint"] = null;
            if (Session["UserName"] == null)
            {
                UserPrefix = "NoUser";
            }
            else
            {
                UserPrefix = Session["UserName"].ToString().Trim();
            }
            if ((Request.QueryString["InvoiceNo"] != null) || (Request.QueryString["OrderNo"] != null))
            {
                // clear out any previous user exports first
                DirectoryInfo OldPages = new DirectoryInfo(Server.MapPath(DocName));
                if (OldPages.Exists)
                {
                    // Get a reference to each file in that directory.
                    FileInfo[] AllOldPages = OldPages.GetFiles();
                    // go through the files
                    foreach (FileInfo OldPage in AllOldPages)
                    {
                        if (OldPage.Name.Substring(0, UserPrefix.Length) == UserPrefix)
                        {
                            OldPage.Delete();
                        }
                    }
                }
                // get the TEST watermark indicator
                DataSet dsAppPref = new DataSet();
                dsAppPref = SqlHelper.ExecuteDataset(connectionString, "[UGEN_SP_Select]",
                                                     new SqlParameter("@tableName", "SystemMaster with (NOLOCK)"),
                                                     new SqlParameter("@displayColumns", "PrintRqst"),
                                                     new SqlParameter("@whereCondition", " SystemMasterID = 0"));
                PrintRequest = dsAppPref.Tables[0].Rows[0]["PrintRqst"].ToString().Trim();
                // load the crystal report using the path in an app pref record
                dsAppPref = SqlHelper.ExecuteDataset(connectionString, "[UGEN_SP_Select]",
                                                     new SqlParameter("@tableName", "AppPref with (NOLOCK)"),
                                                     new SqlParameter("@displayColumns", "AppOptionValue"),
                                                     new SqlParameter("@whereCondition", " (ApplicationCd = 'SOE') AND (AppOptionType = 'InvoiceLocation')"));
                CrystalPath = dsAppPref.Tables[0].Rows[0]["AppOptionValue"].ToString();
                RGADoc.Load(CrystalPath + DocName + ".rpt", OpenReportMethod.OpenReportByTempCopy);
                // set the database connections for the report
                SqlConnectionStringBuilder ConnectBuilder = new SqlConnectionStringBuilder();
                ConnectBuilder.ConnectionString = connectionString;
                ConnectionInfo ConnectInfo = new ConnectionInfo();
                ConnectInfo.DatabaseName = ConnectBuilder["Initial Catalog"].ToString();
                ConnectInfo.UserID       = ConnectBuilder["User Id"].ToString();
                ConnectInfo.Password     = ConnectBuilder["Password"].ToString();
                ConnectInfo.ServerName   = ConnectBuilder["Data Source"].ToString();
                //  AutoDataBind="true"
                foreach (CrystalDecisions.CrystalReports.Engine.Table RGATable in RGADoc.Database.Tables)
                {
                    TableLogOnInfo RGATableLogonInfo = RGATable.LogOnInfo;
                    RGATableLogonInfo.ConnectionInfo = ConnectInfo;
                    RGATable.ApplyLogOnInfo(RGATableLogonInfo);
                }
                //ReportDocument RGASub = new ReportDocument();
                //foreach (CrystalDecisions.CrystalReports.Engine.Section RGASect in RGADoc.ReportDefinition.Sections)
                //{
                //    foreach (CrystalDecisions.CrystalReports.Engine.ReportObject RGAObj in RGASect.ReportObjects)
                //    {
                //        if (RGAObj.Kind == ReportObjectKind.SubreportObject)
                //        {
                //            RGASub = RGADoc.OpenSubreport(RGAObj.Name);
                //            foreach (CrystalDecisions.CrystalReports.Engine.Table RGATable in RGASub.Database.Tables)
                //            {
                //                TableLogOnInfo RGATableLogonInfo = RGATable.LogOnInfo;
                //                RGATableLogonInfo.ConnectionInfo = ConnectInfo;
                //                RGATable.ApplyLogOnInfo(RGATableLogonInfo);
                //            }
                //        }
                //    }
                //}
                // set the selection criteria
                if (Request.QueryString["InvoiceNo"] != null)
                {
                    RGADoc.RecordSelectionFormula = "{SOHeaderRel.InvoiceNo}=\"" + Request.QueryString["InvoiceNo"].ToString() + "\" and isnull({SODetailRel.DeleteDt})";
                }
                if (Request.QueryString["OrderNo"] != null)
                {
                    RGADoc.RecordSelectionFormula = "{SOHeaderRel.OrderNo}=" + Request.QueryString["OrderNo"].ToString() + " and isnull({SODetailRel.DeleteDt})";
                }
                // we are ready to go
                RGADoc.Refresh();
                // Now set up the export
                DiskFileDestinationOptions diskOpts = ExportOptions.CreateDiskFileDestinationOptions();
                ExportOptions exportOpts            = new ExportOptions();
                exportOpts.ExportFormatType         = ExportFormatType.HTML40;
                exportOpts.ExportDestinationType    = ExportDestinationType.DiskFile;
                exportOpts.ExportDestinationOptions = diskOpts;
                HTMLFormatOptions htmlFormatOpts = new HTMLFormatOptions();
                htmlFormatOpts.FirstPageNumber          = 1;
                htmlFormatOpts.HTMLEnableSeparatedPages = true;
                htmlFormatOpts.HTMLHasPageNavigator     = false;
                htmlFormatOpts.HTMLBaseFolderName       = Server.MapPath("");
                htmlFormatOpts.HTMLFileName             = UserPrefix + "RGAExport.htm";
                exportOpts.ExportFormatOptions          = htmlFormatOpts;

                // set the parameters
                if (PrintRequest == "T")
                {
                    RGADoc.SetParameterValue("IsTest", true);
                }
                else
                {
                    RGADoc.SetParameterValue("IsTest", false);
                }

                RGADoc.Export(exportOpts);
                RGADoc.Close();
                // now that we have created the individual pages, make one big page
                DirectoryInfo PageFiles = new DirectoryInfo(Server.MapPath(DocName));
                // Get a reference to each file in that directory.
                FileInfo[] AllPages = PageFiles.GetFiles();
                // start the HTML page
                Response.Write("<html>\n<head>\n<title>RGA Document</title>\n");
                if ((Request.QueryString["ScriptX"] != null) && (Request.QueryString["ScriptX"] == "YES"))
                {
                    // Embed ScriptX objects
                    using (StreamReader sr = new StreamReader(Server.MapPath("common/include/ScriptX.inc")))
                    {
                        String incline;
                        // Read and display lines from the Spriptx include file
                        while ((incline = sr.ReadLine()) != null)
                        {
                            Response.Write(incline + "\n");
                        }
                    }
                    //Response.Write("<!-- #Include virtual=\"common/include/ScriptX.inc\" -->\n");
                    // Load ScriptX javascript function
                    Response.Write("<script src=\"" + ConfigurationManager.AppSettings["SOESiteURL"].ToString() + "Common/JavaScript/ScriptX.js\" type=\"text/javascript\"></script>\n");
                }
                Response.Write("</head>\n<body style=\"margin: 0px\" >\n");
                PagePosition = (decimal)0.0;
                foreach (FileInfo InvPage in AllPages)
                {
                    // get only the files for the current user
                    if (InvPage.Name.Substring(0, UserPrefix.Length) == UserPrefix)
                    {
                        WriteOK = false;
                        Response.Write("<DIV style=\"position:absolute; top:" + PagePosition.ToString() + "pt;  height:1000px; \">\n");
                        //Response.Write("");
                        using (StreamReader sr = new StreamReader(InvPage.FullName))
                        {
                            String line;
                            // Read and display lines from the file until the end of
                            // the file is reached.
                            while ((line = sr.ReadLine()) != null)
                            {
                                if (line.Contains("</BODY>"))
                                {
                                    WriteOK = false;
                                }
                                if (line.Contains("<style>"))
                                {
                                    WriteOK = true;
                                }
                                if (line.Contains("class=\"crystalstyle\""))
                                {
                                    line = line.Replace("31", "0");
                                }
                                if (line.Contains("images/"))
                                {
                                    line = line.Replace("images/", ConfigurationManager.AppSettings["SOESiteURL"].ToString() + DocName + "/images/");
                                }
                                if (line.Contains("<DIV style=\"position:absolute; top:"))
                                {
                                    WriteOK = false;
                                }
                                if (line.Contains("</TR></TABLE></CENTER></Div>"))
                                {
                                    WriteOK = false;
                                }
                                // write the line
                                if (WriteOK)
                                {
                                    Response.Write(line + "\n");
                                }
                                if (line.Contains("</style>"))
                                {
                                    WriteOK = false;
                                }
                                if (line.Contains("<BODY"))
                                {
                                    WriteOK = true;
                                }
                            }
                        }
                        Response.Write("</DIV>\n");
                        if (PagePosition == (decimal)0.0)
                        {
                            PagePosition += (decimal)757;
                        }
                    }
                }
                Response.Write("</body>\n");
                if ((Request.QueryString["ScriptX"] != null) && (Request.QueryString["ScriptX"] == "YES"))
                {
                    Response.Write("<script language=\"javascript\">\n");
                    Response.Write("SetPrintSettings(true, 0.25, 0.25, 0.25, 0.25);\n");
                    Response.Write("</script>\n");
                }
                Response.Write("</html>\n");
            }
        }
    }
        /// <summary>
        /// Set export file type or printer to Report Document object.
        /// </summary>
        private void ApplyReportOutput()
        {
            if (_printToPrinter)
            {
                var printerName = ReportArguments.PrinterName != null?ReportArguments.PrinterName.Trim() : "";

                if (printerName.Length > 0)
                {
                    _reportDoc.PrintOptions.PrinterName = printerName;
                }
                else
                {
                    System.Drawing.Printing.PrinterSettings prinSet = new System.Drawing.Printing.PrinterSettings();

                    if (prinSet.PrinterName.Trim().Length > 0)
                    {
                        _reportDoc.PrintOptions.PrinterName = prinSet.PrinterName;
                    }
                    else
                    {
                        throw new Exception("No printer name is specified");
                    }
                }
            }
            else
            {
                if (_outputFormat.ToUpper() == "RTF")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.RichText;
                }
                else if (_outputFormat.ToUpper() == "TXT")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.Text;
                }
                else if (_outputFormat.ToUpper() == "TAB")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.TabSeperatedText;
                }
                else if (_outputFormat.ToUpper() == "CSV")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.CharacterSeparatedValues;
                }
                else if (_outputFormat.ToUpper() == "PDF")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

                    var grpCnt = _reportDoc.DataDefinition.Groups.Count;
                    if (grpCnt > 0)
                    {
                        _reportDoc.ExportOptions.ExportFormatOptions = new PdfFormatOptions {
                            CreateBookmarksFromGroupTree = true
                        }
                    }
                    ;
                }
                else if (_outputFormat.ToUpper() == "RPT")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.CrystalReport;
                }
                else if (_outputFormat.ToUpper() == "DOC")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows;
                }
                else if (_outputFormat.ToUpper() == "XLS")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.Excel;
                }
                else if (_outputFormat.ToUpper() == "XLSDATA")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.ExcelRecord;
                }
                else if (_outputFormat.ToUpper() == "ERTF")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.EditableRTF;
                }
                else if (_outputFormat.ToUpper() == "XML")
                {
                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.Xml;
                }
                else if (_outputFormat.ToUpper() == "HTM")
                {
                    HTMLFormatOptions htmlFormatOptions = new HTMLFormatOptions();

                    if (_outputFilename.LastIndexOf("\\") > 0) //if absolute output path is specified
                    {
                        htmlFormatOptions.HTMLBaseFolderName = _outputFilename.Substring(0, _outputFilename.LastIndexOf("\\"));
                    }

                    htmlFormatOptions.HTMLFileName             = _outputFilename;
                    htmlFormatOptions.HTMLEnableSeparatedPages = false;
                    htmlFormatOptions.HTMLHasPageNavigator     = true;
                    htmlFormatOptions.FirstPageNumber          = 1;

                    _reportDoc.ExportOptions.ExportFormatType = ExportFormatType.HTML40;
                    _reportDoc.ExportOptions.FormatOptions    = htmlFormatOptions;
                }
            }
        }
예제 #10
0
        private void GenerateHTML()
        {
            ReportDocument rpt = new ReportDocument();

            switch (cboReportType.SelectedItem.Text)
            {
            case "Posted PO":
                rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/PostedPO.rpt"));
                break;

            case "Posted PO Returns":
                rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/PostedPOReturns.rpt"));
                break;

            case "Posted Debit Memo":
                rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/PostedDebitMemo.rpt"));
                break;

            case "By Vendor":
                rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/PurchaseAnalysis.rpt"));
                break;

            default:
                return;
            }

            HTMLFormatOptions htmlOpts = new HTMLFormatOptions();

            ExportOptions exportop          = new ExportOptions();
            DiskFileDestinationOptions dest = new DiskFileDestinationOptions();

            string strPath = Server.MapPath(@"\retailplus\temp\html\");

            string strFileName = cboReportType.SelectedItem.Text.Replace(" ", "").ToLower() + "_" + Session["UserName"].ToString() + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".htm";

            if (System.IO.File.Exists(strPath + strFileName))
            {
                System.IO.File.Delete(strPath + strFileName);
            }

            htmlOpts.HTMLFileName             = strFileName;
            htmlOpts.HTMLEnableSeparatedPages = true;;
            htmlOpts.HTMLHasPageNavigator     = true;
            htmlOpts.HTMLBaseFolderName       = strPath;
            rpt.ExportOptions.FormatOptions   = htmlOpts;

            exportop = rpt.ExportOptions;

            exportop.ExportDestinationType = ExportDestinationType.DiskFile;
            exportop.ExportFormatType      = ExportFormatType.HTML40;

            dest.DiskFileName           = strFileName.ToString();
            exportop.DestinationOptions = dest;

            SetDataSource(rpt);

            Session["ReportDocument"] = rpt;

            rpt.Export();   rpt.Close();    rpt.Dispose();

            strFileName = "//" + Request.ServerVariables["SERVER_NAME"].ToString() + FindHTMLFile(strPath, strFileName);

            fraViewer.Attributes.Add("src", strFileName);
        }
예제 #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("test3ed");
        Response.End();

        // since we are using Crystal to do everything, the web page is built here
        if (!IsPostBack)
        {
            Session["dtPrint"] = null;
            if (Session["UserName"] == null)
            {
                UserPrefix = "NoUser";
            }
            else
            {
                UserPrefix = Session["UserName"].ToString().Trim();
            }
            if (Request.QueryString["ShipperNo"] != null)
            {
                ShipperNo = Request.QueryString["ShipperNo"].ToString();
                // clear out any previous exports first
                DirectoryInfo OldPages = new DirectoryInfo(Server.MapPath(@"SOEShipper"));
                // Get a reference to each file in that directory.
                FileInfo[] AllOldPages = OldPages.GetFiles();

                // go through the files
                foreach (FileInfo OldPage in AllOldPages)
                {
                    if (OldPage.Name.Substring(0, UserPrefix.Length) == UserPrefix)
                    {
                        OldPage.Delete();
                    }
                }

                // load the crystal report using the path in an app pref record
                DataSet dsAppPref = new DataSet();
                dsAppPref = SqlHelper.ExecuteDataset(connectionString, "[UGEN_SP_Select]",
                                                     new SqlParameter("@tableName", "AppPref with (NOLOCK)"),
                                                     new SqlParameter("@displayColumns", "AppOptionValue"),
                                                     new SqlParameter("@whereCondition", " (ApplicationCd = 'SOE') AND (AppOptionType = 'InvoiceLocation')"));
                CrystalPath = dsAppPref.Tables[0].Rows[0]["AppOptionValue"].ToString();

                Response.Write("Windows Account which runs ASP.NET is: " + Environment.Username);
                Response.Write("test3");
                Response.End();
                try
                {
                    ShipperDoc.Load(CrystalPath + "SOEShipper.rpt", OpenReportMethod.OpenReportByTempCopy);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                // set the database connections for the report
                SqlConnectionStringBuilder ConnectBuilder = new SqlConnectionStringBuilder();
                ConnectBuilder.ConnectionString = connectionString;
                ConnectionInfo ConnectInfo = new ConnectionInfo();
                ConnectInfo.DatabaseName = ConnectBuilder["Initial Catalog"].ToString();
                ConnectInfo.UserID       = ConnectBuilder["User Id"].ToString();
                ConnectInfo.Password     = ConnectBuilder["Password"].ToString();
                ConnectInfo.ServerName   = ConnectBuilder["Data Source"].ToString();
                //  AutoDataBind="true"

                foreach (CrystalDecisions.CrystalReports.Engine.Table ShipperTable in ShipperDoc.Database.Tables)
                {
                    TableLogOnInfo ShipperTableLogonInfo = ShipperTable.LogOnInfo;
                    ShipperTableLogonInfo.ConnectionInfo = ConnectInfo;
                    ShipperTable.ApplyLogOnInfo(ShipperTableLogonInfo);
                }
                ShipperDoc.RecordSelectionFormula = "{SOHeaderRel.OrderNo}=" + ShipperNo;
                // we are ready to go
                ShipperDoc.Refresh();
                // Now set up the export
                DiskFileDestinationOptions diskOpts = ExportOptions.CreateDiskFileDestinationOptions();
                ExportOptions exportOpts            = new ExportOptions();
                exportOpts.ExportFormatType         = ExportFormatType.HTML40;
                exportOpts.ExportDestinationType    = ExportDestinationType.DiskFile;
                exportOpts.ExportDestinationOptions = diskOpts;

                HTMLFormatOptions htmlFormatOpts = new HTMLFormatOptions();
                htmlFormatOpts.FirstPageNumber          = 1;
                htmlFormatOpts.HTMLEnableSeparatedPages = true;
                htmlFormatOpts.HTMLHasPageNavigator     = false;
                htmlFormatOpts.HTMLBaseFolderName       = Server.MapPath("");
                htmlFormatOpts.HTMLFileName             = UserPrefix + "ShipperExport.htm";

                exportOpts.ExportFormatOptions = htmlFormatOpts;

                ShipperDoc.Export(exportOpts);
                ShipperDoc.Close();
                // now that we have created the individual pages, make one big page
                DirectoryInfo PageFiles = new DirectoryInfo(Server.MapPath(@"SOEShipper"));
                // Get a reference to each file in that directory.
                FileInfo[] AllPages = PageFiles.GetFiles();
                // start the HTML page
                Response.Write("<head>\n");
                // write the styles
                Response.Write("<style type=\"text/css\">\n");
                Response.Write(".barcode{height:30px;font-size:15pt;color:#000000;font-family:IDAutomationC39M;font-weight:normal;overflow:hidden;}\n");
                Response.Write("</style>\n");
                // finish the header start the body
                Response.Write("\n<title>Shipper Document</title>\n</head>\n<body  LEFTMARGIN=31 TOPMARGIN=31 >\n");
                PagePosition = (decimal)0.0;
                foreach (FileInfo InvPage in AllPages)
                {
                    // get only the files for the current user
                    if (InvPage.Name.Substring(0, UserPrefix.Length) == UserPrefix)
                    {
                        WriteOK = false;
                        Response.Write("<DIV style=\"position:absolute; left:0px; top:" + PagePosition.ToString() + "pt;  height:590px \">\n");
                        //Response.Write("");
                        using (StreamReader sr = new StreamReader(InvPage.FullName))
                        {
                            String line;
                            // Read and display lines from the file until the end of
                            // the file is reached.
                            while ((line = sr.ReadLine()) != null)
                            {
                                if (line.Contains("</BODY>"))
                                {
                                    WriteOK = false;
                                }
                                if (line.Contains("<style>"))
                                {
                                    WriteOK = true;
                                }
                                if (line.Contains("images/"))
                                {
                                    line = line.Replace("images/", ConfigurationManager.AppSettings["SOESiteURL"].ToString() + "SOEShipper/images/");
                                }
                                // write the line
                                if (WriteOK)
                                {
                                    Response.Write(line + "\n");
                                }
                                if (line.Contains("</style>"))
                                {
                                    WriteOK = false;
                                }
                                if (line.Contains("<BODY"))
                                {
                                    WriteOK = true;
                                }
                            }
                        }
                        Response.Write("</DIV>\n");
                        if (PagePosition == (decimal)0.0)
                        {
                            PagePosition += (decimal)590;
                        }
                    }
                }
                Response.Write("</body>\n</html>\n");
            }
        }
    }
        static void Main(string[] args)
        {
            logFilename = "crexport-" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".log";

            try
            {
                ReportInfo rptinfo = new ReportInfo(args);
                enableLog = rptinfo.EnableLog; //determine if to create log file

                if (enableLog)
                {
                    WriteLog("Crystal Reports Exporter version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
                    WriteLog("creport parameters : " + ConvertStringArrayToString(args));
                }

                if (rptinfo.GetHelp)
                {
                    DisplayMessage(2);
                }
                else
                {
                    ReportDocument Report = new ReportDocument();
                    if (enableLog)
                    {
                        WriteLog("Instantiated ReportDocument object");
                    }

                    DisplayMessage(0);
                    try
                    {
                        if (args.Length == 0)
                        {
                            throw new
                                  NullArgumentException("No parameter is specified!");
                        }

                        if (rptinfo.MailTo.Length > 0)
                        {
                            Console.WriteLine("mail to " + rptinfo.MailTo);
                        }

                        //Not neccessary needs to have a Server Name.
                        //if (rptinfo.ServerName == null)
                        //{
                        //    throw new
                        //        InvalidServerException("Unspecified Server Name");
                        //}

                        if (rptinfo.ReportPath == null || rptinfo.ReportPath == "")
                        {
                            throw new Exception("Invalid Crystal Reports file");
                        }

                        if (rptinfo.OutputPath == null && !rptinfo.PrintOuput)
                        {
                            throw new
                                  InvalidOutputException("Unspecified Output path and filename");
                        }

                        //Report.Load(rptinfo.ReportPath, OpenReportMethod.OpenReportByTempCopy);
                        Report.Load(rptinfo.ReportPath, OpenReportMethod.OpenReportByDefault);
                        if (enableLog)
                        {
                            WriteLog("Crystal Reports file " + rptinfo.ReportPath + " loaded");
                        }

                        if (enableLog)
                        {
                            if (!rptinfo.Refresh)
                            {
                                WriteLog("Report is set not to refresh data");
                            }
                        }

                        if (enableLog)
                        {
                            for (int i = 0; i < Report.DataSourceConnections.Count; i++)
                            {
                                WriteLog("Database id = " + i);
                                WriteLog("Integrated Security = " + Report.DataSourceConnections[i].IntegratedSecurity.ToString());
                                WriteLog("Default Server Name = " + Report.DataSourceConnections[i].ServerName);
                                WriteLog("Default Database Name = " + Report.DataSourceConnections[i].DatabaseName);
                                //todo: find out how to get database type like sql server, access, oracle...etc
                            }
                        }

                        if (rptinfo.Refresh)
                        {
                            //logon to Database
                            #region Logon to Database

                            TableLogOnInfo logonInfo = new TableLogOnInfo();
                            foreach (Table table in Report.Database.Tables)
                            {
                                if (rptinfo.ServerName != null)
                                {
                                    logonInfo.ConnectionInfo.ServerName = rptinfo.ServerName;

                                    if (enableLog)
                                    {
                                        WriteLog("Logon to Server = " + rptinfo.ServerName);
                                    }
                                }

                                if (rptinfo.DatabaseName != null)
                                {
                                    logonInfo.ConnectionInfo.DatabaseName = rptinfo.DatabaseName;

                                    if (enableLog)
                                    {
                                        WriteLog("Logon to Database = " + rptinfo.DatabaseName);
                                    }
                                }

                                if (rptinfo.Username == null && rptinfo.Password == null)
                                {
                                    logonInfo.ConnectionInfo.IntegratedSecurity = true;

                                    if (enableLog)
                                    {
                                        WriteLog("Integrated Security = true ");
                                    }
                                }
                                else
                                {
                                    if (rptinfo.Username != null && rptinfo.Username.Length > 0)
                                    {
                                        logonInfo.ConnectionInfo.UserID = rptinfo.Username;

                                        if (enableLog)
                                        {
                                            WriteLog("Logon with user id = " + rptinfo.Username);
                                        }
                                    }

                                    if (rptinfo.Password == null) //to support blank password
                                    {
                                        logonInfo.ConnectionInfo.Password = "";

                                        if (enableLog)
                                        {
                                            WriteLog("Logon with blank password");
                                        }
                                    }
                                    else
                                    {
                                        logonInfo.ConnectionInfo.Password = rptinfo.Password;

                                        if (enableLog)
                                        {
                                            WriteLog("Logon with password = "******"No printer name is specified");
                                }
                            }
                        }
                        else
                        {
                            if (rptinfo.OutputFormat.ToUpper() == "RTF")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.RichText;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "TXT")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.Text;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "TAB")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.TabSeperatedText;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "CSV")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.CharacterSeparatedValues;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "PDF")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "RPT")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.CrystalReport;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "DOC")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "XLS")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.Excel;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "XLSDATA")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.ExcelRecord;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "ERTF")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.EditableRTF;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "XML")
                            {
                                Report.ExportOptions.ExportFormatType = ExportFormatType.Xml;
                            }
                            else if (rptinfo.OutputFormat.ToUpper() == "HTM")
                            {
                                HTMLFormatOptions htmlFormatOptions = new HTMLFormatOptions();

                                if (rptinfo.OutputPath.LastIndexOf("\\") > 0) //if absolute output path is specified
                                {
                                    htmlFormatOptions.HTMLBaseFolderName = rptinfo.OutputPath.Substring(0, rptinfo.OutputPath.LastIndexOf("\\"));
                                }

                                htmlFormatOptions.HTMLFileName             = rptinfo.OutputPath;
                                htmlFormatOptions.HTMLEnableSeparatedPages = false;
                                htmlFormatOptions.HTMLHasPageNavigator     = true;
                                htmlFormatOptions.FirstPageNumber          = 1;

                                Report.ExportOptions.ExportFormatType = ExportFormatType.HTML40;
                                Report.ExportOptions.FormatOptions    = htmlFormatOptions;
                            }
                        }

                        if (enableLog)
                        {
                            WriteLog("Report Output format set to : " + rptinfo.OutputFormat.ToString());
                        }

                        #endregion

                        if (enableLog)
                        {
                            WriteLog("Report attribute : HasSavedData = " + Report.HasSavedData.ToString());
                        }

                        if (Report.ParameterFields.Count > 0)
                        {
                            ParameterFieldDefinitions paramDefs        = Report.DataDefinition.ParameterFields;
                            ParameterValues           paramValues      = new ParameterValues();
                            List <string>             singleParamValue = new List <string>();

                            for (int i = 0; i < paramDefs.Count; i++)
                            {
                                //A report can contains more than One parameters, hence
                                //we loop through all parameters that user has input and match
                                //it with parameter definition of Crystal Reports file.
                                for (int j = 0; j < rptinfo.ReportParameterName.Count; j++)
                                {
                                    if (paramDefs[i].Name == rptinfo.ReportParameterName[j])
                                    {
                                        if (paramDefs[i].EnableAllowMultipleValue && rptinfo.ReportParameterValue[j].IndexOf("|") != -1)
                                        {
                                            singleParamValue = SplitIntoSingleValue(rptinfo.ReportParameterValue[j]); //split multiple value into single value regardless discrete or range

                                            for (int k = 0; k < singleParamValue.Count; k++)
                                            {
                                                AddParameter(ref paramValues, paramDefs[i].DiscreteOrRangeKind, singleParamValue[k], paramDefs[i].Name);
                                            }

                                            singleParamValue.Clear();
                                        }
                                        else
                                        {
                                            AddParameter(ref paramValues, paramDefs[i].DiscreteOrRangeKind, rptinfo.ReportParameterValue[j], paramDefs[i].Name);
                                        }

                                        paramDefs[i].ApplyCurrentValues(paramValues);
                                        paramValues.Clear();

                                        break; //jump into another user input parameter
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (rptinfo.Refresh)
                            {
                                Report.Refresh();
                            }
                            //if report document doesn't come with parameter, just refresh it and job done!
                        }

                        if (enableLog)
                        {
                            WriteLog("Report rows = " + Report.Rows.Count);
                        }

                        if (rptinfo.PrintOuput)
                        {
                            Report.PrintToPrinter(rptinfo.PrintCopy, true, 0, 0);
                            if (enableLog)
                            {
                                WriteLog("Report printed to : " + Report.PrintOptions.PrinterName);
                            }
                        }
                        else
                        {
                            Report.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

                            //DiskFileDestinationOptions
                            DiskFileDestinationOptions diskOptions = new DiskFileDestinationOptions();
                            Report.ExportOptions.DestinationOptions = diskOptions;
                            diskOptions.DiskFileName = rptinfo.OutputPath;

                            Report.Export();
                            if (enableLog)
                            {
                                WriteLog("Report exported to : " + rptinfo.OutputPath);
                            }
                        }
                    }
                    catch (NullArgumentException Er)
                    {
                        Console.WriteLine("\nError: " + Er.Message);
                        if (enableLog)
                        {
                            WriteLog("Error : " + Er.Message);
                        }

                        DisplayMessage(1);
                    }
                    catch (InvalidOutputException Er)
                    {
                        Console.WriteLine("\nError: " + Er.Message);
                        if (enableLog)
                        {
                            WriteLog("Error : " + Er.Message);
                        }

                        DisplayMessage(1);
                    }

                    catch (InvalidServerException Er)
                    {
                        Console.WriteLine("\nError: " + Er.Message);
                        if (enableLog)
                        {
                            WriteLog("Error : " + Er.Message);
                        }

                        DisplayMessage(1);
                    }

                    catch (LogOnException)
                    {
                        Console.WriteLine("\nError: Failed to logon to Database. Check username, password, server name and database name parameter");
                        if (enableLog)
                        {
                            WriteLog("Error : Failed to logon to Database. Check username, password, server name and database name parameter");
                        }
                    }

                    catch (LoadSaveReportException)
                    {
                        Console.WriteLine("\nError: Failed to Load or save Crystal Reports file");
                        if (enableLog)
                        {
                            WriteLog("Failed to Load or save Crystal Reports file");
                        }
                    }

                    catch (NullParamNameException Er)
                    {
                        Console.WriteLine("\nError: {0}", Er.Message);
                        if (enableLog)
                        {
                            WriteLog("Error : " + Er.Message);
                        }
                    }

                    catch (NullExportTypeException Er)
                    {
                        Console.WriteLine("\nError: {0}", Er.Message);
                        if (enableLog)
                        {
                            WriteLog("Error : " + Er.Message);
                        }
                    }

                    catch (Exception Er)
                    {
                        Console.WriteLine("\nMisc Error: {0}", Er.Message);
                        if (enableLog)
                        {
                            WriteLog("Error : " + Er.Message);
                        }
                        DisplayMessage(1);
                    }
                    finally
                    {
                        Report.Close();
                        if (enableLog)
                        {
                            WriteLog("ReportDocument closed");
                        }
                    }
                }
            }
            catch (Exception Er)
            {
                Console.WriteLine("\n System Error: {0}", Er.Message);
            }
        }