Exemple #1
0
 private void EndMonth_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if ((bool)!ChineseCheckbox.IsChecked)
     {
         return;
     }
     if (HintAssist.GetHint(StartMonth).ToString() == "月")
     {
         HintAssist.SetHint(StartMonth, "闰月");
     }
     else
     {
         HintAssist.SetHint(StartMonth, "月");
     }
 }
Exemple #2
0
        private bool GetEndTime(out DateTime endTime)
        {
            endTime = new DateTime();
            ChineseLunisolarCalendar clc = new ChineseLunisolarCalendar();
            DateTime?st;
            int      year, month, day;

            if (!DurationBtn.IsEnabled)  //end time
            {
                st = EndTimePicker.SelectedTime;
                if (!st.HasValue)
                {
                    ShowSnakebar(HintAssist.GetHint(EndTimePicker) + NullError.Text);
                    return(false);
                }
                DateTime selectedTime = (DateTime)st;

                if (GetIntFromTextBox(EndYear, out year) && GetIntFromTextBox(EndMonth, out month) && GetIntFromTextBox(EndDay, out day))
                {
                    if ((bool)ChineseCheckbox.IsChecked)
                    {
                        if (day > clc.GetDaysInMonth(year, month))
                        {
                            ShowSnakebar(EndDateError.Text);
                            return(false);
                        }


                        int leapMonth = clc.GetLeapMonth(year) - 1;
                        if (HintAssist.GetHint(EndMonth).ToString() == "闰月")
                        {
                            if (month == leapMonth)
                            {
                                month++;
                            }
                            else
                            {
                                ShowSnakebar(EndDateError.Text);
                                return(false);
                            }
                        }
                        else
                        {
                            if (leapMonth > 0 && month > leapMonth)
                            {
                                month++;
                            }
                        }
                        endTime = clc.ToDateTime(year, month, day, selectedTime.Hour, selectedTime.Minute, selectedTime.Second, 0);
                    }
                    else
                    {
                        if (day > DateTime.DaysInMonth(year, month))
                        {
                            ShowSnakebar(EndDateError.Text);
                            return(false);
                        }
                        endTime = new DateTime(year, month, day, selectedTime.Hour, selectedTime.Minute, selectedTime.Second);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else   //duration
            {
                if (GetIntFromTextBox(DurationYear, out year) && GetIntFromTextBox(DurationMonth, out month) && GetIntFromTextBox(DurationDay, out day) &&
                    GetIntFromTextBox(DurationHour, out int hour) && GetIntFromTextBox(DurationMinute, out int minute) && GetIntFromTextBox(DurationSecond, out int second))
                {
                    if (year + month + day + hour + minute + second == 0)
                    {
                        ShowSnakebar(DurationBtn.Content + ZerotimeError.Text);
                        return(false);
                    }
                    else
                    {
                        endTime = DdlOperation.AddTime(ddl.StartTime, year, month, day, hour, minute, second, (bool)ChineseCheckbox.IsChecked);
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Exemple #3
0
        private bool GetStartTime(out DateTime startTime)
        {
            startTime = new DateTime();
            ChineseLunisolarCalendar clc = new ChineseLunisolarCalendar();
            DateTime?st;
            int      year, month, day;

            st = StartTimePicker.SelectedTime;
            if (!st.HasValue)
            {
                ShowSnakebar(HintAssist.GetHint(StartTimePicker) + NullError.Text);
                return(false);
            }

            DateTime selectedTime = (DateTime)st;

            if (GetIntFromTextBox(StartYear, out year) && GetIntFromTextBox(StartMonth, out month) && GetIntFromTextBox(StartDay, out day))
            {
                if ((bool)ChineseCheckbox.IsChecked)
                {
                    if (day > clc.GetDaysInMonth(year, month))
                    {
                        ShowSnakebar(StartDateError.Text);
                        return(false);
                    }

                    int leapMonth = clc.GetLeapMonth(year) - 1;
                    if (HintAssist.GetHint(StartMonth).ToString() == "闰月")
                    {
                        if (month == leapMonth)
                        {
                            month++;
                        }
                        else
                        {
                            ShowSnakebar(StartDateError.Text);
                            return(false);
                        }
                    }
                    else
                    {
                        if (leapMonth > 0 && month > leapMonth)
                        {
                            month++;
                        }
                    }

                    startTime = clc.ToDateTime(year, month, day, selectedTime.Hour, selectedTime.Minute, selectedTime.Second, 0);
                }
                else
                {
                    if (day > DateTime.DaysInMonth(year, month))
                    {
                        ShowSnakebar(StartDateError.Text);
                        return(false);
                    }
                    startTime = new DateTime(year, month, day, selectedTime.Hour, selectedTime.Minute, selectedTime.Second);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        private void YesBtn_Click(object sender, RoutedEventArgs e)
        {
            //set name
            if (DdlNameTextBox.Text.Length == 0)
            {
                ShowSnakebar(HintAssist.GetHint(DdlNameTextBox) + NullError.Text);
                return;
            }
            ddl.Name = DdlNameTextBox.Text;

            //set priority
            ddl.Priority = DdlPriority.Value;

            //set start time
            if (!GetStartTime(out DateTime startTime))
            {
                return;
            }
            ddl.StartTime = startTime;

            //set end time
            if (!GetEndTime(out DateTime endTime))
            {
                return;
            }
            ddl.EndTime           = endTime;
            ddl.IsChineseCalender = (bool)ChineseCheckbox.IsChecked;

            //check start time < end time
            if (endTime.CompareTo(startTime) <= 0)
            {
                ShowSnakebar(StartEndTimeError.Text);
                return;
            }

            //set loop
            String loopInterval = "";

            if ((bool)LoopCheckbox.IsChecked && !GetLoopInterval(out loopInterval))
            {
                return;
            }
            ddl.IsLoop = (bool)LoopCheckbox.IsChecked;
            if (ddl.IsLoop)
            {
                ddl.LoopInterval = loopInterval;
            }

            //set inform
            ddl.Inform = ((bool)NoticeCheckbox.IsChecked ? "1" : "0") +
                         ((bool)WindowCheckbox.IsChecked ? "1" : "0") +
                         ((bool)SoundCheckbox.IsChecked ? "1" : "0");

            //set remind
            string remindInterval = "";

            if ((bool)RemindCheckbox.IsChecked && !GetRemindInterval(out remindInterval))
            {
                return;
            }
            ddl.IsRemind = (bool)RemindCheckbox.IsChecked ? 0 : -1;
            if (ddl.IsRemind != -1)
            {
                ddl.RemindInterval = remindInterval;
                DateTime?st = RemindTimePicker.SelectedTime;
                if (!st.HasValue)
                {
                    ShowSnakebar(HintAssist.GetHint(RemindTimePicker) + NullError.Text);
                    return;
                }
                ddl.RemindTime = ddl.StartTime.Date + ((DateTime)st).TimeOfDay;

                if (RemindTimeGrid.SelectedIndex == 1)
                {
                    ddl.IsRemind = 1;
                }
                DdlOperation.NextRemind(ddl, true);
            }

            if (id == -1)
            {
                DatabaseOperation.Insert(ddl);
            }
            else
            {
                DatabaseOperation.Update(ddl);
            }

            DdlOperation.RefreshDdls();

            DialogResult = true;
            CloseWindow(sender, e);
        }