12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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.Start });
- }
-
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
- {
- base.DoReconfigure(options);
- options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.FilterRows);
-
-
- }
- 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);
- }
-
- }
- }
|