| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 | 
							- using Comal.Classes;
 
- using InABox.Clients;
 
- using InABox.Core;
 
- using InABox.DynamicGrid;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.ComponentModel;
 
- using System.Linq;
 
- using System.Windows;
 
- using System.Windows.Controls;
 
- using System.Reflection;
 
- namespace PRSDesktop
 
- {
 
-     /// <summary>
 
-     /// Interaction logic for DataEntryPanel.xaml
 
-     /// </summary>
 
-     /// <remarks>
 
-     /// This is a host because it has a singular code popup editor
 
-     /// </remarks>
 
-     public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHost
 
-     {
 
-         IPopupEditorControl? Popup;
 
-         public DataEntryPanel()
 
-         {
 
-             InitializeComponent();
 
-         }
 
-         public void Setup()
 
-         {
 
-             var types = CoreUtils.Entities
 
-                 .Where(x => x.IsAssignableTo(typeof(Entity))
 
-                 && x.HasInterface(typeof(IRemotable))
 
-                 && x.HasInterface(typeof(IPersistent))
 
-                 && x.GetCustomAttribute<AutoEntity>() is null
 
-                 && Security.CanEdit(x)
 
-                 && x.HasInterface<IScannable>())
 
-                 .Select(x => new Tuple<string, Type?>(x.Name, x)).OrderBy(x => x.Item1).ToList();
 
-             types.Insert(0, new("", null));
 
-             TypeBox.ItemsSource = types;
 
-             TypeBox.DisplayMemberPath = "Item1";
 
-             TypeBox.SelectedValuePath = "Item2";
 
-             ScanPanel.Setup();
 
-         }
 
-         public void Refresh()
 
-         {
 
-             ScanPanel.Refresh();
 
-         }
 
-         public bool IsReady { get; set; }
 
-         public string SectionName => "Data Entry";
 
-         public DataModel DataModel(Selection selection)
 
-         {
 
-             return new EmptyDataModel();
 
-         }
 
-         public event DataModelUpdateEvent? OnUpdateDataModel;
 
-         public void CreateToolbarButtons(IPanelHost host)
 
-         {
 
-             if (Security.IsAllowed<CanSetupScanTags>())
 
-             {
 
-                 host.CreateSetupAction(new PanelAction
 
-                 {
 
-                     Caption = "Scan Tags",
 
-                     OnExecute = (action) =>
 
-                     {
 
-                         var list = new MasterList(typeof(ScanTag));
 
-                         list.ShowDialog();
 
-                     }
 
-                 });
 
-             }
 
-         }
 
-         public void Heartbeat(TimeSpan time)
 
-         {
 
-         }
 
-         public Dictionary<string, object[]> Selected()
 
-         {
 
-             return new Dictionary<string, object[]>();
 
-         }
 
-         
 
-         private void CheckSaved(CancelEventArgs cancel)
 
-         {
 
-             var result = MessageBox.Show("You have changes that have not been saved; do you wish to save these changes?", "Save Changes?", MessageBoxButton.YesNoCancel);
 
-             if (result == MessageBoxResult.Yes)
 
-             {
 
-                 Editor.SaveItem(cancel);
 
-                 if (!cancel.Cancel)
 
-                 {
 
-                     MessageBox.Show("Purchase Order saved.");
 
-                 }
 
-             }
 
-             else if (result == MessageBoxResult.Cancel)
 
-             {
 
-                 cancel.Cancel = true;
 
-             }
 
-         }
 
-         private bool CheckSaved()
 
-         {
 
-             var cancel = new CancelEventArgs();
 
-             CheckSaved(cancel);
 
-             return !cancel.Cancel;
 
-         }
 
-         public void Shutdown(CancelEventArgs? cancel)
 
-         {
 
-             
 
-             if(bChanged)
 
-             {
 
-                 CheckSaved(cancel);
 
-             }
 
-             if (cancel.Cancel == false) 
 
-                 ScanPanel.Shutdown(cancel);
 
-         }
 
-         #region Host
 
-         private HashSet<Type> _loadedTypes = new();
 
-         public DynamicGridColumns Columns { get; set; } = new();
 
-         IEnumerable<DynamicGridColumn> IDynamicEditorHost.Columns => Columns;
 
-         public void LoadColumns(string column, Dictionary<string, string> columns)
 
-         {
 
-             var selectedType = TypeBox.SelectedValue as Type;
 
-             if (selectedType is null) return;
 
-             columns.Clear();
 
-             foreach (var c in LookupFactory.DefineColumns(selectedType).ColumnNames().Where(x => x != "ID"))
 
-             {
 
-                columns.Add(c, c);
 
-             }
 
-             if (Popup?.EditorDefinition is CodePopupEditorControl codePopup && !columns.ContainsKey(codePopup.CodeColumn))
 
-             {
 
-                 columns.Add(codePopup.CodeColumn, codePopup.CodeColumn);
 
-             }
 
-         }
 
-         public IFilter? DefineFilter(Type type) => LookupFactory.DefineFilter(type);
 
-         public void LoadLookups(ILookupEditorControl sender)
 
-         {
 
-             var editor = sender.EditorDefinition as ILookupEditor;
 
-             var colname = sender.ColumnName;
 
-             var values = editor.Values(colname, Editor.Items);
 
-             sender.LoadLookups(values);
 
-         }
 
-         object?[] IDynamicEditorHost.GetItems() => Editor.Items;
 
-         public BaseEditor? GetEditor(DynamicGridColumn column) => column.Editor.CloneEditor();
 
-         #endregion
 
-         private void ClearEditor(Type TEntity)
 
-         {
 
-             UpdateEditor(TEntity, null);
 
-             if(Popup is not null)
 
-             {
 
-                 Popup.Value = Guid.Empty;
 
-             }
 
-         }
 
-         private bool EditorChanged = false;
 
-         private bool bChanged = true;
 
-         
 
-         private IDynamicDataGrid UpdateEditor(Type TEntity, BaseObject[]? items)
 
-         {
 
-             bChanged = false;
 
-             ScanPanel.ScanGrid.IsEnabled = true;
 
-             
 
-             DetailBorder.Child = null;
 
-             Editor = new EmbeddedDynamicEditorForm();
 
-             Editor.SetLayoutType<VerticalDynamicEditorGridLayout>();
 
-             Editor.SetValue(Grid.RowProperty, 1);
 
-             Editor.SetValue(Grid.ColumnProperty, 0);
 
-             Editor.SetValue(Grid.ColumnSpanProperty, 4);
 
-             EditorChanged = false;
 
-             Editor.OnAfterEditorValueChanged += (sender, column) =>
 
-             {
 
-                 EditorChanged = true;
 
-                 return null;
 
-             };
 
-             Editor.OnOK += () =>
 
-             {
 
-                 var cancel = new System.ComponentModel.CancelEventArgs();
 
-                 Editor.SaveItem(cancel);
 
-                 if (!cancel.Cancel)
 
-                 {
 
-                     ClearEditor(TEntity);
 
-                     bChanged = false;
 
-                     ScanPanel.ScanGrid.IsEnabled = true;                }
 
-             };
 
-             Editor.OnCancel += () =>
 
-             {
 
-                 ClearEditor(TEntity);
 
-                 bChanged = false;
 
-                 ScanPanel.ScanGrid.IsEnabled = true;
 
-             };
 
-             Editor.OnChanged += (sender, args) =>
 
-             {
 
-                 bChanged = true;
 
-                 ScanPanel.ScanGrid.IsEnabled = false;
 
-             };
 
-             
 
-             DetailBorder.Child = Editor;
 
-             var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), TEntity);
 
-             grid.InitialiseEditorForm(Editor, items ?? new object[] { Activator.CreateInstance(TEntity)! });
 
-             return (grid as IDynamicDataGrid)!;
 
-         }
 
