Beispiel #1
0
        private void CreateSchedulerItem()
        {
            TaskScheduler.TriggerItem triggerItem = new TaskScheduler.TriggerItem();
            triggerItem.Tag         = textBoxlabelOneTimeOnlyTag.Text;
            triggerItem.StartDate   = dateTimePickerStartDate.Value;
            triggerItem.EndDate     = dateTimePickerEndDate.Value;
            triggerItem.TriggerTime = dateTimePickerTriggerTime.Value;
            triggerItem.OnTrigger  += new TaskScheduler.TriggerItem.OnTriggerEventHandler(triggerItem_OnTrigger); // And the trigger-Event :)

            // Set OneTimeOnly - Active and Date
            triggerItem.TriggerSettings.OneTimeOnly.Active = checkBoxOneTimeOnlyActive.Checked;
            triggerItem.TriggerSettings.OneTimeOnly.Date   = dateTimePickerOneTimeOnlyDay.Value.Date;

            // Set the interval for daily trigger
            triggerItem.TriggerSettings.Daily.Interval = (ushort)numericUpDownDaily.Value;

            // Set the active days for weekly trigger
            for (byte day = 0; day < 7; day++) // Set the active Days
            {
                triggerItem.TriggerSettings.Weekly.DaysOfWeek[day] = checkedListBoxWeeklyDays.GetItemChecked(day);
            }

            // Set the active months for monthly trigger
            for (byte month = 0; month < 12; month++)
            {
                triggerItem.TriggerSettings.Monthly.Month[month] = checkedListBoxMonthlyMonths.GetItemChecked(month);
            }

            // Set active Days (0..30 = Days, 31=last Day) for monthly trigger
            for (byte day = 0; day < 32; day++)
            {
                triggerItem.TriggerSettings.Monthly.DaysOfMonth[day] = checkedListBoxMonthlyDays.GetItemChecked(day);
            }

            // Set the active weekNumber and DayOfWeek for monthly trigger
            // f.e. the first monday, or the last friday...
            for (byte weekNumber = 0; weekNumber < 5; weekNumber++) // 0..4: first, second, third, fourth or last week
            {
                triggerItem.TriggerSettings.Monthly.WeekDay.WeekNumber[weekNumber] = checkedListBoxMonthlyWeekNumber.GetItemChecked(weekNumber);
            }
            for (byte day = 0; day < 7; day++)
            {
                triggerItem.TriggerSettings.Monthly.WeekDay.DayOfWeek[day] = checkedListBoxMonthlyWeekDay.GetItemChecked(day);
            }

            triggerItem.Enabled = true;                       // Set the Item-Active - State
            _taskScheduler.AddTrigger(triggerItem);           // Add the trigger to List
            _taskScheduler.Enabled = checkBoxEnabled.Checked; // Start the Scheduler

            UpdateTaskList();
        }