革博士程序V1仓库
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
19 KiB

  1. using LeatherApp.Device;
  2. using LeatherApp.Interface;
  3. using Models;
  4. using Newtonsoft.Json.Linq;
  5. using Sunny.UI;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace LeatherApp.Page
  17. {
  18. public partial class FProductInfo : UIPage
  19. {
  20. private Service.ProductService service=new Service.ProductService();
  21. private Models.Product model = new Models.Product();
  22. public FProductInfo()
  23. {
  24. InitializeComponent();
  25. #region dataGridView设置
  26. uiDataGridView1.AllowUserToAddRows = uiDataGridView1.AllowUserToDeleteRows = false;//用户添加删除行
  27. uiDataGridView2.AllowUserToAddRows = uiDataGridView2.AllowUserToDeleteRows = false;
  28. uiDataGridView1.AllowUserToResizeRows = uiDataGridView2.AllowUserToResizeRows=false;//用户调整行大小
  29. //dataGridView1.AllowUserToResizeColumns = false;//用户调整列大小
  30. //显示行号与列宽度自动调整
  31. uiDataGridView1.RowHeadersVisible = uiDataGridView2.RowHeadersVisible = true;
  32. uiDataGridView1.RowHeadersWidth = uiDataGridView2.RowHeadersWidth = 50;
  33. uiDataGridView1.ColumnHeadersHeightSizeMode = uiDataGridView2.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  34. uiDataGridView1.RowHeadersWidthSizeMode = uiDataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;//数据量过百绑定太变
  35. //dataGridView1.RowPostPaint += (sender, e) =>//序号列头
  36. //{
  37. // //Utils.Util.showRowNum_onDataGrid_RowPostPaint(this.dataGridView1, sender, e);
  38. // Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dataGridView1.RowHeadersWidth - 4, e.RowBounds.Height);
  39. // TextRenderer.DrawText(e.Graphics, (e.RowIndex * 0.25f).ToString(), dataGridView1.RowHeadersDefaultCellStyle.Font, rectangle, dataGridView1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
  40. //};
  41. //for (int i = 0; i < dataGridView1.Columns.Count; i++)//禁止点击列头排序
  42. // dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
  43. ////行列交叉处标题
  44. //if (dataGridView1.RowHeadersVisible) dataGridView1.TopLeftHeaderCell.Value = "SPH/CYL";
  45. #endregion
  46. initData();
  47. }
  48. private void initData()
  49. {
  50. //var lstMaterial = Config.materialNameList.Select(x => new { code = x.Value<string>("code"), name = x.Value<string>("name") }).ToList();
  51. //cmbMaterial.ValueMember = "code";
  52. //cmbMaterial.DisplayMember = "name";
  53. //cmbMaterial.DataSource = lstMaterial;
  54. //cmbMaterial.SelectedIndex = -1;
  55. var lstColor = Config.colorNameList.Select(x => new { code = x.Value<int>("code"),name = x.Value<string>("name") }).ToList();
  56. cmbColor.ValueMember = "code";
  57. cmbColor.DisplayMember = "name";
  58. cmbColor.DataSource = lstColor;
  59. cmbColor.SelectedIndex = -1;
  60. //
  61. var filePathList = Directory.GetFiles(Application.StartupPath + "\\models\\", "*.trt");//*.onnx,
  62. string[] onlyNameList=new string[filePathList.Length];
  63. for (int i = 0; i < filePathList.Length; i++)
  64. onlyNameList[i]=Path.GetFileName(filePathList[i]);
  65. this.cmbModelName.Items.AddRange(onlyNameList);
  66. //
  67. ABSCamerCardDev devCamer1;
  68. if (Config.Camer_Name == CamerDevNameEnum.海康)
  69. devCamer1 = new CamerCardDev();
  70. else
  71. devCamer1 = new CamerCardDevIK();
  72. var value = devCamer1.getFeatureRangeValue("ExposureTime");
  73. if (value.Length > 0)
  74. {
  75. this.tcbarExposureTime.Minimum = (int)value[0];
  76. this.tcbarExposureTime.Maximum = (int)value[1];
  77. }
  78. value = devCamer1.getFeatureRangeValue("Gain");
  79. if (value.Length > 0)
  80. {
  81. this.tcbarGain.Minimum = (int)value[0];
  82. this.tcbarGain.Maximum = (int)value[1];
  83. }
  84. //
  85. clear(true);
  86. }
  87. private void loadProduct(int id,bool resetAll=false)
  88. {
  89. model = service.GetModelNav(id);
  90. if(model == null)
  91. {
  92. clear(resetAll);
  93. return;
  94. }
  95. loadProduct();
  96. }
  97. /// <summary>
  98. /// 对外,生产页面不存在的CODE进行添加
  99. /// </summary>
  100. /// <param name="pcode"> //PX-6</param>
  101. /// <returns></returns>
  102. public void loadProduct(string pcode, bool resetAll = false)
  103. {
  104. model = service.GetModelNav(pcode);
  105. if (model == null)
  106. {
  107. clear(resetAll);
  108. string[] codes= pcode.Split('-');
  109. if (codes[0]=="0" || Config.SuedeList.Contains(codes[0]))
  110. this.rbMaterial0.Checked = true;
  111. else
  112. this.rbMaterial1.Checked = true;
  113. this.cmbColor.SelectedValue = int.Parse(codes[1]);
  114. }
  115. else
  116. loadProduct();
  117. }
  118. private void loadProduct()
  119. {
  120. if (model == null) return;
  121. if(model.Material=="0")
  122. this.rbMaterial0.Checked = true;
  123. else
  124. this.rbMaterial1.Checked = true;
  125. this.cmbColor.SelectedValue = model.Color;
  126. tcbarLightValue.Value = model.LightValue;
  127. tcbarExposureTime.Value = (int)model.ExposureTime;
  128. tcbarGain.Value = (int)model.Gain;
  129. tcbarTensionValue.Value = (int)model.TensionValue;
  130. this.cmbModelName.Text = model.ModelName;
  131. numDefectAreaLimit.Text = model.DefectAreaLimit.ToString();
  132. numDefectCountLimit.Text = model.DefectCountLimit.ToString();
  133. swcDefectPauseForUser.Active = model.DefectPauseForUser;
  134. //uiDataGridView fill
  135. string code;
  136. QualifiedLimit item1;
  137. for (int i = 0; i < uiDataGridView1.Rows.Count; i++)
  138. {
  139. code = uiDataGridView1.Rows[i].Cells["col_code"].Value.ToString();
  140. item1 = model.QualifiedLimitList.FirstOrDefault(m=>m.Code == code);
  141. if (item1 != null)
  142. {
  143. uiDataGridView1.Rows[i].Cells["col_zxd"].Value=item1.ZXD;
  144. uiDataGridView1.Rows[i].Cells["col_area"].Value = item1.Area;
  145. uiDataGridView1.Rows[i].Cells["col_contrast_top"].Value = item1.ContrastTop;
  146. uiDataGridView1.Rows[i].Cells["col_contrast_lower"].Value = item1.ContrastLower;
  147. uiDataGridView1.Rows[i].Cells["col_IsOR"].Value = item1.IsOR;
  148. }
  149. }
  150. GradeLimit item2;
  151. for (int i = 0; i < uiDataGridView2.Rows.Count; i++)
  152. {
  153. code = uiDataGridView2.Rows[i].Cells["col2_code"].Value.ToString();
  154. item2 = model.GradeLimitList.FirstOrDefault(m => m.Code == code);
  155. if (item2 != null)
  156. {
  157. uiDataGridView2.Rows[i].Cells["col2_1"].Value = item2.A;
  158. uiDataGridView2.Rows[i].Cells["col2_2"].Value = item2.B;
  159. uiDataGridView2.Rows[i].Cells["col2_3"].Value = item2.C;
  160. uiDataGridView2.Rows[i].Cells["col2_4"].Value = item2.D;
  161. uiDataGridView2.Rows[i].Cells["col2_5"].Value = item2.E;
  162. }
  163. }
  164. //
  165. this.btnSave.Visible = this.btnReload.Visible = true;
  166. }
  167. private void clear(bool resetAll=false)
  168. {
  169. model = new Models.Product();
  170. if (resetAll)
  171. {
  172. rbMaterial0.Checked=rbMaterial1.Checked=false;
  173. cmbColor.SelectedIndex = -1;
  174. }
  175. tcbarLightValue.Value = tcbarExposureTime.Value = tcbarGain.Value = tcbarTensionValue.Value=0;
  176. //cmbModelName.SelectedIndex = -1;
  177. numDefectAreaLimit.Text =numDefectCountLimit.Text= "0";
  178. swcDefectPauseForUser.Active = true;
  179. this.btnSave.Visible = true;
  180. this.btnReload.Visible = false;
  181. //
  182. uiDataGridView1.Rows.Clear();
  183. uiDataGridView2.Rows.Clear();
  184. string code, name;
  185. //===uiDataGridView1
  186. //加列
  187. //uiDataGridView1.Columns.Add("col_code", "code");
  188. //uiDataGridView1.Columns.Add("col_zxd", "置信度");
  189. //uiDataGridView1.Columns.Add("col_area", "面积");
  190. //uiDataGridView1.Columns.Add("col_contrast", "对比度");
  191. //禁止点击列头排序
  192. //uiDataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  193. uiDataGridView1.Columns[0].Visible = false;
  194. //加行
  195. foreach (JObject item in Config.defectItemList)
  196. {
  197. code = item.Value<string>("code");
  198. name = item.Value<string>("name");
  199. //color = item.Value<string>("color");
  200. uiDataGridView1.Rows.Add();
  201. uiDataGridView1.Rows[uiDataGridView1.RowCount - 1].HeaderCell.Value = name;
  202. uiDataGridView1[0, uiDataGridView1.RowCount - 1].Value = code;
  203. }
  204. //===uiDataGridView2
  205. //加列
  206. //uiDataGridView2.Columns.Add("col_code", "code");
  207. //uiDataGridView2.Columns.Add("col_1", "A");
  208. //uiDataGridView2.Columns.Add("col_2", "B");
  209. //uiDataGridView2.Columns.Add("col_3", "C");
  210. //uiDataGridView2.Columns.Add("col_4", "D");
  211. //uiDataGridView2.Columns.Add("col_5", "E");
  212. //禁止点击列头排序
  213. //uiDataGridView2.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  214. uiDataGridView2.Columns[0].Visible = false;
  215. //加行
  216. foreach (JObject item in Config.defectItemList)
  217. {
  218. code = item.Value<string>("code");
  219. name = item.Value<string>("name");
  220. //color = item.Value<string>("color");
  221. uiDataGridView2.Rows.Add();
  222. uiDataGridView2.Rows[uiDataGridView2.RowCount - 1].HeaderCell.Value = name;
  223. uiDataGridView2[0, uiDataGridView2.RowCount - 1].Value = code;
  224. }
  225. }
  226. private void FProductInfo_Initialize(object sender, EventArgs e)
  227. {
  228. }
  229. private void btnNew_Click(object sender, EventArgs e)
  230. {
  231. this.clear();
  232. }
  233. private void btnReload_Click(object sender, EventArgs e)
  234. {
  235. try
  236. {
  237. this.loadProduct(model.Id,true);
  238. }
  239. catch (Exception ex)
  240. {
  241. UIMessageTip.ShowError(ex.Message, 2000);
  242. }
  243. }
  244. private void btnSave_Click(object sender, EventArgs e)
  245. {
  246. try
  247. {
  248. if (!this.rbMaterial0.Checked && !rbMaterial1.Checked) throw new Exception("请选择材质!");
  249. if (this.cmbColor.SelectedIndex < 0) throw new Exception("请选择颜色!");
  250. if (this.cmbModelName.SelectedIndex < 0) throw new Exception("请选择模型!");
  251. model.Material = rbMaterial0.Checked ? "0" : "1";
  252. model.Color = (int)cmbColor.SelectedValue;
  253. model.Code = model.Material+"-"+ model.Color;
  254. model.LightValue = tcbarLightValue.Value;
  255. model.TensionValue = tcbarTensionValue.Value;
  256. model.ExposureTime = tcbarExposureTime.Value;
  257. model.Gain = tcbarGain.Value;
  258. model.ModelName = this.cmbModelName.Text.Trim();
  259. model.DefectAreaLimit = double.Parse(numDefectAreaLimit.Text.Trim());
  260. model.DefectCountLimit = int.Parse(numDefectCountLimit.Text.Trim());
  261. model.DefectPauseForUser = swcDefectPauseForUser.Active;
  262. //datagrid
  263. if (model.QualifiedLimitList == null)
  264. model.QualifiedLimitList = new List<Models.QualifiedLimit>();
  265. else
  266. model.QualifiedLimitList.Clear();
  267. QualifiedLimit qualifiedLimit = new QualifiedLimit();
  268. for (int i=0;i< uiDataGridView1.Rows.Count;i++ )
  269. {
  270. qualifiedLimit = new Models.QualifiedLimit()
  271. {
  272. Code = uiDataGridView1.Rows[i].Cells["col_code"].Value.ToString(),
  273. ZXD = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_zxd"].Value) ? Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_zxd"].Value) : 0,
  274. Area = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_area"].Value) ? Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_area"].Value) : 0,
  275. ContrastLower = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_contrast_lower"].Value) ? Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_contrast_lower"].Value) : 0,
  276. ContrastTop = Utils.Util.IsDecimal(uiDataGridView1.Rows[i].Cells["col_contrast_top"].Value) ? Convert.ToDouble(uiDataGridView1.Rows[i].Cells["col_contrast_top"].Value) : 0,
  277. IsOR = Convert.ToBoolean(uiDataGridView1.Rows[i].Cells["col_IsOR"].Value),
  278. ModifyUserCode = Config.loginUser.Code,
  279. CreateUserCode = Config.loginUser.Code
  280. };
  281. if (qualifiedLimit.ContrastLower + qualifiedLimit.ContrastTop > 0 && qualifiedLimit.ContrastTop < qualifiedLimit.ContrastLower)
  282. throw new Exception($"检测标准中第{i+1}行中对比度上限值({qualifiedLimit.ContrastTop})不可小于下限值({qualifiedLimit.ContrastLower})!");
  283. model.QualifiedLimitList.Add(qualifiedLimit);
  284. }
  285. //
  286. if (model.GradeLimitList == null)
  287. model.GradeLimitList = new List<Models.GradeLimit>();
  288. else
  289. model.GradeLimitList.Clear();
  290. for (int i = 0; i < uiDataGridView2.Rows.Count; i++)
  291. {
  292. model.GradeLimitList.Add(
  293. new Models.GradeLimit()
  294. {
  295. Code = uiDataGridView2.Rows[i].Cells["col2_code"].Value.ToString(),
  296. A = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_1"].Value)? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_1"].Value) : 0,
  297. B = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_2"].Value) ? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_2"].Value) : 0,
  298. C = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_3"].Value) ? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_3"].Value) : 0,
  299. D = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_4"].Value) ? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_4"].Value) : 0,
  300. E = Utils.Util.IsNumber(uiDataGridView2.Rows[i].Cells["col2_5"].Value) ? Convert.ToInt32(uiDataGridView2.Rows[i].Cells["col2_5"].Value) : 0,
  301. ModifyUserCode = Config.loginUser.Code,
  302. CreateUserCode = Config.loginUser.Code
  303. });
  304. }
  305. //
  306. model.ModifyUserCode = Config.loginUser.Code;
  307. bool result;
  308. if (model.Id == 0)
  309. {
  310. model.CreateUserCode = Config.loginUser.Code;
  311. result = service.InsertNav(model);
  312. }
  313. else
  314. {
  315. result = service.UpdateNav(model);
  316. }
  317. if (!result)
  318. throw new Exception("保存失败!");
  319. this.btnReload.Visible = true;
  320. UIMessageTip.ShowOk("保存成功!", 1000);
  321. }
  322. catch (Exception ex)
  323. {
  324. UIMessageTip.ShowError(ex.Message, 2000);
  325. }
  326. }
  327. //
  328. private void tcbarLightValue_ValueChanged(object sender, EventArgs e)
  329. {
  330. lblLightValue.Text = $"{tcbarLightValue.Value}/{tcbarLightValue.Maximum}";
  331. }
  332. private void tcbarExposureTime_ValueChanged(object sender, EventArgs e)
  333. {
  334. lblExposureTime.Text = $"{tcbarExposureTime.Value}/{tcbarExposureTime.Maximum}";
  335. }
  336. private void tcbarGainValue_ValueChanged(object sender, EventArgs e)
  337. {
  338. lblGain.Text = $"{tcbarGain.Value}/{tcbarGain.Maximum}";
  339. }
  340. private void tcbarTensionValue_ValueChanged(object sender, EventArgs e)
  341. {
  342. lblTensionValue.Text = $"{tcbarTensionValue.Value}/{tcbarTensionValue.Maximum}";
  343. }
  344. private void button1_Click(object sender, EventArgs e)
  345. {
  346. this.clear(true);
  347. }
  348. private void cmbMaterial_SelectedIndexChanged(object sender, EventArgs e)
  349. {
  350. //if (this.cmbMaterial.SelectedIndex < 0 || this.cmbColor.SelectedIndex < 0)
  351. // return;
  352. if ((!this.rbMaterial0.Checked && !this.rbMaterial1.Checked) || this.cmbColor.SelectedIndex < 0)
  353. return;
  354. this.loadProduct((this.rbMaterial0.Checked?"0":"1") + "-" + this.cmbColor.SelectedValue.ToString());
  355. }
  356. private void btnDefectOption_Click(object sender, EventArgs e)
  357. {
  358. if (this.model == null || this.model.Id==0)
  359. return;
  360. FSelDefect frm = new FSelDefect(model.DefectPauseOption);
  361. frm.Render();
  362. frm.Text = "选择瑕疵";
  363. frm.ShowDialog();
  364. if (frm.IsOK)
  365. {
  366. model.DefectPauseOption = frm.lstCodes;
  367. }
  368. frm.Dispose();
  369. }
  370. private void swcDefectPauseForUser_ValueChanged(object sender, bool value)
  371. {
  372. btnDefectOption.Enabled = swcDefectPauseForUser.Active;
  373. }
  374. }
  375. }