/// <summary>
        ///     When overridden in a derived class, is invoked whenever application code or internal processes call
        ///     <see cref="M:System.Windows.FrameworkElement.ApplyTemplate" />.
        /// </summary>
        public override void OnApplyTemplate()
        {
            UnSubscribeEvents();

            base.OnApplyTemplate();

            _popup        = GetTemplateChild(ElementPopup) as Popup;
            _button       = GetTemplateChild(ElementButton) as Button;
            _hourInput    = GetTemplateChild(ElementHourPicker) as Selector;
            _minuteInput  = GetTemplateChild(ElementMinutePicker) as Selector;
            _secondInput  = GetTemplateChild(ElementSecondPicker) as Selector;
            _hourHand     = GetTemplateChild(ElementHourHand) as FrameworkElement;
            _ampmSwitcher = GetTemplateChild(ElementAmPmSwitcher) as Selector;
            _minuteHand   = GetTemplateChild(ElementMinuteHand) as FrameworkElement;
            _secondHand   = GetTemplateChild(ElementSecondHand) as FrameworkElement;
            _textBox      = GetTemplateChild(ElementTextBox) as DatePickerTextBox;

            SetHandVisibility(HandVisibility);
            SetPickerVisibility(PickerVisibility);

            SetHourPartValues(SelectedDateTime.GetValueOrDefault().TimeOfDay);
            WriteValueToTextBox();

            SetDefaultTimeOfDayValues();
            SubscribeEvents();
            ApplyCulture();
            ApplyBindings();
        }
Example #2
0
        private void GoToPreviousDateTime_Click(object sender, RoutedEventArgs e)
        {
            if (semanticzoomDate.IsZoomedInViewActive)
            {
                if (MonthTitle == 1)
                {
                    MonthTitle = 13;
                }
                MonthTitle--;

                DateTime datetime = DateTime.Now;
                if (MonthTitle == 12)
                {
                    datetime = new DateTime(SelectedDateTime.Year - 1, 12, datetime.Day);
                    YearTitle--;
                }
                else
                {
                    if (SelectedDateTime.Month == 1)
                    {
                        SelectedDateTime = new DateTime(SelectedDateTime.Year, 12, SelectedDateTime.Day, SelectedDateTime.Hour, SelectedDateTime.Minute, SelectedDateTime.Second);
                    }
                    int count = SelectedDateTime.Month - MonthTitle;
                    datetime = new DateTime(SelectedDateTime.Year, MonthTitle, SelectedDateTime.AddMonths(-count).Day);
                }
                UpdateDays(datetime);
            }
            else
            {
                YearTitle--;

                CurrentDateTime = new DateTime(SelectedDateTime.Year - 1, MonthTitle, SelectedDateTime.AddMonths(MonthTitle).Day);
            }
        }
        protected virtual string GetValueForTextBox()
        {
            var format          = SelectedTimeFormat == TimePickerFormat.Long ? string.Intern(SpecificCultureInfo.DateTimeFormat.LongTimePattern) : string.Intern(SpecificCultureInfo.DateTimeFormat.ShortTimePattern);
            var valueForTextBox = SelectedDateTime?.ToString(string.Intern(format), SpecificCultureInfo);

            return(valueForTextBox);
        }
Example #4
0
        /// <inheritdoc/>
        protected override void SetSelectedDateTime()
        {
            if (textBox is null)
            {
                return;
            }

            const DateTimeStyles dateTimeParseStyle = DateTimeStyles.AllowWhiteSpaces
                                                      & DateTimeStyles.AssumeLocal
                                                      & DateTimeStyles.NoCurrentDateDefault;

            if (DateTime.TryParse(textBox.Text, SpecificCultureInfo, dateTimeParseStyle, out var timeSpan))
            {
                SetCurrentValue(SelectedDateTimeProperty, SelectedDateTime.GetValueOrDefault().Date + timeSpan.TimeOfDay);
            }
            else
            {
                SetCurrentValue(SelectedDateTimeProperty, null);
                if (SelectedDateTime == null)
                {
                    // if already null, overwrite wrong data in TextBox
                    WriteValueToTextBox();
                }
            }
        }
