private async void ButtonLoadDocumentClick(object sender, RoutedEventArgs e) { var openPicker = new FileOpenPicker { SuggestedStartLocation = PickerLocationId.ComputerFolder }; openPicker.FileTypeFilter.Add(".mdc"); var storageFile = await openPicker.PickSingleFileAsync(); if (storageFile != null) { ShowProgress(); if (newReport != null) { newReport.Dispose(); newReport = null; } try { newReport = new StiReport(); await newReport.LoadDocumentAsync(storageFile); } catch { newReport = null; } finally { labelLoadDocumentOK.Visibility = Visibility.Visible; if (textBoxReportName.Text.Length == 0) { textBoxReportName.Text = newReport.ReportName; } if (textBoxReportDescription.Text.Length == 0) { textBoxReportDescription.Text = newReport.ReportDescription; } } HideProgress(); } CheckState(); }
public void RunReport(string reportFileName, ReportOperator opera, DataSet reportData, List <KeyValuePair <string, object> > varList) { if (outInfo != null) { outInfo("正在装载报表文件:" + ReportDir + reportFileName); } bool isNewFile = !File.Exists(ReportDir + reportFileName); //是新文件吗 StiReport report = new StiReport(); if (ReportDir + reportFileName != null && !isNewFile) { report.Load(ReportDir + reportFileName); } if (reportData != null) { report.RegData(reportData); } if (outInfo != null) { outInfo("正在初始化报表 ..."); } AddReportVar(report, varList); if (!report.IsStopped) { if (opera == ReportOperator.Previev) { report.Show(true); } else if (opera == ReportOperator.Print) { report.Print(false); } else if (opera == ReportOperator.Design) { if (isNewFile) { report.ReportFile = ReportDir + reportFileName; } report.Design(true); } } report.Dispose(); report = null; if (outInfo != null) { outInfo("准备"); } }
async private void buttonExport_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (listBoxReports.SelectedIndex == -1 || listBoxExports.SelectedIndex == -1) { return; } #region Get Report string fileName = null; switch (listBoxReports.SelectedIndex) { case 0: fileName = "StimulsoftResources\\Reports\\SimpleList.mrt"; break; case 1: fileName = "StimulsoftResources\\Reports\\MultiColumnList.mrt"; break; case 2: fileName = "StimulsoftResources\\Reports\\MasterDetail.mrt"; break; case 3: fileName = "StimulsoftResources\\Reports\\TwoMastersOnOneDetail.mrt"; break; } #endregion if (fileName == null) { return; } ShowProgress(); #region Load Report StorageFile storage = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileName); StiReport report = new StiReport(); await report.LoadAsync(storage); report.RegBusinessObject("Data", "Data", new Data()); await report.RenderAsync(); #endregion #region Create StorageFile ListBoxItem item = listBoxExports.SelectedItem as ListBoxItem; StiExportService service = item.Tag as StiExportService; StorageFile file = await service.GetFileStream(report.ReportName); #endregion #region Export if (file != null) { if (listBoxExports.SelectedIndex == 0) { await((StiPdfExportService)service).ExportPdfAsync(report, file, new StiPdfExportSettings()); } else if (listBoxExports.SelectedIndex == 1) { await((StiCsvExportService)service).ExportCsvAsync(report, file, new StiCsvExportSettings()); } else if (listBoxExports.SelectedIndex == 2) { await((StiDbfExportService)service).ExportDbfAsync(report, file, new StiDbfExportSettings()); } else if (listBoxExports.SelectedIndex == 3) { await((StiExcelExportService)service).ExportExcelAsync(report, file, new StiExcelExportSettings()); } else if (listBoxExports.SelectedIndex == 4) { await((StiExcel2007ExportService)service).ExportExcelAsync(report, file, new StiExcel2007ExportSettings()); } else if (listBoxExports.SelectedIndex == 5) { await((StiExcelXmlExportService)service).ExportExcelAsync(report, file, new StiExcelXmlExportSettings()); } else if (listBoxExports.SelectedIndex == 6) { await((StiHtmlExportService)service).ExportHtmlAsync(report, file, new StiHtmlExportSettings()); } else if (listBoxExports.SelectedIndex == 7) { await((StiPpt2007ExportService)service).ExportPowerPointAsync(report, file, new StiPpt2007ExportSettings()); } else if (listBoxExports.SelectedIndex == 8) { await((StiTxtExportService)service).ExportTxtAsync(report, file, new StiTxtExportSettings()); } else if (listBoxExports.SelectedIndex == 9) { await((StiWord2007ExportService)service).ExportWordAsync(report, file, new StiWord2007ExportSettings()); } } #endregion report.Dispose(); HideProgress(); }
public static GenerateReportResult GenerateReport(string logPath, string directoryName, string dataSource, string reportPath, string reportName, string reportPeriod, string timeFrom, string timeTo, string[] exportFormat, string byProg, JuridicalData JuridicalData, BonusClub BonusClub, string date) { StiExportFormat StiExportFormat = StiExportFormat.Pdf; GenerateReportResult GenerateReportResult = new GenerateReportResult(); List <string> ExportFiles = new List <string>(); DateTime monday = AdditionalFunc.GetMonday(date); string numWeek = AdditionalFunc.GetNumWeek(date), exportPath = string.Empty, exportFileName = string.Empty, bonusClubFolder = "\\" + BonusClub.title; const string period = "period", periodRequest = "periodRequest", timeReport = "timeReport", juridicalID = "juridicalID", clubID = "clubID", shiftHour = "shiftHour", programDivide = "programDivide", year = "year", month = "month"; StiReport report = new StiReport(); try { StiConfig.Services.Add(new StiOracleODPAdapterService()); StiOptions.Engine.ReportCache.AmountOfQuickAccessPages = 5; StiOptions.Engine.ReportCache.AmountOfProcessedPagesForStartGCCollect = 5; report.ReportCacheMode = StiReportCacheMode.On; report.Load(reportPath); foreach (StiOracleODPDatabase db in report.Dictionary.Databases.OfType <StiOracleODPDatabase>()) { db.ConnectionString = dataSource; } foreach (StiOracleODPSource src in report.Dictionary.DataSources.OfType <StiOracleODPSource>()) { src.CommandTimeout = 12000; } if (report.Dictionary.Variables != null && report.Dictionary.Variables.Contains(timeReport) && report.Dictionary.Variables.Contains(period) && report.Dictionary.Variables.Contains(periodRequest)) { if (report.Dictionary.Variables.Contains(juridicalID)) { report.Dictionary.Variables[juridicalID].Value = JuridicalData.jurID.ToString(); } if (report.Dictionary.Variables.Contains(clubID)) { report.Dictionary.Variables[clubID].Value = BonusClub.clubId.ToString(); } if (report.Dictionary.Variables.Contains(shiftHour)) { report.Dictionary.Variables[shiftHour].Value = timeFrom; } if (report.Dictionary.Variables.Contains(programDivide)) { report.Dictionary.Variables[programDivide].Value = byProg; } if (report.Dictionary.Variables.Contains(year)) { report.Dictionary.Variables[year].Value = date.Substring(0, 4); } if (report.Dictionary.Variables.Contains(month)) { report.Dictionary.Variables[month].Value = date.Substring(5, 2); } report.Dictionary.Variables[timeReport].Value = date; switch (reportPeriod) { case Variables.periodAllTime: report.Dictionary.Variables[period].Value = "За все время. Смена с " + timeFrom + ":00 до " + timeTo + ":00"; /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss')<to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd hh24:mi:ss')";*/ report.Dictionary.Variables[periodRequest].Value = "and request_date < to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss') "; // + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") " // + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))"; break; case Variables.periodYear: report.Dictionary.Variables[period].Value = "С 01.01." + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + " " + timeFrom + ":00 по " + DateTime.Parse(date).ToString("dd.MM.yyyy") + " " + timeTo + ":00. Смена с " + timeFrom + ":00 до " + timeTo + ":00"; /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss') between to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss') - 1, 'yyyy')|| '.01.01 " + timeFrom + ":00:00' and to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd')|| ' " + timeTo + ":00:00'";*/ report.Dictionary.Variables[periodRequest].Value = "and request_date between to_date('" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + ".01.01 " + timeFrom + ":00:00', 'yyyy.mm.dd hh24:mi:ss') and to_date('" + DateTime.Parse(date).ToString("yyyy.MM.dd") + " " + timeTo + ":00:00', 'yyyy.mm.dd hh24:mi:ss') "; // + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") " // + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))"; break; case Variables.periodMonth: report.Dictionary.Variables[period].Value = "С 01." + DateTime.Parse(date).AddDays(-1).ToString("MM.yyyy") + " " + timeFrom + ":00 по " + DateTime.Parse(date).ToString("dd.MM.yyyy") + " " + timeTo + ":00. Смена с " + timeFrom + ":00 до " + timeTo + ":00"; /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss') between to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss') - 1, 'yyyy.mm')|| '.01 " + timeFrom + ":00:00' and to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd')|| ' " + timeTo + ":00:00'";*/ report.Dictionary.Variables[periodRequest].Value = "and request_date between to_date('" + DateTime.Parse(date).AddDays(-1).ToString("yyyy.MM") + ".01 " + timeFrom + ":00:00', 'yyyy.mm.dd hh24:mi:ss') " + "and to_date('" + DateTime.Parse(date).ToString("yyyy.MM.dd") + " " + timeTo + ":00:00', 'yyyy.mm.dd hh24:mi:ss') "; // + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") " // + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))"; break; case Variables.periodWeek: report.Dictionary.Variables[period].Value = "С " + monday.ToString("dd.MM.yyyy") + " " + timeFrom + ":00 по " + DateTime.Parse(date).ToString("dd.MM.yyyy") + " " + timeTo + ":00. Смена с " + timeFrom + ":00 до " + timeTo + ":00"; /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss') between to_char(next_day(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss') - 8, 1), 'yyyy.mm.dd')|| ' " + timeFrom + ":00:00' and to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd')|| ' " + timeTo + ":00:00'";*/ report.Dictionary.Variables[periodRequest].Value = "and request_date between to_date('" + monday.ToString("yyyy.MM.dd") + " " + timeFrom + ":00:00', 'yyyy.mm.dd hh24:mi:ss') " + "and to_date('" + DateTime.Parse(date).ToString("yyyy.MM.dd") + " " + timeTo + ":00:00', 'yyyy.mm.dd hh24:mi:ss') "; // + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") " // + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))"; break; case Variables.periodDay: report.Dictionary.Variables[period].Value = "С " + DateTime.Parse(date).AddDays(-1).ToString("dd.MM.yyyy") + " " + timeFrom + ":00 по " + DateTime.Parse(date).ToString("dd.MM.yyyy") + " " + timeTo + ":00. Смена с " + timeFrom + ":00 до " + timeTo + ":00"; /*report.Dictionary.Variables[periodRequest].Value = "and to_char(request_date, 'yyyy.mm.dd hh24:mi:ss') between to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss') - 1, 'yyyy.mm.dd')|| ' " + timeFrom + ":00:00' and to_char(to_date('" + date + "', 'yyyy.mm.dd hh24:mi:ss'), 'yyyy.mm.dd')|| ' " + timeTo + ":00:00'";*/ report.Dictionary.Variables[periodRequest].Value = "and request_date between to_date('" + DateTime.Parse(date).AddDays(-1).ToString("yyyy.MM.dd") + " " + timeFrom + ":00:00', 'yyyy.mm.dd hh24:mi:ss') " + "and to_date('" + DateTime.Parse(date).ToString("yyyy.MM.dd") + " " + timeTo + ":00:00', 'yyyy.mm.dd hh24:mi:ss') "; // + "and (((to_char(request_date,'HH24') >= " + timeFrom + " or to_char(request_date,'HH24') < " + timeTo + ") and " + timeFrom + " >= " + timeTo + ") " // + "or ((to_char(request_date, 'HH24') >= " + timeFrom + " and to_char(request_date, 'HH24') < " + timeTo + ") and " + timeFrom + " < " + timeTo + "))"; break; default: break; } } report.Save(reportPath); report.Render(); StiOptions.Export.Csv.ForcedSeparator = ";"; for (int i = 0; i < exportFormat.Length; i++) { string ef = exportFormat[i].ToLower(); switch (exportFormat[i].ToLower()) { case Variables.formatPDF: StiExportFormat = StiExportFormat.Pdf; break; case Variables.formatCSV: StiExportFormat = StiExportFormat.Csv; break; case Variables.formatDOCX: StiExportFormat = StiExportFormat.Word2007; break; case Variables.formatXLSX: StiExportFormat = StiExportFormat.Excel2007; break; default: break; } switch (reportPeriod) { case Variables.periodAllTime: exportPath = reportName + "\\" + directoryName + bonusClubFolder; if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle)) { exportFileName = JuridicalData.jurInnAndTitle + "." + ef; } else { exportFileName = "За все время-" + directoryName + "." + ef; } if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName); break; case Variables.periodYear: exportPath = reportName + "\\" + directoryName + bonusClubFolder + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + directoryName; if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle)) { exportFileName = JuridicalData.jurInnAndTitle + "." + ef; } else { exportFileName = DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + directoryName + "." + ef; } if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName); break; case Variables.periodMonth: exportPath = reportName + "\\" + directoryName + bonusClubFolder + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + directoryName + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM") + "-" + directoryName; if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle)) { exportFileName = JuridicalData.jurInnAndTitle + "." + ef; } else { exportFileName = DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM") + "-" + directoryName + "." + ef; } if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName); break; case Variables.periodWeek: exportPath = reportName + "\\" + directoryName + bonusClubFolder + "\\" + AdditionalFunc.GetYearByNumWeek(numWeek, date) + "-" + directoryName + "\\Недели\\" + numWeek + "." + monday.ToString("yyyy") + "-" + monday.ToString("MM") + "-" + monday.ToString("dd") + " - " + monday.AddDays(6).ToString("yyyy") + "-" + monday.AddDays(6).ToString("MM") + "-" + monday.AddDays(6).ToString("dd") + "-" + directoryName; if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle)) { exportFileName = JuridicalData.jurInnAndTitle + "." + ef; } else { exportFileName = monday.ToString("yyyy") + "-" + monday.ToString("MM") + "-" + monday.ToString("dd") + " - " + monday.AddDays(6).ToString("yyyy") + "-" + monday.AddDays(6).ToString("MM") + "-" + monday.AddDays(6).ToString("dd") + "-" + directoryName + "." + ef; } if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName); break; case Variables.periodDay: exportPath = reportName + "\\" + directoryName + bonusClubFolder + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + directoryName + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM") + "-" + directoryName + "\\" + DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM") + "-" + DateTime.Parse(date).AddDays(-1).ToString("dd") + "-" + directoryName; if (!String.IsNullOrEmpty(JuridicalData.jurInnAndTitle)) { exportFileName = JuridicalData.jurInnAndTitle + "." + ef; } else { exportFileName = DateTime.Parse(date).AddDays(-1).ToString("yyyy") + "-" + DateTime.Parse(date).AddDays(-1).ToString("MM") + "-" + DateTime.Parse(date).AddDays(-1).ToString("dd") + "-" + directoryName + "." + ef; } if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } report.ExportDocument(StiExportFormat, exportPath + "\\" + exportFileName); break; default: break; } ExportFiles.Add(exportPath + "\\" + exportFileName); GenerateReportResult.ExportFiles = ExportFiles; } GenerateReportResult.generateResult = 0; return(GenerateReportResult); } catch (Exception ex) { AdditionalFunc.LogFile(logPath + "\\" + Variables.fileError, "Отчет: " + reportPath + "\n\n" + "Период: " + reportPeriod + "\n\n" + "ЮЛ: " + JuridicalData.jurInnAndTitle + " " + JuridicalData.jurID + "\n\n" + "БД: " + dataSource.Remove(dataSource.IndexOf(";")) + "\n\n" + ex.Message, true); GenerateReportResult.generateResult = 1; return(GenerateReportResult); } finally { report.Dictionary.Clear(); report.RenderedPages.Clear(); report.Dispose(); } }