1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using Comal.Classes;
- using InABox.DynamicGrid;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PRSDesktop.Grids
- {
- public class OvertimeIntervalGrid : DynamicOneToManyGrid<Overtime, OvertimeInterval>
- {
- protected override void Init()
- {
- base.Init();
- HiddenColumns.Add(x => x.IntervalType);
- }
- protected override void DoReconfigureEditors(DynamicEditorGrid grid, OvertimeInterval[] items)
- {
- base.DoReconfigureEditors(grid, items);
- var intervalEditor = grid.FindEditor(nameof(OvertimeInterval.Interval));
- intervalEditor?.SetEnabled(!items.Any(x => x.IntervalType == OvertimeIntervalType.RemainingTime));
- }
- // EditorPage BeforeSave
- public override void BeforeSave(object item)
- {
- base.BeforeSave(item);
- if (Items.Count == 0)
- {
- throw new Exception("There must be at least one overtime interval.");
- }
- else if (Items.SkipLast(1).Any(x => x.IntervalType == OvertimeIntervalType.RemainingTime))
- {
- throw new Exception($"Only the last interval may have [IntervalType] = '{OvertimeIntervalType.RemainingTime}'");
- }
- else if (Items.Last().IntervalType != OvertimeIntervalType.RemainingTime)
- {
- throw new Exception($"The last overtime interval must have [IntervalType] = '{OvertimeIntervalType.RemainingTime}'");
- }
- }
- }
- }
|