Example #5
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _partTime = Template.FindName("PART_Time", this) as CnDTimeInputTextBox;
            if (_partTime == null)
            {
                throw new Exception("PART_Time is missing");
            }
            _partTime.AddExceptionKey(Key.Add);
            _partTime.AddExceptionKey(Key.Subtract);
            _partTime.TimeChanged += OnTimeChanged;

            var partPreviousDay = Template.FindName("PART_PreviousDay", this) as Button;

            if (partPreviousDay != null)
            {
                partPreviousDay.Click += (s, e) => SelectedDateTime = SelectedDateTime.AddDays(-1);
            }

            var partNextDay = Template.FindName("PART_NextDay", this) as Button;

            if (partNextDay != null)
            {
                partNextDay.Click += (s, e) => SelectedDateTime = SelectedDateTime.AddDays(1);
            }
        }
 public BitDateTimePickerSampleViewModel()
 {
     SelectedDateTime  = DateTime.Now;
     ChangeSelecedDate = new Command(() =>
     {
         SelectedDateTime = SelectedDateTime.AddDays(3);
     });
 }
        ///<summary>
        ///Retrieves the formatted value of the cell.
        ///</summary>
        ///
        ///<returns>
        ///An <see cref="T:System.Object"></see> that represents the formatted version of the cell contents.
        ///</returns>
        ///
        ///<param name="context">A bitwise combination of <see cref="T:System.Windows.Forms.DataGridViewDataErrorContexts"></see> values that specifies the context in which the data is needed.</param>
        public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
        {
            if (mv.MonthViewControl.IsNull)
            {
                return(string.Empty);
            }

            return(SelectedDateTime?.ToString("G"));
        }
        private void ResetAndSelectYear(int year)
        {
            if (GrdYearPanel.Children.Count != 15)
            {
                return;
            }

            BtnYearInterval.Content = SelectedDateTime.AddYears(-7).Year + "年 - " + SelectedDateTime.AddYears(7).Year + "年";

            for (int i = -7; i < 8; i++)
            {
                var radio = GrdYearPanel.Children[i + 7] as PURadioButton;
                radio.Content = (year + i) + "年";
                radio.Tag     = year + i;
                if (i == 0)
                {
                    radio.IsChecked = true;
                }

                if (MaxDateTime == null && MinDateTime == null)
                {
                    radio.IsEnabled = true;
                    radio.Opacity   = 1;
                }

                else if (MaxDateTime != null && MinDateTime != null)
                {
                    if ((year + i) <= ((DateTime)MaxDateTime).Year && (year + i) >= ((DateTime)MinDateTime).Year)
                    {
                        radio.IsEnabled = true;
                        radio.Opacity   = 1;
                    }
                    else
                    {
                        radio.IsEnabled = false;
                        radio.Opacity   = 0.2;
                    }
                }
                else if (MaxDateTime != null && (year + i) <= ((DateTime)MaxDateTime).Year)
                {
                    radio.IsEnabled = true;
                    radio.Opacity   = 1;
                }
                else if (MinDateTime != null && (year + i) >= ((DateTime)MinDateTime).Year)
                {
                    radio.IsEnabled = true;
                    radio.Opacity   = 1;
                }
                else
                {
                    radio.IsEnabled = false;
                    radio.Opacity   = 0.2;
                }
            }
        }
 private void BtnMonthRight_Click(object sender, RoutedEventArgs e)
 {
     if (MaxDateTime == null || SelectedDateTime.AddYears(1) <= MaxDateTime)
     {
         SelectedDateTime = SelectedDateTime.AddYears(1);
     }
     else
     {
         SelectedDateTime = (DateTime)MaxDateTime;
     }
 }
 private void BtnMonthLeft_Click(object sender, RoutedEventArgs e)
 {
     if (MinDateTime == null || SelectedDateTime.AddYears(-1) >= MinDateTime)
     {
         SelectedDateTime = SelectedDateTime.AddYears(-1);
     }
     else
     {
         SelectedDateTime = (DateTime)MinDateTime;
     }
 }
        private void Render()
        {
            SelectedYearMonth   = SelectedDateTime.ToString("yyyy年MM月");
            SelectedYear        = SelectedDateTime.ToString("yyyy年");
            SelectedHour        = SelectedDateTime.ToString("HH");
            SelectedMinutes     = SelectedDateTime.ToString("mm");
            SelectedDateTimeStr = SelectedDateTime.ToString($"yyyy年MM月dd日 星期{ToCNWeekString()} HH:mm");
            YearNum             = SelectedDateTime.Year;
            MonthNum            = SelectedDateTime.Month;

            //SelectedTime = SelectedDateTime.ToString("HH:mm");
        }
