Exemplo n.º 1
0
        void DatePartTextBox_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            DatePartTextBox t = sender as DatePartTextBox;

            if (t == null)
            {
                return;
            }

            TextBoxType tType = t.PartType;

            bool positiveIncrement = e.Delta > 0;
            int  currentValue      = -1;

            ChangedValue(t, tType, positiveIncrement, currentValue);
        }
Exemplo n.º 2
0
        void DatePartTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            bool isArrowsPressed = e.Key == Key.Up || e.Key == Key.Down || e.Key == Key.Left || e.Key == Key.Right;

            if (isArrowsPressed)
            {
                DatePartTextBox t = sender as DatePartTextBox;
                if (t == null)
                {
                    return;
                }

                TextBoxType tType        = t.PartType;
                int         currentValue = -1;

                bool positiveIncrement = e.Key == Key.Up || e.Key == Key.Right;

                ChangedValue(t, tType, positiveIncrement, currentValue);
            }
        }
Exemplo n.º 3
0
        private void ChangedValue(DatePartTextBox t, TextBoxType tType, bool positiveIncrement, int currentValue)
        {
            if (Int32.TryParse(t.Text, out currentValue))
            {
                switch (tType)
                {
                case TextBoxType.Year:
                    if (positiveIncrement)
                    {
                        t.Text = (currentValue + 1).ToString();
                    }
                    else
                    {
                        if (currentValue > 1900)
                        {
                            t.Text = (currentValue - 1).ToString();
                        }
                    }
                    break;

                case TextBoxType.Month:
                    if (positiveIncrement)
                    {
                        if (currentValue < 12)
                        {
                            t.Text = (currentValue + 1).ToString();
                        }
                    }
                    else
                    {
                        if (currentValue > 1)
                        {
                            t.Text = (currentValue - 1).ToString();
                        }
                    }
                    break;

                case TextBoxType.Day:
                {
                    if (positiveIncrement && PartDetail != null)
                    {
                        DateIntervalInputBox dBox = PartDetail as DateIntervalInputBox;
                        if (dBox != null)
                        {
                            if (IsStart)
                            {
                                int daysInMonth = DateTime.DaysInMonth(dBox.DateInterval.StartDateParts.Year, dBox.DateInterval.StartDateParts.Month);
                                if (currentValue < daysInMonth)
                                {
                                    t.Text = (currentValue + 1).ToString();
                                }
                            }
                            else
                            {
                                int daysInMonth = DateTime.DaysInMonth(dBox.DateInterval.EndDateParts.Year, dBox.DateInterval.EndDateParts.Month);
                                if (currentValue < daysInMonth)
                                {
                                    t.Text = (currentValue + 1).ToString();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (currentValue > 1)
                        {
                            t.Text = (currentValue - 1).ToString();
                        }
                    }
                }
                break;
                }
            }

            t.SelectAll();
        }