Пример #1
0
        public static void NextRemind(Ddl ddl, bool recalculate)
        {
            DateTime now = DateTime.Now;

            if (recalculate)
            {
                ddl.RemindTime = now.Date.AddDays(-1) + ddl.RemindTime.TimeOfDay;
            }

            if (ddl.IsRemind == 0)
            {
                DateTime rt = ddl.RemindTime;
                string[] remindIntervalString = ddl.RemindInterval.Split('/');
                int[]    remindInterval       = { int.Parse(remindIntervalString[0]), int.Parse(remindIntervalString[1]), int.Parse(remindIntervalString[2]) };

                while (rt <= now)
                {
                    rt = AddTime(rt, remindInterval[0], remindInterval[1], remindInterval[2], 0, 0, 0, ddl.IsChineseCalender);
                }
                ddl.RemindTime = rt;
                DatabaseOperation.Update(ddl.Id, "RemindTime", rt);
            }
            else
            {
                DateTime rt = ddl.RemindTime;

                while (rt <= now || ddl.RemindInterval[Convert.ToInt16(rt.DayOfWeek)] != '1')
                {
                    rt = rt.AddDays(1);
                }
                ddl.RemindTime = rt;
                DatabaseOperation.Update(ddl.Id, "RemindTime", rt);
            }
        }
Пример #2
0
        private static void NextLoop(Ddl ddl)
        {
            string[] str = ddl.LoopInterval.Split('/');
            DateTime startTime = ddl.StartTime, endTime = ddl.EndTime;

            int[] loopInterval = new int[6];
            for (int i = 0; i < 6; i++)
            {
                loopInterval[i] = int.Parse(str[i]);
            }

            startTime = endTime;
            endTime   = AddTime(endTime, loopInterval[0], loopInterval[1], loopInterval[2], loopInterval[3], loopInterval[4], loopInterval[5], ddl.IsChineseCalender);

            while (endTime <= DateTime.Now)
            {
                startTime = AddTime(startTime, loopInterval[0], loopInterval[1], loopInterval[2], loopInterval[3], loopInterval[4], loopInterval[5], ddl.IsChineseCalender);
                endTime   = AddTime(endTime, loopInterval[0], loopInterval[1], loopInterval[2], loopInterval[3], loopInterval[4], loopInterval[5], ddl.IsChineseCalender);
            }
            ddl.StartTime = startTime;
            ddl.EndTime   = endTime;

            DatabaseOperation.Update(ddl);
        }
Пример #3
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);
        }