using System; using System.Collections.Generic; using System.Linq; using System.Windows; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using java.awt.dnd; namespace PRSDesktop; public class JobITPGrid : DynamicDataGrid, IJobControl, IDataModelSource { public JobITPGrid() { Options.AddRange( DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.AddRows, DynamicGridOption.ImportData, DynamicGridOption.FilterRows, DynamicGridOption.MultiSelect, DynamicGridOption.EditRows, DynamicGridOption.DeleteRows ); ActionColumns.Add(new DynamicMenuColumn(BuildMenu) { Position = DynamicActionColumnPosition.Start }); } public event DataModelUpdateEvent OnUpdateDataModel; public string SectionName => "Job ITPs"; public DataModel DataModel(Selection selection) { var ids = ExtractValues(x => x.ID, selection).ToArray(); return new BaseDataModel(new Filter(x => x.ID).InList(ids)); } public Guid ParentID { get; set; } public JobPanelSettings Settings { get; set; } private void BuildMenu(DynamicMenuColumn column, CoreRow? row) { if (row == null) return; var item = column.AddItem("Digital Forms", PRSDesktop.Resources.kanban, null); DynamicGridUtils.PopulateFormMenu(item, row.Get(x => x.ID), () => row.ToObject()); } protected override void DoAdd(bool OpenEditorOnDirectEdit = false) { if (ParentID.Equals(Guid.Empty) || ParentID.Equals(CoreUtils.FullGuid)) MessageBox.Show("Please select a Job first!"); else base.DoAdd(); } protected override JobITP CreateItem() { var result = base.CreateItem(); result.Job.ID = ParentID; return result; } protected override bool CustomiseImportItem(JobITP item) { item.Job.ID = ParentID; return base.CustomiseImportItem(item); } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { criteria.Add(new Filter(x => x.Job.ID).IsEqualTo(ParentID)); base.Reload(criteria, columns, ref sort, action); } protected override Dictionary EditorValueChanged(IDynamicEditorForm editor, JobITP[] items, string name, object value) { var result = base.EditorValueChanged(editor, items, name, value); if (name == "ITPTypeLink.ID") { var type = typeof(IDynamicEnclosedListGrid<,>).MakeGenericType(typeof(JobITP), typeof(QAQuestion)); var page = editor.Pages.FirstOrDefault(x => x.GetType().GetInterface(type.Name) != null); if (page != null) { var template = new Client().Load(new Filter(x => x.ID).IsEqualTo(value)).FirstOrDefault(); var load = page.GetType().GetMethod("LoadItems"); //load.Invoke(page, new object[] { template != null ? template.Questions : null }); } } return result; } }