ExportMenuSettings.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. using System;
  2. using System.Drawing;
  3. namespace FastReport.Web
  4. {
  5. public class ExportMenuSettings
  6. {
  7. /// <summary>
  8. /// Show Exports menu
  9. /// </summary>
  10. public bool Show { get; set; } = true;
  11. /// <summary>
  12. /// Used to set exports in toolbar.
  13. /// </summary>
  14. public Exports ExportTypes { get; set; } = Exports.Default;
  15. /// <summary>
  16. /// Used to change font family, style in export settings.
  17. /// </summary>
  18. public Font FontSettings { get; set; } = null;
  19. /// <summary>
  20. /// Used to change font color in export settings.
  21. /// </summary>
  22. public Color FontColor { get; set; } = Color.White;
  23. /// <summary>
  24. /// Used to change window, buttons color in export settings.
  25. /// </summary>
  26. public Color Color { get; set; } = Color.Maroon;
  27. /// <summary>
  28. /// Used to on/off export settings.
  29. /// </summary>
  30. public bool EnableSettings { get; set; } = false;
  31. /// <summary>
  32. /// If enabled, the container with the settings will be fixed on the screen and will be in the foreground.
  33. /// </summary>
  34. /// <remarks>
  35. /// Default value: false
  36. /// </remarks>
  37. public bool PinnedSettingsPosition { get; set; } = false;
  38. internal string UserFontSettingsStyle
  39. {
  40. get
  41. {
  42. if (FontSettings != null)
  43. {
  44. return FontSettings.Style + " ";
  45. }
  46. else
  47. return "";
  48. }
  49. }
  50. internal string FixedContainerPosition
  51. {
  52. get => PinnedSettingsPosition ? "position: fixed; top: 0; left: 0;" : "";
  53. }
  54. internal string FixedContainerTags
  55. {
  56. get => PinnedSettingsPosition ? "position : fixed; top: 40%; left: 40%; transform: translate(-50%, -50%);" : "";
  57. }
  58. internal string UserFontSettingsFamily
  59. {
  60. get
  61. {
  62. if (FontSettings != null)
  63. {
  64. return " " + FontSettings.OriginalFontName;
  65. }
  66. else
  67. return "Verdana,Arial";
  68. }
  69. }
  70. /// <summary>
  71. /// Get an instance of ExportMenuSettings with default exports
  72. /// <para>Default : Prepared, Pdf, Excel2007, Word2007, Text, Rtf, Xps, Ods, Odt, XmlExcel, Csv</para>
  73. /// </summary>
  74. public static ExportMenuSettings Default => new ExportMenuSettings
  75. {
  76. ExportTypes = Exports.Default
  77. };
  78. /// <summary>
  79. /// Get an instance of ExportMenuSettings with all exports
  80. /// </summary>
  81. public static ExportMenuSettings All => new ExportMenuSettings
  82. {
  83. ExportTypes = Exports.All
  84. };
  85. /// <summary>
  86. /// Switch a visibility of prepared report export in toolbar
  87. /// </summary>
  88. public bool ShowPreparedReport
  89. {
  90. get => GetExport(Exports.Prepared);
  91. set => SetExport(value, Exports.Prepared);
  92. }
  93. #if !OPENSOURCE
  94. /// <summary>
  95. /// Switches a visibility of PDF (Adobe Acrobat) export in toolbar.
  96. /// </summary>
  97. public bool ShowPdfExport
  98. {
  99. get => GetExport(Exports.Pdf);
  100. set => SetExport(value, Exports.Pdf);
  101. }
  102. /// <summary>
  103. /// Switches a visibility of Excel 2007 export in toolbar.
  104. /// </summary>
  105. public bool ShowExcel2007Export {
  106. get => GetExport(Exports.Excel2007);
  107. set => SetExport(value, Exports.Excel2007);
  108. }
  109. /// <summary>
  110. /// Switches a visibility of Word 2007 export in toolbar.
  111. /// </summary>
  112. public bool ShowWord2007Export {
  113. get => GetExport(Exports.Word2007);
  114. set => SetExport(value, Exports.Word2007);
  115. }
  116. /// <summary>
  117. /// Switches a visibility of PowerPoint 2007 export in toolbar.
  118. /// </summary>
  119. public bool ShowPowerPoint2007Export {
  120. get => GetExport(Exports.PowerPoint2007);
  121. set => SetExport(value, Exports.PowerPoint2007);
  122. }
  123. /// <summary>
  124. /// Switch a visibility of text (plain text) export in toolbar
  125. /// </summary>
  126. public bool ShowTextExport {
  127. get => GetExport(Exports.Text);
  128. set => SetExport(value, Exports.Text);
  129. }
  130. /// <summary>
  131. /// Switches a visibility of RTF export in toolbar.
  132. /// </summary>
  133. public bool ShowRtfExport {
  134. get => GetExport(Exports.Rtf);
  135. set => SetExport(value, Exports.Rtf);
  136. }
  137. /// <summary>
  138. /// Switches a visibility of XPS export in toolbar.
  139. /// </summary>
  140. public bool ShowXpsExport {
  141. get => GetExport(Exports.Xps);
  142. set => SetExport(value, Exports.Xps);
  143. }
  144. /// <summary>
  145. /// Switches a visibility of Open Office Spreadsheet (ODS) export in toolbar.
  146. /// </summary>
  147. public bool ShowOdsExport {
  148. get => GetExport(Exports.Ods);
  149. set => SetExport(value, Exports.Ods);
  150. }
  151. /// <summary>
  152. /// Switches a visibility of Open Office Text (ODT) export in toolbar
  153. /// </summary>
  154. public bool ShowOdtExport {
  155. get => GetExport(Exports.Odt);
  156. set => SetExport(value, Exports.Odt);
  157. }
  158. /// <summary>
  159. /// Switches a visibility of XML (Excel) export in toolbar.
  160. /// </summary>
  161. public bool ShowXmlExcelExport {
  162. get => GetExport(Exports.XmlExcel);
  163. set => SetExport(value, Exports.XmlExcel);
  164. }
  165. /// <summary>
  166. /// Switches a visibility of DBF export in toolbar.
  167. /// </summary>
  168. public bool ShowDbfExport {
  169. get => GetExport(Exports.Dbf);
  170. set => SetExport(value, Exports.Dbf);
  171. }
  172. /// <summary>
  173. /// Switches visibility the CSV (comma separated values) export in toolbar.
  174. /// </summary>
  175. public bool ShowCsvExport {
  176. get => GetExport(Exports.Csv);
  177. set => SetExport(value, Exports.Csv);
  178. }
  179. /// <summary>
  180. /// Switches visibility the MHT export in toolbar.
  181. /// </summary>
  182. public bool ShowMhtExport {
  183. get => GetExport(Exports.Mht);
  184. set => SetExport(value, Exports.Mht);
  185. }
  186. /// <summary>
  187. /// Switches visibility the HTML export in toolbar.
  188. /// </summary>
  189. public bool ShowHTMLExport
  190. {
  191. get => GetExport(Exports.HTML);
  192. set => SetExport(value, Exports.HTML);
  193. }
  194. /// <summary>
  195. /// Switches visibility the HPGL export in toolbar.
  196. /// </summary>
  197. public bool ShowHpglExport
  198. {
  199. get => GetExport(Exports.Hpgl);
  200. set => SetExport(value, Exports.Hpgl);
  201. }
  202. #if !WASM
  203. /// <summary>
  204. /// Switches visibility the Email export in toolbar.
  205. /// </summary>
  206. public bool ShowEmailExport
  207. {
  208. get => GetExport(Exports.Email);
  209. set
  210. {
  211. if (Infrastructure.FastReportGlobal.InternalEmailExportOptions is null)
  212. throw new Exception("Please add your account information when registering for services. Use services.AddFastReport(options => options.EmailExportOptions = new EmailExportOptions() {...} )");
  213. SetExport(value, Exports.Email);
  214. }
  215. }
  216. #endif
  217. /// <summary>
  218. /// Switches visibility the DXF export in toolbar.
  219. /// </summary>
  220. public bool ShowDxfExport
  221. {
  222. get => GetExport(Exports.Dxf);
  223. set => SetExport(value, Exports.Dxf);
  224. }
  225. /// <summary>
  226. /// Switches visibility the Json export in toolbar.
  227. /// </summary>
  228. public bool ShowJsonExport
  229. {
  230. get => GetExport(Exports.Json);
  231. set => SetExport(value, Exports.Json);
  232. }
  233. /// <summary>
  234. /// Switches visibility the LaTeX export in toolbar.
  235. /// </summary>
  236. public bool ShowLaTeXExport
  237. {
  238. get => GetExport(Exports.LaTeX);
  239. set => SetExport(value, Exports.LaTeX);
  240. }
  241. /// <summary>
  242. /// Switches a visibility of Image export in toolbar.
  243. /// </summary>
  244. //public bool ShowImageExport
  245. //{
  246. // get => GetExport(Exports.Image);
  247. // set => SetExport(value, Exports.Image);
  248. //}
  249. /// <summary>
  250. /// Switches visibility the PPML export in toolbar.
  251. /// </summary>
  252. public bool ShowPpmlExport
  253. {
  254. get => GetExport(Exports.Ppml);
  255. set => SetExport(value, Exports.Ppml);
  256. }
  257. /// <summary>
  258. /// Switches visibility the PS export in toolbar.
  259. /// </summary>
  260. public bool ShowPSExport
  261. {
  262. get => GetExport(Exports.PS);
  263. set => SetExport(value, Exports.PS);
  264. }
  265. /// <summary>
  266. /// Switches visibility the XAML export in toolbar.
  267. /// </summary>
  268. public bool ShowXamlExport
  269. {
  270. get => GetExport(Exports.Xaml);
  271. set => SetExport(value, Exports.Xaml);
  272. }
  273. /// <summary>
  274. /// Switches visibility the ZPL export in toolbar.
  275. /// </summary>
  276. public bool ShowZplExport
  277. {
  278. get => GetExport(Exports.Zpl);
  279. set => SetExport(value, Exports.Zpl);
  280. }
  281. /// <summary>
  282. /// Switches visibility the Excel-97 export in toolbar.
  283. /// </summary>
  284. public bool ShowExcel97Export
  285. {
  286. get => GetExport(Exports.Excel97);
  287. set => SetExport(value, Exports.Excel97);
  288. }
  289. /// <summary>
  290. /// Switches visibility the SVG export in toolbar.
  291. /// </summary>
  292. public bool ShowSvgExport
  293. {
  294. get => GetExport(Exports.Svg);
  295. set => SetExport(value, Exports.Svg);
  296. }
  297. #endif
  298. private bool GetExport(Exports export)
  299. {
  300. return (ExportTypes & export) > 0;
  301. }
  302. private void SetExport(bool value, Exports export)
  303. {
  304. if (value)
  305. ExportTypes |= export;
  306. else
  307. ExportTypes &= ~export;
  308. }
  309. }
  310. ///<summary>
  311. ///Used to select exports
  312. /// </summary>
  313. [Flags]
  314. public enum Exports
  315. {
  316. Prepared = 1,
  317. Pdf = 2,
  318. Excel2007 = 4,
  319. Word2007 = 8,
  320. PowerPoint2007 = 16,
  321. XmlExcel = 32,
  322. Text = 64,
  323. Rtf = 128,
  324. Xps = 256,
  325. Ods = 512,
  326. Odt = 1024,
  327. Dbf = 2048,
  328. Csv = 4096,
  329. Mht = 8192,
  330. HTML = 16384,
  331. Hpgl = 32768,
  332. Email = 65536,
  333. Dxf = 131_072,
  334. Json = 262_144,
  335. LaTeX = 524_288,
  336. //Image = 1_048_576,
  337. Ppml = 2_097_152,
  338. PS = 4_194_304,
  339. Xaml = 8_388_608,
  340. Zpl = 16_777_216,
  341. Excel97 = 33_554_432,
  342. Svg = 67_108_864,
  343. Default = Prepared | Pdf | Excel2007 | Word2007 | Text | Rtf
  344. | Xps | Ods | Odt | XmlExcel | Csv,
  345. All = Default | PowerPoint2007 | Dbf | Mht
  346. | HTML | Hpgl /*| Email*/ | Dxf | Json | LaTeX /*| Image*/
  347. | Ppml | PS | Xaml | Zpl | Excel97 | Svg,
  348. }
  349. }