ReportUtils.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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 Filter<ReportTemplate> GetReportFilter(string sectionName, DataModel model)
  258. {
  259. return new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
  260. .And(x => x.Section).IsEqualTo(sectionName)
  261. .And(x => x.Visible).IsEqualTo(true);
  262. }
  263. public static IEnumerable<ReportTemplate> LoadReports(string sectionName, DataModel model, Columns<ReportTemplate>? columns = null)
  264. {
  265. return new Client<ReportTemplate>().Query(
  266. GetReportFilter(sectionName, model),
  267. columns,
  268. new SortOrder<ReportTemplate>(x => x.Name))
  269. .ToObjects<ReportTemplate>();
  270. }
  271. private static void PopulateMenu(ItemsControl menu, string sectionName, DataModel model, bool allowdesign, bool populate = false)
  272. {
  273. var reports = LoadReports(sectionName, model);
  274. foreach (var report in reports)
  275. {
  276. var print = new MenuItem
  277. {
  278. Header = report.Name,
  279. Tag = report
  280. };
  281. print.Click += (sender, args) =>
  282. {
  283. PreviewReport(report, model, false, allowdesign);
  284. };
  285. menu.Items.Add(print);
  286. }
  287. if (allowdesign)
  288. {
  289. if (menu.Items.Count > 0 && menu.Items[^1] is not Separator)
  290. {
  291. menu.Items.Add(new Separator());
  292. }
  293. var manage = new MenuItem
  294. {
  295. Header = "Manage Reports"
  296. };
  297. manage.Click += (sender, args) =>
  298. {
  299. var manager = new ReportManager()
  300. {
  301. DataModel = model,
  302. Section = sectionName,
  303. Populate = populate
  304. };
  305. manager.ShowDialog();
  306. };
  307. menu.Items.Add(manage);
  308. }
  309. }
  310. public static void PopulateMenu(MenuItem menu, string sectionName, DataModel model, bool allowdesign, bool populate = false) =>
  311. PopulateMenu(menu as ItemsControl, sectionName, model, allowdesign, populate);
  312. public static void PopulateMenu(ContextMenu menu, string sectionName, DataModel model, bool allowdesign, bool populate = false) =>
  313. PopulateMenu(menu as ItemsControl, sectionName, model, allowdesign, populate);
  314. public static void PrintMenu(FrameworkElement? element, string sectionName, DataModel model, bool allowdesign, bool populate = false)
  315. {
  316. var menu = new ContextMenu();
  317. PopulateMenu(menu, sectionName, model, allowdesign, populate);
  318. if (menu.Items.Count > 0)
  319. {
  320. menu.PlacementTarget = element;
  321. menu.IsOpen = true;
  322. }
  323. }
  324. public static void PrintMenu<TType>(FrameworkElement? element, string sectionName, DataModel<TType> model, bool allowdesign, bool populate = false)
  325. where TType : Entity, IRemotable, IPersistent, new()
  326. {
  327. PrintMenu(element, sectionName, model, allowdesign, populate);
  328. }
  329. #region Old RDL Stuff (Deprecated)
  330. // private static ReportDefinition SetupReportDefinition(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  331. // {
  332. // ReportDefinition report = null;
  333. // if (String.IsNullOrWhiteSpace(rdl))
  334. // report = CreateReport();
  335. // else
  336. // report = DeserialiseReport(rdl);
  337. //
  338. // if (dataenvironment != null)
  339. // SetupReportData(report, dataenvironment);
  340. // return report;
  341. // }
  342. // public static String SetupReport(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  343. // {
  344. // var defn = SetupReportDefinition(rdl, dataenvironment);
  345. // return SerialiseReport(defn);
  346. // }
  347. //
  348. // public static MemoryStream SetupReportToStream(String rdl, Dictionary<System.Type, CoreTable> dataenvironment = null)
  349. // {
  350. // var defn = SetupReportDefinition(rdl, dataenvironment);
  351. // return SerialiseReportToStream(defn);
  352. // }
  353. // public static String CleanupReport(String rdl)
  354. // {
  355. // ReportDefinition report = null;
  356. // if (String.IsNullOrWhiteSpace(rdl))
  357. // report = CreateReport();
  358. // else
  359. // report = DeserialiseReport(rdl);
  360. //
  361. // CleanupReportData(report);
  362. //
  363. // return SerialiseReport(report);
  364. //
  365. // }
  366. // private static ReportDefinition CreateReport()
  367. // {
  368. // ReportDefinition rd = new ReportDefinition();
  369. // rd.DataSources = new DataSources();
  370. // rd.DataSets = new DataSets();
  371. //
  372. // rd.ReportSections = new ReportSections();
  373. // rd.ReportSections.Add(
  374. // new ReportSection()
  375. // {
  376. // Width = new Syncfusion.RDL.DOM.Size("7.5in"),
  377. // Body = new Body()
  378. // {
  379. // Style = new Syncfusion.RDL.DOM.Style() { BackgroundColor = "White", Border = new Syncfusion.RDL.DOM.Border() },
  380. // Height = new Syncfusion.RDL.DOM.Size("10in"),
  381. //
  382. // },
  383. // Page = new Syncfusion.RDL.DOM.Page()
  384. // {
  385. // PageHeight = new Syncfusion.RDL.DOM.Size("11in"),
  386. // PageWidth = new Syncfusion.RDL.DOM.Size("8.5in"),
  387. // Style = new Syncfusion.RDL.DOM.Style() { BackgroundColor = "White", Border = new Syncfusion.RDL.DOM.Border() },
  388. // }
  389. // }
  390. // );
  391. // rd.EmbeddedImages = new EmbeddedImages();
  392. //
  393. // rd.RDLType = RDLType.RDL2010;
  394. // rd.CodeModules = new CodeModules();
  395. // rd.CodeModules.Add(new CodeModule() { Value = "System.Drawing, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" });
  396. // rd.CodeModules.Add(new CodeModule() { Value = "Syncfusion.Pdf.Base, Version = 13.3350.0.7, Culture = neutral, PublicKeyToken = 3d67ed1f87d44c89" });
  397. // rd.CodeModules.Add(new CodeModule() { Value = "Syncfusion.Linq.Base, Version = 13.3350.0.7, Culture = neutral, PublicKeyToken = 3d67ed1f87d44c89" });
  398. //
  399. // rd.Classes = new Classes();
  400. // rd.Classes.Add(new Class() { ClassName = "Syncfusion.Pdf.Barcode.PDFCode39Barcode", InstanceName = "Code39" });
  401. // rd.Classes.Add(new Class() { ClassName = "Syncfusion.Pdf.Barcode.PdfQRBarcode", InstanceName = "QRCode" });
  402. //
  403. // rd.Code = @"
  404. // Public Function Code39BarCode(Text As String) As String
  405. // Dim _msg as String
  406. // try
  407. // Code39.BarHeight = 100
  408. // Code39.Text = Text
  409. // Code39.EnableCheckDigit = True
  410. // Code39.EncodeStartStopSymbols = True
  411. // Code39.ShowCheckDigit = False
  412. // Code39.TextDisplayLocation = 0
  413. // Dim _img As System.Drawing.Image = Code39.ToImage()
  414. // Dim ms As New System.IO.MemoryStream()
  415. // _img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
  416. // Dim _bytes = ms.ToArray()
  417. // Return System.Convert.ToBase64String(_bytes, 0, _bytes.Length)
  418. // Catch ex As Exception
  419. // _msg = ex.toString()
  420. // End Try
  421. // return Nothing
  422. // End Function
  423. //
  424. // Public Function QRBarCode(Text As String) As String
  425. // Dim _msg as String
  426. // try
  427. // QRCode.Text = Text
  428. // QRCode.XDimension = 4
  429. // Dim _img As System.Drawing.Image = QRCode.ToImage()
  430. // Dim ms As New System.IO.MemoryStream()
  431. // _img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
  432. // Dim _bytes = ms.ToArray()
  433. // Return System.Convert.ToBase64String(_bytes, 0, _bytes.Length)
  434. // Catch ex As Exception
  435. // _msg = ex.toString()
  436. // End Try
  437. // return Nothing
  438. // End Function
  439. //
  440. // ";
  441. // return rd;
  442. //
  443. // //MemoryStream memoryStream = new MemoryStream();
  444. // //TextWriter ws2 = new StreamWriter(memoryStream);
  445. // //xs2.Serialize(ws2, rd, serialize);
  446. // //memoryStream.Position = 0;
  447. // ////To save to a file.
  448. // //StringWriter ws3 = new StringWriter
  449. // //TextWriter ws3 = new StreamWriter(_tempfile);
  450. // //xs2.Serialize(ws3, rd, serialize);
  451. // //ws2.Close();
  452. // //ws3.Close();
  453. // //memoryStream.Close();
  454. //
  455. // }
  456. private static string DataTableToXML(Type type, CoreTable table)
  457. {
  458. var doc = new XmlDocument();
  459. var root = doc.CreateElement("", type.Name.ToLower() + "s", "");
  460. doc.AppendChild(root);
  461. //var properties = CoreUtils.PropertyList(type, x => true, true);
  462. if (table != null)
  463. {
  464. if (table.Rows.Any())
  465. {
  466. foreach (var datarow in table.Rows)
  467. {
  468. var row = doc.CreateElement("", type.Name.ToLower(), "");
  469. foreach (var column in table.Columns)
  470. {
  471. var field = doc.CreateElement("", column.ColumnName.Replace('.', '_'), "");
  472. var oVal = datarow[column.ColumnName];
  473. var value = doc.CreateTextNode(oVal != null ? oVal.ToString() : "");
  474. field.AppendChild(value);
  475. row.AppendChild(field);
  476. }
  477. root.AppendChild(row);
  478. }
  479. }
  480. else
  481. {
  482. var row = doc.CreateElement("", type.Name.ToLower(), "");
  483. foreach (var column in table.Columns)
  484. {
  485. var field = doc.CreateElement("", column.ColumnName.Replace('.', '_'), "");
  486. var value = doc.CreateTextNode("");
  487. field.AppendChild(value);
  488. row.AppendChild(field);
  489. }
  490. root.AppendChild(row);
  491. }
  492. }
  493. var xmlString = "";
  494. using (var wr = new StringWriter())
  495. {
  496. doc.Save(wr);
  497. xmlString = wr.ToString();
  498. }
  499. return xmlString.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n", "");
  500. }
  501. public static DataSet CreateReportDataSource(Dictionary<Type, CoreTable> dataenvironment)
  502. {
  503. var ds = new DataSet();
  504. foreach (var key in dataenvironment.Keys)
  505. {
  506. var table = dataenvironment[key];
  507. var dt = new DataTable(key.EntityName().Split('.').Last());
  508. foreach (var column in table.Columns)
  509. dt.Columns.Add(column.ColumnName);
  510. foreach (var row in table.Rows)
  511. dt.Rows.Add(row.Values.ToArray());
  512. ds.Tables.Add(dt);
  513. }
  514. return ds;
  515. }
  516. // private static void SetupReportData(ReportDefinition report, Dictionary<System.Type,CoreTable> dataenvironment)
  517. // {
  518. //
  519. // report.DataSets.Clear();
  520. // report.DataSources.Clear();
  521. // foreach (System.Type type in dataenvironment.Keys)
  522. // {
  523. // String _tempfile = Path.GetTempFileName();
  524. // String xml = DataTableToXML(type, dataenvironment[type]);
  525. // File.WriteAllText(_tempfile, xml);
  526. // // Create DataSource(s)
  527. // DataSource datasource = new DataSource()
  528. // {
  529. // Name = type.Name,
  530. // ConnectionProperties = new ConnectionProperties()
  531. // {
  532. // DataProvider = "XML",
  533. // IntegratedSecurity = true,
  534. // ConnectString = _tempfile
  535. // },
  536. // SecurityType = SecurityType.None,
  537. // };
  538. // report.DataSources.Add(datasource);
  539. //
  540. // Syncfusion.RDL.DOM.DataSet dataset = new Syncfusion.RDL.DOM.DataSet() { Name = type.Name };
  541. // dataset.Fields = new Fields();
  542. //
  543. // CoreTable table = dataenvironment[type];
  544. // foreach (var column in table.Columns)
  545. // {
  546. // dataset.Fields.Add(
  547. // new Field()
  548. // {
  549. // Name = column.ColumnName.Replace('.', '_'),
  550. // DataField = column.ColumnName.Replace('.', '_'),
  551. // TypeName = column.DataType.Name
  552. // }
  553. // );
  554. // }
  555. //
  556. // //var properties = CoreUtils.PropertyList(type, x => true, true);
  557. //
  558. // //// Create DataSet(s)
  559. // //foreach (String key in properties.Keys)
  560. // //{
  561. // // dataset.Fields.Add(
  562. // // new Field()
  563. // // {
  564. // // Name = key.Replace('.', '_'),
  565. // // DataField = key.Replace('.', '_'),
  566. // // TypeName = properties[key].Name
  567. // // }
  568. // // );
  569. // //}
  570. // dataset.Query = new Query()
  571. // {
  572. // DataSourceName = type.Name,
  573. // CommandType = Syncfusion.RDL.DOM.CommandType.Text,
  574. // CommandText = String.Format("{0}s/{0}", type.Name.ToLower())
  575. // };
  576. // report.DataSets.Add(dataset);
  577. // }
  578. // }
  579. //
  580. // private static void CleanupReportData(ReportDefinition report)
  581. // {
  582. // foreach (var ds in report.DataSources)
  583. // {
  584. // String _tempfile = ds.ConnectionProperties.ConnectString;
  585. // if (File.Exists(_tempfile))
  586. // File.Delete(_tempfile);
  587. // ds.ConnectionProperties.ConnectString = "";
  588. // }
  589. // report.DataSources[0].ConnectionProperties.ConnectString = "";
  590. // }
  591. //
  592. // private static ReportDefinition DeserialiseReport(String rdl)
  593. // {
  594. // String data = rdl;
  595. // try
  596. // {
  597. // byte[] debase64 = Convert.FromBase64String(rdl);
  598. // data = Encoding.UTF8.GetString(debase64);
  599. // }
  600. // catch (Exception e)
  601. // {
  602. // Logger.Send(LogType.Error, "", String.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
  603. // }
  604. // ReportDefinition report = null;
  605. // XmlSerializer xs = new XmlSerializer(typeof(ReportDefinition), "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition");
  606. // using (StringReader stringreader = new StringReader(data)) // root.ToString()))
  607. // {
  608. // report = (ReportDefinition)xs.Deserialize(stringreader);
  609. // }
  610. // return report;
  611. // }
  612. //
  613. // [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
  614. // private static String SerialiseReport(ReportDefinition report)
  615. // {
  616. // var stream = SerialiseReportToStream(report);
  617. // return Encoding.UTF8.GetString(stream.ToArray());
  618. //
  619. // }
  620. //
  621. // [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")]
  622. // private static MemoryStream SerialiseReportToStream(ReportDefinition report)
  623. // {
  624. //
  625. // string nameSpace = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
  626. //
  627. // if (report.RDLType == RDLType.RDL2010)
  628. // nameSpace = "http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition";
  629. //
  630. // XmlSerializerNamespaces serialize = new XmlSerializerNamespaces();
  631. // serialize.Add("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
  632. // XmlSerializer xs2 = new XmlSerializer(typeof(Syncfusion.RDL.DOM.ReportDefinition), nameSpace);
  633. // MemoryStream memoryStream = new MemoryStream();
  634. // TextWriter ws2 = new StreamWriter(memoryStream);
  635. // xs2.Serialize(ws2, report, serialize);
  636. // memoryStream.Position = 0;
  637. // return memoryStream;
  638. // //return Encoding.UTF8.GetString(memoryStream.ToArray());
  639. //
  640. // }
  641. // private static byte[] GhostScriptIt(byte[] pdf)
  642. // {
  643. // String input = Path.GetTempFileName();
  644. // File.WriteAllBytes(input, pdf);
  645. // byte[] result = new byte[] { };
  646. // GhostscriptVersionInfo gv = new GhostscriptVersionInfo(
  647. // new Version(0, 0, 0),
  648. // "gsdll32.dll",
  649. // "",
  650. // GhostscriptLicense.GPL
  651. // );
  652. // GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
  653. // // pipe handle format: %handle%hexvalue
  654. // string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
  655. // using (GhostscriptProcessor processor = new GhostscriptProcessor(gv, true))
  656. // {
  657. // List<string> switches = new List<string>();
  658. // switches.Add("-empty");
  659. // switches.Add("-dQUIET");
  660. // switches.Add("-dSAFER");
  661. // switches.Add("-dBATCH");
  662. // switches.Add("-dNOPAUSE");
  663. // switches.Add("-dNOPROMPT");
  664. // switches.Add("-dCompatibilityLevel=1.4");
  665. // switches.Add("-sDEVICE=pdfwrite");
  666. // switches.Add("-o" + outputPipeHandle);
  667. // switches.Add("-q");
  668. // switches.Add("-f");
  669. // switches.Add(input);
  670. // try
  671. // {
  672. // processor.StartProcessing(switches.ToArray(), null);
  673. // result = gsPipedOutput.Data;
  674. // }
  675. // catch (Exception ex)
  676. // {
  677. // Console.WriteLine(ex.Message);
  678. // }
  679. // finally
  680. // {
  681. // gsPipedOutput.Dispose();
  682. // gsPipedOutput = null;
  683. // }
  684. // }
  685. // File.Delete(input);
  686. // return result;
  687. // }
  688. #endregion
  689. }
  690. }