12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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()
- {
- ActionColumns.Add(new DynamicMenuColumn(BuildMenu) { Position = DynamicActionColumnPosition.Start });
- }
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
- {
- base.DoReconfigure(options);
- options.AddRange(
- DynamicGridOption.RecordCount,
- DynamicGridOption.SelectColumns,
- DynamicGridOption.AddRows,
- DynamicGridOption.ImportData,
- DynamicGridOption.FilterRows,
- DynamicGridOption.MultiSelect,
- DynamicGridOption.EditRows,
- DynamicGridOption.DeleteRows
- );
- }
- 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 Job Job { 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 bool CanCreateItems()
- {
- return Job.ID != Guid.Empty;
- }
- protected override JobITP CreateItem()
- {
- var result = base.CreateItem();
- result.Job.ID = Job.ID;
- result.Job.Synchronise(Job);
- return result;
- }
- protected override bool CustomiseImportItem(JobITP item)
- {
- item.Job.ID = Job.ID;
- item.Job.Synchronise(Job);
- 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(Job.ID));
- 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;
- }
- }
|