/// <summary> /// 获取任务列表 /// </summary> /// <param name="isFirstLoad">是否是第一次加载</param> /// <returns></returns> public List <TimedTask.Model.AutoTask> GetTaskList(bool isFirstLoad) { Bll.AutoTask _bllTask = new Bll.AutoTask(); List <TimedTask.Model.AutoTask> list = _bllTask.GetList(" 1=1 ", null, " CreateDate DESC"); //Helper.Instance.GetTaskList(_xml);//任务列表 if (list == null || list.Count == 0) { return(null); } if (isFirstLoad) { List <TimedTask.Model.AutoTask> listTmp = list.Where(m => m.TaskType == "5").ToList <TimedTask.Model.AutoTask>();//锁屏任务 下次启动时间从打开软件算起 if (listTmp.Count > 0) { foreach (TimedTask.Model.AutoTask m in listTmp) { m.NextStartDate = Convert.ToDateTime(Task.Instance.GetNextStartDateByType(Int32.Parse(m.RunType), m.Dayth, null, m.Interval)); _bllTask.Update(m, " Id=" + m.Id); } } listTmp = list.Where(m => m.TaskType == "2").ToList <TimedTask.Model.AutoTask>();//关机任务 日期换成当前年月日 if (listTmp.Count > 0) { foreach (TimedTask.Model.AutoTask m in listTmp) { string nextDate = ((DateTime)m.NextStartDate).ToString("yyyy-MM-dd"); m.NextStartDate = Convert.ToDateTime( ((DateTime)m.NextStartDate).ToString("yyyy-MM-dd HH:mm:00").Replace(nextDate, DateTime.Now.ToString("yyyy-MM-dd")) ); _bllTask.Update(m, " Id=" + m.Id); } } } return(list); }
//保存 private void btnOK_Click(object sender, RoutedEventArgs e) { string path = this.txtPath.Text.Trim(); string title = this.txtTitle.Text.Trim(); string remark = this.txtRemark.Text.Trim(); string startParameter = this.txtStartParameter.Text.Trim(); string startDate = "", stopDate = "", nextStartDate = "";//起始 停止 下次启动时间 if (this.rbtWeek.IsChecked == true && GetWeeks().Length == 0) { this._statusText = "保存失败,没有星期被选中!"; return; } AutoTask model = new AutoTask(); model.Weeks = ""; if (this.rbtMonth.IsChecked == true) { this._runType = RunType.Month; } if (this.rbtDay.IsChecked == true) { this._runType = RunType.Day; } if (this.rbtHour.IsChecked == true) { this._runType = RunType.Hour; } if (this.rbtMinute.IsChecked == true) { this._runType = RunType.Minute; } if (this.rbtOnce.IsChecked == true) { this._runType = RunType.Once; } if (this.rbtWeek.IsChecked == true) { this._runType = RunType.Week; model.Weeks = GetWeeks(); } try { bool flag = ID == 0 ? true : false;//是否是新增 if (this.cboTaskType.SelectedIndex == 0) { if (path.Length == 0 || !path.EndsWith(".exe")) { this._statusText = "不是可执行文件或文件路径不能为空!"; return; } } this._startTime = this.cboStartHour.SelectedValue + ":" + this.cboStartMinute.Text + ":00"; this._stopTime = this.cboStopHour.SelectedValue + ":" + this.cboStopMinute.Text + ":00"; startDate = this.dp_StartDate.Text + " " + this._startTime; stopDate = this.dp_StopDate.Text + " " + this._stopTime; nextStartDate = GetFirstStartDate(); model.StartParameters = startParameter; model.ApplicationPath = path; model.Title = title; model.Enable = (bool)this.cboEnable.IsChecked ? "1" : "0"; model.StartDate = Convert.ToDateTime(startDate); model.StopDate = Convert.ToDateTime(stopDate); model.Remark = remark; model.AudioPath = this._audio; model.TaskType = this.cboTaskType.SelectedIndex.ToString(); model.Status = ""; model.RunType = ((int)this._runType).ToString(); model.Interval = (this.rbtMinute.IsChecked == true) ? Convert.ToInt32(this.cboMinute.SelectedValue.ToString()) : 0; model.Dayth = (this.rbtMonth.IsChecked == true) ? Convert.ToInt32(this.cboDay.SelectedValue.ToString()) : 0; model.NextStartDate = Convert.ToDateTime(nextStartDate); if (!flag)//修改 { this._bllTask.Update(model, " Id=" + ID); this._statusText = "保存设置成功!" + (DateTime.Now > model.StopDate ? " 警告:任务已过期!" : ""); } else//新增 { Bll.AutoTask bllTask = new Bll.AutoTask(); bllTask.Add(model); this._statusText = "新增成功!" + (DateTime.Now > model.StopDate ? " 警告:任务已过期!" : ""); btnReset_Click(null, null); } } catch (Exception ex) { _statusText = "保存设置失败,可能原因是:未找到指定的配置文件!"; Log.SaveLog("TaskEdit btnOK_Click", _statusText + ex.ToString()); } }