예제 #1
0
        public void TestDT4()
        {
            SchedulerPlanning Plan = Scheduler.CreatePlan(new DateTime(2018, 3, 9, 22, 57, 55), new List <int> {
                1
            }, new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
            });

            Assert.AreEqual(new DateTime(2018, 4, 1, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 56, 54), Plan));
            Assert.AreEqual(new DateTime(2018, 4, 1, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 56, 56), Plan));
            Assert.AreEqual(new DateTime(2018, 4, 1, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 4, 1, 22, 56, 56), Plan));
            Assert.AreEqual(new DateTime(2018, 5, 1, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 4, 1, 22, 57, 56), Plan));
            Plan = Scheduler.CreatePlan(new DateTime(2018, 3, 9, 22, 57, 55), new List <int> {
                29
            }, new List <int> {
                2
            });
            Assert.AreEqual(new DateTime(2020, 2, 29, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 4, 1, 22, 57, 56), Plan));
            Plan = Scheduler.CreatePlan(new DateTime(2018, 3, 9, 22, 57, 55), new List <int> {
                30
            }, new List <int> {
                2
            });
            Assert.AreEqual(null, Scheduler.GetNextRunDate(new DateTime(2018, 4, 1, 22, 57, 56), Plan));
        }
예제 #2
0
        public void TestDT1()
        {
            SchedulerPlanning Plan = Scheduler.CreatePlan(new DateTime(2018, 3, 9, 22, 57, 55));

            Assert.AreEqual(new DateTime(2018, 3, 9, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 57, 54), Plan));
            Assert.AreEqual(null, Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 57, 56), Plan));
        }
예제 #3
0
        public void TestDT3()
        {
            SchedulerPlanning Plan = Scheduler.CreatePlan(new DateTime(2018, 3, 9, 22, 57, 55), 1, new List <DayOfWeek> {
                DayOfWeek.Monday
            });

            Assert.AreEqual(new DateTime(2018, 3, 12, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 57, 54), Plan));
            Assert.AreEqual(new DateTime(2018, 3, 12, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 57, 56), Plan));
            Plan = Scheduler.CreatePlan(new DateTime(2018, 3, 9, 22, 57, 55), 1, new List <DayOfWeek> {
                DayOfWeek.Monday, DayOfWeek.Friday
            });
            Assert.AreEqual(new DateTime(2018, 3, 9, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 57, 54), Plan));
            Assert.AreEqual(new DateTime(2018, 3, 9, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 57, 55), Plan));
            Assert.AreEqual(new DateTime(2018, 3, 12, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 57, 57), Plan));
            Plan = Scheduler.CreatePlan(new DateTime(2018, 3, 9, 22, 57, 55), 4, new List <DayOfWeek> {
                DayOfWeek.Thursday
            });
            Assert.AreEqual(new DateTime(2018, 3, 15, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 9, 22, 57, 54), Plan));
            Assert.AreEqual(new DateTime(2018, 4, 19, 22, 57, 55), Scheduler.GetNextRunDate(new DateTime(2018, 3, 15, 22, 57, 56), Plan));
        }
예제 #4
0
 public frmSetupScheduler(SchedulerPlanning Plan, string Title)
 {
     this.Plan  = Plan;
     this.Title = Title;
     InitializeComponent();
 }
예제 #5
0
        private void cmdOK_Click(object sender, EventArgs e)
        {
            SchedulerPlanning P = new SchedulerPlanning();

            P.RecurInDay      = new List <int>();
            P.RecurInMonths   = new List <int>();
            P.RecurInWeekDays = new List <DayOfWeek>();
            P.StartDate       = DTStart.Value.ToUniversalTime();
            int Tmp;

            switch (lstMethod.SelectedIndex)
            {
            case 0:
                P.Planning = SchedulerPlanningType.None;
                break;

            case 1:
                P.Planning = SchedulerPlanningType.OneTime;
                break;

            case 2:
                P.Planning = SchedulerPlanningType.Daily;
                if (int.TryParse(txtRecurDays.Text, out Tmp) == false)
                {
                    MessageBox.Show(this, "Invalid recurrence number.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                if (Tmp < 1)
                {
                    MessageBox.Show(this, "Recurrence must be more than 0.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                P.Recurrence = Tmp;
                break;

            case 3:
                P.Planning = SchedulerPlanningType.Weekly;
                if (int.TryParse(txtRecurWeeks.Text, out Tmp) == false)
                {
                    MessageBox.Show(this, "Invalid recurrence number.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                if (Tmp < 1)
                {
                    MessageBox.Show(this, "Recurrence must be more than 0.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                P.Recurrence = Tmp;
                for (int i = 0; i < 7; i++)
                {
                    if (lstDayOfWeek.GetItemChecked(i) == true)
                    {
                        P.RecurInWeekDays.Add((DayOfWeek)i);
                    }
                }
                if (P.RecurInWeekDays.Count == 0)
                {
                    MessageBox.Show(this, "Please select at least one day of week.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                break;

            case 4:
                P.Planning = SchedulerPlanningType.Monthly;

                for (int i = 0; i < 32; i++)
                {
                    if (lstDays.GetItemChecked(i) == true)
                    {
                        P.RecurInDay.Add(i + 1);
                    }
                }
                for (int i = 0; i < 12; i++)
                {
                    if (lstMonths.GetItemChecked(i) == true)
                    {
                        P.RecurInMonths.Add(i + 1);
                    }
                }
                if (P.RecurInDay.Count == 0)
                {
                    MessageBox.Show(this, "Please select at least one day.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                if (P.RecurInMonths.Count == 0)
                {
                    MessageBox.Show(this, "Please select at least one month.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                break;
            }
            DateTime?TestDT = Scheduler.GetNextRunDate(DateTime.Now, P);

            if (TestDT == null && P.Planning != SchedulerPlanningType.None)
            {
                MessageBox.Show(this, "This event will never occour.", Program.Title, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            Plan = P;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }