12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- using System.Linq;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop
- {
- public class JobFormGrid : DynamicDataGrid<JobForm>, IJobControl, IDataModelSource
- {
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public string SectionName => "Job Forms";
- public DataModel DataModel(Selection selection)
- {
- var ids = ExtractValues(x => x.ID, selection).ToArray();
- return new AutoDataModel<JobForm>(new Filter<JobForm>(x => x.ID).InList(ids));
- }
- public JobFormGrid()
- {
- ActionColumns.Add(new DynamicActionColumn(PRSDesktop.Resources.pencil.AsBitmapImage(), EditAction));
- }
- public Guid JobID { get; set; }
- private bool EditAction(CoreRow? row)
- {
- if (row == null) return false;
- if(DynamicFormEditWindow.EditDigitalForm<JobForm>(row.Get<JobForm, Guid>(x => x.ID), out var dataModel))
- {
- dataModel.Update(null);
- return true;
- }
- return false;
- }
- protected override void Reload(Filters<JobForm> criteria, Columns<JobForm> columns, ref SortOrder<JobForm>? sort,
- Action<CoreTable?, Exception?> action)
- {
- criteria.Add(new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(JobID));
- base.Reload(criteria, columns, ref sort, action);
- }
- protected override JobForm CreateItem()
- {
- var result = base.CreateItem();
- result.Parent.ID = JobID;
- return result;
- }
- }
- public class JobFormDefinitionGrid : DynamicManyToManyGrid<JobFormDefinition, Job>
- {
- public JobFormDefinitionGrid()
- {
- AddButton("Add All", null, AddAllClick);
- }
- private bool AddAllClick(Button arg1, CoreRow[] arg2)
- {
- var existingforms = ExtractValues(x => x.Form.ID, Selection.All).ToArray();
- var newforms = new Client<DigitalForm>().Query(
- new Filter<DigitalForm>(x => x.Active).IsEqualTo(true)
- .And(x => x.AppliesTo).IsEqualTo("Job")
- .And(x => x.ID).NotInList(existingforms)
- );
- foreach (var row in newforms.Rows)
- {
- var newitem = CreateItem();
- newitem.Job.ID = Item.ID;
- newitem.Form.ID = row.Get<DigitalForm, Guid>(x => x.ID);
- newitem.Form.Synchronise(row.ToObject<DigitalForm>());
- SaveItem(newitem);
- }
- return true;
- }
- }
- }
|