public virtual System.IO.Stream GetStreamReporte(ExportFormatType Formato) { ReportDocument reportDocument = new ReportDocument(); string path = Path.Combine(Path.Combine(Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory), "Reportes\\"), ClaseReporte.ResourceName); reportDocument.Load(path); reportDocument.SetDataSource(GetDatosReporte()); return reportDocument.ExportToStream(Formato); }
public RPT( string file, ExportFormatType type, Dictionary<string, DataSet> listData, Dictionary<string, object> parameters) { _file = file; _type = stringTOExportFormatType(type); _parameters = parameters; _listData = listData; }
public static void GenerateReport(string FileName, ReportDocument rpt, System.Web.UI.Control ClientScriptBlockControl, ExportFormatType pvtExportFormatType) { try { ExportOptions exportop = new ExportOptions(); DiskFileDestinationOptions dest = new DiskFileDestinationOptions(); string strFileExtensionName = ".pdf"; switch (pvtExportFormatType) { case ExportFormatType.PortableDocFormat: strFileExtensionName = ".pdf"; exportop.ExportFormatType = ExportFormatType.PortableDocFormat; break; case ExportFormatType.WordForWindows: strFileExtensionName = ".doc"; exportop.ExportFormatType = ExportFormatType.WordForWindows; break; case ExportFormatType.Excel: strFileExtensionName = ".xls"; exportop.ExportFormatType = ExportFormatType.Excel; break; } string strPath = System.Web.HttpContext.Current.Server.MapPath(@"\retailplus\temp\"); string strFileName = FileName + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + strFileExtensionName; if (System.IO.File.Exists(strPath + strFileName)) System.IO.File.Delete(strPath + strFileName); dest.DiskFileName = strPath + strFileName; exportop.DestinationOptions = dest; exportop.ExportDestinationType = ExportDestinationType.DiskFile; rpt.Export(exportop); //rpt.Close(); rpt.Dispose(); // remove the error if (pvtExportFormatType == ExportFormatType.WordForWindows || pvtExportFormatType == ExportFormatType.Excel || pvtExportFormatType == ExportFormatType.PortableDocFormat) { // the maximum report processing jobs limit configured by your system administrator has been reached. rpt.Close(); rpt.Dispose(); } if (pvtExportFormatType == ExportFormatType.PortableDocFormat) { string newWindowUrl = Constants.ROOT_DIRECTORY + "/temp/" + strFileName; string javaScript = "window.open('" + newWindowUrl + "');"; System.Web.UI.ScriptManager.RegisterClientScriptBlock(ClientScriptBlockControl, ClientScriptBlockControl.GetType(), "openwindow", javaScript, true); } else { string newWindowUrl = Constants.ROOT_DIRECTORY + "/temp/" + strFileName; string javaScript = "window.open('" + newWindowUrl + "','_self');"; System.Web.UI.ScriptManager.RegisterClientScriptBlock(ClientScriptBlockControl, ClientScriptBlockControl.GetType(), "openwindow", javaScript, true); //System.Diagnostics.Process p = new System.Diagnostics.Process(); //p.StartInfo.FileName = System.Web.HttpContext.Current.Server.MapPath(Constants.ROOT_DIRECTORY + "/temp/" + strFileName); //p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; //p.Start(); } } catch (Exception ex) { throw ex; } }
public void generatedCashierReport(String dt_frm, String dt_to) { export_filename = DateTime.Now.ToString("yyyy-MM-dd h:mm:ss tt").Replace("-", "_").Replace(":", "_").Replace(" ", "_"); String expath = ""; //Cashier Report try { ReportDocument report = new ReportDocument(); ExportFormatType efileType = new ExportFormatType(); efileType = ExportFormatType.PortableDocFormat; try { inc_pbar(10); cashierReportBySendingSMS(dt_frm, dt_to); // ahak ani } catch { MessageBox.Show("Sending Failed: Characters is out of range(160 max)."); } inc_pbar(10); //String dnow = DateTime.Now.ToString("yyyy-MM-dd"); String outlet = "All"; String WHERE = ""; inc_pbar(10); //myReportDocument.Load("../..\\Reports/101B_cashier.rpt"); myReportDocument.Load("\\\\RIGHTAPPS\\RightApps\\BALAI\\Auto_SendGenerate_Reports\\Reports\\101B_cashier.rpt"); DataTable dt = db.QueryBySQLCode("SELECT o.ord_code, o.out_code, to_char(o.ord_date, 'MM/dd/yyyy') AS ord_date, o.customer, o.reference, CASE WHEN ol.pay_code='101' THEN (-1 * ol.ln_amnt) ELSE 0.00 END AS cash, CASE WHEN ol.pay_code='102' THEN (-1 * ol.ln_amnt) ELSE 0.00 END AS dcard, CASE WHEN ol.pay_code='103' THEN (-1 * ol.ln_amnt) ELSE 0.00 END AS card, CASE WHEN ol.pay_code='114' THEN (-1 * ol.ln_amnt) ELSE 0.00 END AS check, CASE WHEN ol.pay_code NOT IN('101','102','103','114') THEN (-1 * ol.ln_amnt) ELSE 0.00 END AS other FROM rssys.orhdr o LEFT JOIN rssys.orlne ol ON o.ord_code=ol.ord_code WHERE " + WHERE + " o.ord_date BETWEEN '" + dt_frm + "' AND '" + dt_to + "' AND COALESCE(ol.item_code,'')='' AND COALESCE(ol.ln_amnt,0.00)<0 ORDER BY ord_date"); myReportDocument.Database.Tables[0].SetDataSource(dt); inc_pbar(10); add_fieldparam("comp_name", comp_name); add_fieldparam("comp_addr", comp_addr); add_fieldparam("userid", (GlobalClass.username ?? "")); add_fieldparam("t_date", (dt_frm == dt_to ? dt_to + " DAILY" : dt_frm + " - " + dt_to + " MONTHLY")); add_fieldparam("outlet", outlet); expath = "\\\\RIGHTAPPS\\RightApps\\BALAI\\101B_cashier_" + export_filename + ".pdf"; myReportDocument.ExportToDisk(efileType, "\\\\RIGHTAPPS\\RightApps\\BALAI\\101B_cashier_" + export_filename + ".pdf"); inc_pbar(10); sendEmail1("g"); } catch (Exception er) { MessageBox.Show(er.Message + "\ngeneratedCashierReport_Error" + "\n" + expath); } }
protected void Page_Load(object sender, EventArgs e) { try { if (Connection == null) { Connection.Open(); } rprt.Load(Server.MapPath("~\\Crystal Reports\\UserReport.rpt")); string Query = QueryObj.GetQueryViaFileAndTagName("LogIn.xml", "UserReport"); Connection.Open(); NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(Query, Connection); DataSet dataSetObj = new DataSet(); adapter.Fill(dataSetObj); if (dataSetObj != null) { ExportFormatType formatType = ExportFormatType.NoFormat; switch (rbFormat.SelectedItem.Value = "PDF") { case "Word": formatType = ExportFormatType.WordForWindows; break; case "PDF": formatType = ExportFormatType.PortableDocFormat; break; case "Excel": formatType = ExportFormatType.Excel; break; case "CSV": formatType = ExportFormatType.CharacterSeparatedValues; break; } adapter.Fill(dataSetObj, "User"); rprt.SetDataSource(dataSetObj.Tables[0]); UserReportId.ReportSource = rprt; rprt.ExportToHttpResponse(formatType, Response, false, "UserReport"); } } catch (Exception ex) { string msg = ex.Message; } finally { Connection.Close(); } }
public void Export(ExportFormatType exportFormat) { try { string tmpFileName; string ReportNumber = ""; if (result != null) { ReportNumber = result.REPORTNUMBER + " " + result.CUSTOMER_NAME; } switch (exportFormat) { case ExportFormatType.PortableDocFormat: tmpFileName = FilesUtil.GetTmpPdfFileName(ReportNumber); break; case ExportFormatType.WordForWindows: case ExportFormatType.EditableRTF: tmpFileName = FilesUtil.GetTmpDocFileName(ReportNumber); break; case ExportFormatType.Excel: tmpFileName = FilesUtil.GetTmpXlsFileName(ReportNumber); break; default: tmpFileName = FilesUtil.GetTmpPdfFileName(ReportNumber); break; } using (ReportDocument rpt = new RPT002_WorkPlaceAirQualityReport()) { rpt.SetParameterValue("@p_ID", WPA_ID); rpt.SetDatabaseLogon(OISDataInfo.DatabaseInfomation.USERNAME, OISDataInfo.DatabaseInfomation.PASSWORD, OISDataInfo.DatabaseInfomation.DATASOURCE, OISDataInfo.DatabaseInfomation.DATABASENAME); SetConnection(rpt); rpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4; rpt.ExportToDisk(exportFormat, tmpFileName); Process.Start(tmpFileName); CloseConnection(rpt); } } catch (Exception ex) { throw ex; } }
private void Export(ExportFormatType pvtExportFormatType) { ReportDocument rpt = getReportDocument(); SetDataSource(rpt); if (pvtExportFormatType == ExportFormatType.WordForWindows || pvtExportFormatType == ExportFormatType.Excel || pvtExportFormatType == ExportFormatType.PortableDocFormat) { string strFileName = Session["UserName"].ToString() + "_transferin"; CRSHelper.GenerateReport(strFileName, rpt, this.updPrint, pvtExportFormatType); } else { CRViewer.ReportSource = rpt; Session["ReportDocument"] = rpt; } }
public string ExportReport(ExportFormatType fileType, string fileName, ReportClass report) { string fileFullName = Base.GetServiceInstallPath() + "\\Data\\" + (!fileName.Equals("") ? fileName : Security.EncryptWithMD5(DateTime.Now.ToString())); switch (fileType) { case ExportFormatType.PortableDocFormat: fileFullName += ".pdf"; break; case ExportFormatType.HTML32: fileFullName += ".html"; break; case ExportFormatType.HTML40: fileFullName += ".html"; break; case ExportFormatType.Excel: case ExportFormatType.ExcelRecord: fileFullName += ".xls"; break; case ExportFormatType.WordForWindows: fileFullName += ".doc"; break; case ExportFormatType.CrystalReport: fileFullName += ".rpt"; break; default: fileFullName += ".pdf"; break; } try { report.ExportToDisk(fileType, fileFullName); return(fileFullName); } catch (Exception ex) { throw ex; } }
protected void Button1_Click(object sender, EventArgs e) { string idorden = Request.QueryString["idorden"].ToString(); formatogremision.SetDatabaseLogon(user: "******", password: "******"); formatogremision.VerifyDatabase(); formatogremision.Refresh(); formatogremision.SetParameterValue("@idorden", idorden); CrystalReportViewer1.ReportSource = formatogremision; ExportFormatType formatType = ExportFormatType.NoFormat; formatType = ExportFormatType.PortableDocFormat; formatogremision.ExportToHttpResponse(formatType, Response, true, idorden); // formatogremision.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "C:/reports/generado.pdf"); Response.End(); }
private void Export(ExportFormatType pvtExportFormatType) { ReportDocument rpt = new ReportDocument(); rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/_StockTransactionReport.rpt")); SetDataSource(rpt); ExportOptions exportop = new ExportOptions(); DiskFileDestinationOptions dest = new DiskFileDestinationOptions(); string strPath = Server.MapPath(@"\retailplus\temp\"); string strFileExtensionName = ".pdf"; switch (pvtExportFormatType) { case ExportFormatType.PortableDocFormat: strFileExtensionName = ".pdf"; exportop.ExportFormatType = ExportFormatType.PortableDocFormat; break; case ExportFormatType.WordForWindows: strFileExtensionName = ".doc"; exportop.ExportFormatType = ExportFormatType.WordForWindows; break; case ExportFormatType.Excel: strFileExtensionName = ".xls"; exportop.ExportFormatType = ExportFormatType.Excel; break; } string strFileName = "tranreport_" + Session["UserName"].ToString() + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + strFileExtensionName; if (System.IO.File.Exists(strPath + strFileName)) { System.IO.File.Delete(strPath + strFileName); } dest.DiskFileName = strPath + strFileName; exportop.DestinationOptions = dest; exportop.ExportDestinationType = ExportDestinationType.DiskFile; rpt.Export(exportop); //rpt.Close(); rpt.Dispose(); if (pvtExportFormatType == ExportFormatType.PortableDocFormat) { rpt.Close(); rpt.Dispose(); Response.Redirect(Constants.ROOT_DIRECTORY + "/temp/" + strFileName, false); } else { CRViewer.ReportSource = rpt; Session["ReportDocument"] = rpt; CRSHelper.OpenExportedReport(strFileName); // OpenExportedReport(strFileName); } }
/// <summary> /// Unambiguous identification of the BBAN account of the debtor to which a debit entry will be made as a result of the transaction. /// In Denmark it will be: Reg. no. + Account no. 14 char (4+10) /// </summary> public void CompanyBBAN(String bban, ExportFormatType exportFormat) { if (exportFormat == ExportFormatType.ISO20022_DK || exportFormat == ExportFormatType.BankData || exportFormat == ExportFormatType.BEC_CSV || exportFormat == ExportFormatType.DanskeBank_CSV || exportFormat == ExportFormatType.Nordea_CSV || exportFormat == ExportFormatType.SDC) { bban = bban ?? string.Empty; bban = Regex.Replace(bban, "[^0-9]", ""); if (string.IsNullOrEmpty(bban)) { preCheckErrors.Add(new PreCheckError(String.Format("The Bank Account number (BBAN) has not been filled in. (Format: {0})", credPaymFormat._Format))); } else if (bban.Length > 10) { preCheckErrors.Add(new PreCheckError(String.Format("The Bank Account number (BBAN) has a wrong format. (Format: {0})", credPaymFormat._Format))); } } }
/// <summary> /// Customer identification assigned by an institution. /// Max. 35 characters. /// </summary> public void CustomerIdentificationId(String customerIdentificationId, ExportFormatType exportFormat) { customerIdentificationId = customerIdentificationId ?? string.Empty; if (exportFormat == ExportFormatType.ISO20022_DK) { switch (companyBankEnum) { //Customer identification (Signer) as agreed with(or assigned by) Nordea.If provided by Nordea the identification consists of maximum 13 digits. case CompanyBankENUM.Nordea_DK: if (string.IsNullOrEmpty(customerIdentificationId) || (customerIdentificationId.Length < 10 || customerIdentificationId.Length > 18)) { preCheckErrors.Add(new PreCheckError(String.Format("The customer Identification Id is mandatory for '{0}'. (Min 10 and Max 18 characters may be allowed)", companyBankEnum))); } break; } } }
private void Export(ExportFormatType pvtExportFormatType) { if (string.IsNullOrEmpty(txtTransactionNo.Text)) return; ReportDocument rpt = getReportDocument(); SetDataSource(rpt); if (pvtExportFormatType == ExportFormatType.WordForWindows || pvtExportFormatType == ExportFormatType.Excel || pvtExportFormatType == ExportFormatType.PortableDocFormat) { string strFileName = Session["UserName"].ToString() + "_salesrcvbles"; CRSHelper.GenerateReport(strFileName, rpt, this.updPrint, pvtExportFormatType); } else { CRViewer.ReportSource = rpt; Session["ReportDocument"] = rpt; } }
/// <summary> /// Unique identification of an organisation , as assigned by an institution, using an identification scheme. /// </summary> public void BankIdentificationId(String bankIdentificationId, ExportFormatType exportFormat) { bankIdentificationId = bankIdentificationId ?? string.Empty; if (exportFormat == ExportFormatType.ISO20022_DK) { switch (companyBankEnum) { //Unique identification of Corporate Cash Management agreement with Nordea. Customer agreement identification with Nordea is mandatory (BANK)and the identification consist of minimum 10 and maximum 18 digits. case CompanyBankENUM.Nordea_DK: case CompanyBankENUM.Handelsbanken: if (string.IsNullOrEmpty(bankIdentificationId) || (bankIdentificationId.Length < 10 || bankIdentificationId.Length > 18)) { preCheckErrors.Add(new PreCheckError(String.Format("The Bank Identification Id is mandatory for '{0}'. (Min 10 and Max 18 characters may be allowed)", companyBankEnum))); } break; } } }
/// <summary> /// Registration number for a BBAN account. /// In Denmark it has to be 4 char /// </summary> public void CompanyBBANRegNum(String bbanRegNum, ExportFormatType exportFormat) { if (exportFormat == ExportFormatType.ISO20022_DK || exportFormat == ExportFormatType.BankData || exportFormat == ExportFormatType.BEC_CSV || exportFormat == ExportFormatType.DanskeBank_CSV || exportFormat == ExportFormatType.Nordea_CSV || exportFormat == ExportFormatType.SDC) { bbanRegNum = bbanRegNum ?? string.Empty; bbanRegNum = Regex.Replace(bbanRegNum, "[^0-9]", ""); if (string.IsNullOrEmpty(bbanRegNum)) { preCheckErrors.Add(new PreCheckError(String.Format("The Bank Registration number has not been filled in. (Format: {0})", credPaymFormat._Format))); } else if (bbanRegNum.Length != 4) { preCheckErrors.Add(new PreCheckError(String.Format("The Bank Registration number has a wrong format. (Format: {0})", credPaymFormat._Format))); } } }
protected override void ExportReportUsingCrystal(string reportPath, ExportFormatType reportType) { string absolutePathFilename1 = string.Empty; absolutePathFilename1 = reportPath; Page1 = new LLPotential(); DiskFileDestinationOptions destinationOptions = new DiskFileDestinationOptions(); CrystalDecisions.Shared.TableLogOnInfo myLogin = new CrystalDecisions.Shared.TableLogOnInfo(); myLogin.ConnectionInfo.UserID = ConfigurationManager.AppSettings["CrystalUser"]; myLogin.ConnectionInfo.Password = ConfigurationManager.AppSettings["CrystalPassword"]; myLogin.ConnectionInfo.DatabaseName = ""; myLogin.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["CrystalDB"]; for (int i = 0; i < Page1.Database.Tables.Count; i++) { Page1.Database.Tables[i].ApplyLogOnInfo(myLogin); } SetReportParameters(); Page1.ExportOptions.ExportFormatType = reportType; Page1.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; try { destinationOptions.DiskFileName = absolutePathFilename1; Page1.ExportOptions.DestinationOptions = destinationOptions; Page1.Export(); } catch (Exception ex) { throw new ApplicationException("An unexpected error occurred trying to export the report: " + ex.ToString()); } finally { } }
private CrystalDecisions.Shared.ExportFormatType stringTOExportFormatType(ExportFormatType exportTO) { if (exportTO == ExportFormatType.DOC) { return CrystalDecisions.Shared.ExportFormatType.WordForWindows; } if (exportTO == ExportFormatType.XLS) { return CrystalDecisions.Shared.ExportFormatType.Excel; } if (exportTO == ExportFormatType.HTML) { return CrystalDecisions.Shared.ExportFormatType.HTML40; } if (exportTO == ExportFormatType.TXT) { return CrystalDecisions.Shared.ExportFormatType.RichText; } return CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; }
/// <summary> /// Company IBAN number /// </summary> public void CompanyIBAN(String iban, ExportFormatType exportFormat) { //For now we require that IBAN/SWIFT is always filled in for ISO20022 payments - we probably has to ease the rule on the long run if (formatTypeISO) { IBANok = true; iban = iban ?? string.Empty; iban = Regex.Replace(iban, "[^\\w\\d]", ""); if (string.IsNullOrEmpty(iban)) { preCheckErrors.Add(new PreCheckError(String.Format("The IBAN number has not been filled in. (Format: {0})", credPaymFormat._Format))); IBANok = false; } else if (!StandardPaymentFunctions.ValidateIBAN(iban)) { preCheckErrors.Add(new PreCheckError(String.Format("The IBAN number has not a valid format. (Format: {0})", credPaymFormat._Format))); IBANok = false; } } }
/// <summary> /// Company SWIFT/BIC code /// </summary> public void CompanySWIFT(String swift, ExportFormatType exportFormat) { //For now we require that IBAN/SWIFT is always filled in for ISO20022 payments - we probably has to ease the rule on the long run if (formatTypeISO) { SWIFTok = true; swift = swift ?? string.Empty; swift = Regex.Replace(swift, "[^\\w\\d]", ""); if (string.IsNullOrEmpty(swift)) { preCheckErrors.Add(new PreCheckError(String.Format("The SWIFT code has not been filled in. (Format: {0})", credPaymFormat._Format))); SWIFTok = false; } else if (!StandardPaymentFunctions.ValidateBIC(swift)) { preCheckErrors.Add(new PreCheckError(String.Format("The SWIFT code has not a valid format. (Format: {0})", credPaymFormat._Format))); SWIFTok = false; } } }
public FileResult GenerateReport(string format = "pdf") { var data = db.vwBooks.ToList(); ReportDocument rd = new ReportDocument(); string reportPath = Server.MapPath("~/Reports/BookReport.rpt"); rd.Load(reportPath); rd.SetDataSource(data); string fileExt, fileType; ExportFormatType exportType = ExportFormatType.PortableDocFormat; if (format == "excel") { fileExt = ".xls"; fileType = "application/vnd.ms-excel"; exportType = ExportFormatType.Excel; } else if (format == "word") { fileExt = ".doc"; fileType = "application/msword"; exportType = ExportFormatType.WordForWindows; } else { fileExt = ".pdf"; fileType = "application/pdf"; exportType = ExportFormatType.PortableDocFormat; } Response.Buffer = false; Response.ClearHeaders(); Response.ClearContent(); Stream fStream = rd.ExportToStream(exportType); fStream.Seek(0, SeekOrigin.Begin); return(File(fStream, fileType, $"Students Report{fileExt}")); }
private void PrintReport(bool isPrint, ExportFormatType exportFormat = ExportFormatType.NoFormat) { try { this.Cursor = Cursors.WaitCursor; using (RPT002_Process rpt = new RPT002_Process(this.wpaResult.ID)) { if (isPrint) { rpt.PrintReport(); } else if (!isPrint && exportFormat == ExportFormatType.NoFormat) { rpt.PreviewDialog(); } else if (exportFormat == ExportFormatType.Excel) { rpt.ExportExcelSpecial(); } else if (!isPrint) { rpt.Export(exportFormat); } else { rpt.PrintReport(); } } } catch (Exception ex) { rMessageBox.ShowException(this, ex); } finally { this.Cursor = Cursors.Default; } }
private void Export(ExportFormatType pvtExportFormatType) { ReportDocument rpt = new ReportDocument(); rpt.Load(Server.MapPath(Constants.ROOT_DIRECTORY + "/Reports/_StockTransactionReport.rpt")); SetDataSource(rpt); ExportOptions exportop = new ExportOptions(); DiskFileDestinationOptions dest = new DiskFileDestinationOptions(); string strPath = Server.MapPath(@"\retailplus\temp\"); string strFileExtensionName = ".pdf"; switch (pvtExportFormatType) { case ExportFormatType.PortableDocFormat: strFileExtensionName = ".pdf"; exportop.ExportFormatType = ExportFormatType.PortableDocFormat; break; case ExportFormatType.WordForWindows: strFileExtensionName = ".doc"; exportop.ExportFormatType = ExportFormatType.WordForWindows; break; case ExportFormatType.Excel: strFileExtensionName = ".xls"; exportop.ExportFormatType = ExportFormatType.Excel; break; } string strFileName = "tranreport_" + Session["UserName"].ToString() + "_" + DateTime.Now.ToString("yyyyMMddhhmmssff") + strFileExtensionName; if (System.IO.File.Exists(strPath + strFileName)) System.IO.File.Delete(strPath + strFileName); dest.DiskFileName = strPath + strFileName; exportop.DestinationOptions = dest; exportop.ExportDestinationType = ExportDestinationType.DiskFile; rpt.Export(exportop); //rpt.Close(); rpt.Dispose(); if (pvtExportFormatType == ExportFormatType.PortableDocFormat) { rpt.Close(); rpt.Dispose(); Response.Redirect(Constants.ROOT_DIRECTORY + "/temp/" + strFileName, false); } else { CRViewer.ReportSource = rpt; Session["ReportDocument"] = rpt; CRSHelper.OpenExportedReport(strFileName); // OpenExportedReport(strFileName); } }
protected virtual void ExportReportUsingCrystal(string reportPath, ExportFormatType reportType) { DiskFileDestinationOptions destinationOptions = new DiskFileDestinationOptions(); destinationOptions.DiskFileName = reportPath; //CrystalReportDocument.set //CrystalReportDocument.SetDatabaseLogon("loc", "winter08", "CTS_DEVL", null,true); CrystalReportDocument.SetDataSource(ReportData); if (CrystalReportDocument.Subreports.Count > 0) { PopulateSubreportData(CrystalReportDocument); } SetReportParameters(); //Set the datasource for the report CrystalReportDocument.ExportOptions.DestinationOptions = destinationOptions; CrystalReportDocument.ExportOptions.ExportFormatType = reportType; CrystalReportDocument.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; //Assign the export options so we can export to pdf file //destinationOptions.DiskFileName = reportPath; //Export the report try { //CrystalReportDocument.SetDatabaseLogon //CrystalReportDocument.ExportToStream(CrystalReportDocument.ExportOptions.ExportFormatType); CrystalReportDocument.Export(); } catch (Exception ex) { throw new ApplicationException("An unexpected error occurred trying to export the report: " + ex.ToString()); } }
/// <summary> /// 利用 CrystalReport 匯出 PDF 或是 EXCEL /// </summary> /// <param name="s_FileName">檔名</param> /// <param name="s_rptFilePath">rpt檔的路徑</param> /// <param name="dt_Source">要列印的資料</param> /// <param name="e_Type">PDF or EXCEL</param> private void LoadCrystalReport(string s_FileName, string s_rptFilePath, DataTable dt_Source, ExportFormatType e_Type) { ReportDocument report = new ReportDocument(); report.Load(s_rptFilePath); report.SetDataSource(dt_Source); #region 設定報表參數欄位 string Program_ID = string.Empty; string LoginUser = string.Empty; string LoginName = string.Empty; string strParFDate = string.Empty; string strParFSType = string.Empty; string strParFTaxType = string.Empty; if (this.SLP_InvoDateRange.StartDate == SLP_InvoDateRange.EndDate) { strParFDate = SLP_InvoDateRange.StartDate; } else { strParFDate = SLP_InvoDateRange.StartDate + " ~ " + SLP_InvoDateRange.EndDate; } if (int.Parse(ddlSource_Type_S.SelectedValue) > int.Parse(ddlSource_Type_E.SelectedValue)) { strParFSType = ddlSource_Type_E.SelectedItem.Text + " ~ " + ddlSource_Type_S.SelectedItem.Text; } else { strParFSType = ddlSource_Type_S.SelectedItem.Text + " ~ " + ddlSource_Type_E.SelectedItem.Text; } strParFTaxType = rblTaxType.SelectedItem.Text; Program_ID = this.PageCode.Substring(0, 5) + "R01"; LoginUser = Session["UID"].ToString(); LoginName = ((DataTable)Session["UserInfo"]).Rows[0]["Name"].ToString(); report.SetParameterValue("par_Program_ID", Program_ID); report.SetParameterValue("par_LoginUser", LoginUser); report.SetParameterValue("par_LoginName", LoginName); report.SetParameterValue("par_F_Date", strParFDate); report.SetParameterValue("par_F_Source", strParFSType); report.SetParameterValue("par_F_Tax", strParFTaxType); #endregion System.IO.Stream stream = report.ExportToStream(e_Type); byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); stream.Seek(0, System.IO.SeekOrigin.Begin); //export file Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//檔名 if (e_Type == ExportFormatType.Excel) { Response.ContentType = "application/vnd.ms-excel"; } else if (e_Type == ExportFormatType.PortableDocFormat) { Response.ContentType = "application/pdf"; } Response.OutputStream.Write(bytes, 0, bytes.Length); Response.Flush(); Response.Close(); report.Close(); }
protected ActionResult RenderReport(string reportName, Action<ReportClass> reportCallback,ExportFormatType format) { ReportClass rptH = new ReportClass(); rptH.FileName = Server.MapPath(string.Format("~/Content/report/{0}.rpt", reportName)); reportCallback(rptH); Stream stream = rptH.ExportToStream(format); var contentype = "application/pdf"; switch (format) { case ExportFormatType.Excel: contentype = "application/vnd.ms-excel"; break; } return File(stream, contentype); }
/// <summary> /// 利用 CrystalReport 匯出 PDF 或是 EXCEL /// </summary> /// <param name="s_FileName">檔名</param> /// <param name="s_rptFilePath">rpt檔的路徑</param> /// <param name="dt_Source">要列印的資料</param> /// <param name="e_Type">PDF or EXCEL</param> private void LoadCrystalReport(string s_FileName, string s_rptFilePath, DataTable dt_Source, ExportFormatType e_Type) { ReportDocument report = new ReportDocument(); report.Load(s_rptFilePath); report.SetDataSource(dt_Source); System.IO.Stream stream = report.ExportToStream(e_Type); byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); stream.Seek(0, System.IO.SeekOrigin.Begin); //export file Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("content-disposition", "attachment;filename=" + s_FileName);//檔名 if (e_Type == ExportFormatType.Excel) { Response.ContentType = "application/vnd.ms-excel"; } else if (e_Type == ExportFormatType.PortableDocFormat) { Response.ContentType = "application/pdf"; } Response.OutputStream.Write(bytes, 0, bytes.Length); Response.Flush(); Response.Close(); report.Close(); }
private void Export(ExportFormatType pvtExportFormatType) { if (string.IsNullOrEmpty(lblReferrer.ToolTip)) return; ReportDocument rpt = getReportDocument(); string strUnparsedTask = lblReferrer.ToolTip; string task = strUnparsedTask; if (strUnparsedTask.ToLower() != "transaction") task = Common.Decrypt(strUnparsedTask, Session.SessionID); SetDataSource(rpt, task); if (pvtExportFormatType == ExportFormatType.WordForWindows || pvtExportFormatType == ExportFormatType.Excel || pvtExportFormatType == ExportFormatType.PortableDocFormat) { string strFileName = Session["UserName"].ToString() + "_products"; CRSHelper.GenerateReport(strFileName, rpt, this.updPrint, pvtExportFormatType); } else { CRViewer.ReportSource = rpt; Session["ReportDocument"] = rpt; } }
private void Export(ExportFormatType pvtExportFormatType) { ReportDocument rpt = getReportDocument(); SetDataSource(rpt); if (pvtExportFormatType == ExportFormatType.WordForWindows || pvtExportFormatType == ExportFormatType.Excel || pvtExportFormatType == ExportFormatType.PortableDocFormat) { string strFileName = Session["UserName"].ToString() + "_credit"; switch (cboReportType.SelectedItem.Value) { case ReportTypes.CREDITS_Purchases: strFileName += "purchases"; break; case ReportTypes.CREDITS_Payments: strFileName += "payments"; break; case ReportTypes.CREDITS_CreditorsLedgerSummary: strFileName += "ledger"; break; case ReportTypes.CustomerCreditSummarizedStatistics: strFileName += "stat"; break; default: break; } CRSHelper.GenerateReport(strFileName, rpt, this.updPrint, pvtExportFormatType); } else { CRViewer.ReportSource = rpt; Session["ReportDocument"] = rpt; } }