版博士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.
 
 
 
 

252 lines
11 KiB

  1. using Models;
  2. using Newtonsoft.Json;
  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 FrmProductStep : Form
  15. {
  16. Service.ProductService service = new Service.ProductService();
  17. Models.Product model = new Models.Product();
  18. private int? stepId, reviseStepId;
  19. /// <summary>
  20. /// 产品配方 <StepId,List<Models.ProductProcess>>
  21. /// </summary>
  22. Dictionary<int, List<Models.ProductProcess>> dicProductProcess = new Dictionary<int, List<Models.ProductProcess>>();
  23. public FrmProductStep(Models.Product m)
  24. {
  25. InitializeComponent();
  26. dataGridView1.AutoGenerateColumns = false;
  27. //显示行号与列宽度自动调整
  28. dataGridView1.RowHeadersVisible = true;
  29. dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
  30. dataGridView1.RowPostPaint += (sender, e) =>
  31. {
  32. Utils.Util.showRowNum_onDataGrid_RowPostPaint(this.dataGridView1, sender, e);
  33. };
  34. model = m;
  35. initDataView();
  36. }
  37. private void initDataView()
  38. {
  39. //显示的数据
  40. this.cobStepList.DisplayMember = "Name";
  41. this.cobStepList.ValueMember = "Id";
  42. var list = service.GetStepList(0);
  43. foreach (var item in list)
  44. dicProductProcess.Add(item.Id, new List<Models.ProductProcess>());
  45. if (model.StepId != null)
  46. {
  47. this.stepId = (int)model.StepId;
  48. dicProductProcess[(int)model.StepId] = model.ProductProcessList;
  49. }
  50. if (model.ReviseStepId != null) {
  51. this.reviseStepId = (int)model.ReviseStepId;
  52. dicProductProcess[(int)model.ReviseStepId] = cv2ProductProcess(model.ProductReviseProcessList);
  53. }
  54. this.cobStepList.DataSource = list;
  55. if (model.StepId != null)
  56. this.cobStepList.SelectedValue = (int)model.StepId;
  57. }
  58. private void robtn1_CheckedChanged(object sender, EventArgs e)
  59. {
  60. if (!robtn1.Checked) return;
  61. if (model.StepId != null)
  62. {
  63. dicProductProcess[(int)model.StepId] = model.ProductProcessList;
  64. this.cobStepList.SelectedValue = (int)model.StepId;
  65. }
  66. this.stepId = (int)this.cobStepList.SelectedValue;
  67. }
  68. private void robtn2_CheckedChanged(object sender, EventArgs e)
  69. {
  70. if (!robtn2.Checked) return;
  71. if (model.ReviseStepId != null)
  72. {
  73. dicProductProcess[(int)model.StepId] = cv2ProductProcess(model.ProductReviseProcessList);
  74. this.cobStepList.SelectedValue = (int)model.ReviseStepId;
  75. }
  76. this.reviseStepId = (int)this.cobStepList.SelectedValue;
  77. }
  78. private List<ProductProcess> cv2ProductProcess(List<ProductReviseProcess> list)
  79. {
  80. List<ProductProcess> result=new List<ProductProcess>();
  81. foreach (var item in list)
  82. result.Add(item);
  83. return result;
  84. }
  85. private List<ProductReviseProcess> cv2ProductReviseProcess(List<ProductProcess> list)
  86. {
  87. string json;
  88. List<ProductReviseProcess> result = new List<ProductReviseProcess>();
  89. foreach (var item in list)
  90. {
  91. json=JsonConvert.SerializeObject(item);
  92. result.Add(JsonConvert.DeserializeObject<ProductReviseProcess>(json));
  93. }
  94. return result;
  95. }
  96. private void FrmProductInfo_Load(object sender, EventArgs e)
  97. {
  98. }
  99. private void cobStepList_SelectedIndexChanged(object sender, EventArgs e)
  100. {
  101. var list = this.cobStepList.DataSource as List<Models.Step>;
  102. int liIndex=this.cobStepList.SelectedIndex;
  103. if (liIndex < 0)
  104. return;
  105. dataGridView1.DataSource = new BindingSource(list[liIndex].ProcessList, null);
  106. tsslCount.Text = $"共{list[liIndex].ProcessList.Count}条工序";
  107. if(robtn1.Checked)
  108. this.stepId = (int)this.cobStepList.SelectedValue;
  109. else
  110. this.reviseStepId = (int)this.cobStepList.SelectedValue;
  111. }
  112. private void tsbtnSave_Click(object sender, EventArgs e)
  113. {
  114. try
  115. {
  116. if (stepId == null || reviseStepId == null)
  117. throw new Exception("请设置产品生产和校正流程!");
  118. //int? liOldStepId = model.StepId;
  119. //int liNewStepId = (int)this.cobStepList.SelectedValue;
  120. model.StepId = stepId;
  121. model.ReviseStepId = reviseStepId;
  122. model.ProductProcessList = dicProductProcess[(int)stepId];
  123. model.ProductReviseProcessList = cv2ProductReviseProcess(dicProductProcess[(int)reviseStepId]);
  124. model.ModifyUserCode = Config.loginUser.Code;
  125. bool result = service.UpdateNav(model);
  126. if (!result)
  127. throw new Exception("保存失败!");
  128. MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  129. this.Close();
  130. }
  131. catch (Exception ex)
  132. {
  133. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  134. }
  135. }
  136. private void tsbtnCls_Click(object sender, EventArgs e)
  137. {
  138. try
  139. {
  140. if (this.dataGridView1.CurrentRow == null)
  141. throw new Exception("请选择要清除私有产品配方的工序!");
  142. if(this.dataGridView1.CurrentRow.Cells["colPrivateProcessParams"].Value.ToString() == "")
  143. throw new Exception("此工序未配置私有配方,无需清除!");
  144. //
  145. int liNewStepId = (int)this.cobStepList.SelectedValue;
  146. string processCode= this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
  147. var m = dicProductProcess[liNewStepId].Find(x => x.ProcessCode == processCode);
  148. if (m != null)
  149. {
  150. dicProductProcess[liNewStepId].Remove(m);
  151. this.dataGridView1.CurrentRow.Cells["colProdctPrivate"].Value = "";
  152. this.dataGridView1.CurrentRow.Cells["colPrivateProcessParams"].Value = "";
  153. MessageBox.Show("清除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  154. }
  155. }
  156. catch (Exception ex)
  157. {
  158. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  159. }
  160. }
  161. private void tsbtnClose_Click(object sender, EventArgs e)
  162. {
  163. this.Close();
  164. }
  165. private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
  166. {
  167. if (this.cobStepList.SelectedValue == null)
  168. return;
  169. int liNewStepId = (int)this.cobStepList.SelectedValue;
  170. string processCode;
  171. for (int i = 0; i < dataGridView1.Rows.Count; i++)
  172. {
  173. processCode = dataGridView1.Rows[i].Cells[0].Value.ToString();
  174. //dataGridView1.Rows[i].Cells[1].Value = Config.dicDevType[processCode];
  175. var m= dicProductProcess[liNewStepId].Find(x=>x.ProcessCode==processCode);
  176. if (m != null)
  177. {
  178. dataGridView1.Rows[i].Cells["colProdctPrivate"].Value = "是";
  179. dataGridView1.Rows[i].Cells["colPrivateProcessParams"].Value = m.ProcessParams;
  180. }
  181. else
  182. {
  183. dataGridView1.Rows[i].Cells["colProdctPrivate"].Value = "";
  184. dataGridView1.Rows[i].Cells["colPrivateProcessParams"].Value = "";
  185. }
  186. }
  187. }
  188. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  189. {
  190. int liNewStepId = (int)this.cobStepList.SelectedValue;
  191. int Index = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  192. if (Index < this.dataGridView1.Rows.Count && this.dataGridView1.CurrentCell.Value.ToString() == "设置")
  193. {
  194. string processCode = this.dataGridView1.Rows[Index].Cells["colProcessCode"].Value.ToString();
  195. string processParams = "";
  196. if (this.dataGridView1.Rows[Index].Cells["colPrivateProcessParams"].Value != null && this.dataGridView1.Rows[Index].Cells["colPrivateProcessParams"].Value.ToString()!="")
  197. processParams = this.dataGridView1.Rows[Index].Cells["colPrivateProcessParams"].Value.ToString();
  198. else if (this.dataGridView1.Rows[Index].Cells["colStepProcessParams"].Value != null && this.dataGridView1.Rows[Index].Cells["colStepProcessParams"].Value.ToString()!="")
  199. processParams = this.dataGridView1.Rows[Index].Cells["colStepProcessParams"].Value.ToString();
  200. FrmSetParams frm = new FrmSetParams(processCode, processParams);
  201. if (frm.ShowDialog() == DialogResult.OK)
  202. {
  203. this.dataGridView1.Rows[Index].Cells["colProdctPrivate"].Value = "是";
  204. this.dataGridView1.Rows[Index].Cells["colPrivateProcessParams"].Value = frm.ParamsData;
  205. var m = dicProductProcess[liNewStepId].Find(x => x.ProcessCode == processCode);
  206. if (m == null)
  207. dicProductProcess[liNewStepId].Add(new Models.ProductProcess()
  208. {
  209. Pid = model.Id,
  210. ProcessCode = processCode,
  211. ProcessParams = frm.ParamsData,
  212. ModifyUserCode=Config.loginUser.Code,
  213. CreateUserCode = Config.loginUser.Code,
  214. });
  215. else
  216. {
  217. m.ProcessParams = frm.ParamsData;
  218. m.ModifyUserCode = Config.loginUser.Code;
  219. }
  220. }
  221. }
  222. }
  223. private void FrmProductStep_FormClosing(object sender, FormClosingEventArgs e)
  224. {
  225. if (MessageBox.Show($"确认修改已保存,是否退出?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
  226. {
  227. e.Cancel = true;
  228. return;
  229. }
  230. }
  231. }
  232. }