1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 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<JobITP>, 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<JobITP>(new Filter<JobITP>(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<JobITPForm, JobITP, JobITPLink>(item, row.Get<JobITP, Guid>(x => x.ID), () => row.ToObject<JobITP>());
- }
- 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<JobITP> criteria, Columns<JobITP> columns, ref SortOrder<JobITP> sort, Action<CoreTable, Exception> action)
- {
- criteria.Add(new Filter<JobITP>(x => x.Job.ID).IsEqualTo(ParentID));
- base.Reload(criteria, columns, ref sort, action);
- }
- protected override Dictionary<string, object> 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<DigitalForm>().Load(new Filter<DigitalForm>(x => x.ID).IsEqualTo(value)).FirstOrDefault();
- var load = page.GetType().GetMethod("LoadItems");
- //load.Invoke(page, new object[] { template != null ? template.Questions : null });
- }
- }
- return result;
- }
- }
|