123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop
- {
- internal class JobScopeGrid : DynamicDataGrid<JobScope>
- {
- private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
- public JobScopeGrid()
- {
- HiddenColumns.Add(x=>x.Job.DefaultScope.ID);
- HiddenColumns.Add(x=>x.Job.ID);
- ActionColumns.Add(new DynamicImageColumn(IsDefaultImage, SelectDefaultAction) { Position = DynamicActionColumnPosition.End });
- }
-
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
- {
- base.DoReconfigure(options);
- options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.FilterRows);
- }
- protected override void DeleteItems(params CoreRow[] rows)
- {
- base.DeleteItems(rows);
- var row = rows.FirstOrDefault(x => x.Get<JobScope, Guid>(x => x.Job.DefaultScope.ID) == x.Get<JobScope, Guid>(x => x.ID));
- if (row is not null)
- {
- var job = Client.Query(
- new Filter<Job>(x => x.ID).IsEqualTo(row.Get<JobScope, Guid>(x => x.Job.ID)),
- new Columns<Job>(x => x.ID).Add(x => x.DefaultScope.ID)
- ).Rows.FirstOrDefault()?.ToObject<Job>();
- if (job != null)
- {
- job.DefaultScope.ID = row.Get<JobScope, Guid>(x => x.ID);
- Client.Save(job, "Updated Default Scope");
- }
- }
- }
- private BitmapImage? IsDefaultImage(CoreRow? row)
- {
- return row == null
- ? tick
- : row.Get<JobScope, Guid>(x => x.Job.DefaultScope.ID) == row.Get<JobScope, Guid>(x => x.ID)
- ? tick
- : null;
- }
- private bool SelectDefaultAction(CoreRow? row)
- {
- if ((row == null) ||row.Get<JobScope, Guid>(x => x.Job.DefaultScope.ID) == row.Get<JobScope, Guid>(x => x.ID))
- return false;
- using (new WaitCursor())
- {
- var job = new Client<Job>().Query(
- new Filter<Job>(x => x.ID).IsEqualTo(row.Get<JobScope, Guid>(x => x.Job.ID)),
- new Columns<Job>(x => x.ID).Add(x => x.DefaultScope.ID)
- ).Rows.FirstOrDefault()?.ToObject<Job>();
- if (job != null)
- {
- job.DefaultScope.ID = row.Get<JobScope, Guid>(x => x.ID);
- new Client<Job>().Save(job, "Updated Default Scope");
- return true;
- }
- }
- return false;
- }
- public Job Job { get; set; }
- protected override bool CanCreateItems()
- {
- return Job.ID != Guid.Empty;
- }
-
- protected override JobScope CreateItem()
- {
- var result = base.CreateItem();
- result.Job.ID = Job.ID;
- result.Job.Synchronise(Job);
- result.Type = Data.Rows.Any() ? JobScopeType.Variation : JobScopeType.Contract;
- return result;
- }
- protected override void Reload(Filters<JobScope> criteria, Columns<JobScope> columns, ref SortOrder<JobScope>? sort, Action<CoreTable?, Exception?> action)
- {
- criteria.Add(new Filter<JobScope>(x => x.Job.ID).IsEqualTo(Job.ID));
- base.Reload(criteria, columns, ref sort, action);
- }
-
- }
- }
|