public cCheckPlan() { if (!File.Exists(Program.getPrjPath() + "tasks\\plan\\plan.xml")) { cPlans cs = new cPlans(); cs.NewIndexFile(); cs = null; } try { m_runTasks = new List <cPlan>(); IniCheckPlan(); //初始化任务文件监听类,,根据文件变化不断更新任务监控信息 m_FileMonitor = new cFileMonitor(Program.getPrjPath() + "tasks\\plan\\plan.xml"); m_FileMonitor.ReloadPlanFile += this.On_Reload; //系统默认为启动文件监听 StartListenPlanFile(); } catch (System.Exception ex) { if (e_ListenErrorEvent != null) { e_ListenErrorEvent(this, new cListenErrorEventArgs(ex.Message)); } } }
//相应新增运行任务事件 private void OnAddRunTask(object sender, cAddRunTaskEventArgs e) { //任务增加后,会自动运行 m_rTask.AddTask(e.RunTask); //判断此计划是否过期,如果过期,则修改计划的状态 cPlans cp = new cPlans(); cp.IfEnabled(Int64.Parse(e.RunTask.PlanID), false); cp = null; }
private void AutoState() { cPlans cp = new cPlans(); for (int i = 0; i < m_runTasks.Count; i++) { if (m_runTasks[i].IsDisabled == true) { cp.IfEnabled(m_runTasks[i].PlanID, true); } } cp = null; }
public void LoadPlan(Int64 PlanID) { cPlans ps = new cPlans(); cPlan p = ps.GetSinglePlan(PlanID); this.txtPlanName.Text = p.PlanName; this.txtPlanID.Text = p.PlanID.ToString(); this.txtPlanDemo.Text = p.PlanRemark; this.txtPlanState.Text = cGlobalParas.ConvertName(p.PlanState); if (p.IsOverRun == true) { this.cboxIsRun.Checked = true; } else { this.cboxIsRun.Checked = false; } if (p.IsDisabled == true) { this.cboxIsDisabled.Checked = true; } else { this.cboxIsDisabled.Checked = false; } if (p.DisabledType == (int)cGlobalParas.PlanDisabledType.RunTime) { this.raNumber.Checked = true; } else if (p.DisabledType == (int)cGlobalParas.PlanDisabledType.RunDateTime) { this.raDateTime.Checked = true; } this.DisabledRunNum.Value = p.DisabledTime; this.DisabledDateTime.Value = p.DisabledDateTime; ListViewItem litem; for (int i = 0; i < p.RunTasks.Count; i++) { litem = new ListViewItem(); litem.Text = cGlobalParas.ConvertName(p.RunTasks[i].RunTaskType); if (p.RunTasks[i].RunTaskType == (int)cGlobalParas.RunTaskType.DataTask) { litem.SubItems.Add(cGlobalParas.ConvertName(int.Parse(p.RunTasks[i].RunTaskName))); } else { litem.SubItems.Add(p.RunTasks[i].RunTaskName); } litem.SubItems.Add(p.RunTasks[i].RunTaskPara); this.listTask.Items.Add(litem); } this.EnabledDate.Value = DateTime.Parse(p.EnabledDateTime); switch (p.RunTaskPlanType) { case (int)cGlobalParas.RunTaskPlanType.Ones: this.raOneTime.Checked = true; this.RunOnceTime.Value = DateTime.Parse(p.RunOnesTime); break; case (int)cGlobalParas.RunTaskPlanType.DayOnes: this.raDay.Checked = true; this.raRunones.Checked = true; this.RunDayOnesTime.Value = DateTime.Parse(p.RunDayTime); break; case (int)cGlobalParas.RunTaskPlanType.DayTwice: this.raDay.Checked = true; this.raRuntwice.Checked = true; this.RunDayTwice1Time.Value = DateTime.Parse(p.RunAMTime); this.RunDayTwice2Time.Value = DateTime.Parse(p.RunPMTime); break; case (int)cGlobalParas.RunTaskPlanType.Weekly: this.raWeekly.Checked = true; this.RunWeeklyTime.Value = DateTime.Parse(p.RunWeeklyTime); string rWeekly = p.RunWeekly; foreach (string sc in rWeekly.Split(',')) { string ss = sc.Trim(); switch (ss) { case "0": this.cboxSunday.Checked = true; break; case "1": this.cboxMonday.Checked = true; break; case "2": this.cboxTuesday.Checked = true; break; case "3": this.cboxWednesday.Checked = true; break; case "4": this.cboxThursday.Checked = true; break; case "5": this.cboxFriday.Checked = true; break; case "6": this.cboxSunday.Checked = true; break; default: break; } } break; case (int)cGlobalParas.RunTaskPlanType.Custom: this.raCustom.Checked = true; this.FirstRunTime.Value = DateTime.Parse(p.FirstRunTime); this.udRunInterval.Value = decimal.Parse(p.RunInterval); break; } p = null; ps = null; }
private Int64 SaveTaskPlan() { cPlan NewPlan = new cPlan(); Int64 Nid = GetNewID(); if (Nid == 0) { throw new cSoukeyException(rm.GetString("Error21")); } NewPlan.PlanID = Nid; NewPlan.PlanName = this.txtPlanName.Text; NewPlan.PlanRemark = this.txtPlanDemo.Text; //系统自动判断当前任务的状态 if (this.cboxIsDisabled.Checked == true) { if (this.raNumber.Checked == true) { if (this.DisabledRunNum.Value == 1 && DateTime.Compare(DateTime.Now, this.RunOnceTime.Value) > 0) { NewPlan.PlanState = (int)cGlobalParas.PlanState.Disabled; } else { NewPlan.PlanState = (int)cGlobalParas.PlanState.Enabled; } } else if (this.raDateTime.Checked == true) { if (DateTime.Compare(DateTime.Now, this.DisabledDateTime.Value) < 0) { NewPlan.PlanState = (int)cGlobalParas.PlanState.Disabled; } else { NewPlan.PlanState = (int)cGlobalParas.PlanState.Enabled; } } } else { NewPlan.PlanState = (int)cGlobalParas.PlanState.Enabled; } if (this.cboxIsRun.Checked == true) { NewPlan.IsOverRun = true; } else { NewPlan.IsOverRun = false; } if (this.cboxIsDisabled.Checked == true) { NewPlan.IsDisabled = true; } else { NewPlan.IsDisabled = false; } if (this.raNumber.Checked == true) { NewPlan.DisabledType = (int)cGlobalParas.PlanDisabledType.RunTime; } else if (this.raDateTime.Checked == true) { NewPlan.DisabledType = (int)cGlobalParas.PlanDisabledType.RunDateTime; } NewPlan.DisabledTime = int.Parse(this.DisabledRunNum.Value.ToString()); NewPlan.DisabledDateTime = this.DisabledDateTime.Value; cTaskPlan tp; for (int i = 0; i < this.listTask.Items.Count; i++) { tp = new cTaskPlan(); tp.RunTaskType = cGlobalParas.ConvertID(this.listTask.Items[i].Text); if (cGlobalParas.ConvertID(this.listTask.Items[i].Text) == (int)cGlobalParas.RunTaskType.DataTask) { tp.RunTaskName = cGlobalParas.ConvertID(this.listTask.Items[i].SubItems[1].Text.ToString()).ToString(); } else { tp.RunTaskName = this.listTask.Items[i].SubItems[1].Text.ToString(); } tp.RunTaskPara = this.listTask.Items[i].SubItems[2].Text.ToString(); NewPlan.RunTasks.Add(tp); } if (this.raOneTime.Checked == true) { NewPlan.RunTaskPlanType = (int)cGlobalParas.RunTaskPlanType.Ones; } else if (this.raDay.Checked == true) { if (this.raRunones.Checked == true) { NewPlan.RunTaskPlanType = (int)cGlobalParas.RunTaskPlanType.DayOnes; } else if (this.raRuntwice.Checked == true) { NewPlan.RunTaskPlanType = (int)cGlobalParas.RunTaskPlanType.DayTwice; } } else if (this.raWeekly.Checked == true) { NewPlan.RunTaskPlanType = (int)cGlobalParas.RunTaskPlanType.Weekly; } else if (this.raCustom.Checked == true) { NewPlan.RunTaskPlanType = (int)cGlobalParas.RunTaskPlanType.Custom; } NewPlan.EnabledDateTime = this.EnabledDate.Value.ToLongDateString(); NewPlan.RunOnesTime = this.RunOnceTime.Value.ToString(); NewPlan.RunDayTime = this.RunDayOnesTime.Value.ToLongTimeString(); NewPlan.RunAMTime = this.RunDayTwice1Time.Value.ToLongTimeString(); NewPlan.RunPMTime = this.RunDayTwice2Time.Value.ToLongTimeString(); NewPlan.RunWeeklyTime = this.RunWeeklyTime.Value.ToLongTimeString(); NewPlan.FirstRunTime = this.FirstRunTime.Value.ToLongTimeString(); NewPlan.RunInterval = this.udRunInterval.Value.ToString(); string runWeekly = ""; if (this.cboxSunday.Checked == true) { runWeekly = "0"; } if (this.cboxMonday.Checked == true) { runWeekly += ",1"; } if (this.cboxTuesday.Checked == true) { runWeekly += ",2"; } if (this.cboxWednesday.Checked == true) { runWeekly += ",3"; } if (this.cboxThursday.Checked == true) { runWeekly += ",4"; } if (this.cboxFriday.Checked == true) { runWeekly += ",5"; } if (this.cboxSturday.Checked == true) { runWeekly += ",6"; } NewPlan.RunWeekly = runWeekly; cPlans p = new cPlans(); if (this.FormState == cGlobalParas.FormState.New) { p.InsertPlan(NewPlan); } else if (this.FormState == cGlobalParas.FormState.Edit) { p.EditPlan(NewPlan); } p = null; return(Nid); }