|
@@ -0,0 +1,83 @@
|
|
|
+using Comal.Classes;
|
|
|
+using InABox.Clients;
|
|
|
+using InABox.Core;
|
|
|
+using InABox.DynamicGrid;
|
|
|
+using Microsoft.Win32;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Windows;
|
|
|
+
|
|
|
+namespace PRSDesktop;
|
|
|
+
|
|
|
+public class JobScopeDocumentGrid : DynamicDocumentGrid<JobScopeDocument, JobScope, JobScopeLink>, IJobScopeGrid
|
|
|
+{
|
|
|
+ public JobScope? Scope
|
|
|
+ {
|
|
|
+ get => Item;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ Load(value ?? new JobScope(), null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
|
|
|
+ {
|
|
|
+ if((Scope?.ID ?? Guid.Empty) == Guid.Empty)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Please select a scope.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ base.DoAdd(OpenEditorOnDirectEdit);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SaveItem(JobScopeDocument item)
|
|
|
+ {
|
|
|
+ Client.Save(item, "Updated by user.");
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void SaveItems(JobScopeDocument[] items)
|
|
|
+ {
|
|
|
+ Client.Save(items, "Updated by user.");
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void DeleteItems(params CoreRow[] rows)
|
|
|
+ {
|
|
|
+ Client.Delete(rows.Select(x => new JobScopeDocument { ID = x.Get<JobScopeDocument, Guid>(x => x.ID) }), "Deleted by user.");
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override JobScopeDocument LoadItem(CoreRow row)
|
|
|
+ {
|
|
|
+ var id = row.Get<JobScopeDocument, Guid>(x => x.ID);
|
|
|
+ return Client.Query(
|
|
|
+ new Filter<JobScopeDocument>(x => x.ID).IsEqualTo(id),
|
|
|
+ DynamicGridUtils.LoadEditorColumns(DataColumns()))
|
|
|
+ .ToObjects<JobScopeDocument>()
|
|
|
+ .FirstOrDefault()
|
|
|
+ ?? throw new Exception($"No {nameof(JobScopeDocument)} with ID {id}");
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override JobScopeDocument[] LoadItems(CoreRow[] rows)
|
|
|
+ {
|
|
|
+ var ids = rows.Select(x => x.Get<JobScopeDocument, Guid>(x => x.ID));
|
|
|
+ return Client.Query(
|
|
|
+ new Filter<JobScopeDocument>(x => x.ID).InList(ids),
|
|
|
+ DynamicGridUtils.LoadEditorColumns(DataColumns()))
|
|
|
+ .ToObjects<JobScopeDocument>().ToArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void Reload(Filters<JobScopeDocument> criteria, Columns<JobScopeDocument> columns, ref SortOrder<JobScopeDocument>? sort, Action<CoreTable?, Exception?> action)
|
|
|
+ {
|
|
|
+ if(Scope is null || Scope.ID == Guid.Empty)
|
|
|
+ {
|
|
|
+ criteria.Add(new Filter<JobScopeDocument>().None());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ criteria.Add(new Filter<JobScopeDocument>(x => x.EntityLink.ID).IsEqualTo(Scope?.ID ?? Guid.Empty));
|
|
|
+ }
|
|
|
+ new Client<JobScopeDocument>().Query(criteria.Combine(), columns, sort, action);
|
|
|
+ }
|
|
|
+}
|