/// <summary> /// Determines the ordinal week day for the month /// e.g first Monday, last weekday or second Tuesday /// </summary> protected int GetOrdinalWeekDay(ScheduleOrdinal ordinal, ScheduleDay weekday, int month, int year) { int result = -1; int index = 0; int[] days = new int[32]; if ((ordinal == ScheduleOrdinal.None) || (weekday == ScheduleDay.None)) { return(result); } DateTime date = new DateTime(year, month, 1); int limit = DateTime.DaysInMonth(date.Year, date.Month); for (int i = 0; i < limit; i++) { if ((GetScheduleDayFlag(date) & weekday) > 0) { days[index++] = date.Day; } date = date.AddDays(1); } switch (ordinal) { case ScheduleOrdinal.First: result = days[0]; break; case ScheduleOrdinal.Second: result = days[1]; break; case ScheduleOrdinal.Third: result = days[2]; break; case ScheduleOrdinal.Fourth: result = days[3]; break; case ScheduleOrdinal.Last: result = days[index - 1]; break; default: break; } return(result); }
private void LoadMonthlySchedule() { tabPages.SelectedTab = tabMonthly; _dayofmonth.Value = Convert.ToDecimal(Schedule.IfExistsExtractInt(ConfigXml, "/schedule/dayofmonth", 0)); if (_dayofmonth.Value == 0) { ScheduleOrdinal ordinal = Schedule.ExtractScheduleOrdinal(ConfigXml, "/schedule/ordinal", false); int index = ordinalDropDown.Items.IndexOf(ordinal.ToString()); ordinalDropDown.SelectedIndex = index; ScheduleDay weekDay = Schedule.ExtractScheduleDay(ConfigXml, "/schedule/weekday", false); string strWeekday = weekDay.ToString(); if (strWeekday == "All") { strWeekday = "Day"; } index = weekdayDropDown.Items.IndexOf(strWeekday); weekdayDropDown.SelectedIndex = index; radioDayofMonth.Checked = false; } else { radioDayofMonth.Checked = true; } ScheduleMonth months = Schedule.ExtractScheduleMonth(ConfigXml, "/schedule/months", false); if ((months & ScheduleMonth.February) > 0) { monthFebruary.Checked = true; } if ((months & ScheduleMonth.March) > 0) { monthMarch.Checked = true; } if ((months & ScheduleMonth.April) > 0) { monthApril.Checked = true; } if ((months & ScheduleMonth.May) > 0) { monthMay.Checked = true; } if ((months & ScheduleMonth.June) > 0) { monthJune.Checked = true; } if ((months & ScheduleMonth.July) > 0) { monthJuly.Checked = true; } if ((months & ScheduleMonth.August) > 0) { monthAugust.Checked = true; } if ((months & ScheduleMonth.September) > 0) { monthSeptember.Checked = true; } if ((months & ScheduleMonth.October) > 0) { monthOctober.Checked = true; } if ((months & ScheduleMonth.November) > 0) { monthNovember.Checked = true; } if ((months & ScheduleMonth.December) > 0) { monthDecember.Checked = true; } }