-         private void TypeBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
 
-         {
 
-             var selectedType = TypeBox.SelectedValue as Type;
 
-             if (selectedType is not null)
 
-             {
 
-                 var dataGrid = UpdateEditor(selectedType, null);
 
-                 var editorColumns = dataGrid.LoadEditorColumns();
 
-                 if (Popup is UIElement element)
 
-                     DetailHeader.Children.Remove(element);
 
-                 var code = DatabaseSchema.Properties(selectedType)
 
-                     .Where(x => x.Parent is null && (x.Editor is CodeEditor || x.Editor is UniqueCodeEditor)
 
-                         && x.Editor.Editable.EditorVisible())
 
-                     .FirstOrDefault();
 
-                 BaseEditor editor;
 
-                 if (code is not null)
 
-                 {
 
-                     editor = new CodePopupEditor(selectedType) { CodeColumn = code.Name };
 
-                     Popup = new CodePopupEditorControl { Margin = new Thickness(5), CodeColumn = code.Name };
 
-                 }
 
-                 else
 
-                 {
 
-                     editor = new PopupEditor(selectedType);
 
-                     Popup = new PopupEditorControl { Margin = new Thickness(5) };
 
-                 }
 
-                 if (Popup is IPopupEditorControl popupEditor)
 
-                 {
 
-                     Popup.ColumnName = "ID";
 
-                     popupEditor.Host = this;
 
-                     Columns = new DynamicGridColumns();
 
-                     Columns.ExtractColumns(selectedType);
 
-                 }
 
-                 var el = (Popup as UIElement)!;
 
-                 el.SetValue(DockPanel.DockProperty,Dock.Left);
 
-                 Popup.EditorDefinition = editor;
 
-                 Popup.OnEditorValueChanged += (s, v) =>
 
-                 {
 
-                     var entityID = (Guid)v["ID"];
 
-                     BaseObject[]? objs = null;
 
-                     if (entityID != Guid.Empty)
 
-                     {
 
-                         var obj = Client.Create(selectedType)
 
-                             .Query(
 
-                                 Filter.Create<Entity>(selectedType, x => x.ID).IsEqualTo(entityID),
 
-                                 editorColumns)
 
-                             .ToObjects(selectedType)
 
-                             .FirstOrDefault();
 
-                         if (obj is not null)
 
-                         {
 
-                             objs = new BaseObject[] { obj };
 
-                         }
 
-                     }
 
-                     UpdateEditor(selectedType, objs);
 
-                 };
 
-                 Popup.Configure();
 
-                 Popup.Loaded = true;
 
-                 DetailHeader.Children.Add(el);
 
-             }
 
-             else
 
-             {
 
-                 DetailBorder.Child = null;
 
-                 if (Popup is UIElement el)
 
-                     DetailHeader.Children.Remove(el);
 
-             }
 
-         }
 
-         private void ScanPanel_OnSelectAppliesTo(string appliesTo)
 
-         {
 
-             CoreUtils.TryGetEntity(appliesTo, out var entity);
 
-             TypeBox.SelectedValue = entity;
 
-         }
 
-     }
 
- }
 
 
  |