Example #12
0
        async public Task <Challenge> PostChallenge()
        {
            Challenge.ProposedTime = SelectedDateTime.ToUniversalTime();
            var success = await AzureService.Instance.ChallengeManager.InsertAsync(Challenge);

            Challenge.League.LocalRefresh();

            if (success)
            {
                MessagingCenter.Send(App.Instance, Messages.ChallengesUpdated);
                return(Challenge);
            }

            return(null);
        }
        private void MarkSelectedBtn()
        {
            //标记选择的日期
            string key = SelectedDateTime.ToString("yyyyMd");

            if (daysButtons.ContainsKey(key))
            {
                daysButtons[key].IsEnabled = false;
                if (selectedButton != null)
                {
                    selectedButton.IsEnabled = true;
                }
                selectedButton = daysButtons[key];
            }
        }
        async public Task <Challenge> PostChallenge()
        {
            Challenge.ProposedTime = SelectedDateTime.ToUniversalTime();
            var task = AzureService.Instance.SaveChallenge(Challenge);

            await RunSafe(task);

            if (task.IsFaulted)
            {
                return(null);
            }

            Challenge.League.RefreshChallenges();
            MessagingCenter.Send <App>(App.Current, Messages.ChallengesUpdated);
            return(Challenge);
        }
Example #15
0
        private void UpdateText()
        {
            switch (DateTimePickerMode)
            {
            case DateTimePickerMode.DateTime:
                Text = SelectedDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                break;

            case DateTimePickerMode.Date:
                Text = SelectedDateTime.ToString("yyyy-MM-dd");
                break;

            case DateTimePickerMode.Time:
                Text = SelectedDateTime.ToString("HH:mm:ss");
                break;
            }
        }
 /// <summary>
 /// Updates text representation of the selected value
 /// </summary>
 public override void UpdateTextValue()
 {
     if (mv.MonthViewControl.IsNull)
     {
         Text = FALocalizeManager.GetLocalizerByCulture(Thread.CurrentThread.CurrentUICulture).GetLocalizedString(StringID.Validation_NullText);
     }
     else
     {
         if (mv.MonthViewControl.DefaultCulture.Equals(mv.MonthViewControl.PersianCulture))
         {
             Text = ((PersianDate)SelectedDateTime).ToString(GetFormatByFormatInfo(FormatInfo));
         }
         else
         {
             Text = SelectedDateTime.ToString(GetFormatByFormatInfo(FormatInfo), mv.MonthViewControl.DefaultCulture);
         }
     }
 }
 public HseDatePicker()
 {
     this.InitializeComponent();
     //DataContext = this;
     InputTextBox.AddHandler(KeyDownEvent, new KeyEventHandler((s, e) =>
     {
         if (e.Key == Windows.System.VirtualKey.Enter || e.Key == Windows.System.VirtualKey.Space)
         {
             //DatePickerPart.SelectedDateRange = new CalendarDateRange(SelectedDateTime, SelectedDateTime);
             //DatePickerPart.DisplayDate = SelectedDateTime;
             UpdateSelectedDateTimeString(SelectedDateTime.ToString("dd/MM/yyyy"));
         }
         else if (e.Key == Windows.System.VirtualKey.Delete)
         {
             SelectedDateTime = new DateTime();
             //DatePickerPart.SelectedDateRange = null;
             //DatePickerPart.MoveToDate(DateTime.Now);
             UpdateSelectedDateTimeString("");
         }
     }), true);
 }
Example #18
0
 /// <summary>
 /// 텍스트 반환 오버라이딩 함수
 /// </summary>
 ///
 /// <returns>[string] yyyy-MM-dd HH:mm 형식의 시간 문자열</returns>
 protected override string GetValueForTextBox()
 {
     return(SelectedDateTime?.ToString("yyyy-MM-dd HH:mm"));
 }
