1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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>
- {
- public DatabaseScriptGrid()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns);
- HiddenColumns.Add(x => x.Section);
- HiddenColumns.Add(x => x.Code);
- ActionColumns.Add(new DynamicImageColumn(PRSDesktop.Resources.script.AsBitmapImage(), EditScript));
- OnCustomiseEditor += CustomiseEditor;
- }
- 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;
- }
- }
- }
- }
|