示例#1
0
        /// <summary>
        /// 强制执行一次任务,不改变任务状态
        /// </summary>
        /// <param name="scheID"></param>
        public void ExecuteNow(int scheID)
        {
            M_Content_ScheTask taskMod = scheBll.SelReturnModel(scheID);

            switch (taskMod.TaskType)
            {
            case (int)M_Content_ScheTask.TaskTypeEnum.ExecuteSQL:
            {
                if (taskMod.TaskContent.StartsWith("/"))         //若以'/'或'\'开头则为脚本
                {
                    DBHelper.ExecuteSqlScript(DBCenter.DB.ConnectionString, function.VToP(taskMod.TaskContent));
                }
                else
                {
                    SqlHelper.ExecuteSql(taskMod.TaskContent);
                }
            }
            break;

            //case (int)M_Content_ScheTask.TaskTypeEnum.Release:
            //    break;
            case (int)M_Content_ScheTask.TaskTypeEnum.Content:
            {
                conBll.UpdateStatus(taskMod.TaskContent, 99);
                scheBll.UpdateStatus(taskMod.ID.ToString(), 100);
            }
            break;
            }
            //增加一条日志
            taskMod.LastTime = DateTime.Now.ToString();
            DBCenter.UpdateSQL(taskMod.TbName, "LastTime='" + DateTime.Now + "'", "ID=" + taskMod.ID);
            B_Content_ScheLog logBll = new B_Content_ScheLog();
            M_Content_ScheLog logMod = new M_Content_ScheLog();

            logMod.TaskID   = taskMod.ID;
            logMod.TaskName = taskMod.TaskName;
            logMod.Result   = 1;
            logBll.Insert(logMod);
        }
示例#2
0
        // 到达时间,执行任务
        protected void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                bool flag = false;
                switch (scheMod.ExecuteType)
                {
                case (int)M_Content_ScheTask.ExecuteTypeEnum.JustOnce:
                    if (DateTime.Now >= scheMod.ExecuteTime2 && scheMod.Status == 0)
                    {
                        ExecuteFunc(sender, e);
                        flag = true;
                        //scheMod.Status = 100;
                        //DBCenter.UpdateSQL(scheMod.TbName, "Status=100", "ID=" + scheMod.ID);
                        TaskCenter.RemoveTask(scheMod.ID);
                    }
                    break;

                case (int)M_Content_ScheTask.ExecuteTypeEnum.EveryDay:
                    //已到时间,且今天未执行过
                    if (string.IsNullOrEmpty(scheMod.LastTime) || scheMod.LastTime2.DayOfYear != DateTime.Now.DayOfYear)
                    {
                        if (DateTime.Now >= scheMod.ExecuteTime2)
                        {
                            ExecuteFunc(sender, e);
                            flag = true;
                        }
                    }
                    break;

                case (int)M_Content_ScheTask.ExecuteTypeEnum.Interval:
                {
                    ExecuteFunc(sender, e);
                    flag = true;
                }
                break;

                case (int)M_Content_ScheTask.ExecuteTypeEnum.EveryMonth:
                {
                    //未执行过,或当本月未执行过
                    if (string.IsNullOrEmpty(scheMod.LastTime) || scheMod.LastTime2.Month != DateTime.Now.Month)
                    {
                        DateTime time = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/") + scheMod.ExecuteTime2.ToString("dd HH:mm:ss"));
                        if (DateTime.Now >= time)
                        {
                            ExecuteFunc(sender, e);
                            flag = true;
                        }
                    }
                }
                break;
                }
                if (flag)
                {
                    //更新任务状态和执行日志
                    scheMod.LastTime = DateTime.Now.ToString();
                    DBCenter.UpdateSQL(scheMod.TbName, "LastTime='" + DateTime.Now + "'", "ID=" + scheMod.ID);
                    M_Content_ScheLog logMod = new M_Content_ScheLog();
                    logMod.TaskID   = scheMod.ID;
                    logMod.TaskName = scheMod.TaskName;
                    logMod.Result   = 1;
                    logBll.Insert(logMod);
                }
            }
            catch (Exception ex) { ZLLog.L("TaskCenter-->[" + scheMod.TaskName + "]出错,原因" + ex.Message); }
        }