using System; using System.Windows; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; using ScriptEditor = InABox.DynamicGrid.ScriptEditor; namespace PRSDesktop.Configuration { internal class CustomModuleGrid : DynamicDataGrid, ISpecificGrid { public string Section { get; set; } public DataModel? DataModel { get; set; } = null; public CustomModuleGrid() { Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns); ActionColumns.Add(new DynamicScheduleEditorColumn { Position = DynamicActionColumnPosition.Start }); HiddenColumns.Add(x => x.ActiveSchedules); HiddenColumns.Add(x => x.Section); HiddenColumns.Add(x => x.Script); ActionColumns.Add(new DynamicActionColumn(PRSDesktop.Resources.script.AsBitmapImage(), EditScript)); } private bool EditScript(CoreRow arg) { if (arg == null) { MessageBox.Show("Please select a module first"); return false; } var module = arg.ToObject(); var code = module.Script; var editor = new ScriptEditor(code); if (editor.ShowDialog() == true) { module.Script = editor.Script; new Client().Save(module, "Updated by User"); return true; } return false; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { sort = new SortOrder(x => x.Name); criteria.Add(new Filter(x => x.Section).IsEqualTo(Section).And(x => x.DataModel).IsEqualTo(DataModel?.Name ?? "")); base.Reload(criteria, columns, ref sort, action); } protected 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 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; } } }