private void btnRemoveIntervalFromQueryList_Click(object sender, EventArgs e) { if (comboQueryDateRangeList.SelectedIndex > -1) { var dateIntervalId = (ComboBoxItem)comboQueryDateRangeList.SelectedItem; DateRangeList.RemoveAll(x => x.Id == (int)dateIntervalId.Value); comboQueryDateRangeList.Items.Clear(); if (DateRangeList.Count > 0) { foreach (DateRange dr in DateRangeList.OrderBy(x => x.From)) { var queryDateRangeItem = new ComboBoxItem { Value = dr.Id, Text = $"{dr.From} - {dr.To}" }; comboQueryDateRangeList.Items.Add(queryDateRangeItem); } comboQueryDateRangeList.SelectedIndex = 0; } else { comboQueryDateRangeList.Text = string.Empty; btnRemoveIntervalFromQueryList.Enabled = false; } lblFilteredDateIntervalCount.Text = "Date range count: " + DateRangeList.Count.ToString(); } }
private void btnAddIntervalToQueryList_Click(object sender, EventArgs e) { DateTime queryStartTime, queryEndTime; queryStartTime = dtStartDateTime.Value; queryEndTime = dtEndDateTime.Value; if (queryStartTime < queryEndTime) { if (DateRangeList.Count == 0 || !IsThereOverlap(DateRangeList, queryStartTime, queryEndTime)) { var dateRange = new DateRange() { Id = DateRangeList.Count == 0 ? 1 : DateRangeList.Max(x => x.Id) + 1, From = queryStartTime, To = queryEndTime }; DateRangeList.Add(dateRange); comboQueryDateRangeList.Items.Clear(); foreach (DateRange dr in DateRangeList.OrderBy(x => x.From)) { var queryDateRangeItem = new ComboBoxItem { Value = dr.Id, Text = $"{dr.From} - {dr.To}" }; comboQueryDateRangeList.Items.Add(queryDateRangeItem); } comboQueryDateRangeList.SelectedIndex = 0; lblFilteredDateIntervalCount.Text = "Date range count: " + DateRangeList.Count.ToString(); btnRemoveIntervalFromQueryList.Enabled = true; } else { MessageBox.Show("There are overlapping dates! Please check the selected date interval."); } } else { MessageBox.Show("Please specify the query start and end dates correctly! Start date must be smaller than end date."); } }