123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.Wpf;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- 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)
- {
- MessageWindow.ShowMessage("Please select a scope.", "No scope selected.");
- return;
- }
- base.DoAdd(OpenEditorOnDirectEdit);
- }
- public override void SaveItem(JobScopeDocument item)
- {
- Client.Save(item, "Updated by user.");
- }
- public override void SaveItems(IEnumerable<JobScopeDocument> items)
- {
- Client.Save(items, "Updated by user.");
- }
- public override void DeleteItems(params CoreRow[] rows)
- {
- Client.Delete(rows.Select(x => new JobScopeDocument { ID = x.Get<JobScopeDocument, Guid>(x => x.ID) }), "Deleted by user.");
- }
- public 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}");
- }
- public override JobScopeDocument[] LoadItems(IList<CoreRow> rows)
- {
- var ids = rows.ToArray(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,
- CancellationToken token, 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));
- }
- Client.Query(criteria.Combine(), columns, sort, CoreRange.All, action);
- }
- }
|