private void RefreshInterval() { int index = this.comboBoxInterval.SelectedIndex; IntervalDate custom = null; if (this.comboBoxInterval.Items.Count > 4) { IntervalDate tmp = (this.comboBoxInterval.Items[4] as IntervalDate); custom = new IntervalDate() { Label = "Custom", Date = this.startTime, DateFormat = tmp.DateFormat, DelayType = tmp.DelayType, Delay = tmp.Delay }; } this.comboBoxInterval.Items.Clear(); this.comboBoxInterval.Items.Add(new IntervalDate() { Label = "Day", Date = this.startTime, Delay = 1 }); IntervalDate week = new IntervalDate() { Label = "Week", DelayType = DelayType.Week }; switch(this.startTime.DayOfWeek) { case DayOfWeek.Monday: week.Date = this.startTime; break; case DayOfWeek.Tuesday: week.Date = this.startTime.AddDays(-1); break; case DayOfWeek.Wednesday: week.Date = this.startTime.AddDays(-2); break; case DayOfWeek.Thursday: week.Date = this.startTime.AddDays(-3); break; case DayOfWeek.Friday: week.Date = this.startTime.AddDays(-4); break; case DayOfWeek.Saturday: week.Date = this.startTime.AddDays(-5); break; case DayOfWeek.Sunday: week.Date = this.startTime.AddDays(-6); break; } this.comboBoxInterval.Items.Add(week); IntervalDate month = new IntervalDate() { Label = "Month", Date = new DateTime(this.startTime.Year, this.startTime.Month, 1), DateFormat = "MM.yyyy", DelayType = DelayType.Month}; this.comboBoxInterval.Items.Add(month); IntervalDate year = new IntervalDate() { Label = "Year", Date = new DateTime(this.startTime.Year, 1, 1), DateFormat = "yyyy", DelayType = DelayType.Year }; this.comboBoxInterval.Items.Add(year); if (custom != null) { this.comboBoxInterval.Items.Add(custom); } this.comboBoxInterval.SelectedIndex = index; }
private void buttonSelect_Click(object sender, RoutedEventArgs e) { IntervalWindow window = new IntervalWindow(); window.Owner = this; window.StartDate = this.startTime; window.EndDate = this.startTime; if (window.ShowDialog() == true) { int delay = (int)(window.EndDate.Value.AddDays(1) - window.StartDate.Value).TotalDays; IntervalDate custom = new IntervalDate() { Label = "Custom", Date = window.StartDate.Value.Date.ToUniversalTime(), DateFormat = "dd.MM.yyyy", DelayType = DelayType.Day, Delay= delay }; this.comboBoxInterval.Items.Add(custom); this.comboBoxInterval.SelectedIndex = this.comboBoxInterval.Items.Count - 1; } }