/// <summary> /// 新增一条计划任务记录 /// </summary> /// <param name="item">要新增的计划任务实例</param> /// <returns>返回影响行数</returns> public int AddJob(JobHttpScheduler item) { if (item == null) { return(-1); } StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO dbo.JobHttpScheduler(JobName, GroupName, RequestURL, RequestType, JobDescription, StartTime, TriggerType, "); sql.AppendLine("RepeatCount, RepeatInterval, CronExpression, JobStatus, AddTime) "); sql.AppendLine("VALUES(@JobName, @GroupName, @RequestURL, @RequestType, @JobDescription, @StartTime, @TriggerType, "); sql.AppendLine("@RepeatCount, @RepeatInterval, @CronExpression, @JobStatus, GETDATE());"); using (var conn = new SqlConnection(ConnectionStr.FxDb)) { conn.Open(); return(conn.Execute(sql.ToString(), new { JobName = item.JobName, GroupName = item.GroupName, RequestURL = item.RequestURL, RequestType = item.RequestType, JobDescription = item.JobDescription, StartTime = item.StartTime, TriggerType = item.TriggerType, RepeatCount = item.RepeatCount, RepeatInterval = item.RepeatInterval, CronExpression = item.CronExpression, JobStatus = item.JobStatus })); } }
public ActionResult Edit(int id, FormCollection collection) { try { JobHttpScheduler model = new JobHttpScheduler(); model.JobHttpSchedulerID = id; model.JobName = collection["JobName"]; model.GroupName = collection["GroupName"]; model.RequestURL = collection["RequestURL"]; model.RequestType = Convert.ToInt32(collection["RequestType"]); model.JobDescription = collection["JobDescription"] ?? ""; model.StartTime = Convert.ToDateTime(collection["StartTime"]); model.TriggerType = Convert.ToInt32(collection["TriggerType"]); model.RepeatCount = Convert.ToInt32(collection["RepeatCount"]); model.RepeatInterval = Convert.ToInt32(collection["RepeatInterval"]); model.CronExpression = collection["CronExpression"].Trim(); model.JobStatus = Convert.ToInt32(collection["JobStatus"]); if (model.TriggerType == 1 && string.IsNullOrEmpty(model.CronExpression)) { return(this.Back("请输入正确的Cron-Like表达式。")); } if (model.TriggerType == 0 && model.RepeatInterval <= 0) { return(this.Back("执行计划间隔时间输入错误。")); } logic.UpdateJob(model); return(this.RefreshParent()); } catch (Exception ex) { return(this.Back("修改任务发生异常。" + ex.Message)); } }
/// <summary> /// 更新一条计划任务记录 /// </summary> /// <param name="item">要更新的计划任务实例</param> /// <returns>返回影响行数</returns> public int UpdateJob(JobHttpScheduler item) { if (item == null || item.JobHttpSchedulerID < 1) { return(-1); } StringBuilder sql = new StringBuilder(); sql.AppendLine("UPDATE dbo.JobHttpScheduler SET "); sql.AppendLine("JobName = @JobName,"); sql.AppendLine("GroupName = @GroupName,"); sql.AppendLine("RequestURL = @RequestURL,"); sql.AppendLine("RequestType = @RequestType,"); sql.AppendLine("JobDescription = @JobDescription,"); sql.AppendLine("StartTime = @StartTime,"); sql.AppendLine("TriggerType = @TriggerType,"); sql.AppendLine("RepeatCount = @RepeatCount,"); sql.AppendLine("RepeatInterval = @RepeatInterval,"); sql.AppendLine("CronExpression = @CronExpression,"); sql.AppendLine("JobStatus = @JobStatus "); sql.AppendLine("WHERE JobHttpSchedulerID = @JobHttpSchedulerID"); using (var conn = new SqlConnection(ConnectionStr.FxDb)) { conn.Open(); return(conn.Execute(sql.ToString(), new { JobHttpSchedulerID = item.JobHttpSchedulerID, JobName = item.JobName, GroupName = item.GroupName, RequestURL = item.RequestURL, RequestType = item.RequestType, JobDescription = item.JobDescription, StartTime = item.StartTime, TriggerType = item.TriggerType, RepeatCount = item.RepeatCount, RepeatInterval = item.RepeatInterval, CronExpression = item.CronExpression, JobStatus = item.JobStatus })); } }
public ActionResult Create(FormCollection collection) { try { JobHttpScheduler model = new JobHttpScheduler(); model.JobName = collection["JobName"]; model.GroupName = string.IsNullOrEmpty(collection["GroupName"]) ? "DefaultGroup" : collection["GroupName"]; model.RequestURL = collection["RequestURL"]; model.RequestType = Convert.ToInt32(collection["RequestType"]); model.JobDescription = collection["JobDescription"]; model.StartTime = Convert.ToDateTime(collection["StartTime"]); model.TriggerType = Convert.ToInt32(collection["TriggerType"]); model.RepeatCount = Convert.ToInt32(collection["RepeatCount"]); model.RepeatInterval = Convert.ToInt32(collection["RepeatInterval"]); model.CronExpression = collection["CronExpression"].Trim(); model.JobStatus = Convert.ToInt32(collection["JobStatus"]); if (string.IsNullOrEmpty(model.JobName)) { return(this.Back("请输入任务名称。")); } if (model.TriggerType == 1 && string.IsNullOrEmpty(model.CronExpression)) { return(this.Back("请输入正确的Cron-Like表达式。")); } if (model.TriggerType == 0 && model.RepeatInterval <= 0) { return(this.Back("执行计划间隔时间输入错误。")); } if (logic.GetJobInfo(model.JobName) == null) { logic.AddJob(model); return(this.RefreshParent()); } else { return(this.Back("执行计划名称重复。")); } } catch (Exception ex) { return(this.Back("新增Job发生异常。" + ex.Message)); } }
public IEnumerable <JobHttpScheduler> GetJobList(JobHttpScheduler searchCondition, PageItem pageItem = null) { StringBuilder sql = new StringBuilder(); sql.AppendLine("SELECT JobHttpSchedulerID,JobName,GroupName,RequestURL,RequestType, "); sql.AppendLine("JobDescription,StartTime,TriggerType,RepeatCount,RepeatInterval,CronExpression,JobStatus,AddTime "); sql.AppendLine("FROM JobHttpScheduler WITH(NOLOCK) WHERE 1=1 "); if (searchCondition != null) { if (searchCondition.JobHttpSchedulerID > 0) { sql.AppendLine(" AND JobHttpSchedulerID = " + searchCondition.JobHttpSchedulerID); } if (!string.IsNullOrWhiteSpace(searchCondition.JobName)) { sql.AppendLine(" AND JobName LIKE '%" + searchCondition.JobName + "%'"); } if (searchCondition.JobStatus > -1) { sql.AppendLine(" AND JobStatus = " + searchCondition.JobStatus); } } return(DapperHelper <JobHttpScheduler> .GetPageList(ConnectionStr.FxDb, sql.ToString(), pageItem)); }
public IEnumerable <JobHttpScheduler> GetJobPageList(JobHttpScheduler searchCondition, PageItem pageItem) { return(dal.GetJobList(searchCondition, pageItem)); }
/// <summary> /// 更新一条计划任务记录 /// </summary> /// <param name="item">要更新的计划任务实例</param> /// <returns>返回影响行数</returns> public int UpdateJob(JobHttpScheduler item) { return(dal.UpdateJob(item)); }
/// <summary> /// 新增一条计划任务记录 /// </summary> /// <param name="item">要新增的计划任务实例</param> /// <returns>返回影响行数</returns> public int AddJob(JobHttpScheduler item) { return(dal.AddJob(item)); }