123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Threading;
- using System.Windows;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
- namespace PRSDesktop.Configuration
- {
- internal class CustomModuleGrid : DynamicDataGrid<CustomModule>, ISpecificGrid
- {
- public string Section { get; set; }
- public DataModel? DataModel { get; set; } = null;
- protected override void Init()
- {
- base.Init();
- ActionColumns.Add(new DynamicScheduleEditorColumn<CustomModule> { Position = DynamicActionColumnPosition.Start });
- HiddenColumns.Add(x => x.ActiveSchedules);
- HiddenColumns.Add(x => x.Section);
- HiddenColumns.Add(x => x.Script);
- ActionColumns.Add(new DynamicImageColumn(PRSDesktop.Resources.script.AsBitmapImage(), EditScript));
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.RecordCount = true;
- options.SelectColumns = true;
- }
- private bool EditScript(CoreRow? arg)
- {
- if (arg == null)
- {
- MessageBox.Show("Please select a module first");
- return false;
- }
-
- var module = arg.ToObject<CustomModule>();
- var code = module.Script;
- var editor = new ScriptEditor(code);
- if (editor.ShowDialog() == true)
- {
- module.Script = editor.Script;
- new Client<CustomModule>().Save(module, "Updated by User");
- return true;
- }
- return false;
- }
- protected override void Reload(
- Filters<CustomModule> criteria, Columns<CustomModule> columns, ref SortOrder<CustomModule>? sort,
- CancellationToken token, Action<CoreTable?, Exception?> action)
- {
- sort = new SortOrder<CustomModule>(x => x.Name);
- criteria.Add(new Filter<CustomModule>(x => x.Section).IsEqualTo(Section).And(x => x.DataModel).IsEqualTo(DataModel?.Name ?? ""));
- base.Reload(criteria, columns, ref sort, token, action);
- }
- public override CustomModule CreateItem()
- {
- var module = base.CreateItem();
- module.Section = Section;
- module.DataModel = DataModel?.Name ?? "";
- module.Script =
- @"using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime;
- using System.Windows;
- using System.Windows.Controls;
- using InABox.Core;
- using InABox.Clients;
- using InABox.DynamicGrid;
- using InABox.Logging;
- using InABox.WPF;
- using Comal.Classes;
- using PRSDesktop;
- public class Module
- {
-
- public DataModel Model { get; set; }
-
- public void BeforeLoad(){
- // Code to customise Model here
- }
- public void CheckTables(List<string> tables){
- // Customise tables of Model.
- }
-
- public bool Execute()
- {
- Progress.Show("""");
- try
- {
-
- // Enter your code here
-
- Progress.Close();
- }
- catch (Exception e)
- {
- Progress.Close();
- MessageBox.Show(e.Message);
- }
- MessageBox.Show(""All Done!"");
- return true;
- }
-
- }";
- return module;
- }
- }
- }
|