版博士V2.0程序
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.
 
 
 
 

178 lines
7.2 KiB

  1. using Models;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace ProductionControl
  13. {
  14. public partial class FrmStepList : Form
  15. {
  16. Service.StepService service=new Service.StepService();
  17. public FrmStepList()
  18. {
  19. InitializeComponent();
  20. #region dataGridView设置
  21. dataGridView1.AutoGenerateColumns = false;//自动创建列
  22. dataGridView1.AllowUserToAddRows = dataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
  23. dataGridView1.AllowUserToResizeRows = true;//用户调整行大小
  24. //dataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
  25. //显示行号与列宽度自动调整
  26. dataGridView1.RowHeadersVisible = true;
  27. dataGridView1.RowHeadersWidth = 50;
  28. dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
  29. dataGridView1.RowPostPaint += (sender, e) =>//序号列头
  30. {
  31. Utils.Util.showRowNum_onDataGrid_RowPostPaint(this.dataGridView1, sender, e);
  32. };
  33. dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  34. //for (int i = 0; i < dataGridView1.Columns.Count; i++)//禁止点击列头排序
  35. // dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  36. //行列交叉处标题
  37. //if (dataGridView1.RowHeadersVisible) dataGridView1.TopLeftHeaderCell.Value = "SPH/CYL";
  38. #endregion
  39. }
  40. private void initDataView(int selIndex=-1)
  41. {
  42. var list = service.GetListNav(0);
  43. tsslCount.Text = $"共 {list.Count} 条记录";
  44. int liIndex = 0;
  45. if(selIndex>0) liIndex = selIndex;
  46. else if (this.dataGridView1.CurrentRow != null)
  47. liIndex = this.dataGridView1.CurrentRow.Index;
  48. dataGridView1.DataSource = new BindingSource(list, null);
  49. if (dataGridView1.Rows.Count > liIndex)
  50. dataGridView1.CurrentCell = dataGridView1[1, liIndex];
  51. }
  52. private void FrmStepList_Load(object sender, EventArgs e)
  53. {
  54. initDataView();
  55. }
  56. private void tsbtnAdd_Click(object sender, EventArgs e)
  57. {
  58. FrmStepInfo frm = new FrmStepInfo();
  59. frm.ShowDialog();
  60. initDataView();
  61. }
  62. private void tsbtnDel_Click(object sender, EventArgs e)
  63. {
  64. try
  65. {
  66. if(this.dataGridView1.CurrentRow==null)
  67. return;
  68. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
  69. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  70. if (service.InUse(list[liIndex].Id))
  71. throw new Exception("此流程已有产品在使用中,不可删除!");
  72. if (MessageBox.Show($"确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  73. {
  74. if (!service.DelNav(list[liIndex]))
  75. throw new Exception("删除失败!");
  76. MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  77. this.dataGridView1.Rows.RemoveAt(liIndex);
  78. if (this.dataGridView1.Rows.Count == 0)
  79. initDataView();
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  85. }
  86. }
  87. private void tsbtnClone_Click(object sender, EventArgs e)
  88. {
  89. if (this.dataGridView1.CurrentRow == null)
  90. {
  91. MessageBox.Show("请选择要克隆的流程!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  92. return;
  93. }
  94. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
  95. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  96. Step newStep = new Step()
  97. {
  98. Code = list[liIndex].Code + "_clone",
  99. Name = $"{list[liIndex].Name} (克隆)",
  100. StartTimeIndex = list[liIndex].StartTimeIndex,
  101. ModifyUserCode = Config.loginUser.Code,
  102. CreateUserCode = Config.loginUser.Code,
  103. ProcessList = new List<StepProcess>()
  104. };
  105. foreach(var item in list[liIndex].ProcessList)
  106. {
  107. StepProcess sp;
  108. string spPrarms = "";
  109. if (item.ProcessCode == "Size")
  110. {
  111. if (item.ProcessParams.IndexOf("MapPath") > 0)
  112. {
  113. JObject jo = JObject.Parse(item.ProcessParams);//解析成json
  114. jo["MapPath"] = "";//修改需要的字段
  115. jo["GetPointList"] = null;
  116. spPrarms = Convert.ToString(jo);
  117. }
  118. else
  119. spPrarms = item.ProcessParams;
  120. }
  121. else
  122. spPrarms = item.ProcessParams;
  123. sp = new StepProcess()
  124. {
  125. Order = item.Order,
  126. ProcessCode = item.ProcessCode,
  127. ProcessName = item.ProcessName,
  128. ProcessParams = spPrarms,
  129. ModifyUserCode = Config.loginUser.Code,
  130. CreateUserCode = Config.loginUser.Code
  131. };
  132. newStep.ProcessList.Add(sp);
  133. }
  134. try
  135. {
  136. bool result = service.InsertNav(newStep);
  137. if (result)
  138. {
  139. MessageBox.Show("克隆成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  140. initDataView(dataGridView1.Rows.Count);
  141. }
  142. else
  143. throw new Exception("克隆失败!");
  144. }
  145. catch (Exception ex)
  146. {
  147. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  148. }
  149. }
  150. private void tsbtnClose_Click(object sender, EventArgs e)
  151. {
  152. this.Close();
  153. }
  154. private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  155. {
  156. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Step>;
  157. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  158. FrmStepInfo frm = new FrmStepInfo(list[liIndex]);
  159. frm.ShowDialog(this);
  160. initDataView();
  161. }
  162. }
  163. }