ScheduledScriptsGrid.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using Comal.Classes;
  2. using FastReport.Messaging.Xmpp;
  3. using InABox.Core;
  4. using InABox.DynamicGrid;
  5. using InABox.WPF;
  6. using PRS.Shared;
  7. using Syncfusion.DocIO.DLS;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Media.Imaging;
  14. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
  15. using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
  16. namespace PRSServer
  17. {
  18. public class ScheduledScriptsGrid : DynamicDataGrid<ScheduledScript>
  19. {
  20. private const string DefaultScript = @"using System;
  21. using System.Collections.Generic;
  22. using System.Linq;
  23. using System.Runtime;
  24. using System.Windows;
  25. using InABox.Core;
  26. using InABox.Clients;
  27. using InABox.Logging;
  28. using Comal.Classes;
  29. public class Module
  30. {
  31. public Object Data { get; set; }
  32. public bool Execute()
  33. {
  34. return true;
  35. }
  36. }";
  37. public ScheduledScriptsGrid()
  38. {
  39. HiddenColumns.Add(x => x.Script);
  40. ActionColumns.Add(new DynamicImageColumn(ScriptImage, ScriptAction));
  41. ActionColumns.Add(new DynamicImageColumn(ScheduleImage, ScheduleAction));
  42. }
  43. protected override void DoReconfigure(DynamicGridOptions options)
  44. {
  45. base.DoReconfigure(options);
  46. options.Clear();
  47. options.AddRows = true;
  48. options.EditRows = true;
  49. options.DeleteRows = true;
  50. }
  51. public override ScheduledScript CreateItem()
  52. {
  53. var item = base.CreateItem();
  54. item.Script = DefaultScript;
  55. return item;
  56. }
  57. private bool ScriptAction(CoreRow? arg)
  58. {
  59. if (arg is null) return false;
  60. var script = LoadItem(arg);
  61. var editor = new ScriptEditor(script.Script);
  62. editor.OnSave += (e, args) =>
  63. {
  64. if (script.Script != editor.Script)
  65. {
  66. script.Script = editor.Script;
  67. SaveItem(script);
  68. }
  69. };
  70. if (editor.ShowDialog() == true)
  71. {
  72. if (script.Script != editor.Script)
  73. {
  74. script.Script = editor.Script;
  75. SaveItem(script);
  76. }
  77. }
  78. return false;
  79. }
  80. private bool ScheduleAction(CoreRow? arg)
  81. {
  82. if (arg is null) return false;
  83. var script = LoadItem(arg);
  84. var form = new ScheduleForm(script);
  85. form.ShowDialog();
  86. return false;
  87. }
  88. private BitmapImage ScriptImage(CoreRow? arg)
  89. {
  90. return Properties.Resources.script.AsBitmapImage();
  91. }
  92. private BitmapImage ScheduleImage(CoreRow? arg)
  93. {
  94. return Properties.Resources.schedule.AsBitmapImage();
  95. }
  96. }
  97. }