frmChildInspectionCheck.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.FrmCustom;
  3. using NXWMS.Client.Model.AppModels.Condition.Common;
  4. using NXWMS.Client.Model.AppModels.Result.Common;
  5. using NXWMS.Client.Model.AppModels.Result.Inspection;
  6. using NXWMS.Client.Model.AppModels.Result.Instock;
  7. using NXWMS.Client.Model.CoreModels;
  8. using NXWMS.Commons;
  9. using NXWMS.Services;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Drawing;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Web.UI.WebControls;
  18. using System.Windows.Forms;
  19. namespace NXWMS.Forms.Inspection.frmInspectionChild
  20. {
  21. /// <summary>
  22. /// 质检审核窗体类
  23. /// </summary>
  24. public partial class frmChildInspectionCheck : KryptonForm
  25. {
  26. /// <summary>
  27. /// 窗体构造函数
  28. /// </summary>
  29. public frmChildInspectionCheck()
  30. {
  31. InitializeComponent();
  32. }
  33. #region 全局变量
  34. /// <summary>
  35. /// 质检单主键ID
  36. /// </summary>
  37. public string InspectionId { get; set; }
  38. /// <summary>
  39. /// 数据库中的质检单所有数据(包括主、明细表)。
  40. /// 未进行编辑过。
  41. /// </summary>
  42. private WmsQaInspectionResult InspectionDataNotEdit = new WmsQaInspectionResult();
  43. #endregion
  44. #region 初始化数据
  45. /// <summary>
  46. /// 窗体加载函数
  47. /// </summary>
  48. /// <param name="sender"></param>
  49. /// <param name="e"></param>
  50. private void frmChildInspectionCheck_Load(object sender, EventArgs e)
  51. {
  52. InitComboBoxItemData();
  53. InitDataGridViewColumn();
  54. kdtp_InspectionTime.Checked = false;
  55. LoadWmsQaInspectionDtlData();
  56. }
  57. /// <summary>
  58. /// 初始化下拉列表数据
  59. /// </summary>
  60. private void InitComboBoxItemData()
  61. {
  62. /*
  63. ToDo:后续把下拉列表转为 后台获取数据,目前是写死的。
  64. */
  65. List<BasDictionaryResult> results = new List<BasDictionaryResult>();
  66. #region 质检单类型
  67. results = BasDictionaryUtil.basDictionaryResultLst.FindAll(x => x.DICTIONARY_CODE == "InspectionTypeDesc");
  68. if (results.Count > 0)
  69. {
  70. kcmb_InspectionType.Items.Clear();
  71. foreach (var item in results)
  72. {
  73. kcmb_InspectionType.Items.Add(new ListItem
  74. {
  75. Value = item.DICTIONARY_ITEM_CODE,
  76. Text = item.DICTIONARY_ITEM_NAME,
  77. });
  78. }
  79. kcmb_InspectionType.SelectedIndex = 0;
  80. }
  81. else
  82. {
  83. KryptonMessageBox.Show("未找到质检单类型的字典项数据!");
  84. }
  85. #endregion
  86. #region 质检方式
  87. results = BasDictionaryUtil.basDictionaryResultLst.FindAll(x => x.DICTIONARY_CODE == "InspectionWayDesc");
  88. if (results.Count > 0)
  89. {
  90. kcmb_InspectionWay.Items.Clear();
  91. foreach (var item in results)
  92. {
  93. kcmb_InspectionWay.Items.Add(new ListItem
  94. {
  95. Value = item.DICTIONARY_ITEM_CODE,
  96. Text = item.DICTIONARY_ITEM_NAME,
  97. });
  98. }
  99. kcmb_InspectionWay.SelectedIndex = 0;
  100. }
  101. else
  102. {
  103. KryptonMessageBox.Show("未找到质检方式的字典项数据!");
  104. }
  105. #endregion
  106. }
  107. /// <summary>
  108. /// 初始化DataGridView列信息
  109. /// </summary>
  110. private void InitDataGridViewColumn()
  111. {
  112. DataGridViewColumn column1 = new KryptonDataGridViewTextBoxColumn();
  113. column1.HeaderText = "序号";
  114. column1.Width = 50;
  115. column1.ReadOnly = true;
  116. //column1.
  117. kdgv_InspectionDtlData.Columns.Add(column1);
  118. column1 = new KryptonDataGridViewTextBoxColumn();
  119. column1.HeaderText = "到货通知单号";
  120. column1.Width = 150;
  121. column1.ReadOnly = true;
  122. kdgv_InspectionDtlData.Columns.Add(column1);
  123. column1 = new KryptonDataGridViewTextBoxColumn();
  124. column1.HeaderText = "物料编码";
  125. column1.Width = 150;
  126. column1.ReadOnly = true;
  127. kdgv_InspectionDtlData.Columns.Add(column1);
  128. column1 = new KryptonDataGridViewTextBoxColumn();
  129. column1.HeaderText = "物料名称";
  130. column1.Width = 200;
  131. column1.ReadOnly = true;
  132. kdgv_InspectionDtlData.Columns.Add(column1);
  133. column1 = new KryptonDataGridViewTextBoxColumn();
  134. column1.HeaderText = "物料条码";
  135. column1.Width = 150;
  136. column1.ReadOnly = true;
  137. kdgv_InspectionDtlData.Columns.Add(column1);
  138. DataGridViewComboBoxColumn cmb_Unit = new DataGridViewComboBoxColumn();
  139. cmb_Unit.HeaderText = "质检结果";
  140. cmb_Unit.Width = 90;
  141. //目前写死下拉列表的数据项,后续改为后台获取
  142. cmb_Unit.Items.AddRange(new ListItem[]
  143. {
  144. new ListItem{ Value = "Wait",Text = "待检"},
  145. new ListItem{ Value = "OK",Text = "合格"},
  146. new ListItem{ Value = "NG",Text = "不合格"}
  147. });
  148. cmb_Unit.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
  149. kdgv_InspectionDtlData.Columns.Add(cmb_Unit);
  150. column1 = new KryptonDataGridViewTextBoxColumn();
  151. column1.HeaderText = "批次号";
  152. column1.Width = 120;
  153. column1.ReadOnly = true;
  154. kdgv_InspectionDtlData.Columns.Add(column1);
  155. column1 = new KryptonDataGridViewTextBoxColumn();
  156. column1.HeaderText = "单位";
  157. column1.Width = 70;
  158. column1.ReadOnly = true;
  159. kdgv_InspectionDtlData.Columns.Add(column1);
  160. column1 = new KryptonDataGridViewTextBoxColumn();
  161. column1.HeaderText = "供应商";
  162. column1.Width = 120;
  163. column1.ReadOnly = true;
  164. kdgv_InspectionDtlData.Columns.Add(column1);
  165. column1 = new KryptonDataGridViewTextBoxColumn();
  166. column1.HeaderText = "包装";
  167. column1.Width = 80;
  168. column1.ReadOnly = true;
  169. kdgv_InspectionDtlData.Columns.Add(column1);
  170. KryptonDataGridViewDateTimePickerColumn column_ProductTime = new KryptonDataGridViewDateTimePickerColumn();
  171. column_ProductTime.HeaderText = "生产日期";
  172. column_ProductTime.Width = 160;
  173. column_ProductTime.Format = DateTimePickerFormat.Custom;
  174. column_ProductTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  175. column_ProductTime.ReadOnly = true;
  176. kdgv_InspectionDtlData.Columns.Add(column_ProductTime);
  177. KryptonDataGridViewDateTimePickerColumn column_ExpTime = new KryptonDataGridViewDateTimePickerColumn();
  178. column_ExpTime.HeaderText = "失效日期";
  179. column_ExpTime.Width = 160;
  180. column_ExpTime.Format = DateTimePickerFormat.Custom;
  181. column_ExpTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  182. column_ExpTime.ReadOnly = true;
  183. kdgv_InspectionDtlData.Columns.Add(column_ExpTime);
  184. column1 = new KryptonDataGridViewTextBoxColumn();
  185. column1.HeaderText = "到货通知单明细ID";
  186. column1.Width = 30;
  187. column1.Visible = false;
  188. column1.ReadOnly = true;
  189. kdgv_InspectionDtlData.Columns.Add(column1);
  190. }
  191. /// <summary>
  192. /// 调用服务端接口,请求质检单明细表数据
  193. /// </summary>
  194. /// <returns></returns>
  195. private string LoadWmsQaInspectionDtlData()
  196. {
  197. var result = WmsInspectionService.wmsQaInspectionService.GetWmsQaInspectionDtlListForId(new WmsQaInspectionResult { INSPECTION_ID = Convert.ToInt32(this.InspectionId) });
  198. if (result.Status == OperateStatus.Success)
  199. {
  200. ktb_InspectionNo.Text = result.Data.INSPECTION_NO;
  201. ktb_InspectionNo.Enabled = false;
  202. ktb_InspectionUser.Text = result.Data.INSPECTION_USER;
  203. ktb_InspectionUser.Enabled = false;
  204. kcmb_InspectionType.Text = result.Data.INSPECTION_TYPE_NAME;
  205. kcmb_InspectionType.Enabled = false;
  206. kcmb_InspectionWay.Text = result.Data.INSPECTION_WAY_NAME;
  207. kcmb_InspectionWay.Enabled = false;
  208. ktb_Describe.Text = result.Data.DESCRIBE;
  209. if (result.Data.INSPECTION_TIME != new DateTime())
  210. {
  211. kdtp_InspectionTime.Value = result.Data.INSPECTION_TIME;
  212. }
  213. InspectionDataNotEdit = result.Data;
  214. kdgv_InspectionDtlData.Rows.Clear();
  215. foreach (WmsQaInspectionDtlResult item in result.Data.WmsQaInspectionDtlList)
  216. {
  217. int index = kdgv_InspectionDtlData.Rows.Add();
  218. kdgv_InspectionDtlData.Rows[index].Cells[0].Value = index + 1;
  219. kdgv_InspectionDtlData.Rows[index].Cells[1].Value = item.BILL_NO;
  220. kdgv_InspectionDtlData.Rows[index].Cells[2].Value = item.MATERIEL_CODE;
  221. kdgv_InspectionDtlData.Rows[index].Cells[3].Value = item.MATERIEL_NAME;
  222. kdgv_InspectionDtlData.Rows[index].Cells[4].Value = item.MATERIEL_BARCODE;
  223. ListItem inspectionResultLstItm = GetComboBoxItem((DataGridViewComboBoxCell)kdgv_InspectionDtlData.Rows[index].Cells[5], item.INSPECTION_RESULT);
  224. kdgv_InspectionDtlData.Rows[index].Cells[5].Value = inspectionResultLstItm;
  225. kdgv_InspectionDtlData.Rows[index].Cells[6].Value = item.BATCH_NO;
  226. kdgv_InspectionDtlData.Rows[index].Cells[7].Value = item.UNIT_CODE;
  227. kdgv_InspectionDtlData.Rows[index].Cells[8].Value = item.SUPPLIER_NAME;
  228. kdgv_InspectionDtlData.Rows[index].Cells[9].Value = item.PACKAGE_CODE;
  229. kdgv_InspectionDtlData.Rows[index].Cells[10].Value = item.PRODUCT_DATE;
  230. kdgv_InspectionDtlData.Rows[index].Cells[11].Value = item.EXP_DATE;
  231. kdgv_InspectionDtlData.Rows[index].Cells[12].Value = item.BILL_DTL_ID;
  232. }
  233. return string.Empty;
  234. }
  235. else
  236. {
  237. return result.Message;
  238. }
  239. }
  240. #endregion
  241. #region 按钮事件
  242. /// <summary>
  243. /// 确认按钮事件
  244. /// 提交编辑完成的质检单数据
  245. /// </summary>
  246. /// <param name="sender"></param>
  247. /// <param name="e"></param>
  248. private void btnConfirm_Click(object sender, EventArgs e)
  249. {
  250. WmsQaInspectionResult mdInspection = new WmsQaInspectionResult();
  251. mdInspection.INSPECTION_ID = InspectionDataNotEdit.INSPECTION_ID;
  252. mdInspection.INSPECTION_NO = InspectionDataNotEdit.INSPECTION_NO;
  253. mdInspection.INSPECTION_TYPE = Convert.ToInt32(((ListItem)kcmb_InspectionType.SelectedItem).Value);
  254. mdInspection.INSPECTION_USER = ktb_InspectionUser.Text;
  255. mdInspection.INSPECTION_WAY = Convert.ToInt32(((ListItem)kcmb_InspectionType.SelectedItem).Value);
  256. if (kdtp_InspectionTime.Checked)
  257. {
  258. mdInspection.INSPECTION_TIME = kdtp_InspectionTime.Value;
  259. }
  260. else
  261. {
  262. mdInspection.INSPECTION_TIME = new DateTime();
  263. }
  264. mdInspection.INSPECTION_STATUS = (int)InspectionStatus.结果确认完成;
  265. mdInspection.DESCRIBE = ktb_Describe.Text.Trim();
  266. mdInspection.CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  267. mdInspection.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  268. List<WmsQaInspectionDtlResult> mdInspectionDtlList = new List<WmsQaInspectionDtlResult>();
  269. if (kdgv_InspectionDtlData.Rows.Count > 0 && !kdgv_InspectionDtlData.Rows[0].IsNewRow)
  270. {
  271. foreach (DataGridViewRow dvr in kdgv_InspectionDtlData.Rows)
  272. {
  273. if (!dvr.IsNewRow)
  274. {
  275. #region 校验每一行数据的完整性
  276. string RowCheckMsg = string.Empty;
  277. if (!CheckDataGridViewRowFormat(dvr, ref RowCheckMsg))
  278. {
  279. KryptonMessageBox.Show(RowCheckMsg);
  280. return;
  281. }
  282. #endregion
  283. string receiptNo = dvr.Cells[1].Value.ToString();
  284. string materielCode = dvr.Cells[2].Value.ToString();
  285. string materielName = dvr.Cells[3].Value.ToString();
  286. string materielBarcode = dvr.Cells[4].Value == null ? null : dvr.Cells[4].Value.ToString();
  287. string inspectionResult = GetComboBoxItem((DataGridViewComboBoxCell)dvr.Cells[5]).Value;
  288. string batchNo = dvr.Cells[6].Value == null ? null : dvr.Cells[6].Value.ToString();
  289. string unitCode = dvr.Cells[7].Value == null ? null : dvr.Cells[7].Value.ToString();
  290. string supplierCode = dvr.Cells[8].Value == null ? null : dvr.Cells[8].Value.ToString();
  291. string packageCode = dvr.Cells[9].Value == null ? null : dvr.Cells[9].Value.ToString();
  292. DateTime productTime = Convert.ToDateTime(dvr.Cells[10].Value);
  293. DateTime expTime = Convert.ToDateTime(dvr.Cells[11].Value);
  294. int billDtlId = dvr.Cells[12].Value == null ? 0 : Convert.ToInt32(dvr.Cells[12].Value);
  295. WmsQaInspectionDtlResult mdQaResult = InspectionDataNotEdit.WmsQaInspectionDtlList.Find(y => y.BILL_DTL_ID == billDtlId);
  296. mdInspectionDtlList.Add(new WmsQaInspectionDtlResult
  297. {
  298. INSPECTION_DTL_ID = mdQaResult.INSPECTION_DTL_ID,
  299. INSPECTION_ID = mdQaResult.INSPECTION_ID,
  300. BILL_NO = mdQaResult.BILL_NO,
  301. BILL_DTL_ID = billDtlId,
  302. MATERIEL_CODE = materielCode,
  303. MATERIEL_NAME = materielName,
  304. MATERIEL_BARCODE = materielBarcode,
  305. BATCH_NO = batchNo,
  306. UNIT_CODE = unitCode,
  307. SUPPLIER_CODE = mdQaResult.SUPPLIER_CODE,
  308. SUPPLIER_NAME = mdQaResult.SUPPLIER_NAME,
  309. PACKAGE_CODE = packageCode,
  310. PRODUCT_DATE = productTime,
  311. EXP_DATE = expTime,
  312. INSPECTION_RESULT = inspectionResult,
  313. ITEM_STATUS = mdQaResult.ITEM_STATUS,
  314. INSPECTION_DTL_STATUS = (int)InspectionStatus.结果确认完成,
  315. CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId,
  316. UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId,
  317. DESCRIBE = null
  318. });
  319. }
  320. }
  321. mdInspection.WmsQaInspectionDtlList = mdInspectionDtlList;
  322. var result = WmsInspectionService.wmsQaInspectionService.QaInspectionExamine(mdInspection);
  323. if (result.Status == OperateStatus.Success)
  324. {
  325. KryptonMessageBox.Show(result.Message);
  326. frmWmsQaInspection.RefreshFrmHost();
  327. this.Close();
  328. }
  329. else
  330. {
  331. KryptonMessageBox.Show(result.Message);
  332. }
  333. }
  334. else
  335. {
  336. KryptonMessageBox.Show("请添加数据行!");
  337. }
  338. }
  339. /// <summary>
  340. /// 校验DataGridView输入行数据的正确性
  341. /// </summary>
  342. /// <param name="dvr">DataGridView输入行</param>
  343. /// <param name="OutMssg">校验结果信息</param>
  344. /// <returns></returns>
  345. private bool CheckDataGridViewRowFormat(DataGridViewRow dvr, ref string OutMssg)
  346. {
  347. if (dvr.Cells[1].Value == null)
  348. {
  349. OutMssg = $"第【{dvr.Index + 1}】行未输入物料编码!";
  350. return false;
  351. }
  352. if (dvr.Cells[2].Value == null)
  353. {
  354. OutMssg = $"第【{dvr.Index + 1}】行未输入物料编码!";
  355. return false;
  356. }
  357. if (dvr.Cells[3].Value == null)
  358. {
  359. OutMssg = $"第【{dvr.Index + 1}】行未输入物料名称!";
  360. return false;
  361. }
  362. if (dvr.Cells[5].Value == null)
  363. {
  364. OutMssg = $"第【{dvr.Index + 1}】行未选择质检结果!";
  365. return false;
  366. }
  367. if (dvr.Cells[7].Value == null)
  368. {
  369. OutMssg = $"第【{dvr.Index + 1}】行未选择单位信息!";
  370. return false;
  371. }
  372. if (dvr.Cells[8].Value == null)
  373. {
  374. OutMssg = $"第【{dvr.Index + 1}】行未选择供应商信息!";
  375. return false;
  376. }
  377. if (dvr.Cells[10].Value == null)
  378. {
  379. OutMssg = $"第【{dvr.Index + 1}】行未输入生产日期!";
  380. return false;
  381. }
  382. if (dvr.Cells[11].Value == null)
  383. {
  384. OutMssg = $"第【{dvr.Index + 1}】行未输入失效日期!";
  385. return false;
  386. }
  387. if (DateTime.Compare(Convert.ToDateTime(dvr.Cells[10].Value), Convert.ToDateTime(dvr.Cells[11].Value)) >= 0)
  388. {
  389. OutMssg = $"第【{dvr.Index + 1}】行未输入的生产日期大于失效日期,不符合实际情况,请重新输入!";
  390. return false;
  391. }
  392. OutMssg = "校验成功!";
  393. return true;
  394. }
  395. /// <summary>
  396. /// 取消按钮事件
  397. /// 退出编辑页面
  398. /// </summary>
  399. /// <param name="sender"></param>
  400. /// <param name="e"></param>
  401. private void btnCancel_Click(object sender, EventArgs e)
  402. {
  403. this.Close();
  404. }
  405. private ListItem GetComboBoxItem(DataGridViewComboBoxCell dataGridViewComboBoxCell)
  406. {
  407. foreach (var item in dataGridViewComboBoxCell.Items)
  408. {
  409. if (((ListItem)item).Text == dataGridViewComboBoxCell.Value.ToString())
  410. {
  411. return (ListItem)item;
  412. }
  413. }
  414. return new ListItem();
  415. }
  416. private ListItem GetComboBoxItem(DataGridViewComboBoxCell dataGridViewComboBoxCell, string value)
  417. {
  418. foreach (var item in dataGridViewComboBoxCell.Items)
  419. {
  420. if (((ListItem)item).Value == value)
  421. {
  422. return (ListItem)item;
  423. }
  424. }
  425. return new ListItem();
  426. }
  427. #endregion
  428. #region DataGridView相关事件
  429. /// <summary>
  430. /// 针对ComboBox下拉列表的DataGridView数据列单元格。
  431. /// 由于DataGridView的ComboBox列的Item至使用的是KeyValue形式的ListItem,
  432. /// 所以单元格结束编辑的时候。需要给单元格设定一个类型为ListItem的值。
  433. /// </summary>
  434. /// <param name="sender"></param>
  435. /// <param name="e"></param>
  436. private void kdgv_InspectionDtlData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  437. {
  438. int rowIndex = e.RowIndex;
  439. int columnIndex = e.ColumnIndex;
  440. if (kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex] is DataGridViewComboBoxCell)
  441. {
  442. ListItem tstlst = GetComboBoxItem((DataGridViewComboBoxCell)kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex]);
  443. kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex].Value = tstlst;
  444. }
  445. }
  446. private void kdgv_InspectionDtlData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
  447. {
  448. int index = kdgv_InspectionDtlData.Rows.Count;
  449. kdgv_InspectionDtlData.Rows[index - 1].Cells[0].Value = index;
  450. }
  451. #endregion
  452. #region 鼠标右键单击事件
  453. /// <summary>
  454. /// 重新加载正在编辑的质检单明细数据
  455. /// </summary>
  456. /// <param name="sender"></param>
  457. /// <param name="e"></param>
  458. private void 重新加载ToolStripMenuItem_Click(object sender, EventArgs e)
  459. {
  460. var loadfrm = new frmLoading();
  461. loadfrm.Show();
  462. var message = loadfrm.EventCalExec(LoadWmsQaInspectionDtlData);
  463. if (!string.IsNullOrWhiteSpace(message))
  464. {
  465. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  466. }
  467. }
  468. #endregion
  469. }
  470. }