frmChildRetreatTray.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.FrmCustom;
  3. using NXWMS.Client.Model.AppModels.Result.Balance;
  4. using NXWMS.Client.Model.AppModels.Result.Common;
  5. using NXWMS.Client.Model.AppModels.Result.Instock;
  6. using NXWMS.Client.Model.CoreModels;
  7. using NXWMS.Services;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Runtime.InteropServices;
  15. using System.Text;
  16. using System.Text.RegularExpressions;
  17. using System.Web.UI.WebControls;
  18. using System.Windows.Forms;
  19. using static NXWMS.Client.FrmCustom.CustomEventMsg;
  20. namespace NXWMS.Forms.Instock.frmInstockChild
  21. {
  22. /// <summary>
  23. /// 退料组盘操作窗体
  24. /// </summary>
  25. public partial class frmChildRetreatTray : KryptonForm
  26. {
  27. /// <summary>
  28. /// 窗体构造函数
  29. /// </summary>
  30. public frmChildRetreatTray()
  31. {
  32. InitializeComponent();
  33. }
  34. #region 全局变量
  35. /// <summary>
  36. /// 退料单主键ID
  37. /// </summary>
  38. public string RetreatId { get; set; }
  39. /// <summary>
  40. /// 退料单号
  41. /// </summary>
  42. public string RetreatNo { get; set; }
  43. /// <summary>
  44. /// 数据库中的退料单所有数据(包括主、明细表)。
  45. /// </summary>
  46. private WmsInRetreatResult RetreatDataNotEdit = new WmsInRetreatResult();
  47. [DllImport("user32.dll")]
  48. public static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time);//引用DLL
  49. #endregion
  50. #region 初始化数据
  51. /// <summary>
  52. /// 窗体加载事件
  53. /// </summary>
  54. /// <param name="sender"></param>
  55. /// <param name="e"></param>
  56. private void frmChildRetreatTray_Load(object sender, EventArgs e)
  57. {
  58. ktb_RetreatNo.Text = RetreatNo;
  59. ktb_RetreatNo.Enabled = false;
  60. InitDataGridViewColumn();
  61. ktb_PalletNo.Focus();
  62. }
  63. /// <summary>
  64. /// 初始化DataGridView列信息
  65. /// </summary>
  66. private void InitDataGridViewColumn()
  67. {
  68. DataGridViewColumn column1 = new KryptonDataGridViewTextBoxColumn();
  69. column1.HeaderText = "序号";
  70. column1.Width = 50;
  71. column1.ReadOnly = true;
  72. kdgv_RetreatTrayDtlData.Columns.Add(column1);
  73. DataTable dt = CreateTable();
  74. DataGridViewColumn column = new DataGridViewDataWindowColumn();
  75. (column as DataGridViewDataWindowColumn).SDisplayField = "物料编码,物料名称,物料条码,物料类型编码,物料类型名称";
  76. (column as DataGridViewDataWindowColumn).SDisplayMember = "物料编码";
  77. (column as DataGridViewDataWindowColumn).SKeyWords = "物料编码";
  78. (column as DataGridViewDataWindowColumn).DataSource = dt;
  79. column.Width = 150;
  80. column.HeaderText = "物料编码";
  81. kdgv_RetreatTrayDtlData.Columns.Add(column);
  82. column = new DataGridViewDataWindowColumn();
  83. (column as DataGridViewDataWindowColumn).SDisplayField = "物料编码,物料名称,物料条码,物料类型编码,物料类型名称";
  84. (column as DataGridViewDataWindowColumn).SDisplayMember = "物料名称";
  85. (column as DataGridViewDataWindowColumn).SKeyWords = "物料名称";
  86. (column as DataGridViewDataWindowColumn).DataSource = dt;
  87. column.HeaderText = "物料名称";
  88. column.Width = 200;
  89. kdgv_RetreatTrayDtlData.Columns.Add(column);
  90. column = new DataGridViewDataWindowColumn();
  91. (column as DataGridViewDataWindowColumn).SDisplayField = "物料编码,物料名称,物料条码,物料类型编码,物料类型名称";
  92. (column as DataGridViewDataWindowColumn).SDisplayMember = "物料条码";
  93. (column as DataGridViewDataWindowColumn).SKeyWords = "物料条码";
  94. (column as DataGridViewDataWindowColumn).DataSource = dt;
  95. column.HeaderText = "物料条码";
  96. column.Width = 150;
  97. kdgv_RetreatTrayDtlData.Columns.Add(column);
  98. column1 = new KryptonDataGridViewTextBoxColumn();
  99. column1.HeaderText = "批次号";
  100. column1.Width = 120;
  101. kdgv_RetreatTrayDtlData.Columns.Add(column1);
  102. column1 = new KryptonDataGridViewTextBoxColumn();
  103. column1.HeaderText = "退料单明细未组盘数量";
  104. column1.Width = 130;
  105. kdgv_RetreatTrayDtlData.Columns.Add(column1);
  106. column1 = new KryptonDataGridViewTextBoxColumn();
  107. column1.HeaderText = "组盘明细数量";
  108. column1.Width = 100;
  109. kdgv_RetreatTrayDtlData.Columns.Add(column1);
  110. DataGridViewComboBoxColumn cmb_Unit = new DataGridViewComboBoxColumn();
  111. cmb_Unit.HeaderText = "单位";
  112. cmb_Unit.Width = 70;
  113. //目前写死下拉列表的数据项,后续改为后台获取
  114. cmb_Unit.Items.AddRange(new ListItem[]
  115. {
  116. new ListItem{ Value = "kg",Text = "千克"},
  117. new ListItem{ Value = "ge",Text = "个"},
  118. new ListItem{ Value = "pkg",Text = "箱"}
  119. });
  120. cmb_Unit.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
  121. kdgv_RetreatTrayDtlData.Columns.Add(cmb_Unit);
  122. DataGridViewComboBoxColumn cmb_Supplier = new DataGridViewComboBoxColumn();
  123. cmb_Supplier.HeaderText = "供应商";
  124. cmb_Supplier.Width = 120;
  125. //目前写死下拉列表的数据项,后续改为后台获取
  126. cmb_Supplier.Items.AddRange(new ListItem[]
  127. {
  128. new ListItem{ Value ="WX_NXZB_001" ,Text = "无锡南兴装备"},
  129. new ListItem{ Value ="WX_NXZB_002" ,Text = "东莞南兴装备"}
  130. });
  131. cmb_Supplier.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
  132. kdgv_RetreatTrayDtlData.Columns.Add(cmb_Supplier);
  133. column1 = new KryptonDataGridViewTextBoxColumn();
  134. column1.HeaderText = "包装";
  135. column1.Width = 80;
  136. kdgv_RetreatTrayDtlData.Columns.Add(column1);
  137. KryptonDataGridViewDateTimePickerColumn column_ProductTime = new KryptonDataGridViewDateTimePickerColumn();
  138. column_ProductTime.HeaderText = "生产日期";
  139. column_ProductTime.Width = 160;
  140. column_ProductTime.Format = DateTimePickerFormat.Custom;
  141. column_ProductTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  142. kdgv_RetreatTrayDtlData.Columns.Add(column_ProductTime);
  143. KryptonDataGridViewDateTimePickerColumn column_ExpTime = new KryptonDataGridViewDateTimePickerColumn();
  144. column_ExpTime.HeaderText = "失效日期";
  145. column_ExpTime.Width = 160;
  146. column_ExpTime.Format = DateTimePickerFormat.Custom;
  147. column_ExpTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  148. kdgv_RetreatTrayDtlData.Columns.Add(column_ExpTime);
  149. column1 = new KryptonDataGridViewTextBoxColumn();
  150. column1.HeaderText = "";
  151. column1.Width = 30;
  152. column1.Visible = false;
  153. kdgv_RetreatTrayDtlData.Columns.Add(column1);
  154. column1 = new KryptonDataGridViewTextBoxColumn();
  155. column1.HeaderText = "退料明细数量";
  156. column1.Width = 30;
  157. column1.Visible = false;
  158. kdgv_RetreatTrayDtlData.Columns.Add(column1);
  159. }
  160. /// <summary>
  161. /// 创建数据源表格
  162. /// </summary>
  163. /// <returns></returns>
  164. private DataTable CreateTable()
  165. {
  166. DataTable dt = new DataTable();
  167. DataColumn dc = new DataColumn("物料编码");
  168. dt.Columns.Add(dc);
  169. dc = new DataColumn("物料名称");
  170. dt.Columns.Add(dc);
  171. dc = new DataColumn("物料条码");
  172. dt.Columns.Add(dc);
  173. dc = new DataColumn("物料类型编码");
  174. dt.Columns.Add(dc);
  175. dc = new DataColumn("物料类型名称");
  176. dt.Columns.Add(dc);
  177. dc = new DataColumn("退料单明细ID");
  178. dt.Columns.Add(dc);
  179. if (string.IsNullOrEmpty(this.RetreatId))
  180. {
  181. var result = WmsInstockService.materielMsgForAddArrivalService.GetMaterielMsgForAddArrival();
  182. if (result.Status == OperateStatus.Success)
  183. {
  184. foreach (MaterielMsgForAddArrivalResult item in result.Data)
  185. {
  186. DataRow dr = dt.NewRow();
  187. dr["物料编码"] = item.MATERIEL_CODE;
  188. dr["物料名称"] = item.MATERIEL_NAME;
  189. dr["物料条码"] = item.MATERIEL_BARCODE;
  190. dr["物料类型编码"] = item.MATERIEL_TYPE_CODE;
  191. dr["物料类型名称"] = item.MATERIEL_TYPE_NAME;
  192. dr["退料单明细ID"] = 0;
  193. dt.Rows.Add(dr);
  194. }
  195. RetreatDataNotEdit = new WmsInRetreatResult();
  196. }
  197. }
  198. else
  199. {
  200. var result = WmsInstockService.wmsInRetreatService.GetWmsInRetreatDtlListForId(new WmsInRetreatResult { RETREAT_ID = Convert.ToInt32(this.RetreatId), REMARKS1 = "查询未组盘完成的退料单明细" });
  201. if (result.Status == OperateStatus.Success)
  202. {
  203. foreach (WmsInRetreatDtlResult item in result.Data.WmsInRetreatDtlList)
  204. {
  205. DataRow dr = dt.NewRow();
  206. dr["物料编码"] = item.MATERIEL_CODE;
  207. dr["物料名称"] = item.MATERIEL_NAME;
  208. dr["物料条码"] = item.MATERIEL_BARCODE;
  209. dr["物料类型编码"] = item.MATERIEL_TYPE_CODE;
  210. dr["物料类型名称"] = item.MATERIEL_TYPE_NAME;
  211. dr["退料单明细ID"] = item.RETREAT_DTL_ID;
  212. dt.Rows.Add(dr);
  213. }
  214. RetreatDataNotEdit = result.Data;
  215. }
  216. }
  217. return dt;
  218. }
  219. #endregion
  220. #region 按钮事件
  221. /// <summary>
  222. /// 取消按钮事件
  223. /// 关闭窗体
  224. /// </summary>
  225. /// <param name="sender"></param>
  226. /// <param name="e"></param>
  227. private void btnCancel_Click(object sender, EventArgs e)
  228. {
  229. this.Close();
  230. }
  231. /// <summary>
  232. /// 确认按钮事件
  233. /// 提交组盘数据
  234. /// </summary>
  235. /// <param name="sender"></param>
  236. /// <param name="e"></param>
  237. private void btnConfirm_Click(object sender, EventArgs e)
  238. {
  239. /*
  240. * ToDo:后续增加验证托盘号是否合法的代码。
  241. */
  242. if(string.IsNullOrEmpty(ktb_PalletNo.Text))
  243. {
  244. KryptonMessageBox.Show("请输入或扫描托盘号!");
  245. return;
  246. }
  247. WmsStkTrayResult wmsStkTrayResult = new WmsStkTrayResult();
  248. wmsStkTrayResult.PALLET_CODE = ktb_PalletNo.Text.Trim();
  249. wmsStkTrayResult.TRAYS_TYPE = 2;
  250. wmsStkTrayResult.TRAY_LOADED_TYPE = 1;
  251. wmsStkTrayResult.TRAY_STATUS = 0;
  252. wmsStkTrayResult.CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  253. wmsStkTrayResult.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  254. List<WmsStkTrayDtlResult> wmsStkTrayDtlList = new List<WmsStkTrayDtlResult>();
  255. if (kdgv_RetreatTrayDtlData.Rows.Count > 0 && !kdgv_RetreatTrayDtlData.Rows[0].IsNewRow)
  256. {
  257. foreach (DataGridViewRow dvr in kdgv_RetreatTrayDtlData.Rows)
  258. {
  259. if (!dvr.IsNewRow)
  260. {
  261. #region 校验每一行数据的完整性
  262. string RowCheckMsg = string.Empty;
  263. if (!CheckDataGridViewRowFormat(dvr, ref RowCheckMsg))
  264. {
  265. KryptonMessageBox.Show(RowCheckMsg);
  266. return;
  267. }
  268. #endregion
  269. int retreatDtlId = Convert.ToInt32(dvr.Cells[12].Value);
  270. WmsStkTrayDtlResult trayDtlMd = new WmsStkTrayDtlResult();
  271. WmsStkTrayDtlExtResult trayDtlExtMd = new WmsStkTrayDtlExtResult();
  272. WmsInRetreatRecordResult retreatRecordMd = new WmsInRetreatRecordResult();
  273. WmsInRetreatDtlResult retreatDtlMd = RetreatDataNotEdit.WmsInRetreatDtlList.Find(x => x.RETREAT_DTL_ID == retreatDtlId);
  274. string materielCode = dvr.Cells[1].Value.ToString();
  275. string materielName = dvr.Cells[2].Value.ToString();
  276. string materielBarcode = dvr.Cells[3].Value == null ? null : dvr.Cells[3].Value.ToString();
  277. string batchNo = dvr.Cells[4].Value == null ? null : dvr.Cells[4].Value.ToString();
  278. decimal retreatDtlQty = dvr.Cells[13].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[13].Value.ToString());
  279. decimal trayDtlQty = Convert.ToDecimal(dvr.Cells[6].Value);
  280. string unitCode = GetComboBoxItem((DataGridViewComboBoxCell)dvr.Cells[7]).Value;
  281. string supplierCode = GetComboBoxItem((DataGridViewComboBoxCell)dvr.Cells[8]).Value;
  282. string supplierName = GetComboBoxItem((DataGridViewComboBoxCell)dvr.Cells[8]).Text;
  283. string packageCode = dvr.Cells[9].Value == null ? null : dvr.Cells[9].Value.ToString();
  284. DateTime productTime = Convert.ToDateTime(dvr.Cells[10].Value);
  285. DateTime expTime = Convert.ToDateTime(dvr.Cells[11].Value);
  286. trayDtlMd.MATERIEL_CODE = materielCode;
  287. trayDtlMd.MATERIEL_NAME = materielName;
  288. trayDtlMd.MATERIEL_BARCODE = materielBarcode;
  289. trayDtlMd.QTY = trayDtlQty;
  290. trayDtlMd.TRAY_DTL_STATUS = 0;
  291. trayDtlMd.CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  292. trayDtlMd.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  293. trayDtlExtMd.MATERIEL_SPEC = retreatDtlMd.MATERIEL_SPEC;
  294. trayDtlExtMd.PACKAGE_CODE = packageCode;
  295. trayDtlExtMd.UNIT_CODE = unitCode;
  296. trayDtlExtMd.BATCH_NO = batchNo;
  297. trayDtlExtMd.SUPPLIER_CODE = supplierCode;
  298. trayDtlExtMd.SUPPLIER_NAME = supplierName;
  299. trayDtlExtMd.PRODUCT_DATE = productTime;
  300. trayDtlExtMd.EXP_DATE = expTime;
  301. trayDtlExtMd.INSPECTION_RESULT = retreatDtlMd.INSPECTION_RESULT;
  302. trayDtlExtMd.LOCK_FLAG = 0;
  303. trayDtlExtMd.MIN_PKG_QTY = 0;
  304. trayDtlExtMd.ECTEND_TIME_LEN = 0;
  305. trayDtlExtMd.ITEM_STATUS = retreatDtlMd.ITEM_STATUS;
  306. trayDtlExtMd.CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  307. trayDtlExtMd.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  308. retreatRecordMd.RETREAT_DTL_ID = retreatDtlMd.RETREAT_DTL_ID;
  309. retreatRecordMd.RETREAT_ID = Convert.ToInt32(RetreatId);
  310. retreatRecordMd.RETREAT_NO = RetreatNo;
  311. retreatRecordMd.SOURCE_NO = RetreatDataNotEdit.SOUCE_NO;
  312. retreatRecordMd.REGION_CODE = "";
  313. retreatRecordMd.REGION_NAME = "";
  314. retreatRecordMd.BIN_CODE = "";
  315. retreatRecordMd.BIN_NAME = "";
  316. retreatRecordMd.PALLET_CODE = ktb_PalletNo.Text.Trim();
  317. retreatRecordMd.RETREAT_TIME = RetreatDataNotEdit.RETREAT_TIME;
  318. retreatRecordMd.RETREATER = RetreatDataNotEdit.RETREATER;
  319. retreatRecordMd.MATERIEL_CODE = materielCode;
  320. retreatRecordMd.MATERIEL_NAME = materielName;
  321. retreatRecordMd.MATERIEL_BARCODE = materielBarcode;
  322. retreatRecordMd.MATERIEL_SPEC = retreatDtlMd.MATERIEL_SPEC;
  323. retreatRecordMd.SUPPLIER_CODE = supplierCode;
  324. retreatRecordMd.SUPPLIER_NAME = supplierName;
  325. retreatRecordMd.PACKAGE_CODE = packageCode;
  326. retreatRecordMd.UNIT_CODE = unitCode;
  327. retreatRecordMd.BATCH_NO = batchNo;
  328. retreatRecordMd.PRODUCT_DATE = productTime;
  329. retreatRecordMd.EXP_DATE = expTime;
  330. retreatRecordMd.INSPECTION_RESULT = retreatDtlMd.INSPECTION_RESULT;
  331. retreatRecordMd.ITEM_STATUS = retreatDtlMd.ITEM_STATUS;
  332. retreatRecordMd.RETREAT_QTY = trayDtlQty;
  333. retreatRecordMd.RETREAT_RECORD_STATUS = 0;
  334. retreatRecordMd.CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  335. retreatRecordMd.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  336. trayDtlMd.WmsStkTrayDtlExtMd = trayDtlExtMd;
  337. trayDtlMd.WmsInRetreatRecord = retreatRecordMd;
  338. wmsStkTrayDtlList.Add(trayDtlMd);
  339. }
  340. }
  341. wmsStkTrayResult.WmsStkTrayDtlList = wmsStkTrayDtlList;
  342. #region 校验明细行 不能存在相同批次、物料条码的数据行
  343. var strList = wmsStkTrayDtlList.GroupBy(x => new { x.MATERIEL_CODE, x.WmsStkTrayDtlExtMd.BATCH_NO }).Select(x => new { Key = x.Count(), MATERIEL_CODE = x.Key.MATERIEL_CODE, BATCH_NO = x.Key.BATCH_NO }).ToList();
  344. foreach (var item in strList)
  345. {
  346. if (item.Key > 1)
  347. {
  348. KryptonMessageBox.Show($"相同的物料:【{item.MATERIEL_CODE}】,批次号:【{item.BATCH_NO}】只能添加一行数据,请修正输入数据行!");
  349. return;
  350. }
  351. }
  352. #endregion
  353. var result = WmsInstockService.wmsInRetreatService.AddWmsInRetreatTrayData(wmsStkTrayResult);
  354. if (result.Status == OperateStatus.Success)
  355. {
  356. MessageBoxTimeoutA(this.Handle, result.Message, "提示", 0, 0, 1000);
  357. frmWmsInRetreat.RefreshFrmHost();
  358. kdgv_RetreatTrayDtlData.Columns.Clear();
  359. InitDataGridViewColumn();
  360. ktb_PalletNo.Text = "";
  361. }
  362. else
  363. {
  364. KryptonMessageBox.Show(result.Message);
  365. }
  366. }
  367. else
  368. {
  369. KryptonMessageBox.Show("请添加退料组盘明细数据!");
  370. }
  371. }
  372. /// <summary>
  373. /// 校验DataGridView输入行数据的正确性
  374. /// </summary>
  375. /// <param name="dvr">DataGridView输入行</param>
  376. /// <param name="OutMssg">校验结果信息</param>
  377. /// <returns></returns>
  378. private bool CheckDataGridViewRowFormat(DataGridViewRow dvr, ref string OutMssg)
  379. {
  380. if (dvr.Cells[1].Value == null)
  381. {
  382. OutMssg = $"第【{dvr.Index + 1}】行未输入物料编码!";
  383. return false;
  384. }
  385. if (dvr.Cells[2].Value == null)
  386. {
  387. OutMssg = $"第【{dvr.Index + 1}】行未输入物料名称!";
  388. return false;
  389. }
  390. if (dvr.Cells[6].Value == null)
  391. {
  392. OutMssg = $"第【{dvr.Index + 1}】行未输入退料明细数量!";
  393. return false;
  394. }
  395. else
  396. {
  397. if (!Regex.IsMatch(dvr.Cells[6].Value.ToString(), @"([1-9]\d*(\.\d*[1-9])?)"))
  398. {
  399. OutMssg = $"第【{dvr.Index + 1}】行输入的组盘明细数量不是合法的数字类型,请检查!";
  400. return false;
  401. }
  402. else
  403. {
  404. if (!string.IsNullOrEmpty(ktb_RetreatNo.Text))
  405. {
  406. decimal trayDtlQty = Convert.ToDecimal(dvr.Cells[6].Value);
  407. decimal rexeiptDtlQty_NoTray = Convert.ToDecimal(dvr.Cells[5].Value);
  408. if (trayDtlQty > rexeiptDtlQty_NoTray)
  409. {
  410. OutMssg = $"第【{dvr.Index + 1}】行输入的组盘明细数量大于退料单明细未退料组盘数量,请修改组盘明细数量!";
  411. return false;
  412. }
  413. }
  414. }
  415. }
  416. if (dvr.Cells[7].Value == null)
  417. {
  418. OutMssg = $"第【{dvr.Index + 1}】行未选择单位信息!";
  419. return false;
  420. }
  421. if (dvr.Cells[8].Value == null)
  422. {
  423. OutMssg = $"第【{dvr.Index + 1}】行未选择供应商信息!";
  424. return false;
  425. }
  426. if (dvr.Cells[10].Value == null)
  427. {
  428. OutMssg = $"第【{dvr.Index + 1}】行未输入生产日期!";
  429. return false;
  430. }
  431. if (dvr.Cells[11].Value == null)
  432. {
  433. OutMssg = $"第【{dvr.Index + 1}】行未输入失效日期!";
  434. return false;
  435. }
  436. if (DateTime.Compare(Convert.ToDateTime(dvr.Cells[10].Value), Convert.ToDateTime(dvr.Cells[11].Value)) >= 0)
  437. {
  438. OutMssg = $"第【{dvr.Index + 1}】行未输入的生产日期大于失效日期,不符合实际情况,请重新输入!";
  439. return false;
  440. }
  441. OutMssg = "校验成功!";
  442. return true;
  443. }
  444. private ListItem GetComboBoxItem(DataGridViewComboBoxCell dataGridViewComboBoxCell, string value)
  445. {
  446. foreach (var item in dataGridViewComboBoxCell.Items)
  447. {
  448. if (((ListItem)item).Value == value)
  449. {
  450. return (ListItem)item;
  451. }
  452. }
  453. return new ListItem();
  454. }
  455. private void kdgv_RetreatTrayDtlData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
  456. {
  457. int index = kdgv_RetreatTrayDtlData.Rows.Count;
  458. kdgv_RetreatTrayDtlData.Rows[index - 1].Cells[0].Value = index;
  459. }
  460. #endregion
  461. #region DataGridView 相关事件
  462. /// <summary>
  463. /// 编辑单元格控件时触发的事件
  464. /// </summary>
  465. /// <param name="sender"></param>
  466. /// <param name="e"></param>
  467. private void kdgv_RetreatTrayDtlData_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  468. {
  469. if (e.Control is DataGridViewOfComoBoxCustom)
  470. {
  471. (e.Control as DataGridViewOfComoBoxCustom).AfterSelector -= new AfterSelectorEventHandler(SalePageAddOrEditForm_AfterSelector);
  472. (e.Control as DataGridViewOfComoBoxCustom).AfterSelector += new AfterSelectorEventHandler(SalePageAddOrEditForm_AfterSelector);
  473. }
  474. }
  475. /// <summary>
  476. /// 悬浮datagridview数据窗体,行选择后事件
  477. /// </summary>
  478. /// <param name="sender"></param>
  479. /// <param name="e"></param>
  480. void SalePageAddOrEditForm_AfterSelector(object sender, AfterSelectorEventArgs e)
  481. {
  482. try
  483. {
  484. DataGridViewRow row = e.Value as DataGridViewRow;
  485. DataRowView dataRow = row.DataBoundItem as DataRowView;
  486. WmsInRetreatDtlResult mdRecDtl = new WmsInRetreatDtlResult();
  487. int retreatDtlId = Convert.ToInt32(dataRow["退料单明细ID"].ToString().Trim());
  488. mdRecDtl = RetreatDataNotEdit.WmsInRetreatDtlList.Find(x => x.RETREAT_DTL_ID == retreatDtlId);
  489. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[1].Value = dataRow["物料编码"].ToString().Trim();
  490. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[2].Value = dataRow["物料名称"].ToString().Trim();
  491. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[3].Value = dataRow["物料条码"].ToString().Trim();
  492. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[4].Value = mdRecDtl.BATCH_NO;
  493. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[5].Value = mdRecDtl.RETREAT_QTY - mdRecDtl.RETREAT_TRAY_QTY;
  494. ListItem unitLstItm = GetComboBoxItem((DataGridViewComboBoxCell)kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[7], mdRecDtl.UNIT_CODE);
  495. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[7].Value = unitLstItm;
  496. ListItem supplierLstItm = GetComboBoxItem((DataGridViewComboBoxCell)kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[8], mdRecDtl.SUPPLIER_CODE);
  497. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[8].Value = supplierLstItm;
  498. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[9].Value = mdRecDtl.PACKAGE_CODE;
  499. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[10].Value = mdRecDtl.PRODUCT_DATE;
  500. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[11].Value = mdRecDtl.EXP_DATE;
  501. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[13].Value = mdRecDtl.RETREAT_QTY;
  502. kdgv_RetreatTrayDtlData.Rows[e.RowIndex].Cells[12].Value = dataRow["退料单明细ID"].ToString().Trim();
  503. kdgv_RetreatTrayDtlData.CurrentCell = this.kdgv_RetreatTrayDtlData[e.ColumnIndex, e.RowIndex + 1];
  504. }
  505. catch (Exception ex)
  506. {
  507. KryptonMessageBox.Show(ex.Message);
  508. }
  509. }
  510. private ListItem GetComboBoxItem(DataGridViewComboBoxCell dataGridViewComboBoxCell)
  511. {
  512. foreach (var item in dataGridViewComboBoxCell.Items)
  513. {
  514. if (((ListItem)item).Text == dataGridViewComboBoxCell.Value.ToString())
  515. {
  516. return (ListItem)item;
  517. }
  518. }
  519. return new ListItem();
  520. }
  521. private void kdgv_RetreatTrayDtlData_DataError(object sender, DataGridViewDataErrorEventArgs e)
  522. {
  523. }
  524. #endregion
  525. #region 鼠标右键单击事件
  526. private void 删除选中行ToolStripMenuItem_Click(object sender, EventArgs e)
  527. {
  528. if (!kdgv_RetreatTrayDtlData.CurrentRow.IsNewRow)
  529. {
  530. DataGridViewRow item = kdgv_RetreatTrayDtlData.CurrentCell.OwningRow;
  531. decimal currCellTrayQty = item.Cells[6].Value == null ? 0 : Convert.ToDecimal(item.Cells[6].Value);
  532. int currCellRecDtlId = item.Cells[13].Value == null ? 0 : Convert.ToInt32(item.Cells[13].Value);
  533. if (currCellTrayQty > 0)
  534. {
  535. WmsInRetreatDtlResult recDtlMd = RetreatDataNotEdit.WmsInRetreatDtlList.Find(x => x.RETREAT_DTL_ID == currCellRecDtlId);
  536. RetreatDataNotEdit.WmsInRetreatDtlList.Find(x => x.RETREAT_DTL_ID == currCellRecDtlId).RETREAT_TRAY_QTY = recDtlMd.RETREAT_TRAY_QTY - currCellTrayQty;
  537. }
  538. kdgv_RetreatTrayDtlData.Rows.Remove(kdgv_RetreatTrayDtlData.CurrentCell.OwningRow);
  539. foreach (DataGridViewRow item1 in kdgv_RetreatTrayDtlData.Rows)
  540. {
  541. int index = item1.Index;
  542. kdgv_RetreatTrayDtlData.Rows[index].Cells[0].Value = index + 1;
  543. }
  544. }
  545. }
  546. private void 全部删除ToolStripMenuItem_Click(object sender, EventArgs e)
  547. {
  548. foreach (DataGridViewRow item in kdgv_RetreatTrayDtlData.Rows)
  549. {
  550. decimal currCellTrayQty = item.Cells[6].Value == null ? 0 : Convert.ToDecimal(item.Cells[6].Value);
  551. int currCellRecDtlId = item.Cells[13].Value == null ? 0 : Convert.ToInt32(item.Cells[13].Value);
  552. if (currCellTrayQty > 0)
  553. {
  554. WmsInRetreatDtlResult recDtlMd = RetreatDataNotEdit.WmsInRetreatDtlList.Find(x => x.RETREAT_DTL_ID == currCellRecDtlId);
  555. RetreatDataNotEdit.WmsInRetreatDtlList.Find(x => x.RETREAT_DTL_ID == currCellRecDtlId).RETREAT_TRAY_QTY = recDtlMd.RETREAT_TRAY_QTY - currCellTrayQty;
  556. }
  557. }
  558. kdgv_RetreatTrayDtlData.Rows.Clear();
  559. }
  560. #endregion
  561. }
  562. }