123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
- namespace PRSDesktop
- {
- public class DatabaseScriptGrid : DynamicDataGrid<Script>
- {
- protected override void Init()
- {
- base.Init();
- HiddenColumns.Add(x => x.Section);
- HiddenColumns.Add(x => x.Code);
- ActionColumns.Add(new DynamicImageColumn(PRSDesktop.Resources.script.AsBitmapImage(), EditScript));
- OnCustomiseEditor += CustomiseEditor;
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.RecordCount = true;
- options.SelectColumns = true;
- }
- protected override void DoValidate(Script[] items, List<string> errors)
- {
- base.DoValidate(items, errors);
- if (items.Any(x => string.IsNullOrWhiteSpace(x.Section)))
- errors.Add("[Section] must not be blank");
- if (items.Any(x => x.ScriptType == ScriptType.None))
- errors.Add("[Script Type] must not be None or empty");
- }
- private bool EditScript(CoreRow? arg)
- {
- if (arg == null)
- {
- MessageBox.Show("Please select a module first");
- return false;
- }
- var script = arg.ToObject<Script>();
- var code = script.Code;
- var editor = new ScriptEditor(code);
- if (editor.ShowDialog() == true)
- {
- script.Code = editor.Script;
- new Client<Script>().Save(script, "Updated by User");
- return true;
- }
- return false;
- }
- private void CustomiseEditor(IDynamicEditorForm sender, Script[]? items, DynamicGridColumn column, BaseEditor editor)
- {
- if (string.Equals(column.ColumnName, "Section"))
- {
- var script = items?.FirstOrDefault();
- editor.Editable = !string.IsNullOrWhiteSpace(script?.Section) ? Editable.Disabled : Editable.Enabled;
- }
- }
- }
- }
|