Example #1
0
        private void ButtonControl_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            string LStrDateTime   = string.Empty;
            string LStrSenderName = string.Empty;

            try
            {
                Microsoft.Windows.Controls.DatePicker LDateTimeSender = sender as Microsoft.Windows.Controls.DatePicker;
                LStrSenderName = LDateTimeSender.Name;
                if (LStrSenderName == "StartDate" && TextStartDateTime.IsEnabled == true)
                {
                    LStrDateTime           = TextStartDateTime.Text.Substring(11);
                    TextStartDateTime.Text = LDateTimeSender.SelectedDate.Value.ToString("yyyy-MM-dd") + " " + LStrDateTime;
                }
                if (LStrSenderName == "StartDate" && TextStartDateTime.IsEnabled == false)
                {
                    LStrDateTime = TextStartDateTime.Text.Substring(0, 10) + " 00:00:00";
                    LDateTimeSender.SelectedDate = Convert.ToDateTime(LStrDateTime);
                }
                if (LStrSenderName == "EndDate" && TextEndDateTime.IsEnabled == true)
                {
                    LStrDateTime         = TextEndDateTime.Text.Substring(11);
                    TextEndDateTime.Text = LDateTimeSender.SelectedDate.Value.ToString("yyyy-MM-dd") + " " + LStrDateTime;
                }
                if (LStrSenderName == "EndDate" && TextEndDateTime.IsEnabled == false)
                {
                    LStrDateTime = TextEndDateTime.Text.Substring(0, 10) + " 00:00:00";
                    LDateTimeSender.SelectedDate = Convert.ToDateTime(LStrDateTime);
                }
            }
            catch { }
        }
Example #2
0
        private void DatePickerCalendarClosed(object sender, RoutedEventArgs e)
        {
            // From .Net3.5 => .Net4.0,
            Microsoft.Windows.Controls.DatePicker picker = (Microsoft.Windows.Controls.DatePicker)sender;
            if (picker.Name == "FromDate")
            {
                DateTime?dt = picker.SelectedDate;
                if (dt.HasValue)
                {
                    this.FromDateText.Text = dt.Value.ToString();
                }

                if (!this.ValidTimeRange(this.FromDateText.Text, this.ToDateText.Text))
                {
                    this.FromDateText.Background = Brushes.Pink;
                }
                else
                {
                    this.FromDateText.Background = Brushes.White;
                    this.ToDateText.Background   = Brushes.White;
                }
            }
            else if (picker.Name == "ToDate")
            {
                DateTime?dt = picker.SelectedDate;
                if (dt.HasValue)
                {
                    DateTime to = dt.Value.AddDays(1).AddSeconds(-1);
                    this.ToDateText.Text = to.ToString();
                }

                if (!this.ValidTimeRange(this.FromDateText.Text, this.ToDateText.Text))
                {
                    this.ToDateText.Background = Brushes.Pink;
                }
                else
                {
                    this.FromDateText.Background = Brushes.White;
                    this.ToDateText.Background   = Brushes.White;
                }
            }
        }