123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace PRSDesktop;
- public class SupplierBillApprovalGrid : DynamicDataGrid<BillApproval>, ISpecificGrid
- {
- private Bill Bill;
- public SupplierBillApprovalGrid(Bill bill)
- {
- Bill = bill;
- }
- private Button ApproveButton = null!;
- protected override void Init()
- {
- base.Init();
- HiddenColumns.Add(x => x.Employee.ID);
- HiddenColumns.Add(x => x.IsCustom);
- ApproveButton = AddButton("Mark as Approved", null, ApproveButton_Click);
- ApproveButton.IsEnabled = false;
- }
- private bool ApproveButton_Click(Button button, CoreRow[] rows)
- {
- var items = LoadItems(rows);
- if(items.Any(x => x.Approved == DateTime.MinValue))
- {
- foreach(var item in items)
- {
- item.Approved = DateTime.Now;
- }
- }
- else
- {
- foreach(var item in items)
- {
- item.Approved = DateTime.MinValue;
- }
- }
- SaveItems(items);
- DoChanged();
- return true;
- }
- protected override void SelectItems(CoreRow[]? rows)
- {
- base.SelectItems(rows);
- if(rows is null || rows.Length == 0)
- {
- ApproveButton.IsEnabled = false;
- }
- else
- {
- ApproveButton.IsEnabled = true;
- if(rows.Any(x => x.Get<BillApproval, DateTime>(x => x.Approved) == DateTime.MinValue))
- {
- ApproveButton.Content = "Mark as Approved";
- }
- else
- {
- ApproveButton.Content = "Mark as Unapproved";
- }
- }
- }
- #region UI Component
- private class UIComponent : DynamicGridGridUIComponent<BillApproval>
- {
- protected override Brush? GetCellBackground(CoreRow row, DynamicColumnBase column)
- {
- if(row.Get<BillApproval, bool>(x => x.IsCustom))
- {
- return null;
- }
- else
- {
- return Colors.Gainsboro.ToBrush(0.5);
- }
- }
- }
- protected override IDynamicGridUIComponent<BillApproval> CreateUIComponent()
- {
- return new UIComponent { Parent = this };
- }
- #endregion
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.AddRows = Security.IsAllowed<ManageBillApprovals>();
- options.EditRows = Security.IsAllowed<ManageBillApprovals>();
- options.DeleteRows = Security.IsAllowed<ManageBillApprovals>();
- }
- public override BillApproval CreateItem()
- {
- var item = base.CreateItem();
- item.Bill.CopyFrom(Bill);
- item.IsCustom = true;
- return item;
- }
- protected override void Reload(Filters<BillApproval> criteria, Columns<BillApproval> columns, ref SortOrder<BillApproval>? sort, CancellationToken token, Action<CoreTable?, Exception?> action)
- {
- criteria.Add(new Filter<BillApproval>(x => x.Bill.ID).IsEqualTo(Bill.ID));
- base.Reload(criteria, columns, ref sort, token, action);
- }
- protected override void DoEdit()
- {
- if(SelectedRows.Any(x => !x.Get<BillApproval, bool>(x => x.IsCustom)))
- {
- return;
- }
- else
- {
- base.DoEdit();
- }
- }
- protected override void DoDelete()
- {
- if(SelectedRows.Any(x => !x.Get<BillApproval, bool>(x => x.IsCustom)))
- {
- return;
- }
- else
- {
- base.DoDelete();
- }
- }
- protected override void DoAdd(bool openEditorOnDirectEdit = false)
- {
- if (MultiSelectDialog<Employee>.SelectItem(out var employee,
- LookupFactory.DefineLookupFilter<BillApproval, Employee, EmployeeLink>(x => x.Employee, []),
- LookupFactory.DefineLookupColumns<BillApproval, Employee, EmployeeLink>(x => x.Employee),
- "Select Bill Approval Employee:"))
- {
- CreateItems(() =>
- {
- var approval = CreateItem();
- approval.Employee.CopyFrom(employee);
- return CoreUtils.One(approval);
- });
- }
- }
- }
|