/// <summary> /// 初始化 /// </summary> private void Init() { //数据库 Banana.Uow.ConnectionBuilder.ConfigRegist(Properties.Settings.Default.strConnetion, Banana.Uow.Models.DBType.SqlServer); taskDataView.MultiSelect = false; taskDataView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; taskDataView.Columns.Clear(); taskDataView.Columns.Add("任务ID", "任务ID"); taskDataView.Columns.Add("网站", "网站"); taskDataView.Columns.Add("运行状态", "运行状态"); taskDataView.Columns.Add("频率", "频率"); taskDataView.Columns.Add("最近启动时间", "最近启动时间"); taskDataView.Columns.Add("运行次数", "运行次数"); taskDataView.Columns.Add("失败次数", "失败次数"); taskDataView.Columns.Add("备注", "备注"); RefreshDataGridView(TaskMngBLL.GetInstance().TaskInfos); tbSysLog.AppendText("运行中:任务正在运行中,请勿修改配置;\r\n"); tbSysLog.AppendText("\r\n"); tbSysLog.AppendText("挂起中:任务就绪状态,允许修改配置;\r\n"); tbSysLog.AppendText("\r\n"); tbSysLog.AppendText("已停止:任务已被禁用,允许修改配置、启动。\r\n"); //运行频率 int interval = 30; if (Properties.Settings.Default.runInterval_s > 0) { interval = Properties.Settings.Default.runInterval_s; } timerAuto.Interval = interval * 1000; timerAuto.Start(); }
private void taskTreeView_AfterSelect(object sender, TreeViewEventArgs e) { var node = e.Node; if (node != null) { var taskList = TaskMngBLL.GetInstance().TaskInfos; if (node.Text.Equals("运行中")) { RefreshDataGridView(taskList.FindAll(t => t.RunState == ERunState.Running)); } else if (node.Text.Equals("挂起中")) { RefreshDataGridView(taskList.FindAll(t => t.RunState == ERunState.HangUp)); } else if (node.Text.Equals("已停止")) { RefreshDataGridView(taskList.FindAll(t => t.RunState == ERunState.Stop)); } else { RefreshDataGridView(taskList); } } }
/// <summary> /// 定时运行 /// </summary> private void timerAuto_Tick(object sender, EventArgs e) { if (TaskMngBLL.GetInstance().Run(this)) { RefreshDataGridView(TaskMngBLL.GetInstance().TaskInfos); } }
private void btnTaskOff_Click(object sender, EventArgs e) { if (taskDataView.SelectedCells.Count != 0) { int taskid = Convert.ToInt16(taskDataView.CurrentRow.Cells[0].Value); string msg = TaskMngBLL.GetInstance().ChangeState(taskid, 0); if (!string.IsNullOrEmpty(msg)) { MessageBox.Show(msg); return; } RefreshDataGridView(TaskMngBLL.GetInstance().GetTask(taskid)); } }
private void btnRun_Click(object sender, EventArgs e) { if (taskDataView.SelectedCells.Count != 0) { int taskid = Convert.ToInt16(taskDataView.CurrentRow.Cells[0].Value); var taskInfo = TaskMngBLL.GetInstance().GetTask(taskid); taskInfo.Run(this, () => { RefreshDataGridView(taskInfo); }, MessageBox.Show("爬取结果是否保存到数据库?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK); RefreshDataGridView(taskInfo); } }
private void tbNewTask_Click(object sender, EventArgs e) { taskForm taskForm = new taskForm(this); if (taskForm.ShowDialog() == DialogResult.OK) { var newTask = taskForm.taskInfo; bool b = TaskMngBLL.GetInstance().AddNewTask(newTask); if (!b) { MessageBox.Show("保存任务失败了"); return; } FillTaksInfo(newTask); } }
private void btnTaskDelete_Click(object sender, EventArgs e) { if (taskDataView.SelectedCells.Count != 0) { if (MessageBox.Show("确认删除?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { int taskid = Convert.ToInt16(taskDataView.CurrentRow.Cells[0].Value); string msg = TaskMngBLL.GetInstance().ChangeState(taskid, -1); if (!string.IsNullOrEmpty(msg)) { MessageBox.Show(msg); return; } RefreshDataGridView(TaskMngBLL.GetInstance().TaskInfos); } } }
private void taskDataView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { if (taskDataView.SelectedCells.Count != 0) { int taskid = Convert.ToInt16(taskDataView.CurrentRow.Cells[0].Value); var taskInfo = TaskMngBLL.GetInstance().GetTask(taskid); if (taskInfo.RunState == ERunState.Running) { MessageBox.Show("任务运行中,不能进行编辑"); return; } taskForm taskForm = new taskForm(this); taskForm.Set(taskInfo); if (taskForm.ShowDialog() == DialogResult.OK) { if (!TaskMngBLL.GetInstance().UpdateTask(taskForm.taskInfo)) { MessageBox.Show("保存任务失败了"); return; } } RefreshDataGridView(taskInfo); } }