ReportUtils.cs 30 KB

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