ReportUtils.cs 30 KB

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