| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 | using Comal.Classes;using InABox.Core;using InABox.DynamicGrid;using InABox.WPF;using PRS.Shared.Events;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Markup.Localizer;using System.Windows.Media.Imaging;namespace PRS.Shared.Grids.EventEditor;internal class ScheduledEventDayOfWeekGrid : DynamicItemsListGrid<ScheduledEventDayOfWeek>{    private static readonly BitmapImage _tick = InABox.Wpf.Resources.tick.AsBitmapImage();    public SchedulePeriod Period { get; set; }    protected override void Init()    {        base.Init();        HiddenColumns.Add(x => x.Enabled);        ActionColumns.Add(new DynamicTickColumn<ScheduledEventDayOfWeek, bool>(x => x.Enabled, _tick, _tick, null, Enabled_Click));    }    protected override void DoReconfigure(DynamicGridOptions options)    {        base.DoReconfigure(options);        options.DirectEdit = true;        options.HideDirectEditButton = true;        options.EditRows = false;    }    private bool Enabled_Click(CoreRow? row)    {        if (row is null) return false;        var item = LoadItem(row);        item.Enabled = !item.Enabled;        SaveItem(item);        return true;    }    protected override DynamicGridColumns LoadColumns()    {        var columns = new DynamicGridColumns<ScheduledEventDayOfWeek>();        columns.Add(x => x.DayOfWeek);        columns.Add(x => x.StartTime, caption: Period == SchedulePeriod.Day ? "Time" : "StartTime");        if(Period != SchedulePeriod.Day)        {            columns.Add(x => x.EndTime);        }        return columns;    }}internal class ScheduledEventPropertiesGrid : DynamicItemsListGrid<ScheduledEventProperties>{    private readonly Column<ScheduledEventProperties> PeriodColumn = new(x => x.Period);    private readonly Column<ScheduledEventProperties> DayOfWeekSettingsColumn = new(x => x.DayOfWeekSettings);    private readonly Column<ScheduledEventProperties> NextScheduleColumn = new(x => x.NextSchedule);    protected override void CustomiseEditor(IDynamicEditorForm form, ScheduledEventProperties[] items, DynamicGridColumn column, BaseEditor editor)    {        base.CustomiseEditor(form, items, column, editor);        var item = items[0];        if (DayOfWeekSettingsColumn.IsEqualTo(column.ColumnName))        {            editor.Editable = item.Period == SchedulePeriod.Minute || item.Period == SchedulePeriod.Hour || item.Period == SchedulePeriod.Day                ? Editable.Enabled                : Editable.Disabled;        }        else if (NextScheduleColumn.IsEqualTo(column.ColumnName))        {            editor.Editable = item.Period == SchedulePeriod.Minute || item.Period == SchedulePeriod.Hour || item.Period == SchedulePeriod.Day                ? Editable.Disabled                : Editable.Enabled;        }    }    protected override void DoReconfigureEditors(DynamicEditorGrid grid, ScheduledEventProperties[] items)    {        base.DoReconfigureEditors(grid, items);        if(grid.Form.TryFindEditor<ListEmbeddedListEditorControl>(DayOfWeekSettingsColumn.Property, out var editor))        {            editor.CustomiseGrid = g =>            {                if (g is ScheduledEventDayOfWeekGrid dowGrid)                {                    dowGrid.Period = items[0].Period;                }            };        }    }    protected override void OnAfterEditorValueChanged(DynamicEditorGrid? grid, ScheduledEventProperties[] items, AfterEditorValueChangedArgs args, Dictionary<string, object?> changes)    {        base.OnAfterEditorValueChanged(grid, items, args, changes);        if(grid is null)        {            return;        }        if(args.ChangedValues.TryGetValue(PeriodColumn.Property, out var value) && value is SchedulePeriod period)        {            var daysOfWeekEditor = grid.Form.FindEditor<ListEmbeddedListEditorControl>(DayOfWeekSettingsColumn.Property);            var nextScheduleEditor = grid.Form.FindEditor<DateTimeEditorControl>(NextScheduleColumn.Property);            if(daysOfWeekEditor is not null && nextScheduleEditor is not null)            {                switch (period)                {                    case SchedulePeriod.Minute:                    case SchedulePeriod.Hour:                    case SchedulePeriod.Day:                        daysOfWeekEditor.IsEnabled = true;                        nextScheduleEditor.IsEnabled = false;                        break;                    case SchedulePeriod.Week:                    case SchedulePeriod.Month:                    case SchedulePeriod.Year:                        daysOfWeekEditor.IsEnabled = false;                        nextScheduleEditor.IsEnabled = true;                        break;                }            }        }    }}
 |