public CalendarEventWindow(CampaignState state, Calendar calendar, decimal now, Guid?entry_guid = null, Guid?guid = null)
        {
            this.valid   = false;
            this.state   = state.copy();
            this.now     = now;
            this.actions = new List <EntryAction>();
            if (guid is null)
            {
                if (entry_guid is null)
                {
                    throw new ArgumentNullException(nameof(entry_guid));
                }
                this.guid = Guid.NewGuid();
                ActionCalendarEventCreate add_action = new ActionCalendarEventCreate(this.guid, new CalendarEvent(entry_guid.Value, now, ""));
                this.actions.Add(add_action);
                this.evt = add_action.evt;
            }
            else
            {
                this.guid = guid.Value;
                this.evt  = this.state.events.events[this.guid];
            }
            InitializeComponent();
            FrameworkElement timestamp_box = calendar.timestamp_control();

            Grid.SetRow(timestamp_box, 0);
            Grid.SetColumn(timestamp_box, 1);
            this.main_grid.Children.Add(timestamp_box);
            this.timestamp_box = timestamp_box as ICalendarControl;
            if (this.timestamp_box is null)
            {
                throw new InvalidOperationException();
            }
            this.timestamp_box.calendar_value = this.evt.timestamp;
            FrameworkElement timestamp_diff_box = calendar.interval_control();

            Grid.SetRow(timestamp_diff_box, 0);
            Grid.SetColumn(timestamp_diff_box, 3);
            this.main_grid.Children.Add(timestamp_diff_box);
            this.timestamp_diff_box = timestamp_diff_box as ICalendarControl;
            if (this.timestamp_diff_box is null)
            {
                throw new InvalidOperationException();
            }
            decimal timestamp_diff = this.evt.timestamp - now;

            if (timestamp_diff < 0)
            {
                this.timestamp_diff_label.Content = "before";
                timestamp_diff = -timestamp_diff;
            }
            else
            {
                this.timestamp_diff_label.Content = "after";
            }
            this.timestamp_diff_box.calendar_value = timestamp_diff;
            this.current_timestamp_box.Text        = calendar.format_timestamp(now);
            this.timestamp_box.value_changed       = this.timestamp_changed;
            this.timestamp_diff_box.value_changed  = this.timestamp_diff_changed;
            this.repeat_box.IsChecked = (this.evt.interval is not null);
            FrameworkElement interval_box = calendar.interval_control();

            Grid.SetRow(interval_box, 0);
            Grid.SetColumn(interval_box, 9);
            this.main_grid.Children.Add(interval_box);
            this.interval_box = interval_box as ICalendarControl;
            if (this.interval_box is null)
            {
                throw new InvalidOperationException();
            }
            this.interval_box.calendar_value = (this.evt.interval ?? 0);
            this.name_box.Text        = this.evt.name;
            this.description_box.Text = this.evt.description;
        }
示例#2
0
 public override void merge_to(List <EntryAction> actions)
 {
     for (int i = actions.Count - 1; i >= 0; i--)
     {
         if (actions[i] is ActionCalendarEventCreate ext_evt_create)
         {
             if (ext_evt_create.guid == this.guid)
             {
                 // existing ActionCalendarEventCreate with this guid; update its "evt" field based on our "to" field and we're done
                 if (this.set_timestamp)
                 {
                     ext_evt_create.evt.timestamp = this.to.timestamp;
                 }
                 if (this.set_name)
                 {
                     ext_evt_create.evt.name = this.to.name;
                 }
                 if (this.set_desc)
                 {
                     ext_evt_create.evt.description = this.to.description;
                 }
                 if (this.set_interval)
                 {
                     ext_evt_create.evt.interval = this.to.interval;
                 }
                 return;
             }
         }
         if (actions[i] is ActionCalendarEventUpdate ext_evt_update)
         {
             if (ext_evt_update.guid == this.guid)
             {
                 // existing ActionCalendarEventUpdate with this guid; replace with a new adjust action with the sum of both adjustments
                 decimal from_timestamp = ext_evt_update.from.timestamp, to_timestamp = ext_evt_update.to.timestamp;
                 string  from_name = ext_evt_update.from.name, to_name = ext_evt_update.to.name;
                 string  from_description = ext_evt_update.from.description, to_description = ext_evt_update.to.description;
                 decimal?from_interval = ext_evt_update.from.interval, to_interval = ext_evt_update.to.interval;
                 bool    set_timestamp = ext_evt_update.set_timestamp || this.set_timestamp, set_name = ext_evt_update.set_name || this.set_name,
                         set_desc = ext_evt_update.set_desc || this.set_desc, set_interval = ext_evt_update.set_interval || this.set_interval;
                 if (this.set_timestamp)
                 {
                     if (!ext_evt_update.set_timestamp)
                     {
                         from_timestamp = this.from.timestamp;
                     }
                     to_timestamp = this.to.timestamp;
                 }
                 if (this.set_name)
                 {
                     if (!ext_evt_update.set_name)
                     {
                         from_name = this.from.name;
                     }
                     to_name = this.to.name;
                 }
                 if (this.set_desc)
                 {
                     if (!ext_evt_update.set_desc)
                     {
                         from_description = this.from.description;
                     }
                     to_description = this.to.description;
                 }
                 if (this.set_interval)
                 {
                     if (!ext_evt_update.set_interval)
                     {
                         from_interval = this.from.interval;
                     }
                     to_interval = this.to.interval;
                 }
                 if ((set_timestamp) && (from_timestamp == to_timestamp))
                 {
                     set_timestamp = false;
                 }
                 if ((set_name) && (from_name == to_name))
                 {
                     set_name  = false;
                     from_name = null;
                     to_name   = null;
                 }
                 if ((set_desc) && (from_description == to_description))
                 {
                     set_desc         = false;
                     from_description = null;
                     to_description   = null;
                 }
                 if ((set_interval) && (from_interval == to_interval))
                 {
                     set_interval  = false;
                     from_interval = null;
                     to_interval   = null;
                 }
                 actions.RemoveAt(i);
                 if ((set_timestamp) || (set_name) || (set_desc) || (set_interval))
                 {
                     CalendarEvent from = new CalendarEvent(ext_evt_update.from.entry_guid, from_timestamp, from_name, from_description, from_interval),
                                   to   = new CalendarEvent(this.to.entry_guid, to_timestamp, to_name, to_description, to_interval);
                     new ActionCalendarEventUpdate(this.guid, from, to, set_timestamp, set_name, set_desc, set_interval).merge_to(actions);
                 }
                 return;
             }
         }
     }
     actions.Add(this);
 }