Example #19
0
        //------------------------------------------------------------------------------------------
        protected override void Render(HtmlTextWriter writer)
        {
            Table table = new Table();

            table.BorderColor = BorderColor;
            table.BackColor   = BackColor;
            table.BorderStyle = BorderStyle;
            table.BorderWidth = BorderWidth;
            table.CellPadding = 0;
            table.CellSpacing = 0;

            int selectedmonth = DateTime.Now.Month;
            int selectedyear  = DateTime.Now.Year;

            WeavverCalendarMonthLoadEventArgs monthloadargs = new WeavverCalendarMonthLoadEventArgs(SelectedDateTime);

            if (MonthLoad != null)
            {
                MonthLoad(this, monthloadargs);
            }

            DateTime datetime = SelectedDateTime.Subtract(TimeSpan.FromDays(SelectedDateTime.Day));

            datetime    = datetime.Subtract(TimeSpan.FromDays(DayNumber(datetime.DayOfWeek) - 1));
            table.Width = Width;

            table.Rows.Add(new TableRow());
            TableCell header1 = new TableCell();

            header1.BackColor       = ColorTranslator.FromHtml("#AFB29C");
            header1.Height          = Unit.Parse("30px");
            header1.ColumnSpan      = 7;
            header1.HorizontalAlign = HorizontalAlign.Center;
            header1.Text            = MonthText(datetime.Month);
            table.Rows[0].Controls.Add(header1);

            table.Rows.Add(new TableRow());
            table.Rows[1].BackColor       = DaysBackColor;
            table.Rows[1].HorizontalAlign = HorizontalAlign.Center;
            AddHeaderColumn(table, "Sunday");
            AddHeaderColumn(table, "Monday");
            AddHeaderColumn(table, "Tuesday");
            AddHeaderColumn(table, "Wednesday");
            AddHeaderColumn(table, "Thursday");
            AddHeaderColumn(table, "Friday");
            AddHeaderColumn(table, "Saturday");
            table.Rows.Add(new TableRow());
            while (true)
            {
                TableCell daycell;
                if (selectedmonth == datetime.Month)
                {
                    daycell = AddDayColumn(table, datetime.Day.ToString(), NormalColor);
                }
                else
                {
                    daycell           = AddDayColumn(table, datetime.Day.ToString(), ShadeColor);
                    daycell.ForeColor = Color.LightGray;
                }
                WeavverCalendarDayLoadEventArgs dayloadargs = new WeavverCalendarDayLoadEventArgs(datetime, daycell);
                if (DayLoad != null)
                {
                    DayLoad(this, dayloadargs);
                }

                if (selectedmonth != datetime.Month &&
                    !GreaterMonth(selectedmonth, selectedyear, datetime.Month, datetime.Year) &&
                    datetime.DayOfWeek == DayOfWeek.Saturday)
                {
                    break;
                }
                else if (datetime.DayOfWeek == DayOfWeek.Saturday)
                {
                    table.Rows.Add(new TableRow());
                }
                datetime = datetime.AddDays(1);
            }

            table.Rows.Add(new TableRow());
            table.Rows[table.Rows.Count - 1].BackColor = HeaderBackColor;

            DropDownList monthlist = new DropDownList();

            monthlist.Items.Add("January");
            monthlist.Items.Add("February");
            monthlist.Items.Add("March");
            monthlist.Items.Add("April");
            monthlist.Items.Add("May");
            monthlist.Items.Add("June");
            monthlist.Items.Add("July");
            monthlist.Items.Add("August");
            monthlist.Items.Add("September");
            monthlist.Items.Add("October");
            monthlist.Items.Add("November");
            monthlist.Items.Add("December");
            monthlist.Width = Unit.Parse("100px");

            TableCell headera = new TableCell();

            headera.ColumnSpan = 2;

            TableCell headerb = new TableCell();

            headerb.ColumnSpan      = 3;
            headerb.HorizontalAlign = HorizontalAlign.Left;
            //headerb.Text                  = MonthText(datetime.Month);

            Button yearprevious = new Button();

            yearprevious.Text        = "-";
            yearprevious.BorderWidth = Unit.Parse("1px");
            yearprevious.BorderStyle = BorderStyle.Solid;
            yearprevious.Width       = Unit.Parse("22px");
            yearprevious.BorderColor = Color.DarkGray;

            TextBox year = new TextBox();

            year.Text        = " " + SelectedDateTime.Year.ToString();
            year.BorderWidth = Unit.Parse("1px");
            year.Height      = Unit.Parse("22px");
            year.BorderStyle = BorderStyle.Solid;
            year.BorderColor = Color.DarkGray;
            year.Width       = Unit.Parse("50px");

            Button yearnext = new Button();

            yearnext.Text        = "+";
            yearnext.BorderWidth = Unit.Parse("1px");
            yearnext.BorderStyle = BorderStyle.Solid;
            yearnext.BorderColor = Color.DarkGray;
            yearnext.Width       = Unit.Parse("22px");

            TableCell headerc = new TableCell();

            headerc.ColumnSpan      = 2;
            headerc.HorizontalAlign = HorizontalAlign.Right;

            headera.Controls.Add(yearprevious);
            headera.Controls.Add(year);
            headera.Controls.Add(yearnext);

            headerc.Controls.Add(monthlist);

            table.Rows[table.Rows.Count - 1].Style.Add("padding", "2");
            table.Rows[table.Rows.Count - 1].Controls.Add(headera);
            table.Rows[table.Rows.Count - 1].Controls.AddAt(1, headerb);
            table.Rows[table.Rows.Count - 1].Controls.AddAt(2, headerc);

            this.Controls.Add(table);
            base.Render(writer);
        }
Example #20
0
        protected virtual string GetValueForTextBox()
        {
            var valueForTextBox = SelectedDateTime?.ToString();

            return(valueForTextBox);
        }