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

354 lines
15 KiB

  1. using Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace ProductionControl
  12. {
  13. public partial class FrmProductList : Form
  14. {
  15. Service.ProductService service = new Service.ProductService();
  16. public Models.Product Product { get; private set; }
  17. public FrmProductList(bool isProductRevise=false)
  18. {
  19. InitializeComponent();
  20. this.tsbtnAdd.Enabled=this.tsbtnDel.Enabled =this.tsbtnSetting.Enabled= !isProductRevise;
  21. this.tsbtnRevise.Visible=isProductRevise;
  22. if (isProductRevise)
  23. {
  24. this.Text = "产品基准厚度校正";
  25. }
  26. #region dataGridView设置
  27. dataGridView1.AutoGenerateColumns = false;//自动创建列
  28. dataGridView1.AllowUserToAddRows = dataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
  29. dataGridView1.AllowUserToResizeRows = true;//用户调整行大小
  30. //dataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
  31. //显示行号与列宽度自动调整
  32. dataGridView1.RowHeadersVisible = true;
  33. dataGridView1.RowHeadersWidth = 50;
  34. dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
  35. dataGridView1.RowPostPaint += (sender, e) =>//序号列头
  36. {
  37. Utils.Util.showRowNum_onDataGrid_RowPostPaint(this.dataGridView1, sender, e);
  38. };
  39. dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  40. //for (int i = 0; i < dataGridView1.Columns.Count; i++)//禁止点击列头排序
  41. // dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  42. //行列交叉处标题
  43. //if (dataGridView1.RowHeadersVisible) dataGridView1.TopLeftHeaderCell.Value = "SPH/CYL";
  44. #endregion
  45. }
  46. private void initDataView(int selIndex = -1)
  47. {
  48. Product = null;
  49. var list = service.GetListNav();
  50. tsslCount.Text = $"共 {list.Count} 条记录";
  51. int liIndex = 0;
  52. if (selIndex > 0) liIndex = selIndex;
  53. else if (this.dataGridView1.CurrentRow!=null)
  54. liIndex=this.dataGridView1.CurrentRow.Index;
  55. dataGridView1.DataSource = new BindingSource(list, null);
  56. if (dataGridView1.Rows.Count > liIndex)
  57. dataGridView1.CurrentCell = dataGridView1[1, liIndex];
  58. }
  59. private void FrmProductList_Load(object sender, EventArgs e)
  60. {
  61. initDataView();
  62. }
  63. private void tsbtnRefresh_Click(object sender, EventArgs e)
  64. {
  65. initDataView();
  66. }
  67. private void tsbtnAdd_Click(object sender, EventArgs e)
  68. {
  69. FrmProductInfo frm = new FrmProductInfo();
  70. frm.ShowDialog();
  71. initDataView();
  72. }
  73. private void tsbtnDel_Click(object sender, EventArgs e)
  74. {
  75. try
  76. {
  77. if (this.dataGridView1.CurrentRow == null)
  78. return;
  79. if (MessageBox.Show($"确认删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  80. {
  81. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  82. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  83. if (!service.DelNav(list[liIndex]))
  84. throw new Exception("删除失败!");
  85. MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  86. //initDataView();
  87. this.dataGridView1.Rows.RemoveAt(liIndex);
  88. if(this.dataGridView1.Rows.Count == 0)
  89. initDataView();
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  95. }
  96. }
  97. private void tsbtnSetting_Click(object sender, EventArgs e)
  98. {
  99. if(this.dataGridView1.CurrentRow == null) return;
  100. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  101. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  102. FrmProductStep frm = new FrmProductStep(list[liIndex]);
  103. frm.ShowDialog();
  104. initDataView();
  105. }
  106. private void tsbtnRevise_Click(object sender, EventArgs e)
  107. {
  108. try
  109. {
  110. if (this.dataGridView1.CurrentRow == null)
  111. throw new Exception("请选择要校正的产品!");
  112. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  113. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  114. if (list[liIndex].ReviseStepId==null || list[liIndex].ReviseStepId<1)
  115. throw new Exception("此产品未设置校正流程!");
  116. if (MessageBox.Show($"确认执行校正产品流程?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  117. {
  118. Product=list[liIndex];
  119. this.DialogResult = DialogResult.Yes;
  120. this.Close();
  121. }
  122. }
  123. catch (Exception ex)
  124. {
  125. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  126. }
  127. }
  128. private void tsbtnClose_Click(object sender, EventArgs e)
  129. {
  130. this.Close();
  131. }
  132. private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  133. {
  134. if (!this.tsbtnAdd.Enabled) return;
  135. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  136. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  137. FrmProductInfo frm = new FrmProductInfo(list[liIndex]);
  138. frm.ShowDialog(this);
  139. initDataView();
  140. }
  141. private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
  142. {
  143. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  144. for (int i = 0; i < dataGridView1.Rows.Count; i++)
  145. {
  146. if (list[i].ClassesInfo != null)
  147. dataGridView1.Rows[i].Cells["colClasses"].Value = list[i].ClassesInfo.Name;
  148. if (list[i].StepInfo != null)
  149. dataGridView1.Rows[i].Cells["colStepName"].Value = list[i].StepInfo.Name;
  150. if (list[i].ReviseStepInfo != null)
  151. dataGridView1.Rows[i].Cells["colReviseStepName"].Value = list[i].ReviseStepInfo.Name;
  152. }
  153. }
  154. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  155. {
  156. }
  157. private void tsbtnClasses_Click(object sender, EventArgs e)
  158. {
  159. FrmClassesSingle frm = new FrmClassesSingle(0, "产品类型管理");
  160. if(frm.ShowDialog() == DialogResult.OK)
  161. {
  162. this.initDataView();
  163. }
  164. }
  165. private void tsbtnDefectClasses_Click(object sender, EventArgs e)
  166. {
  167. }
  168. private void tsbtnClone_Click(object sender, EventArgs e)
  169. {
  170. if (this.dataGridView1.CurrentRow == null)
  171. {
  172. MessageBox.Show("请选择要克隆的产品!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  173. return;
  174. }
  175. var list = ((BindingSource)dataGridView1.DataSource).DataSource as List<Product>;
  176. int liIndex = this.dataGridView1.CurrentRow.Index;//获取当前选中行的索引
  177. Product newProduct = new Product()
  178. {
  179. Code = list[liIndex].Code + "_clone",
  180. Name = $"{list[liIndex].Name} (克隆)",
  181. Spec = list[liIndex].Spec,
  182. ClassesId = list[liIndex].ClassesId,
  183. ClassesInfo = list[liIndex].ClassesInfo,
  184. HoleCount = list[liIndex].HoleCount,
  185. DefectModelFile = list[liIndex].DefectModelFile,
  186. AttachmentList = new List<Attachment>(),
  187. BatchId = list[liIndex].BatchId,
  188. TargetCount = list[liIndex].TargetCount,
  189. CompleteCount = list[liIndex].CompleteCount,
  190. BatchHistoryList = new List<BatchHistory>(),
  191. QualifiedCriterionList = new List<QualifiedCriterion>(),
  192. Note = list[liIndex].Note,
  193. TensionBaseValue = list[liIndex].TensionBaseValue,
  194. TensionUpFloatValue = list[liIndex].TensionUpFloatValue,
  195. TensionDownFloatValue = list[liIndex].TensionDownFloatValue,
  196. HeightBaseValue = list[liIndex].HeightBaseValue,
  197. HeightUpFloatValue = list[liIndex].HeightUpFloatValue,
  198. HeightDownFloatValue = list[liIndex].HeightDownFloatValue,
  199. LineWidthBaseValue = list[liIndex].LineWidthBaseValue,
  200. LineWidthUpFloatValue = list[liIndex].LineWidthUpFloatValue,
  201. LineWidthDownFloatValue = list[liIndex].LineWidthDownFloatValue,
  202. PTBaseValue = list[liIndex].PTBaseValue,
  203. PTUpFloatValue = list[liIndex].PTUpFloatValue,
  204. PTDownFloatValue = list[liIndex].PTDownFloatValue,
  205. HeightBaseDec = list[liIndex].HeightBaseDec,
  206. StepId = list[liIndex].StepId,
  207. StepInfo = list[liIndex].StepInfo,
  208. ProductProcessList = new List<ProductProcess>(),
  209. ReviseStepId = list[liIndex].ReviseStepId,
  210. ReviseStepInfo = list[liIndex].ReviseStepInfo,
  211. ProductReviseProcessList = new List<ProductReviseProcess>(),
  212. AssistStepId = list[liIndex].AssistStepId,
  213. AssistStepInfo = list[liIndex].AssistStepInfo,
  214. ProductAssistProcessList = new List<ProductAssistProcess>(),
  215. MarkType = list[liIndex].MarkType,
  216. MarkSize = list[liIndex].MarkSize,
  217. MapPath = "",
  218. GetPointList = "",
  219. //OrderList = new List<Order>(),
  220. ModifyUserCode = Config.loginUser.Code,
  221. CreateUserCode = Config.loginUser.Code
  222. };
  223. foreach (var item in list[liIndex].AttachmentList)
  224. {
  225. newProduct.AttachmentList.Add(new Attachment()
  226. {
  227. TBName = item.TBName,
  228. Type = item.Type,
  229. Pid = item.Pid,
  230. Name = item.Name,
  231. NameTimestamp = item.NameTimestamp,
  232. ExtendName = item.ExtendName,
  233. ModifyUserCode = Config.loginUser.Code,
  234. CreateUserCode = Config.loginUser.Code
  235. });
  236. }
  237. foreach (var item in list[liIndex].BatchHistoryList)
  238. {
  239. newProduct.BatchHistoryList.Add(new BatchHistory()
  240. {
  241. Pid = item.Pid,
  242. BatchId = item.BatchId,
  243. TargetCount = item.TargetCount,
  244. CompleteCount = item.CompleteCount,
  245. ModifyUserCode = Config.loginUser.Code,
  246. CreateUserCode = Config.loginUser.Code
  247. });
  248. }
  249. foreach (var item in list[liIndex].QualifiedCriterionList)
  250. {
  251. newProduct.QualifiedCriterionList.Add(new QualifiedCriterion()
  252. {
  253. Pid = item.Pid,
  254. DefectCode = item.DefectCode,
  255. Size = item.Size,
  256. MaxDefectCount = item.MaxDefectCount,
  257. ModifyUserCode = Config.loginUser.Code,
  258. CreateUserCode = Config.loginUser.Code
  259. });
  260. }
  261. foreach (var item in list[liIndex].ProductProcessList)
  262. {
  263. newProduct.ProductProcessList.Add(new ProductProcess()
  264. {
  265. Pid = item.Pid,
  266. ProcessCode = item.ProcessCode,
  267. ProcessParams = item.ProcessParams,
  268. ModifyUserCode = Config.loginUser.Code,
  269. CreateUserCode = Config.loginUser.Code
  270. });
  271. }
  272. foreach (var item in list[liIndex].ProductReviseProcessList)
  273. {
  274. newProduct.ProductReviseProcessList.Add(new ProductReviseProcess()
  275. {
  276. Pid = item.Pid,
  277. ProcessCode = item.ProcessCode,
  278. ProcessParams = item.ProcessParams,
  279. ModifyUserCode = Config.loginUser.Code,
  280. CreateUserCode = Config.loginUser.Code
  281. });
  282. }
  283. foreach (var item in list[liIndex].ProductAssistProcessList)
  284. {
  285. newProduct.ProductAssistProcessList.Add(new ProductAssistProcess()
  286. {
  287. Pid = item.Pid,
  288. ProcessCode = item.ProcessCode,
  289. ProcessParams = item.ProcessParams,
  290. ModifyUserCode = Config.loginUser.Code,
  291. CreateUserCode = Config.loginUser.Code
  292. });
  293. }
  294. /*
  295. foreach (var item in list[liIndex].OrderList)
  296. {
  297. newProduct.OrderList.Add(new Order()
  298. {
  299. ProductId = item.ProductId,
  300. ProductInfo = item.ProductInfo,
  301. SN = item.SN,
  302. ModifyUserCode = Config.loginUser.Code,
  303. CreateUserCode = Config.loginUser.Code
  304. });
  305. }*/
  306. try
  307. {
  308. bool result = service.InsertNav(newProduct);
  309. if (result)
  310. {
  311. MessageBox.Show("克隆成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  312. initDataView(dataGridView1.Rows.Count);
  313. }
  314. else
  315. throw new Exception("克隆失败!");
  316. }
  317. catch (Exception ex)
  318. {
  319. MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  320. }
  321. }
  322. }
  323. }