ReportUtils.cs 30 KB

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