版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

239 строки
9.6 KiB

  1. using MaiMuAOI.SysCtrl;
  2. using Microsoft.Office.Interop.Excel;
  3. using Models;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace MaiMuAOI.SysUI.ProcessStep
  16. {
  17. public partial class StepListFrm : Form
  18. {
  19. private Service.StepService service = new Service.StepService();
  20. public StepListFrm()
  21. {
  22. InitializeComponent();
  23. UIStyle.SetUIStyle(this);
  24. this.uiTitel1.FatherForm = this;
  25. #region dataGridView设置
  26. dataGridView1.AutoGenerateColumns = false;//自动创建列
  27. dataGridView1.AllowUserToAddRows = dataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
  28. dataGridView1.AllowUserToResizeRows = true;//用户调整行大小
  29. //dataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
  30. //显示行号与列宽度自动调整
  31. dataGridView1.RowHeadersVisible = true;
  32. dataGridView1.RowHeadersWidth = 50;
  33. dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
  34. dataGridView1.RowPostPaint += (sender, e) =>//序号列头
  35. {
  36. SysMgr.showRowNum_onDataGrid_RowPostPaint(this.dataGridView1, sender, e);
  37. };
  38. dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  39. #endregion
  40. this.tbSearch.Top = toolStrip1.Top + 15;
  41. }
  42. private void InitDataView(int selIndex = -1)
  43. {
  44. var list = service.GetListNav(0);
  45. tsslCount.Text = $"共 {list.Count} 条记录";
  46. int liIndex = 0;
  47. if (selIndex > 0) liIndex = selIndex;
  48. else if (this.dataGridView1.CurrentRow != null)
  49. liIndex = this.dataGridView1.CurrentRow.Index;
  50. dataGridView1.DataSource = new BindingSource(list, null);
  51. if (dataGridView1.Rows.Count > liIndex)
  52. dataGridView1.CurrentCell = dataGridView1[2, liIndex];
  53. }
  54. private void StepListFrm_Load(object sender, EventArgs e)
  55. {
  56. this.Cursor = Cursors.WaitCursor;
  57. InitDataView();
  58. this.Cursor = Cursors.Default;
  59. }
  60. private void tsbtnAdd_Click(object sender, EventArgs e)
  61. {
  62. StepSelectFrm stepSelectFrm = new StepSelectFrm();
  63. stepSelectFrm.ShowDialog();
  64. if (stepSelectFrm.ProcessSelect == 200)
  65. {
  66. //老流程
  67. StepInfoFrm frm = new StepInfoFrm();
  68. frm.ShowDialog();
  69. }
  70. else if (stepSelectFrm.ProcessSelect == 100)
  71. {
  72. //新流程
  73. StepProcessFrm frm = new StepProcessFrm();
  74. frm.ShowDialog();
  75. }
  76. InitDataView();
  77. }
  78. private void tsbtnDel_Click(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. if (this.dataGridView1.CurrentRow == null)
  83. return;
  84. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
  85. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  86. if (service.InUse(list[liIndex].Id))
  87. throw new Exception("此流程已有产品在使用中,不可删除!");
  88. if (MessageBox.Show($"确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  89. {
  90. if (!service.DelNav(list[liIndex]))
  91. throw new Exception("删除失败!");
  92. SysMgr.Instance.WriteSysEditLog("流程删除", JsonConvert.SerializeObject(list[liIndex]));
  93. MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  94. this.dataGridView1.Rows.RemoveAt(liIndex);
  95. if (this.dataGridView1.Rows.Count == 0)
  96. InitDataView();
  97. }
  98. }
  99. catch (Exception ex)
  100. {
  101. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  102. }
  103. }
  104. private void tsbtnClone_Click(object sender, EventArgs e)
  105. {
  106. if (this.dataGridView1.CurrentRow == null)
  107. {
  108. MessageBox.Show("请选择要克隆的流程!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  109. return;
  110. }
  111. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
  112. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  113. Step newStep = new Step()
  114. {
  115. Code = list[liIndex].Code + $"_{DateTime.Now.ToString("yyyyMMddHHmmss")}clone",
  116. Name = $"{list[liIndex].Name} (克隆)",
  117. StartTimeIndex = list[liIndex].StartTimeIndex,
  118. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  119. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  120. ProcessList = new List<StepProcess>(),
  121. ProcessType = list[liIndex].ProcessType,
  122. };
  123. foreach (var item in list[liIndex].ProcessList)
  124. {
  125. StepProcess sp;
  126. string spPrarms = "";
  127. if (item.ProcessCode == "Size")
  128. {
  129. if (item.ProcessParams.IndexOf("MapPath") > 0)
  130. {
  131. JObject jo = JObject.Parse(item.ProcessParams);//解析成json
  132. jo["MapPath"] = "";//修改需要的字段
  133. jo["GetPointList"] = null;
  134. spPrarms = Convert.ToString(jo);
  135. }
  136. else
  137. spPrarms = item.ProcessParams;
  138. }
  139. else
  140. spPrarms = item.ProcessParams;
  141. sp = new StepProcess()
  142. {
  143. Order = item.Order,
  144. ProcessCode = item.ProcessCode,
  145. ProcessName = item.ProcessName,
  146. ProcessParams = spPrarms,
  147. ModifyUserCode = SysMgr.Instance.UserMgr.LoginUser.Code,
  148. CreateUserCode = SysMgr.Instance.UserMgr.LoginUser.Code
  149. };
  150. newStep.ProcessList.Add(sp);
  151. }
  152. try
  153. {
  154. bool result = service.InsertNav(newStep);
  155. if (result)
  156. {
  157. SysMgr.Instance.WriteSysEditLog("流程克隆", JsonConvert.SerializeObject(newStep));
  158. MessageBox.Show("克隆成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  159. InitDataView(dataGridView1.Rows.Count);
  160. }
  161. else
  162. throw new Exception("克隆失败!");
  163. }
  164. catch (Exception ex)
  165. {
  166. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  167. }
  168. }
  169. private void tsbtnClose_Click(object sender, EventArgs e)
  170. {
  171. this.Close();
  172. }
  173. private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  174. {
  175. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
  176. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  177. //新老流程判断
  178. if (list[liIndex].ProcessType == "快速流程")
  179. {
  180. StepProcessFrm frm = new StepProcessFrm(list[liIndex]);
  181. frm.ShowDialog(this);
  182. }
  183. else
  184. {
  185. StepInfoFrm frm = new StepInfoFrm(list[liIndex]);
  186. frm.ShowDialog(this);
  187. }
  188. InitDataView();
  189. }
  190. private void tbSearch_TextChanged(object sender, EventArgs e)
  191. {
  192. if (tbSearch.Text != "")
  193. {
  194. int count = 0;
  195. foreach (DataGridViewRow row in dataGridView1.Rows)
  196. {
  197. for (int i = 0; i < row.Cells.Count; i++)
  198. {
  199. if (row.Cells[i].Value != null && row.Cells[i].Value.ToString().Contains(tbSearch.Text))
  200. {
  201. count = count + 1;
  202. }
  203. }
  204. if (count == 0)
  205. {
  206. CurrencyManager cm = (CurrencyManager)BindingContext[dataGridView1.DataSource];
  207. cm.SuspendBinding(); //挂起数据绑定
  208. row.Visible = false;
  209. cm.ResumeBinding(); //恢复数据绑定
  210. }
  211. count = 0;
  212. }
  213. }
  214. else
  215. {
  216. for (int i = 0; i < dataGridView1.Rows.Count; i++)
  217. {
  218. dataGridView1.Rows[i].Visible = true;
  219. }
  220. }
  221. }
  222. }
  223. }