天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

280 lines
8.2 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QMTask.Client.TaskService;
namespace QMTask.Client
{
/// <summary>
/// 计划管理
/// </summary>
public partial class PlanListForm : Form
{
//计划列表
PlanInfo[] _plan;
//任务调度服务
TaskService.TaskServiceClient tsc = ServiceUtil.GetTaskService();
public PlanListForm()
{
InitializeComponent();
}
#region 窗体载入
private void PlanListForm_Load(object sender, EventArgs e)
{
//加载计划列表
loadData();
GridViewBind();
}
#endregion
#region 加载计划列表
/// <summary>
/// 加载计划列表
/// </summary>
private void loadData()
{
try
{
_plan = tsc.GetPlanList();
}
catch (Exception ex)
{
MessageBox.Show("加载计划失败:" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void GridViewBind()
{
if (_plan == null)
return;
dataGridView1.Rows.Clear();
List<TaskInfo> tasks = tsc.GetTaskList().ToList();
foreach (var a in _plan)
{
TaskInfo task = tasks.Find(p => p.TaskID == a.TaskID);
string periodType = "";
string intervalType = "";
switch (a.IntervalType)
{
case "s":
intervalType = "秒";
break;
case "m":
intervalType = "分";
break;
case "h":
intervalType = "小时";
break;
}
switch (a.PeriodType)
{
case "d":
if (string.IsNullOrEmpty(a.OnceTime) == false)
{
periodType = "每天";
}
else
{
periodType = "每"+a.Interval+intervalType;
}
break;
case "w":
periodType = "每周";
break;
case "m":
if (a.Period == 1)
{
periodType = "每月";
}
else
{
periodType = "每"+a.Period.ToString()+"月";
}
break;
}
string PlanEndDate = "无";
if (a.PlanEndDate != new DateTime())
{
PlanEndDate =a.PlanEndDate.ToString();
}
dataGridView1.Rows.Add(a.PlanID, a.PlanName, task.TaskName, periodType, a.IsUse == "true" ? "是" : "否", a.PlanStartDate, PlanEndDate);
}
}
#endregion
#region 编辑计划
private void btn_update_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("请选择要编辑的计划。");
return;
}
PlanEditForm editForm = new PlanEditForm();
editForm.Plan = _plan[dataGridView1.SelectedRows[0].Index];
editForm.ShowDialog();
string action = editForm.Action;
if (string.IsNullOrEmpty(action) == true)
return;
//加载计划列表
loadData();
GridViewBind();
}
#endregion
#region 删除计划
/// <summary>
/// 删除计划
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_del_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("请选择要删除的计划。");
return;
}
string PlanID = dataGridView1.SelectedRows[0].Cells["PlanID"].Value.ToString();
if (MessageBox.Show("是否删除选中的计划信息?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
{
try
{
bool r=tsc.DeletePlan(new PlanInfo() { PlanID = PlanID });
if (r == false)
{
MessageBox.Show("删除失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
catch (Exception ex)
{
MessageBox.Show("删除失败:" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//重新加载计划
loadData();
GridViewBind();
}
}
#endregion
#region 添加计划
private void btn_add_Click(object sender, EventArgs e)
{
PlanEditForm editForm = new PlanEditForm();
editForm.ShowDialog();
string action = editForm.Action;
if (string.IsNullOrEmpty(action) == true)
return;
//加载计划列表
loadData();
GridViewBind();
}
#endregion
private void btn_start_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("请选择要启用的计划。");
return;
}
PlanInfo plan = _plan[dataGridView1.SelectedRows[0].Index];
if (MessageBox.Show("是否启用选中的计划?", "启用", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
{
try
{
bool r = tsc.StartPlan(plan);
if (r == false)
{
MessageBox.Show("启用失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
catch (Exception ex)
{
MessageBox.Show("启用失败:" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//重新加载计划
loadData();
GridViewBind();
}
}
private void btn_stop_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("请选择要停用的计划。");
return;
}
PlanInfo plan =_plan[dataGridView1.SelectedRows[0].Index];
if (MessageBox.Show("是否停用选中的计划?", "停用", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
{
try
{
bool r = tsc.StopPlan(plan);
if (r == false)
{
MessageBox.Show("停用失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
catch (Exception ex)
{
MessageBox.Show("停用失败:" + ex.Message.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//重新加载计划
loadData();
GridViewBind();
}
}
}
}