frmTaskTimed.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Code.Extends;
  3. using NXWMS.Client.Model.AppModels.Condition.Rule;
  4. using NXWMS.Client.Model.AppModels.Result;
  5. using NXWMS.Client.Model.AppModels.Result.Rule;
  6. using NXWMS.Client.Model.CoreModels;
  7. using NXWMS.Client.String.Enums;
  8. using NXWMS.Commons;
  9. using NXWMS.Services;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Drawing;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Windows.Forms;
  18. namespace NXWMS.Forms.Rule
  19. {
  20. public partial class frmTaskTimed : Form
  21. {
  22. /// <summary>
  23. /// 客户端字段排序列表
  24. /// </summary>
  25. private List<ClientFieldOrderResult> _clientFieldOrderList;
  26. /// <summary>
  27. /// 界面最后执行操作
  28. /// </summary>
  29. private EnumOperation _LastOperation;
  30. private int _pageSize;
  31. private int _pageIndex;
  32. private int _totalCount;
  33. public frmTaskTimed()
  34. {
  35. InitializeComponent();
  36. InitData();
  37. InitControl();
  38. }
  39. private int _selectIndex;
  40. private int _selectId;
  41. private string _selectNo;
  42. /// <summary>
  43. /// 主键Key
  44. /// </summary>
  45. private string _PrimaryKey = "TIMED_TASK_ID";
  46. /// <summary>
  47. /// 主键编码
  48. /// </summary>
  49. private string _PrimaryNo = "TIMED_TASK_CODE";
  50. /// <summary>
  51. /// 选择行主键列表
  52. /// </summary>
  53. private List<string> _CheckRowIdList = new List<string>();
  54. /// <summary>
  55. /// 数据初始化
  56. /// </summary>
  57. private void InitData()
  58. {
  59. _clientFieldOrderList = new List<ClientFieldOrderResult>();
  60. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "TIMED_TASK_CODE", FieldDesc = "定时任务编码" });
  61. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "TIMED_TASK_CONTENT", FieldDesc = "定时任务内容" });
  62. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "TimedTaskTypeName", FieldDesc = "定时任务类型" });
  63. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "FrequencyTypeName", FieldDesc = "频率" });
  64. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "EXEC_TIME", FieldDesc = "执行时间" });
  65. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "EXEC_INTERVAL", FieldDesc = "执行间隔" });
  66. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "ExecIntervalTypeName", FieldDesc = "执行间隔类型" });
  67. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "DESCRIBE", FieldDesc = "描述" });
  68. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
  69. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
  70. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
  71. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
  72. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
  73. }
  74. /// <summary>
  75. /// 控件初始化
  76. /// </summary>
  77. private void InitControl()
  78. {
  79. CheckForIllegalCrossThreadCalls = false;
  80. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  81. groupOperation.MouseDown += new MouseEventHandler(this.groupOperation_MouseDown);
  82. groupOperation.MouseMove += new MouseEventHandler(this.groupOperation_MouseMove);
  83. dataGridView.CellDoubleClick += new DataGridViewCellEventHandler(this.dataGridView_CellDoubleClick);
  84. cmbTaskType.DataSource = new List<FieldValue>().GetFieldValueIdList<TimedTaskType>();
  85. cmbTaskType.DisplayMember = "Name";
  86. cmbTaskType.ValueMember = "Id";
  87. cmbFrequenyType.DataSource = new List<FieldValue>().GetFieldValueIdList<FrequencyType>();
  88. cmbFrequenyType.DisplayMember = "Name";
  89. cmbFrequenyType.ValueMember = "Id";
  90. cmbIntervalType.DataSource = new List<FieldValue>().GetFieldValueIdList<ExecIntervalType>();
  91. cmbIntervalType.DisplayMember = "Name";
  92. cmbIntervalType.ValueMember = "Id";
  93. _pageIndex = 1;
  94. _pageSize = 20;
  95. }
  96. private Point mouse_offset;
  97. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  98. {
  99. mouse_offset = new Point(-e.X, -e.Y);
  100. }
  101. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  102. {
  103. ((Control)sender).Cursor = Cursors.Arrow;
  104. if (e.Button == MouseButtons.Left)
  105. {
  106. Point mousePos = MousePosition;
  107. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  108. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  109. Application.DoEvents();
  110. }
  111. }
  112. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  113. {
  114. SelectInit();
  115. if (_selectIndex >= 0)
  116. {
  117. _LastOperation = EnumOperation.Edit;
  118. txtTaskCode.Enabled = false;
  119. tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  120. richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  121. dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  122. groupOperation.Visible = true;
  123. groupOperation.Focus();
  124. }
  125. }
  126. private void SelectInit()
  127. {
  128. if (dataGridView.SelectedRows.Count > 0)
  129. {
  130. _selectIndex = dataGridView.SelectedRows[0].Index;
  131. if (_selectIndex >= 0)
  132. {
  133. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  134. _selectNo = dataGridView.Rows[_selectIndex].Cells[_PrimaryNo].Value.ToString();
  135. }
  136. }
  137. else
  138. {
  139. _selectIndex = -1;
  140. }
  141. _CheckRowIdList = new List<string>();
  142. foreach (DataGridViewRow item in dataGridView.Rows)
  143. {
  144. if (item.Cells["#SELECTED"].Value.GetObjectToInt() == 1)
  145. {
  146. _CheckRowIdList.Add(item.Cells[_PrimaryKey].Value.ToString());
  147. }
  148. }
  149. }
  150. private void btnSearch_Click(object sender, EventArgs e)
  151. {
  152. _pageIndex = 1;
  153. var loadfrm = new frmLoading();
  154. loadfrm.Show();
  155. var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
  156. pageTool.DataCount = _totalCount;
  157. if (!string.IsNullOrWhiteSpace(message))
  158. {
  159. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  160. }
  161. }
  162. private string LoadSearch(int pageIndex, int pageSize)
  163. {
  164. var result = RuleServices.taskTimedService.GetList(new TaskTimedSearchCondition
  165. {
  166. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  167. IsUsed = chkSearchUse.Checked,
  168. TaskCode=txtTaskCode.Text,
  169. TaskContent=txtTaskContent.Text,
  170. PageIndex = pageIndex,
  171. PageSize = pageSize
  172. });
  173. if (result.Status == OperateStatus.Success)
  174. {
  175. _totalCount = result.Data.TotalCount;
  176. _pageIndex = pageIndex;
  177. _pageSize = pageSize;
  178. if (result.Data.RowData.Any())
  179. {
  180. dataGridView.Columns.Clear();
  181. dataGridView.DataSource = result.Data.RowData.ToList();
  182. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  183. }
  184. else
  185. {
  186. if (dataGridView.DataSource != null)
  187. {
  188. dataGridView.DataSource = new List<TaskTimedResult>();
  189. }
  190. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  191. }
  192. return string.Empty;
  193. }
  194. else
  195. {
  196. return result.Message;
  197. }
  198. }
  199. private void btnSearchExport_Click(object sender, EventArgs e)
  200. {
  201. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  202. }
  203. private void btnAdd_Click(object sender, EventArgs e)
  204. {
  205. if (!groupOperation.Visible)
  206. {
  207. tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  208. richDescibe.Text = "";
  209. _LastOperation = EnumOperation.Add;
  210. txtTaskCode.Enabled = true;
  211. numInterval.Value = 1;
  212. chkUse.Checked = true;
  213. groupOperation.Visible = true;
  214. groupOperation.Focus();
  215. }
  216. }
  217. private void btnEdit_Click(object sender, EventArgs e)
  218. {
  219. if (!groupOperation.Visible)
  220. {
  221. SelectInit();
  222. if (_selectIndex >= 0)
  223. {
  224. _LastOperation = EnumOperation.Edit;
  225. richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  226. dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  227. groupOperation.Visible = true;
  228. tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  229. txtTaskCode.Enabled = false;
  230. groupOperation.Visible = true;
  231. groupOperation.Focus();
  232. }
  233. }
  234. }
  235. private void btnRemove_Click(object sender, EventArgs e)
  236. {
  237. SelectInit();
  238. if (_CheckRowIdList.Count == 0)
  239. {
  240. return;
  241. }
  242. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  243. {
  244. var editResult = RuleServices.printTemplateService.Deleted(new PrintTemplateCondition
  245. {
  246. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  247. TemplateIds = string.Join(",", _CheckRowIdList),
  248. });
  249. if (editResult.Status == OperateStatus.Success)
  250. {
  251. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  252. btnSearch_Click(null, null);
  253. }
  254. else
  255. {
  256. KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  257. }
  258. }
  259. }
  260. private void btnSave_Click(object sender, EventArgs e)
  261. {
  262. if (string.IsNullOrWhiteSpace(txtTaskCode.Text))
  263. {
  264. KryptonMessageBox.Show($"请输入定时任务编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  265. return;
  266. }
  267. if (string.IsNullOrWhiteSpace(txtTaskContent.Text))
  268. {
  269. KryptonMessageBox.Show($"请输入定时任务内容。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  270. return;
  271. }
  272. if (string.IsNullOrWhiteSpace(cmbTaskType.Text))
  273. {
  274. KryptonMessageBox.Show($"请选择定时任务类型。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  275. return;
  276. }
  277. if (string.IsNullOrWhiteSpace(cmbFrequenyType.Text))
  278. {
  279. KryptonMessageBox.Show($"请选择定时任务频率。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  280. return;
  281. }
  282. if (string.IsNullOrWhiteSpace(cmbIntervalType.Text))
  283. {
  284. KryptonMessageBox.Show($"请输入执行间隔。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  285. return;
  286. }
  287. switch (_LastOperation)
  288. {
  289. case EnumOperation.Add:
  290. var addResult = RuleServices.taskTimedService.Add(new TaskTimedCondition
  291. {
  292. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  293. IsUsed = chkUse.Checked,
  294. Describe = richDescibe.Text,
  295. ExecInverval=Convert.ToInt32(numInterval.Value),
  296. ExecInvervalType=cmbIntervalType.SelectedValue.GetObjectToInt().Value,
  297. ExecTime= dtpExecTime.Value.ToString(),
  298. TaskCode=txtTaskCode.Text,
  299. FrequencyType=cmbFrequenyType.SelectedValue.GetObjectToInt(),
  300. TaskContent=txtTaskContent.Text,
  301. TaskType=cmbTaskType.SelectedValue.GetObjectToInt().Value,
  302. });
  303. if (addResult.Status == OperateStatus.Success)
  304. {
  305. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  306. InitControl();
  307. groupOperation.Visible = false;
  308. btnSearch_Click(null, null);
  309. dataGridView.ClearSelection();
  310. }
  311. else
  312. {
  313. KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  314. }
  315. break;
  316. case EnumOperation.Edit:
  317. var editResult = RuleServices.taskTimedService.Edit(new TaskTimedCondition
  318. {
  319. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  320. IsUsed = chkUse.Checked,
  321. Describe = richDescibe.Text,
  322. ExecInverval = Convert.ToInt32(numInterval.Value),
  323. ExecInvervalType = cmbIntervalType.SelectedValue.GetObjectToInt().Value,
  324. ExecTime = dtpExecTime.Value.ToString(),
  325. TaskCode = txtTaskCode.Text,
  326. FrequencyType = cmbFrequenyType.SelectedValue.GetObjectToInt(),
  327. TaskContent = txtTaskContent.Text,
  328. TaskType = cmbTaskType.SelectedValue.GetObjectToInt().Value,
  329. TaskId = _selectId,
  330. });
  331. if (editResult.Status == OperateStatus.Success)
  332. {
  333. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  334. InitControl();
  335. groupOperation.Visible = false;
  336. btnSearch_Click(null, null);
  337. dataGridView.ClearSelection();
  338. }
  339. else
  340. {
  341. KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  342. }
  343. break;
  344. }
  345. }
  346. private void btnExit_Click(object sender, EventArgs e)
  347. {
  348. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  349. {
  350. groupOperation.Visible = false;
  351. }
  352. else
  353. {
  354. groupOperation.Visible = true;
  355. groupOperation.Focus();
  356. }
  357. }
  358. }
  359. }