ReportUtils.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. //using Ghostscript.NET;
  2. //using Ghostscript.NET.Processor;
  3. using System.Data;
  4. using System.Drawing.Printing;
  5. using System.IO;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Forms.Integration;
  9. using FastReport;
  10. using FastReport.Data;
  11. using FastReport.Design;
  12. using FastReport.Design.StandardDesigner;
  13. using FastReport.Export.Pdf;
  14. using FastReport.Utils;
  15. using InABox.Clients;
  16. using InABox.Core;
  17. using InABox.Reports.Common;
  18. using InABox.Scripting;
  19. using InABox.WPF;
  20. using MessageBox = System.Windows.Forms.MessageBox;
  21. using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
  22. using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
  23. using XmlDocument = System.Xml.XmlDocument;
  24. namespace InABox.Reports
  25. {
  26. public enum ReportExportType
  27. {
  28. PDF,
  29. HTML,
  30. RTF,
  31. Excel,
  32. Text,
  33. Image
  34. }
  35. public delegate void ReportExportDefinitionClicked();
  36. public class ReportExportDefinition
  37. {
  38. public ReportExportDefinition(string caption, Bitmap image, ReportExportType type, Action<DataModel, byte[]> action)
  39. {
  40. Caption = caption;
  41. Image = image;
  42. Type = type;
  43. Action = action;
  44. }
  45. public ReportExportDefinition(string caption, ContentControl control, ReportExportType type, Action<DataModel, byte[]> action)
  46. {
  47. Caption = caption;
  48. Type = type;
  49. Action = action;
  50. Control = control;
  51. }
  52. public event ReportExportDefinitionClicked OnReportDefinitionClicked;
  53. public string Caption { get; }
  54. public Bitmap Image { get; }
  55. public ContentControl Control { get; }
  56. public ReportExportType Type { get; }
  57. public Action<DataModel, byte[]> Action { get; }
  58. }
  59. [LibraryInitializer]
  60. public static class ReportUtils
  61. {
  62. public static List<ReportExportDefinition> ExportDefinitions { get; } = new();
  63. public static void RegisterClasses()
  64. {
  65. CoreUtils.RegisterClasses(typeof(ReportTemplate).Assembly, typeof(ReportUtils).Assembly);
  66. foreach (string printer in PrinterSettings.InstalledPrinters)
  67. ReportPrinters.Register(printer);
  68. RegisteredObjects.Add(typeof(MultiImageObject), "ReportPage", Properties.Resources.multi_image, "Multi-Image");
  69. RegisteredObjects.Add(typeof(MultiSignatureObject), "ReportPage", Properties.Resources.signature, "Multi-Signature");
  70. }
  71. public static void PreviewReport(ReportTemplate template, DataModel data, bool printandclose = false, bool allowdesigner = false)
  72. {
  73. var isrdl = template != null && template.IsRDL;
  74. if (isrdl)
  75. {
  76. MessageBox.Show("RDL Reports are no longer supported!");
  77. }
  78. else
  79. {
  80. PreviewWindow window = new(template, data)
  81. {
  82. AllowDesign = allowdesigner,
  83. Title = string.Format("Report Preview - {0}", template.Name),
  84. Height = 800,
  85. Width = 1200,
  86. WindowState = WindowState.Maximized,
  87. };
  88. window.Show();
  89. }
  90. }
  91. public static Report SetupReport(ReportTemplate template, DataModel data, bool repopulate)
  92. {
  93. var templaterdl = template != null ? string.IsNullOrWhiteSpace(template.RDL) ? "" : template.RDL : "";
  94. var tables = new List<string>();
  95. if (!string.IsNullOrWhiteSpace(templaterdl))
  96. {
  97. var xml = new XmlDocument();
  98. xml.LoadString(templaterdl);
  99. var datasources = xml.GetElementsByTagName("TableDataSource");
  100. for (var i = 0; i < datasources.Count; i++)
  101. {
  102. var datasource = datasources[i];
  103. tables.Add(datasource.Attributes.GetNamedItem("Name").Value);
  104. }
  105. }
  106. else
  107. {
  108. foreach(var table in data.DefaultTables)
  109. {
  110. tables.Add(table.TableName);
  111. }
  112. }
  113. var report = new Report();
  114. report.LoadFromString(templaterdl);
  115. report.FileName = template.Name;
  116. foreach(var tableName in data.TableNames)
  117. {
  118. var modelTable = data.GetDataModelTable(tableName);
  119. var dataSource = report.GetDataSource(tableName);
  120. if (dataSource != null)
  121. {
  122. var columnNames = CoreUtils.GetColumnNames(modelTable.Type, x => true);
  123. foreach (var column in dataSource.Columns)
  124. {
  125. if(column is FastReport.Data.Column col && !col.Enabled)
  126. {
  127. //columns.Add(col.Name.Replace('_','.'));
  128. columnNames.Remove(col.Name.Replace('_', '.'));
  129. }
  130. /*if (column is FastReport.Data.Column col && col.DataType != null && col.DataType.IsAssignableTo(typeof(IEnumerable<byte[]>)))
  131. {
  132. col.BindableControl = ColumnBindableControl.Custom;
  133. col.CustomBindableControl = "MultiImageObject";
  134. }*/
  135. }
  136. var columns = Columns.Create(modelTable.Type);
  137. foreach(var column in columnNames)
  138. {
  139. columns.Add(column);
  140. }
  141. modelTable.Columns = columns;
  142. }
  143. }
  144. var script = new ScriptDocument(template.Script);
  145. var ScriptOK = false;
  146. if (!string.IsNullOrWhiteSpace(template.Script))
  147. if (script.Compile())
  148. {
  149. script.SetValue("Model", data);
  150. ScriptOK = script.Execute("Report", "Init");
  151. }
  152. if (repopulate)
  153. data.LoadModel(tables);
  154. if (ScriptOK)
  155. {
  156. script.SetValue("RequireTables", tables);
  157. script.Execute("Report", "Populate");
  158. }
  159. var ds = data.AsDataSet();
  160. report.RegisterData(ds);
  161. foreach (var tableName in data.TableNames)
  162. {
  163. var columns = data.GetColumns(tableName)?.AsDictionary();
  164. var dataSource = report.GetDataSource(tableName);
  165. if(dataSource != null)
  166. {
  167. foreach (var column in dataSource.Columns)
  168. {
  169. if (column is FastReport.Data.Column col)
  170. {
  171. if (col.DataType != null && col.DataType.IsAssignableTo(typeof(IEnumerable<byte[]>)))
  172. {
  173. col.BindableControl = ColumnBindableControl.Custom;
  174. col.CustomBindableControl = "MultiImageObject";
  175. }
  176. col.Enabled = columns is null ? true : columns.ContainsKey(col.Name.Replace('_', '.'));
  177. }
  178. }
  179. }
  180. }
  181. if (string.IsNullOrWhiteSpace(templaterdl))
  182. {
  183. foreach (var table in data.DefaultTables)
  184. {
  185. var dataSource = report.GetDataSource(table.TableName);
  186. dataSource.Enabled = true;
  187. }
  188. foreach (Relation relation in report.Dictionary.Relations)
  189. if (data.DefaultTables.Any(x => x.TableName.Equals(relation.ParentDataSource.Alias)) &&
  190. data.DefaultTables.Any(x => x.TableName.Equals(relation.ChildDataSource.Alias)))
  191. relation.Enabled = true;
  192. }
  193. return report;
  194. }
  195. public static void DesignReport(ReportTemplate template, DataModel data, bool populate = false)
  196. {
  197. var isrdl = template != null && template.IsRDL;
  198. var templaterdl = template != null ? string.IsNullOrWhiteSpace(template.RDL) ? "" : template.RDL : "";
  199. if (isrdl)
  200. MessageBox.Show("RDL Reports are not supported!");
  201. else
  202. {
  203. PreviewWindow window = new(template, data)
  204. {
  205. AllowDesign = true,
  206. Title = string.Format("Report Designer - {0}", template.Name),
  207. Height = 800,
  208. Width = 1200,
  209. WindowState = WindowState.Maximized,
  210. IsPreview = false,
  211. ShouldPopulate = populate
  212. };
  213. window.Show();
  214. }
  215. }
  216. public static byte[] ReportToPDF(ReportTemplate template, DataModel data, bool repopulate = true)
  217. {
  218. byte[] result = null;
  219. if (template.IsRDL)
  220. MessageBox.Show("RDL Reports are not supported!");
  221. // using (var pdf = new MemoryStream())
  222. // {
  223. // using (var ms = ReportUtils.SetupReportToStream(template.RDL, data.AsDictionary))
  224. // {
  225. // using (ReportWriter reportWriter = new ReportWriter(ms))
  226. // {
  227. // reportWriter.ReportProcessingMode = Syncfusion.ReportWriter.ProcessingMode.Local;
  228. // reportWriter.Save(pdf, WriterFormat.PDF);
  229. //
  230. // //String filename = Path.Combine(GetPath(), "report.pdf");
  231. // //reportWriter.Save(filename, WriterFormat.PDF);
  232. // //PdfLoadedDocument rpt = new PdfLoadedDocument(filename);
  233. //
  234. // PdfLoadedDocument rpt = new PdfLoadedDocument(pdf);
  235. // PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
  236. // PdfDocument.Merge(doc, rpt);
  237. // var msFinal = new MemoryStream();
  238. // doc.Save(msFinal);
  239. // result = msFinal.GetBuffer();
  240. // }
  241. // }
  242. // //result = GhostScriptIt(pdf.GetBuffer());
  243. // //result = pdf.GetBuffer();
  244. // }
  245. else
  246. using (var report = SetupReport(template, data, repopulate))
  247. {
  248. report.Prepare();
  249. var ms = new MemoryStream();
  250. report.Export(new PDFExport(), ms);
  251. result = ms.GetBuffer();
  252. }
  253. return result;
  254. }
  255. public static IEnumerable<ReportTemplate> LoadReports(string sectionName, DataModel model)
  256. {
  257. return new Client<ReportTemplate>().Query(
  258. new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
  259. .And(x => x.Section).IsEqualTo(sectionName),
  260. null,
  261. new SortOrder<ReportTemplate>(x => x.Name)).Rows.Select(x => x.ToObject<ReportTemplate>());
  262. }
  263. private static void PopulateMenu(ItemsControl menu, string sectionName, DataModel model, bool allowdesign, bool populate = false)
  264. {
  265. var reports = new Client<ReportTemplate>().Query(
  266. new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
  267. .And(x => x.Section).IsEqualTo(sectionName),
  268. null,
  269. new SortOrder<ReportTemplate>(x => x.Name)
  270. );
  271. foreach (var row in reports.Rows)
  272. {
  273. var print = new MenuItem();
  274. print.Header = row.Get<ReportTemplate, string>(x => x.Name);
  275. print.Tag = row.ToObject<ReportTemplate>();
  276. print.Click += (sender, args) =>
  277. {
  278. var template = (sender as MenuItem)!.Tag as ReportTemplate;
  279. if (template != null)
  280. PreviewReport(template, model, false, allowdesign);
  281. };
  282. menu.Items.Add(print);
  283. }
  284. if (allowdesign)
  285. {
  286. if (reports.Rows.Any())
  287. menu.Items.Add(new Separator());
  288. var manage = new MenuItem();
  289. manage.Header = "Manage Reports";
  290. manage.Click += (sender, args) =>
  291. {
  292. var manager = new ReportManager()
  293. {
  294. DataModel = model,
  295. Section = sectionName,
  296. Populate = populate
  297. };
  298. manager.ShowDialog();
  299. };
  300. menu.Items.Add(manage);
  301. }
  302. }
  303. public static void PopulateMenu(MenuItem menu, string sectionName, DataModel model, bool allowdesign, bool populate = false) =>
  304. PopulateMenu(menu as ItemsControl, sectionName, model, allowdesign, populate);
  305. public static void PopulateMenu(ContextMenu menu, string sectionName, DataModel model, bool allowdesign, bool populate = false) =>
  306. PopulateMenu(menu as ItemsControl, sectionName, model, allowdesign, populate);
  307. public static void PrintMenu(FrameworkElement? element, string sectionName, DataModel model, bool allowdesign, bool populate = false)
  308. {
  309. var menu = new ContextMenu();
  310. PopulateMenu(menu, sectionName, model, allowdesign, populate);
  311. if (menu.Items.Count > 0)
  312. {
  313. menu.PlacementTarget = element;
  314. menu.IsOpen = true;
  315. }
  316. }
  317. public static void PrintMenu<TType>(FrameworkElement? element, string sectionName, DataModel<TType> model, bool allowdesign, bool populate = false)
  318. where TType : Entity, IRemotable, IPersistent, new()
  319. {
  320. PrintMenu(element, sectionName, model, allowdesign, populate);
  321. }
  322. #region Old RDL Stuff (Deprecated)
  323. // private static ReportDefinition SetupReportDefinition(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  324. // {
  325. // ReportDefinition report = null;
  326. // if (String.IsNullOrWhiteSpace(rdl))
  327. // report = CreateReport();
  328. // else
  329. // report = DeserialiseReport(rdl);
  330. //
  331. // if (dataenvironment != null)
  332. // SetupReportData(report, dataenvironment);
  333. // return report;
  334. // }
  335. // public static String SetupReport(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  336. // {
  337. // var defn = SetupReportDefinition(rdl, dataenvironment);
  338. // return SerialiseReport(defn);
  339. // }
  340. //
  341. // public static MemoryStream SetupReportToStream(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  342. // {
  343. // var defn = SetupReportDefinition(rdl, dataenvironment);
  344. // return SerialiseReportToStream(defn);
  345. // }
  346. // public static String CleanupReport(String rdl)
  347. // {
  348. // ReportDefinition report = null;
  349. // if (String.IsNullOrWhiteSpace(rdl))
  350. // report = CreateReport();
  351. // else
  352. // report = DeserialiseReport(rdl);
  353. //
  354. // CleanupReportData(report);
  355. //
  356. // return SerialiseReport(report);
  357. //
  358. // }
  359. // private static ReportDefinition CreateReport()
  360. // {
  361. // ReportDefinition rd = new ReportDefinition();
  362. // rd.DataSources = new DataSources();
  363. // rd.DataSets = new DataSets();
  364. //
  365. // rd.ReportSections = new ReportSections();
  366. // rd.ReportSections.Add(
  367. // new ReportSection()
  368. // {
  369. // Width = new Syncfusion.RDL.DOM.Size("7.5in"),
  370. // Body = new Body()
  371. // {
  372. // Style = new Syncfusion.RDL.DOM.Style() { BackgroundColor = "White", Border = new Syncfusion.RDL.DOM.Border() },
  373. // Height = new Syncfusion.RDL.DOM.Size("10in"),
  374. //
  375. // },
  376. // Page = new Syncfusion.RDL.DOM.Page()
  377. // {
  378. // PageHeight = new Syncfusion.RDL.DOM.Size("11in"),
  379. // PageWidth = new Syncfusion.RDL.DOM.Size("8.5in"),
  380. // Style = new Syncfusion.RDL.DOM.Style() { BackgroundColor = "White", Border = new Syncfusion.RDL.DOM.Border() },
  381. // }
  382. // }
  383. // );
  384. // rd.EmbeddedImages = new EmbeddedImages();
  385. //
  386. // rd.RDLType = RDLType.RDL2010;
  387. // rd.CodeModules = new CodeModules();
  388. // rd.CodeModules.Add(new CodeModule() { Value = "System.Drawing, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" });
  389. // rd.CodeModules.Add(new CodeModule() { Value = "Syncfusion.Pdf.Base, Version = 13.3350.0.7, Culture = neutral, PublicKeyToken = 3d67ed1f87d44c89" });
  390. // rd.CodeModules.Add(new CodeModule() { Value = "Syncfusion.Linq.Base, Version = 13.3350.0.7, Culture = neutral, PublicKeyToken = 3d67ed1f87d44c89" });
  391. //
  392. // rd.Classes = new Classes();
  393. // rd.Classes.Add(new Class() { ClassName = "Syncfusion.Pdf.Barcode.PDFCode39Barcode", InstanceName = "Code39" });
  394. // rd.Classes.Add(new Class() { ClassName = "Syncfusion.Pdf.Barcode.PdfQRBarcode", InstanceName = "QRCode" });
  395. //
  396. // rd.Code = @"
  397. // Public Function Code39BarCode(Text As String) As String
  398. // Dim _msg as String
  399. // try
  400. // Code39.BarHeight = 100
  401. // Code39.Text = Text
  402. // Code39.EnableCheckDigit = True
  403. // Code39.EncodeStartStopSymbols = True
  404. // Code39.ShowCheckDigit = False
  405. // Code39.TextDisplayLocation = 0
  406. // Dim _img As System.Drawing.Image = Code39.ToImage()
  407. // Dim ms As New System.IO.MemoryStream()
  408. // _img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
  409. // Dim _bytes = ms.ToArray()
  410. // Return System.Convert.ToBase64String(_bytes, 0, _bytes.Length)
  411. // Catch ex As Exception
  412. // _msg = ex.toString()
  413. // End Try
  414. // return Nothing
  415. // End Function
  416. //
  417. // Public Function QRBarCode(Text As String) As String
  418. // Dim _msg as String
  419. // try
  420. // QRCode.Text = Text
  421. // QRCode.XDimension = 4
  422. // Dim _img As System.Drawing.Image = QRCode.ToImage()
  423. // Dim ms As New System.IO.MemoryStream()
  424. // _img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
  425. // Dim _bytes = ms.ToArray()
  426. // Return System.Convert.ToBase64String(_bytes, 0, _bytes.Length)
  427. // Catch ex As Exception
  428. // _msg = ex.toString()
  429. // End Try
  430. // return Nothing
  431. // End Function
  432. //
  433. // ";
  434. // return rd;
  435. //
  436. // //MemoryStream memoryStream = new MemoryStream();
  437. // //TextWriter ws2 = new StreamWriter(memoryStream);
  438. // //xs2.Serialize(ws2, rd, serialize);
  439. // //memoryStream.Position = 0;
  440. // ////To save to a file.
  441. // //StringWriter ws3 = new StringWriter
  442. // //TextWriter ws3 = new StreamWriter(_tempfile);
  443. // //xs2.Serialize(ws3, rd, serialize);
  444. // //ws2.Close();
  445. // //ws3.Close();
  446. // //memoryStream.Close();
  447. //
  448. // }
  449. private static string DataTableToXML(Type type, CoreTable table)
  450. {
  451. var doc = new XmlDocument();
  452. var root = doc.CreateElement(string.Empty, type.Name.ToLower() + "s", string.Empty);
  453. doc.AppendChild(root);
  454. //var properties = CoreUtils.PropertyList(type, x => true, true);
  455. if (table != null)
  456. {
  457. if (table.Rows.Any())
  458. {
  459. foreach (var datarow in table.Rows)
  460. {
  461. var row = doc.CreateElement(string.Empty, type.Name.ToLower(), string.Empty);
  462. foreach (var column in table.Columns)
  463. {
  464. var field = doc.CreateElement(string.Empty, column.ColumnName.Replace('.', '_'), string.Empty);
  465. var oVal = datarow[column.ColumnName];
  466. var value = doc.CreateTextNode(oVal != null ? oVal.ToString() : "");
  467. field.AppendChild(value);
  468. row.AppendChild(field);
  469. }
  470. root.AppendChild(row);
  471. }
  472. }
  473. else
  474. {
  475. var row = doc.CreateElement(string.Empty, type.Name.ToLower(), string.Empty);
  476. foreach (var column in table.Columns)
  477. {
  478. var field = doc.CreateElement(string.Empty, column.ColumnName.Replace('.', '_'), string.Empty);
  479. var value = doc.CreateTextNode("");
  480. field.AppendChild(value);
  481. row.AppendChild(field);
  482. }
  483. root.AppendChild(row);
  484. }
  485. }
  486. var xmlString = "";
  487. using (var wr = new StringWriter())
  488. {
  489. doc.Save(wr);
  490. xmlString = wr.ToString();
  491. }
  492. return xmlString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n", "");
  493. }
  494. public static DataSet CreateReportDataSource(Dictionary<Type, CoreTable> dataenvironment)
  495. {
  496. var ds = new DataSet();
  497. foreach (var key in dataenvironment.Keys)
  498. {
  499. var table = dataenvironment[key];
  500. var dt = new DataTable(key.EntityName().Split('.').Last());
  501. foreach (var column in table.Columns)
  502. dt.Columns.Add(column.ColumnName);
  503. foreach (var row in table.Rows)
  504. dt.Rows.Add(row.Values.ToArray());
  505. ds.Tables.Add(dt);
  506. }
  507. return ds;
  508. }
  509. // private static void SetupReportData(ReportDefinition report, Dictionary<System.Type,CoreTable> dataenvironment)
  510. // {
  511. //
  512. // report.DataSets.Clear();
  513. // report.DataSources.Clear();
  514. // foreach (System.Type type in dataenvironment.Keys)
  515. // {
  516. // String _tempfile = Path.GetTempFileName();
  517. // String xml = DataTableToXML(type, dataenvironment[type]);
  518. // File.WriteAllText(_tempfile, xml);
  519. // // Create DataSource(s)
  520. // DataSource datasource = new DataSource()
  521. // {
  522. // Name = type.Name,
  523. // ConnectionProperties = new ConnectionProperties()
  524. // {
  525. // DataProvider = "XML",
  526. // IntegratedSecurity = true,
  527. // ConnectString = _tempfile
  528. // },
  529. // SecurityType = SecurityType.None,
  530. // };
  531. // report.DataSources.Add(datasource);
  532. //
  533. // Syncfusion.RDL.DOM.DataSet dataset = new Syncfusion.RDL.DOM.DataSet() { Name = type.Name };
  534. // dataset.Fields = new Fields();
  535. //
  536. // CoreTable table = dataenvironment[type];
  537. // foreach (var column in table.Columns)
  538. // {
  539. // dataset.Fields.Add(
  540. // new Field()
  541. // {
  542. // Name = column.ColumnName.Replace('.', '_'),
  543. // DataField = column.ColumnName.Replace('.', '_'),
  544. // TypeName = column.DataType.Name
  545. // }
  546. // );
  547. // }
  548. //
  549. // //var properties = CoreUtils.PropertyList(type, x => true, true);
  550. //
  551. // //// Create DataSet(s)
  552. // //foreach (String key in properties.Keys)
  553. // //{
  554. // // dataset.Fields.Add(
  555. // // new Field()
  556. // // {
  557. // // Name = key.Replace('.', '_'),
  558. // // DataField = key.Replace('.', '_'),
  559. // // TypeName = properties[key].Name
  560. // // }
  561. // // );
  562. // //}
  563. // dataset.Query = new Query()
  564. // {
  565. // DataSourceName = type.Name,
  566. // CommandType = Syncfusion.RDL.DOM.CommandType.Text,
  567. // CommandText = String.Format("{0}s/{0}", type.Name.ToLower())
  568. // };
  569. // report.DataSets.Add(dataset);
  570. // }
  571. // }
  572. //
  573. // private static void CleanupReportData(ReportDefinition report)
  574. // {
  575. // foreach (var ds in report.DataSources)
  576. // {
  577. // String _tempfile = ds.ConnectionProperties.ConnectString;
  578. // if (File.Exists(_tempfile))
  579. // File.Delete(_tempfile);
  580. // ds.ConnectionProperties.ConnectString = "";
  581. // }
  582. // report.DataSources[0].ConnectionProperties.ConnectString = "";
  583. // }
  584. //
  585. // private static ReportDefinition DeserialiseReport(String rdl)
  586. // {
  587. // String data = rdl;
  588. // try
  589. // {
  590. // byte[] debase64 = Convert.FromBase64String(rdl);
  591. // data = Encoding.UTF8.GetString(debase64);
  592. // }
  593. // catch (Exception e)
  594. // {
  595. // Logger.Send(LogType.Error, "", String.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  596. // }
  597. // ReportDefinition report = null;
  598. // XmlSerializer xs = new XmlSerializer(typeof(ReportDefinition), "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition");
  599. // using (StringReader stringreader = new StringReader(data)) // root.ToString()))
  600. // {
  601. // report = (ReportDefinition)xs.Deserialize(stringreader);
  602. // }
  603. // return report;
  604. // }
  605. //
  606. // [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
  607. // private static String SerialiseReport(ReportDefinition report)
  608. // {
  609. // var stream = SerialiseReportToStream(report);
  610. // return Encoding.UTF8.GetString(stream.ToArray());
  611. //
  612. // }
  613. //
  614. // [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
  615. // private static MemoryStream SerialiseReportToStream(ReportDefinition report)
  616. // {
  617. //
  618. // string nameSpace = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
  619. //
  620. // if (report.RDLType == RDLType.RDL2010)
  621. // nameSpace = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
  622. //
  623. // XmlSerializerNamespaces serialize = new XmlSerializerNamespaces();
  624. // serialize.Add("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
  625. // XmlSerializer xs2 = new XmlSerializer(typeof(Syncfusion.RDL.DOM.ReportDefinition), nameSpace);
  626. // MemoryStream memoryStream = new MemoryStream();
  627. // TextWriter ws2 = new StreamWriter(memoryStream);
  628. // xs2.Serialize(ws2, report, serialize);
  629. // memoryStream.Position = 0;
  630. // return memoryStream;
  631. // //return Encoding.UTF8.GetString(memoryStream.ToArray());
  632. //
  633. // }
  634. // private static byte[] GhostScriptIt(byte[] pdf)
  635. // {
  636. // String input = Path.GetTempFileName();
  637. // File.WriteAllBytes(input, pdf);
  638. // byte[] result = new byte[] { };
  639. // GhostscriptVersionInfo gv = new GhostscriptVersionInfo(
  640. // new Version(0, 0, 0),
  641. // "gsdll32.dll",
  642. // string.Empty,
  643. // GhostscriptLicense.GPL
  644. // );
  645. // GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
  646. // // pipe handle format: %handle%hexvalue
  647. // string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
  648. // using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true))
  649. // {
  650. // List<string> switches = new List<string>();
  651. // switches.Add("-empty");
  652. // switches.Add("-dQUIET");
  653. // switches.Add("-dSAFER");
  654. // switches.Add("-dBATCH");
  655. // switches.Add("-dNOPAUSE");
  656. // switches.Add("-dNOPROMPT");
  657. // switches.Add("-dCompatibilityLevel=1.4");
  658. // switches.Add("-sDEVICE=pdfwrite");
  659. // switches.Add("-o" + outputPipeHandle);
  660. // switches.Add("-q");
  661. // switches.Add("-f");
  662. // switches.Add(input);
  663. // try
  664. // {
  665. // processor.StartProcessing(switches.ToArray(), null);
  666. // result = gsPipedOutput.Data;
  667. // }
  668. // catch (Exception ex)
  669. // {
  670. // Console.WriteLine(ex.Message);
  671. // }
  672. // finally
  673. // {
  674. // gsPipedOutput.Dispose();
  675. // gsPipedOutput = null;
  676. // }
  677. // }
  678. // File.Delete(input);
  679. // return result;
  680. // }
  681. #endregion
  682. }
  683. }