//新建定时发布任务 protected void scheSure_Btn_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(scheTime_T2.Text) && string.IsNullOrEmpty(scheTime_T.Text)) { return; } scheTime_T.Text = scheTime_T.Text.Trim(); DataTable schDT = null;// scheBll.SelByTaskType(M_Content_ScheTask.TaskTypeEnum.Release); if (schDT != null && schDT.Rows.Count > 0) { scheMod = scheMod.GetModelFromDR(schDT.Rows[0]); scheMod.ExecuteTime = DateTime.Now.ToString("yyyy/MM/dd ") + scheTime_T.Text; scheBll.Update(scheMod); } else { scheMod.TaskName = "定时发布首页"; scheMod.TaskContent = "index"; scheMod.TaskType = (int)M_Content_ScheTask.TaskTypeEnum.Release; scheMod.ExecuteType = (int)M_Content_ScheTask.ExecuteTypeEnum.EveryDay;//暂时无效,原本用来决定是否IsLoop scheMod.ExecuteTime = DateTime.Now.ToString("yyyy/MM/dd ") + scheTime_T.Text; scheMod.Status = 0; scheBll.Add(scheMod); } Response.Redirect("SchedTask.aspx"); }
//更新计划任务 public void UpdateSched(int gid, M_Content_ScheTask.TaskTypeEnum type, string datetext) { M_Content_ScheTask taskmod = taskBll.SelByGid(GeneralID, type); if (!string.IsNullOrEmpty(datetext)) { if (taskmod == null) { taskmod = new M_Content_ScheTask(); } taskmod.TaskType = (int)type; taskmod.TaskContent = GeneralID.ToString(); taskmod.ExecuteTime = datetext; taskmod.LastTime = DateTime.Parse(datetext); taskmod.Status = 0; if (taskmod.ID > 0) { taskBll.Update(taskmod); } else { taskBll.Add(taskmod); } } else if (taskmod != null) { taskBll.Delete(taskmod.ID); } }
/// <summary> /// 根据判断,增加自动审核|过期任务 /// </summary> /// <param name="CData">当前内容模型</param> /// <param name="taskInfo">任务信息</param> /// <param name="name">audit|expire</param> /// <param name="timeStr">日期时间字符串</param> /// <returns></returns> private JObject AddContentTask(M_CommonData CData, JObject taskInfo, string name, string timeStr) { //audit if (taskInfo[name] == null) { taskInfo.Add(name, 0); taskInfo.Add(name + "_time", ""); } int taskId = DataConvert.CLng(taskInfo[name]); //如果未设置任务,并且指定了时间字符串,则新建 if (taskId == 0 && !string.IsNullOrEmpty(timeStr)) { DateTime time = DateTime.Now; if (DateTime.TryParse(timeStr, out time)) { taskInfo[name] = AddTask(CData.GeneralID.ToString(), name, time); taskInfo[name + "_time"] = timeStr; } } //对比时间是否修改,如果修改,则创建任务 else if (taskId > 0) { string taskTimeStr = taskInfo[name + "_time"].ToString(); M_Content_ScheTask taskMod = taskBll.GetModel(taskId); //不匹配则修改 if (!taskTimeStr.Equals(timeStr)) { if (string.IsNullOrEmpty(timeStr)) { taskInfo[name] = 0; taskInfo[name + "_time"] = ""; taskBll.DelByID(taskId.ToString()); } else { taskMod.ExecuteTime = timeStr; taskBll.Update(taskMod); taskInfo[name + "_time"] = timeStr; } } } return(taskInfo); }
public IActionResult TaskAdd_Submit() { if (Mid > 0) { scheMod = scheBll.GetModel(Mid); } scheMod.TaskName = RequestEx["TaskName_T"]; //scheMod.ExecuteTime = ExecuteTime_T1.Text; scheMod.Interval = DataConvert.CLng(RequestEx["Interval_T"]); string taskContent = RequestEx["TaskContent_T"].Trim(); if (taskContent.StartsWith("/"))//任务内容为脚本路径时 { if (!System.IO.File.Exists(function.VToP(taskContent))) { return(WriteErr("脚本不存在")); } else { scheMod.TaskContent = taskContent; } } else { scheMod.TaskContent = taskContent; } scheMod.Remind = RequestEx["Remind_T"]; //任务类型不允许修改 if (Mid <= 0) { scheMod.TaskType = DataConvert.CLng(Request.Form["taskType_rad"]); } scheMod.ExecuteType = DataConvert.CLng(Request.Form["executeType_rad"]); scheMod.Status = DataConvert.CLng(Request.Form["status_rad"]); if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.Interval) { if (scheMod.Interval <= 0) { return(WriteErr("未指定正确的间隔时间")); } } else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.JustOnce) { scheMod.ExecuteTime = RequestEx["ExecuteTime_T1"]; if (DataConvert.CDate(scheMod.ExecuteTime) < DateTime.Now) { return(WriteErr("执行时间无效")); } } else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.EveryDay) { scheMod.ExecuteTime = RequestEx["ExecuteTime_T2"]; } else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.EveryMonth) { scheMod.ExecuteTime = RequestEx["ExecuteTime_T1"]; } if (Mid > 0) { scheBll.Update(scheMod); } else { scheMod.CDate = DateTime.Now; scheMod.AdminID = adminMod.AdminId; scheMod.ID = scheBll.Add(scheMod); } HFHelper.AddTask(scheMod); return(WriteOK("操作成功", "TaskList")); }
protected void Save_Btn_Click(object sender, EventArgs e) { if (Mid > 0) { scheMod = scheBll.GetModel(Mid); } scheMod.TaskName = TaskName_T.Text; //scheMod.ExecuteTime = ExecuteTime_T1.Text; scheMod.Interval = DataConvert.CLng(Interval_T.Text); if (TaskContent_T.Text.StartsWith("/"))//任务内容为脚本路径时 { if (!File.Exists(function.VToP(TaskContent_T.Text))) { function.WriteErrMsg("脚本不存在"); } else { scheMod.TaskContent = TaskContent_T.Text; } } else { scheMod.TaskContent = TaskContent_T.Text; } scheMod.Remind = Remind_T.Text; //任务类型不允许修改 if (Mid <= 0) { scheMod.TaskType = DataConvert.CLng(Request.Form["taskType_rad"]); } scheMod.ExecuteType = DataConvert.CLng(Request.Form["executeType_rad"]); scheMod.Status = DataConvert.CLng(Request.Form["status_rad"]); if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.Interval) { if (scheMod.Interval <= 0) { function.WriteErrMsg("未指定正确的间隔时间"); } } else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.JustOnce) { scheMod.ExecuteTime = ExecuteTime_T1.Text; if (DataConvert.CDate(scheMod.ExecuteTime) < DateTime.Now) { function.WriteErrMsg("执行时间无效"); } } else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.EveryDay) { scheMod.ExecuteTime = ExecuteTime_T2.Text; } else if (scheMod.ExecuteType == (int)M_Content_ScheTask.ExecuteTypeEnum.EveryMonth) { scheMod.ExecuteTime = ExecuteTime_T1.Text; } if (Mid > 0) { scheBll.Update(scheMod); } else { M_AdminInfo adminMod = B_Admin.GetLogin(); scheMod.CDate = DateTime.Now; scheMod.AdminID = adminMod.AdminId; scheMod.ID = scheBll.Add(scheMod); } TaskCenter.AddTask(scheMod); function.WriteSuccessMsg("操作成功", "Default.aspx"); }