public TaskWindow(CampaignSave save_state, CampaignState state, Calendar calendar, decimal now, Guid?entry_guid = null, Guid?guid = null) { this.valid = false; this.save_state = save_state; 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(); ActionTaskCreate add_action = new ActionTaskCreate(this.guid, new Task(entry_guid.Value, "")); this.actions.Add(add_action); this.task = add_action.task; } else { this.guid = guid.Value; this.task = this.state.tasks.tasks[this.guid]; } InitializeComponent(); this.name_box.Text = this.task.name; this.description_box.Text = this.task.description; this.current_timestamp_box.Text = calendar.format_timestamp(now); if (this.task.completed_guid is null) { FrameworkElement due_box = calendar.timestamp_control(); Grid.SetRow(due_box, 2); Grid.SetColumn(due_box, 1); this.main_grid.Children.Add(due_box); this.due_box = due_box as ICalendarControl; if (this.due_box is null) { throw new InvalidOperationException(); } FrameworkElement due_diff_box = calendar.interval_control(); Grid.SetRow(due_diff_box, 2); Grid.SetColumn(due_diff_box, 3); this.main_grid.Children.Add(due_diff_box); this.due_diff_box = due_diff_box as ICalendarControl; if (this.due_diff_box is null) { throw new InvalidOperationException(); } if (this.task.due is null) { this.due_checkbox.IsChecked = false; this.due_box.calendar_value = now; this.due_box.IsReadOnly = true; this.due_diff_box.calendar_value = 0; this.due_diff_box.IsReadOnly = true; } else { this.due_checkbox.IsChecked = true; this.due_box.calendar_value = this.task.due.Value; this.due_box.IsReadOnly = false; decimal due_diff = this.task.due.Value - now; if (due_diff < 0) { this.timestamp_diff_label.Content = "before"; due_diff = -due_diff; } else { this.timestamp_diff_label.Content = "after"; } this.due_diff_box.calendar_value = due_diff; this.due_diff_box.IsReadOnly = false; } this.due_box.value_changed = this.due_changed; this.due_diff_box.value_changed = this.due_diff_changed; } else { decimal?completed_timestamp = null; if (task.completed_guid == entry_guid) { completed_timestamp = now; } else { foreach (Entry entry in this.save_state.domain.entries) { if (entry.guid == task.completed_guid) { completed_timestamp = entry.timestamp; break; } } } if (completed_timestamp is null) { throw new InvalidOperationException(); } if (this.task.failed) { this.status_label.Content = "Failed:"; } else { this.status_label.Content = "Completed:"; } this.status_label.Visibility = Visibility.Visible; this.due_checkbox.Visibility = Visibility.Collapsed; this.timestamp_box.Text = calendar.format_timestamp(completed_timestamp.Value); this.timestamp_box.Visibility = Visibility.Visible; decimal timestamp_diff = completed_timestamp.Value - 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.Text = calendar.format_interval(timestamp_diff); this.timestamp_diff_box.Visibility = Visibility.Visible; } }
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; }