ReportUtils.cs 30 KB

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