Пример #1
0
        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();
            }
        }
Пример #2
0
        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.");
            }
        }
Пример #3
0
        public override void OnApplyTemplate()
        {
            // base.OnApplyTemplate(); //not needed if deriving from Control

            PrevRangeButton = GetTemplateChild(PrevRangeButtonName) as Button;
            NextRangeButton = GetTemplateChild(NextRangeButtonName) as Button;

            SetTextBlockLocalizedText(FromTextBlockName, FromTextBlockResourceKey);
            SetTextBlockLocalizedText(ToTextBlockName, ToTextBlockResourceKey);

            if (null == _dateRanges)
            {
                _dateRanges = DateRangeHelper.BuildDateRangeList(_firstDayOfWeekProvider, _resourceManager);
                _dateRanges.CurrentChanged += OnCurrentChanged;
            }

            InitDatePropertiesSetByUser();

            var rangeComboBox     = GetTemplateChild(RangeComboBoxName) as ItemsControl;
            var bindingExpression = rangeComboBox?.GetBindingExpression(ItemsControl.ItemsSourceProperty);

            bindingExpression?.UpdateTarget();
        }