// Open report file in flex viewer private void OpenFile(string rptFile, string rptName) { try { _flexReport = new C1FlexReport(); string filePath = rptFile.Substring(rptFile.IndexOf("Reports")); System.IO.Stream file = null; if (File.Exists(rptFile)) { file = new FileStream(rptFile, FileMode.Open, FileAccess.Read); ChangeConStrin(ref file); _flexReport.Load(file, rptName); } else if (File.Exists(filePath)) { file = new FileStream(filePath, FileMode.Open, FileAccess.Read); ChangeConStrin(ref file); _flexReport.Load(file, rptName); } else { throw new FileNotFoundException(new FileNotFoundException() + " " + filePath); } flexViewer.DocumentSource = null; flexViewer.DocumentSource = _flexReport; } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { c1DataSource1.ViewSources["Products"].FilterDescriptors[0].Value = ((Categories)cbxCategory.SelectedItem).CategoryID; _report.Load(@"..\..\ReportDefinition.flxr", "Report"); _report.DataSource.Recordset = c1DataSource1.ViewSources["Products"].DataView; c1FlexViewer.DocumentSource = _report; }
private void c1DockingTab1_TabClick(object sender, EventArgs e) { var flexViewer = c1DockingTab1.SelectedTab.Tag as C1FlexViewer ?? new C1FlexViewer() { Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top, Dock = DockStyle.Fill, ZoomMode = FlexViewerZoomMode.PageWidth, Parent = c1DockingTab1.SelectedTab }; if (flexViewer.DocumentSource == null) { flexViewer.Ribbon.Minimized = true; var flexReport = new C1FlexReport(); var reportStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DashboardWinForms.Reports." + _reps[c1DockingTab1.SelectedIndex]); string[] reports = C1FlexReport.GetReportList(reportStream); if (reports.Count() == 0) { return; } var reportName = reports[0]; if (!string.IsNullOrEmpty(reportName)) { reportStream.Seek(0, SeekOrigin.Begin); flexReport.Load(reportStream, reportName); flexViewer.DocumentSource = flexReport; c1DockingTab1.SelectedTab.Tag = flexViewer; } } }
async void CbReport_SelectionChanged(object sender, SelectionChangedEventArgs e) { string selectedReport = cbReport.SelectedItem as string; if (string.IsNullOrEmpty(selectedReport)) { return; } // load report try { // load from resource stream Assembly asm = typeof(ExportPage).GetTypeInfo().Assembly; using (Stream stream = asm.GetManifestResourceStream("FlexReportSamples.Resources.FlexCommonTasks_UWP.flxr")) _report.Load(stream, selectedReport); } catch (Exception ex) { MessageDialog md = new MessageDialog(string.Format(Strings.FailedToLoadFmt, selectedReport, ex.Message), "Error"); await md.ShowAsync(); return; } flexViewerPane.DocumentSource = null; flexViewerPane.DocumentSource = _report; }
public CategoryList(Stream stream) { _stream = stream; string[] reports = C1FlexReport.GetReportList(stream); using (C1FlexReport fr = new C1FlexReport()) { foreach (string reportName in reports) { stream.Seek(0, SeekOrigin.Begin); fr.Load(stream, reportName); string keywords = fr.ReportInfo.Keywords; string[] ss = keywords.Split(new string[] { "\r\n" }, StringSplitOptions.None); for (int i = 0; i < ss.Length; i++) { var categoryName = ss[i]; if (Contains(categoryName)) { this[categoryName].AddReport(reportName); } else { var ci = new CategoryItem(categoryName); ci.AddReport(reportName); this.Add(ci); } } } } }
private void BuildCategoriesReport() { // request data from OData service System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; // force Tls12 var service = new DemoODataService.DemoService(ODataUri); // select all categrues var categories = service.Categories.Execute().ToList(); // load report definition from resources Assembly asm = Assembly.GetExecutingAssembly(); using (Stream stream = asm.GetManifestResourceStream("Binding.Resources.Reports.flxr")) _report.Load(stream, "Categories"); // assign dataset to the report _report.DataSource.Recordset = categories; }
private void btnExport_Click(object sender, RoutedEventArgs e) { if (_report.IsBusy) { return; } string selectedReport = cbReport.SelectedItem as string; if (string.IsNullOrEmpty(selectedReport)) { return; } if (cbExportFilter.SelectedIndex < 0 || cbExportFilter.SelectedIndex >= _report.SupportedExportProviders.Length) { return; } // load report try { // load from resource stream Assembly asm = Assembly.GetExecutingAssembly(); using (Stream stream = asm.GetManifestResourceStream("FlexReportSamples.Resources.FlexCommonTasks_XML.flxr")) _report.Load(stream, selectedReport); } catch (Exception ex) { MessageBox.Show(string.Format("Failed to load report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // prepare ExportFilter object ExportProvider ep = _report.SupportedExportProviders[cbExportFilter.SelectedIndex]; SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = string.Format("{0}.{1}", selectedReport, ep.DefaultExtension); sfd.Filter = string.Format("{0} Files (*.{1})|*.{1}", ep.FormatName, ep.DefaultExtension); sfd.CheckPathExists = true; if (!sfd.ShowDialog().Value) { return; } ExportFilter ef = ep.NewExporter() as ExportFilter; ef.FileName = sfd.FileName; ef.Preview = cbOpenDocument.IsChecked.Value; // try { _report.RenderToFilter(ef); } catch (Exception ex) { MessageBox.Show(string.Format("Failed to export report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public C1FlexReport GetReport(string reportName) { if (_stream != null) { _stream.Seek(0, SeekOrigin.Begin); var fr = new C1FlexReport(); fr.Load(_stream, reportName); return(fr); } return(null); }
void OnLoaded(object sender, RoutedEventArgs rea) { Loaded -= OnLoaded; using (_reportStream = File.OpenRead("Assets/Reports/RegionWiseSalesData.flxr")) { string[] reports = C1FlexReport.GetReportList(_reportStream); fv.DocumentSource = null; _reportStream.Seek(0, SeekOrigin.Begin); _flexReport.Load(_reportStream, reports[0]); fv.DocumentSource = _flexReport; } }
private void LoadReport(string reportName) { if (report.IsBusy) { return; } // load C1FlexReport with selected report report.Load(doc, reportName); // assign report to the flex viewer control c1FlexViewer1.DocumentSource = report; }
private void btnPrint_Click(object sender, RoutedEventArgs e) { if (_report.IsBusy) { return; } string selectedReport = cbReport.SelectedItem as string; if (string.IsNullOrEmpty(selectedReport)) { return; } PrintInfo pi = cbPrinter.SelectedItem as PrintInfo; if (pi == null) { return; } // load report try { // load from resource stream Assembly asm = Assembly.GetExecutingAssembly(); using (Stream stream = asm.GetManifestResourceStream("FlexReportSamples.Resources.FlexCommonTasks_XML.flxr")) _report.Load(stream, selectedReport); } catch (Exception ex) { MessageBox.Show(string.Format("Failed to load report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // render and print report try { _report.Render(); C1PrintOptions po = new C1PrintOptions(); po.PrintQueue = pi.PrintQueue; _report.Print(po); } catch (Exception ex) { MessageBox.Show(string.Format("Failed to print report [{0}], exception:\r\n{1}", selectedReport, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
void ReportCombo_SelectionCommitted(object sender, C1.WPF.PropertyChangedEventArgs <object> e) { if (_flexReport.IsBusy || _flexReport.IsDisposed) { return; } var reportName = fv.DocumentListCombo.SelectedItem as string; if (!string.IsNullOrEmpty(reportName)) { fv.DocumentSource = null; _reportStream.Seek(0, SeekOrigin.Begin); _flexReport.Load(_reportStream, reportName); fv.DocumentSource = _flexReport; fv.FocusPane(); } }
private void BuildTopicBar() { // get list of the reports string fileName = @"..\..\" + c_FlexCommonTasks; string[] reports = C1FlexReport.GetReportList(fileName); // go over reports and get category from C1FlexReport.ReportInfo.Keywords using (C1FlexReport fr = new C1FlexReport()) { List <Category> categories = new List <Category>(); foreach (string reportName in reports) { fr.Load(fileName, reportName); string keywords = fr.ReportInfo.Keywords; string[] ss = keywords.Split(new string[] { "\r\n" }, StringSplitOptions.None); for (int i = 0; i < ss.Length; i++) { Category c = categories.Find((item) => string.Compare(item.Name, ss[i], true) == 0); if (c == null) { c = new Category() { Name = ss[i] }; categories.Add(c); } c.Reports.Add(reportName); } } categories.Sort(CompareCategories); foreach (Category c in categories) { // build items in the C1TopicBar C1TopicPage tp = new C1TopicPage(c.Name); foreach (string s in c.Reports) { C1TopicLink tl = new C1TopicLink(s); tp.Links.Add(tl); } tbReports.Pages.Add(tp); } } }
async Task LoadReport(string reportName) { // load report try { using (Stream stream = _asm.GetManifestResourceStream("FlexReportSamples.Resources.FlexCommonTasks_UWP.flxr")) _report.Load(stream, reportName); } catch (Exception ex) { MessageDialog md = new MessageDialog(string.Format(Strings.FailedToLoadFmt, reportName, ex.Message), "Error"); await md.ShowAsync(); return; } flexViewer.DocumentSource = _report; }
void LoadReport(string reportName) { var report = new C1FlexReport(); report.Load(_doc, reportName); var oldReport = _report; _report = report; // assign report to the flex viewer control fv.DocumentSource = report; if (oldReport != null) { oldReport.Dispose(); } UpdateEnabled(); }
public async Task LoadReport(string categoryName, string reportFileName, string reportName) { // load report try { using (Stream fs = File.OpenRead("Assets/Reports/" + categoryName.Trim() + "/" + reportFileName.Trim())) { _report.Load(fs, reportName); } } catch (Exception ex) { MessageDialog md = new MessageDialog(string.Format(Strings.ErrorFormat, reportName, ex.Message), Strings.ErrorTitle); await md.ShowAsync(); return; } // flexViewer.DocumentSource = null; // render report progressRing.IsActive = true; try { await _report.RenderAsync(); } catch (Exception ex) { MessageDialog md = new MessageDialog(string.Format(Strings.ErrorFormat, reportName, ex.Message), Strings.ErrorTitle); await md.ShowAsync(); return; } finally { progressRing.IsActive = false; } // assign rendered report to the viewer flexViewer.DocumentSource = _report; }
private async void PdfButton_Click(object sender, RoutedEventArgs e) { // 現在、FlexGrid に表示されている順のデータ var currentData = this.flexgrid1.Rows.Select(r => r.DataItem).Cast <Book>(); // FlexReportの定義を読み込む var rpt = new C1FlexReport(); using (var stream = File.OpenRead("Assets/BooksReport.flxr")) rpt.Load(stream, "BooksReport"); // データを連結 rpt.DataSource.Recordset = currentData.ToList(); // IEnumerable<T>は不可 // レポートを生成 await rpt.RenderAsync(); // 印刷する場合 //await rpt.ShowPrintUIAsync(); // PDF ファイルに直接保存する場合 var picker = new FileSavePicker() { SuggestedStartLocation = PickerLocationId.DocumentsLibrary }; picker.FileTypeChoices.Add("PDF ファイル", new string[] { ".pdf", }); picker.SuggestedFileName = "BarCodeControlSample"; var file = await picker.PickSaveFileAsync(); if (file != null) { // 出力先となる PdfFilter オブジェクトを作成 var filter = new PdfFilter(); filter.StorageFile = file; // Windows Forms 等では、filter.FileName = file.Path; とする // ファイルへ出力 await rpt.RenderToFilterAsync(filter); } }
/// <summary> /// Tries to load the specified report from 3 locations, in order: /// - from embedded resource; /// - from file in Reports folder rel to .exe; /// - from file in ..\..\Reports folder rel to .exe. /// </summary> /// <param name="category"></param> /// <param name="reportFile"></param> /// <param name="reportName"></param> /// <returns></returns> private C1FlexReport LoadReport(string category, string reportFile, string reportName) { try { Assembly thisExe = Assembly.GetExecutingAssembly(); Stream file = thisExe.GetManifestResourceStream("C1.C1FlexReportExplorer.Reports." + category + "." + reportFile); if (file == null) { var exePath = Path.GetDirectoryName(thisExe.Location); var tFile = Path.Combine(exePath, "Reports", category, reportFile); if (File.Exists(tFile)) { file = new FileStream(tFile, FileMode.Open, FileAccess.Read); } else { file = new FileStream(Path.Combine(exePath, @"..\..\Reports", category, reportFile), FileMode.Open, FileAccess.Read); } if (file == null) { return(null); } } flxRpt = new C1FlexReport(); flxRpt.Load(file, reportName); // FixConnectionStrings(flxRpt); // return(flxRpt); } catch (Exception exc) { MessageBox.Show(exc.Message); return(null); } }
/// <summary> /// Converts a single file which may contain multiple reports. /// </summary> /// <param name="fileName"></param> /// <returns></returns> private ConvertFileItem ConvertFile(string fileName) { // Create a ConvertFileItem object which will hold the info about the file being converted. // If successuflly converted, that object will be passed to the method writing the .flxr file. ConvertFileItem convertFile = new ConvertFileItem(); convertFile.InputFile = fileName; convertFile.OutputFile = Path.ChangeExtension(fileName, ".flxr"); if (!string.IsNullOrEmpty(_txtOutputFolder.Text)) { convertFile.OutputFile = Path.Combine(_txtOutputFolder.Text, Path.GetFileName(convertFile.OutputFile)); } // load XML document XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; try { LogLine("Converting " + fileName + "..."); doc.Load(fileName); } catch (Exception ex) { string msg = string.Format("Could not load file: {0}.", ex.Message); LogLine(msg); convertFile.Error = msg; LogLine("Converting " + fileName + " aborted."); return(convertFile); } // Get the list of reports in the file. string[] reports = C1FlexReport.GetReportList(doc); if (reports == null || reports.Length == 0) { string msg = "No reports found in file."; LogLine(msg); convertFile.Error = msg; LogLine("Converting " + fileName + " aborted."); return(convertFile); } // Loop through reports, loading them into C1FlexReport instances, thus performing the conversion. int cnt = reports.Length; for (int i = 0; i < cnt; ++i) { ConvertReportItem convertReport = new ConvertReportItem(); C1FlexReport flexReport = new C1FlexReport(); try { bool converted; flexReport.Load(doc, reports[i], out converted); convertReport.Report = flexReport; LogLine(string.Format(" Converted {0}", flexReport.ReportName)); } catch (Exception x) { string msg = string.Format("Failed to convert \"{0}\": {1}", reports[i], x.Message); LogLine(" " + msg); convertReport.Error = msg; } convertFile.ConvertReports.Add(convertReport); } // Done. The convertFile object contains the list of converted reports. LogLine(fileName + " done."); return(convertFile); }
private bool DoImport(string criName, bool useNewDomain) { string reportsFileName = Path.GetTempFileName(); string messagesFileName = Path.GetTempFileName(); try { AppDomain domain; if (useNewDomain) { var info = new AppDomainSetup(); domain = AppDomain.CreateDomain(criName, null, info); domain.DoCallBack(LoadThisAssembly); } else { domain = AppDomain.CurrentDomain; } var filter = domain.CreateInstanceAndUnwrap(criName, CrystalFilterType); var method = filter.GetType() .GetMethod("Import", new[] { typeof(string), typeof(string), typeof(string) }); var errorCode = (int)method.Invoke(filter, new object[] { _crystalFileName, reportsFileName, messagesFileName }); if (errorCode == CrystalImportErrorCodes.RASNotAvailable || errorCode == CrystalImportErrorCodes.CrystalNotInstalled) { MessageForm.Error(Strings.CrystalFilter.ErrNoCrystalWithRAS); return(false); } if (!File.Exists(reportsFileName) || new FileInfo(reportsFileName).Length == 0) { // file with reports does not exist, or it is empty return(false); } // load reports try { var doc = new XmlDocument(); doc.Load(reportsFileName); string[] reportNames = C1FlexReport.GetReportList(doc); if (reportNames == null) { return(false); } foreach (string name in reportNames) { try { var report = new C1FlexReport(); report.Load(doc, name); _rptList.Add(report); if (Loading != null) { Loading(this, EventArgs.Empty); } } catch { } } } catch (Exception ex) { // some internal error occurs show error message and exit ShowInternalError(ex); return(false); } // load messages if (errorCode != CrystalImportErrorCodes.ErrorSavingMessages && File.Exists(messagesFileName) && new FileInfo(reportsFileName).Length > 0) { try { _messages.Load(messagesFileName); } catch { } } // looks like we have some reports now return(true); } finally { // delete temporary files try { if (File.Exists(reportsFileName)) { File.Delete(reportsFileName); } if (File.Exists(messagesFileName)) { File.Delete(messagesFileName); } } catch { } } }
public CommonReports() { InitializeComponent(); C1Zoom.Target = null; // put C1TopicBur in the C1FlexViewer control tbReports.Parent = null; splitter1.Parent = null; var viewerControls = c1FlexViewer1.Controls; var c1 = viewerControls[0]; var c2 = viewerControls[1]; var c3 = viewerControls[2]; viewerControls.Clear(); viewerControls.Add(c1); viewerControls.Add(splitter1); viewerControls.Add(tbReports); viewerControls.Add(c2); viewerControls.Add(c3); // prepare the list of reports doc = new XmlDocument(); doc.PreserveWhitespace = true; doc.LoadXml(ControlExplorer.Properties.Resources.FlexCommonTasks); // get the list of reports in the file string[] reports = C1FlexReport.GetReportList(doc); // // go over reports and get category from C1FlexReport.ReportInfo.Keywords using (C1FlexReport fr = new C1FlexReport()) { foreach (string reportName in reports) { fr.Load(doc, reportName); string keywords = fr.ReportInfo.Keywords; string[] ss = keywords.Split(new string[] { "\r\n" }, StringSplitOptions.None); for (int i = 0; i < ss.Length; i++) { List <string> reps; if (!categories.TryGetValue(ss[i], out reps)) { reps = new List <string>(); categories.Add(ss[i], reps); } reps.Add(reportName); } } // now categories dictionary contains list of categories and list of the reports in the each category // build content of the C1TopicBar foreach (KeyValuePair <string, List <string> > kvp in categories) { C1TopicPage tp = new C1TopicPage(kvp.Key); tp.ImageIndex = 0; tp.ImageList = imageList1; foreach (string s in kvp.Value) { C1TopicLink tl = new C1TopicLink(s); tp.Links.Add(tl); } tbReports.Pages.Add(tp); } } // add list of the reports to the ribbon var ribbon = c1FlexViewer1.Ribbon; tbMoreReports = new RibbonToggleButton(); tbMoreReports.Pressed = true; tbMoreReports.SmallImage = ControlExplorer.Properties.Resources.MoreReports; tbMoreReports.Text = "Reports panel"; tbMoreReports.PressedChanged += MoreReports_PressedChanged; ribbon.QatItemsHolder.Insert(0, tbMoreReports); ribbon.Qat.Items.Insert(0, tbMoreReports); ribbon.Qat.MenuItems.Insert(0, tbMoreReports); comboReports = new RibbonComboBox(); comboReports.GripHandleVisible = true; comboReports.TextAreaWidth = 170; comboReports.MaxDropDownItems = 12; comboReports.DropDownStyle = RibbonComboBoxStyle.DropDownList; comboReports.SelectedIndexChanged += comboReports_SelectedIndexChanged; var coll = comboReports.Items; foreach (string rn in reports) { coll.Add(new RibbonButton(rn)); } ribbon.QatItemsHolder.Insert(0, comboReports); ribbon.Qat.ItemLinks.Insert(0, comboReports); var selReportLabel = new C1.Win.Ribbon.RibbonButton(); ribbon.QatItemsHolder.Insert(0, selReportLabel); ribbon.Qat.ItemLinks.Insert(0, selReportLabel); selReportLabel.Text = "Select Report:"; selReportLabel.Click += selReportLabel_Click; report = new C1FlexReport(); }