/// <summary> /// 删除任务功能 /// 先删除当前线程中的任务,然后再删除数据库表中的任务状态 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Delete(object sender, CommandEventArgs e) { try { string missionid = e.CommandArgument.ToString(); Model.TimerMission model = _bll.GetModel(new Guid(missionid)); //删除线程中的任务 _missionControl.DeleteJob(model.GroupName, model.MissionName); //更改存储在数据库中当前的任务状态ISDel=1 bool isdel = _bll.Delete(new Guid(missionid)); UiHelper.Alert(this, isdel ? "删除成功" : "删除失败"); NewDatabind(Convert.ToInt32(countDDL.SelectedValue)); } catch (Exception) { UiHelper.Alert(this, "删除失败,未知错误"); throw; } }
/// <summary> /// 修改任务并立即执行 /// 操作步骤:先将当前进程中任务删除,然后再重新添加到进程中 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEditMissionBeginNow_Click(object sender, EventArgs e) { try { //获取当前修改的任务的主键 string missionid = EditTimerMission(); if (missionid != "") { //当前的任务模型 Model.TimerMission model = _bll.GetModel(new Guid(missionid)); //删除线程中的任务 _missionControl.DeleteJob(model.GroupName, model.MissionName); bool issuccess = _missionControl.AddSqlExecuteJob(model.SqlStr, Convert.ToDateTime(model.StartTime), Convert.ToDateTime(model.EndTime), model.GroupName, model.MissionName, model.TimeCorn); if (issuccess) { UiHelper.Alert(this, "修改任务成功,当前任务已开始运行!"); model.MissionState = 1; _bll.Update(model); //更新数据 NewDatabind(Convert.ToInt32(countDDL.SelectedValue)); //重新绑定数据 } else { UiHelper.Alert(this, "操作失败,请重试!"); } } else { UiHelper.Alert(this, "操作失败,请重试!"); } } catch (Exception) { UiHelper.Alert(this, "操作失败,未知错误!"); throw; } }
/// <summary> /// 任务修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnMissionEdit_Click(object sender, EventArgs e) { string edit = EditTimerMission(); UiHelper.Alert(this, edit != "" ? "修改任务成功,当前任务状态恢复为未执行状态!" : "修改任务失败,请校验数据后重试!"); }
/// <summary> /// TimerMission表数据修改 /// </summary> /// <returns>返回修改的任务主键</returns> private string EditTimerMission() { try { #region 校验非空错误提示 string strErr = ""; if (this.txtEditMissionName.Text.Trim().Length == 0) { strErr += "任务名称不能为空!\\n"; } if (this.txtEditGroupName.Text.Trim().Length == 0) { strErr += "组名称不能为空!\\n"; } if (this.txtEditSqlStr.Text.Trim().Length == 0) { strErr += "SQL执行语句不能为空!\\n"; } if (this.txtEditTimeCorn.Text.Trim().Length == 0) { strErr += "时间调度表达式不能为空!\\n"; } if (this.txtEditMissionStartTime.Text.Trim().Length == 0) { strErr += "任务开始时间不能为空!\\n"; } if (this.txtEditMissionEndTime.Text.Trim().Length == 0) { strErr += "任务结束时间不能为空!\\n"; } if (Convert.ToDateTime(this.txtEditMissionStartTime.Text.Trim()) >= Convert.ToDateTime(this.txtEditMissionEndTime.Text.Trim())) { strErr += "任务开始时间不可大于结束时间\\n"; } if (strErr != "") { UiHelper.Alert(this, strErr); return(""); } #endregion var model = _bll.GetModel(new Guid(txtHiddenText.Text)); string missionName = this.txtEditMissionName.Text; string groupName = this.txtEditGroupName.Text; //判断除去当前数据外是否存在重名数据 var isrepeat = _bll.TestRepeat(missionName, groupName, model.ID.ToString()); if (isrepeat) //判断当前任务名和组名是否重复 { UiHelper.Alert(this, "当前已存在重复的任务组名和任务名,请修改名称后再进行操作!"); return(""); } else { model.MissionName = missionName; model.GroupName = groupName; model.SqlStr = this.txtEditSqlStr.Text; model.TimeCorn = this.txtEditTimeCorn.Text; model.RepeatCount = int.Parse(this.txtEditRepeatCount.Text); model.StartTime = DateTime.Parse(this.txtEditMissionStartTime.Text); model.EndTime = DateTime.Parse(this.txtEditMissionEndTime.Text); model.CreateTime = DateTime.Now; model.InveralTime = 0; model.MissionExplain = this.txtEditMissionExplain.Text; model.MissionState = 2;//默认设置当前的MissionState为空 //数据添加 bool issuccess = _bll.Update(model); if (issuccess) { //重新进行数据绑定 NewDatabind(Convert.ToInt32(countDDL.SelectedValue)); //清空原有的输入框数据 foreach (TextBox tbx in this.form1.Controls.OfType <TextBox>()) { if (tbx != null) { tbx.Text = ""; } } } return(issuccess ? model.ID.ToString() : ""); } } catch { UiHelper.Alert(this, "未知原因,操作失败!"); return(""); } }
/// <summary> /// TimerMission表数据添加 /// </summary> /// <returns></returns> private string AddTimerMission() { try { #region 校验非空错误提示 string strErr = ""; if (this.txtAddMissionName.Text.Trim().Length == 0) { strErr += "任务名称不能为空!\\n"; } if (this.txtAddGroupName.Text.Trim().Length == 0) { strErr += "组名称不能为空!\\n"; } if (this.txtAddSqlStr.Text.Trim().Length == 0) { strErr += "SQL执行语句不能为空!\\n"; } if (this.txtAddTimeCorn.Text.Trim().Length == 0) { strErr += "时间调度表达式不能为空!\\n"; } if (this.txtAddMissionStartTime.Text.Trim().Length == 0) { strErr += "任务开始时间不能为空!\\n"; } if (this.txtAddMissionEndTime.Text.Trim().Length == 0) { strErr += "任务结束时间不能为空!\\n"; } if (Convert.ToDateTime(this.txtAddMissionStartTime.Text.Trim()) >= Convert.ToDateTime(this.txtAddMissionEndTime.Text.Trim())) { strErr += "任务开始时间不可大于结束时间\\n"; } if (strErr != "") { UiHelper.Alert(this, strErr); return(""); } #endregion string missionName = this.txtAddMissionName.Text; string groupName = this.txtAddGroupName.Text; bool isrepeat = _bll.TestRepeat(missionName, groupName); if (isrepeat) //判断当前任务名和组名是否重复 { UiHelper.Alert(this, "当前已存在重复的任务组名和任务名,请修改后再进行添加!"); return(""); } else { Model.TimerMission model = new Model.TimerMission { ID = Guid.NewGuid(), MissionName = missionName, GroupName = groupName, SqlStr = this.txtAddSqlStr.Text, TimeCorn = this.txtAddTimeCorn.Text, RepeatCount = int.Parse(this.txtAddRepeatCount.Text), StartTime = DateTime.Parse(this.txtAddMissionStartTime.Text), EndTime = DateTime.Parse(this.txtAddMissionEndTime.Text), CreateTime = DateTime.Now, InveralTime = 0, MissionExplain = this.txtAddMissionExplain.Text, MissionState = 2//默认设置当前的MissionState为空 }; //数据添加 int issuccess = _bll.Add(model); UiHelper.Alert(this, issuccess > 0 ? "保存成功!" : "数据添加失败,请校验数据后重试!"); if (issuccess > 0) { //重新进行数据绑定 NewDatabind(Convert.ToInt32(countDDL.SelectedValue)); //清空原有的输入框数据 foreach (object item in this.form1.Controls) { var box = item as TextBox; if (box != null) { TextBox tbx = box; tbx.Text = ""; } } } if (issuccess > 0) { return(model.ID.ToString()); } else { return(""); } } } catch (Exception) { UiHelper.Alert(this, "未知原因,操作失败!"); return(""); throw; } }