class Schedule
    {
     
        public static void SetTimeJobSchedule(SPJobDefinition timerJob, ScheduleType type, int begin, int end, int week, int interval)
        {
            switch (type)
            {
                case ScheduleType.Weekly:
                    SPWeeklySchedule weeklySchedule = new SPWeeklySchedule();
                    weeklySchedule.BeginDayOfWeek = (DayOfWeek)week;
                    weeklySchedule.BeginHour = begin;
                    weeklySchedule.EndHour = end;
                    timerJob.Schedule = weeklySchedule;
                    break;
                case ScheduleType.Daily:
                    SPDailySchedule dailySchedule = new SPDailySchedule();
                    dailySchedule.BeginHour = begin;
                    dailySchedule.EndHour = end;
                    timerJob.Schedule = dailySchedule;
                    break;
                case ScheduleType.Hourly:
                    SPHourlySchedule hourlySchedule = new SPHourlySchedule();
                    hourlySchedule.BeginMinute = begin;
                    hourlySchedule.EndMinute = end;
                    timerJob.Schedule = hourlySchedule;
                    break;
                case ScheduleType.Minute:
                    SPMinuteSchedule minuteSchedule = new SPMinuteSchedule();
                    minuteSchedule.BeginSecond = begin;
                    minuteSchedule.EndSecond = end;
                    minuteSchedule.Interval = interval;
                    timerJob.Schedule = minuteSchedule;
                    break;
                default:
                    break;
            }
            timerJob.Update();
        }
    }
    public enum ScheduleType
    {
        Weekly,
        Daily,
        Hourly,
        Minute
    }

 

posted on 2011-11-22 13:26  gzh4455  阅读(260)  评论(0编辑  收藏  举报