frmChildAddWmsQaInspection.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. using static NXWMS.Client.FrmCustom.CustomEventMsg;
  20. namespace NXWMS.Forms.Inspection.frmInspectionChild
  21. {
  22. /// <summary>
  23. /// 新增质检单窗体类
  24. /// </summary>
  25. public partial class frmChildAddWmsQaInspection : KryptonForm
  26. {
  27. /// <summary>
  28. /// 窗体构造函数
  29. /// </summary>
  30. public frmChildAddWmsQaInspection()
  31. {
  32. InitializeComponent();
  33. }
  34. #region 全局变量
  35. List<WmsInArrivalDtlResult> lstReceiptDtl = new List<WmsInArrivalDtlResult>();
  36. #endregion
  37. #region 初始化数据
  38. /// <summary>
  39. /// 窗体加载函数
  40. /// </summary>
  41. /// <param name="sender"></param>
  42. /// <param name="e"></param>
  43. private void frmChildAddWmsQaInspection_Load(object sender, EventArgs e)
  44. {
  45. InitComboBoxItemData();
  46. InitDataGridViewColumn();
  47. kdtp_InspectionTime.Checked = false;
  48. }
  49. /// <summary>
  50. /// 初始化下拉列表数据
  51. /// </summary>
  52. private void InitComboBoxItemData()
  53. {
  54. /*
  55. ToDo:后续把下拉列表转为 后台获取数据,目前是写死的。
  56. */
  57. List<BasDictionaryResult> results = new List<BasDictionaryResult>();
  58. #region 质检单类型
  59. results = BasDictionaryUtil.basDictionaryResultLst.FindAll(x=>x.DICTIONARY_CODE == "InspectionTypeDesc");
  60. if (results.Count > 0)
  61. {
  62. kcmb_InspectionType.Items.Clear();
  63. foreach (var item in results)
  64. {
  65. kcmb_InspectionType.Items.Add(new ListItem
  66. {
  67. Value = item.DICTIONARY_ITEM_CODE,
  68. Text = item.DICTIONARY_ITEM_NAME,
  69. });
  70. }
  71. kcmb_InspectionType.SelectedIndex = 0;
  72. }
  73. else
  74. {
  75. KryptonMessageBox.Show("未找到质检单类型的字典项数据!");
  76. }
  77. #endregion
  78. #region 质检方式
  79. results = BasDictionaryUtil.basDictionaryResultLst.FindAll(x => x.DICTIONARY_CODE == "InspectionWayDesc");
  80. if (results.Count > 0)
  81. {
  82. kcmb_InspectionWay.Items.Clear();
  83. foreach (var item in results)
  84. {
  85. kcmb_InspectionWay.Items.Add(new ListItem
  86. {
  87. Value = item.DICTIONARY_ITEM_CODE,
  88. Text = item.DICTIONARY_ITEM_NAME,
  89. });
  90. }
  91. kcmb_InspectionWay.SelectedIndex = 0;
  92. }
  93. else
  94. {
  95. KryptonMessageBox.Show("未找到质检方式的字典项数据!");
  96. }
  97. #endregion
  98. }
  99. /// <summary>
  100. /// 初始化DataGridView列信息
  101. /// </summary>
  102. private void InitDataGridViewColumn()
  103. {
  104. DataGridViewColumn column1 = new KryptonDataGridViewTextBoxColumn();
  105. column1.HeaderText = "序号";
  106. column1.Width = 50;
  107. column1.ReadOnly = true;
  108. //column1.
  109. kdgv_InspectionDtlData.Columns.Add(column1);
  110. DataTable dt = CreateTable();
  111. DataGridViewColumn column = new DataGridViewDataWindowColumn();
  112. (column as DataGridViewDataWindowColumn).SDisplayField = "到货通知单号,物料编码,物料名称,物料条码,批次号";
  113. (column as DataGridViewDataWindowColumn).SDisplayMember = "到货通知单号";
  114. (column as DataGridViewDataWindowColumn).SKeyWords = "到货通知单号";
  115. (column as DataGridViewDataWindowColumn).DataSource = dt;
  116. column.Width = 150;
  117. column.HeaderText = "到货通知单号";
  118. kdgv_InspectionDtlData.Columns.Add(column);
  119. column = new DataGridViewDataWindowColumn();
  120. (column as DataGridViewDataWindowColumn).SDisplayField = "到货通知单号,物料编码,物料名称,物料条码,批次号";
  121. (column as DataGridViewDataWindowColumn).SDisplayMember = "物料编码";
  122. (column as DataGridViewDataWindowColumn).SKeyWords = "物料编码";
  123. (column as DataGridViewDataWindowColumn).DataSource = dt;
  124. column.HeaderText = "物料编码";
  125. column.Width = 200;
  126. kdgv_InspectionDtlData.Columns.Add(column);
  127. column = new DataGridViewDataWindowColumn();
  128. (column as DataGridViewDataWindowColumn).SDisplayField = "到货通知单号,物料编码,物料名称,物料条码,批次号";
  129. (column as DataGridViewDataWindowColumn).SDisplayMember = "物料名称";
  130. (column as DataGridViewDataWindowColumn).SKeyWords = "物料名称";
  131. (column as DataGridViewDataWindowColumn).DataSource = dt;
  132. column.HeaderText = "物料名称";
  133. column.Width = 200;
  134. kdgv_InspectionDtlData.Columns.Add(column);
  135. column = new DataGridViewDataWindowColumn();
  136. (column as DataGridViewDataWindowColumn).SDisplayField = "到货通知单号,物料编码,物料名称,物料条码,批次号";
  137. (column as DataGridViewDataWindowColumn).SDisplayMember = "物料条码";
  138. (column as DataGridViewDataWindowColumn).SKeyWords = "物料条码";
  139. (column as DataGridViewDataWindowColumn).DataSource = dt;
  140. column.HeaderText = "物料条码";
  141. column.Width = 150;
  142. kdgv_InspectionDtlData.Columns.Add(column);
  143. DataGridViewComboBoxColumn cmb_Unit = new DataGridViewComboBoxColumn();
  144. cmb_Unit.HeaderText = "质检结果";
  145. cmb_Unit.Width = 90;
  146. //目前写死下拉列表的数据项,后续改为后台获取
  147. cmb_Unit.Items.AddRange(new ListItem[]
  148. {
  149. new ListItem{ Value = "Wait",Text = "待检"},
  150. new ListItem{ Value = "OK",Text = "合格"},
  151. new ListItem{ Value = "NG",Text = "不合格"}
  152. });
  153. cmb_Unit.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
  154. kdgv_InspectionDtlData.Columns.Add(cmb_Unit);
  155. column1 = new KryptonDataGridViewTextBoxColumn();
  156. column1.HeaderText = "批次号";
  157. column1.Width = 120;
  158. kdgv_InspectionDtlData.Columns.Add(column1);
  159. column1 = new KryptonDataGridViewTextBoxColumn();
  160. column1.HeaderText = "单位";
  161. column1.Width = 70;
  162. kdgv_InspectionDtlData.Columns.Add(column1);
  163. column1 = new KryptonDataGridViewTextBoxColumn();
  164. column1.HeaderText = "供应商";
  165. column1.Width = 120;
  166. kdgv_InspectionDtlData.Columns.Add(column1);
  167. column1 = new KryptonDataGridViewTextBoxColumn();
  168. column1.HeaderText = "包装";
  169. column1.Width = 80;
  170. kdgv_InspectionDtlData.Columns.Add(column1);
  171. KryptonDataGridViewDateTimePickerColumn column_ProductTime = new KryptonDataGridViewDateTimePickerColumn();
  172. column_ProductTime.HeaderText = "生产日期";
  173. column_ProductTime.Width = 160;
  174. column_ProductTime.Format = DateTimePickerFormat.Custom;
  175. column_ProductTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  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. kdgv_InspectionDtlData.Columns.Add(column_ExpTime);
  183. column1 = new KryptonDataGridViewTextBoxColumn();
  184. column1.HeaderText = "到货通知单明细ID";
  185. column1.Width = 30;
  186. column1.Visible = false;
  187. kdgv_InspectionDtlData.Columns.Add(column1);
  188. }
  189. /// <summary>
  190. /// 创建数据源表格
  191. /// </summary>
  192. /// <returns></returns>
  193. private DataTable CreateTable()
  194. {
  195. DataTable dt = new DataTable();
  196. DataColumn dc = new DataColumn("到货通知单号");
  197. dt.Columns.Add(dc);
  198. dc = new DataColumn("物料编码");
  199. dt.Columns.Add(dc);
  200. dc = new DataColumn("物料名称");
  201. dt.Columns.Add(dc);
  202. dc = new DataColumn("物料条码");
  203. dt.Columns.Add(dc);
  204. dc = new DataColumn("批次号");
  205. dt.Columns.Add(dc);
  206. dc = new DataColumn("到货通知单明细ID");
  207. dt.Columns.Add(dc);
  208. //var result = WmsInstockService.wmsInReceiptService.GetAllWaitForQaReceiptDtlData();
  209. var result = WmsInstockService.wmsInArrivalService.GetAllWaitForQaArrivalDtlData();
  210. if (result.Status == OperateStatus.Success)
  211. {
  212. foreach (WmsInArrivalDtlResult item in result.Data)
  213. {
  214. DataRow dr = dt.NewRow();
  215. dr["到货通知单号"] = item.ARRIVAL_NO;
  216. dr["物料编码"] = item.MATERIEL_CODE;
  217. dr["物料名称"] = item.MATERIEL_NAME;
  218. dr["物料条码"] = item.MATERIEL_BARCODE;
  219. dr["批次号"] = item.BATCH_NO;
  220. dr["到货通知单明细ID"] = item.ARRIVAL_DTL_ID;
  221. dt.Rows.Add(dr);
  222. }
  223. lstReceiptDtl = result.Data;
  224. }
  225. return dt;
  226. }
  227. #endregion
  228. #region 按钮事件
  229. /// <summary>
  230. /// 确认按钮事件
  231. /// 提交新增完成的质检单数据
  232. /// </summary>
  233. /// <param name="sender"></param>
  234. /// <param name="e"></param>
  235. private void btnConfirm_Click(object sender, EventArgs e)
  236. {
  237. WmsQaInspectionResult mdInspection = new WmsQaInspectionResult();
  238. mdInspection.INSPECTION_TYPE = Convert.ToInt32(((ListItem)kcmb_InspectionType.SelectedItem).Value);
  239. mdInspection.INSPECTION_USER = ktb_InspectionUser.Text;
  240. mdInspection.INSPECTION_WAY = Convert.ToInt32(((ListItem)kcmb_InspectionType.SelectedItem).Value);
  241. if (kdtp_InspectionTime.Checked)
  242. {
  243. mdInspection.INSPECTION_TIME = kdtp_InspectionTime.Value;
  244. }
  245. else
  246. {
  247. mdInspection.INSPECTION_TIME = new DateTime();
  248. }
  249. mdInspection.INSPECTION_STATUS = (int)InspectionStatus.初始创建;
  250. mdInspection.DESCRIBE = ktb_Describe.Text.Trim();
  251. mdInspection.CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  252. mdInspection.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  253. List<WmsQaInspectionDtlResult> mdInspectionDtlList = new List<WmsQaInspectionDtlResult>();
  254. if (kdgv_InspectionDtlData.Rows.Count > 0 && !kdgv_InspectionDtlData.Rows[0].IsNewRow)
  255. {
  256. foreach (DataGridViewRow dvr in kdgv_InspectionDtlData.Rows)
  257. {
  258. if (!dvr.IsNewRow)
  259. {
  260. #region 校验每一行数据的完整性
  261. string RowCheckMsg = string.Empty;
  262. if (!CheckDataGridViewRowFormat(dvr, ref RowCheckMsg))
  263. {
  264. KryptonMessageBox.Show(RowCheckMsg);
  265. return;
  266. }
  267. #endregion
  268. string receiptNo = dvr.Cells[1].Value.ToString();
  269. string materielCode = dvr.Cells[2].Value.ToString();
  270. string materielName = dvr.Cells[3].Value.ToString();
  271. string materielBarcode = dvr.Cells[4].Value == null ? null : dvr.Cells[4].Value.ToString();
  272. string inspectionResult = GetComboBoxItem((DataGridViewComboBoxCell)dvr.Cells[5]).Value;
  273. string batchNo = dvr.Cells[6].Value == null ? null : dvr.Cells[6].Value.ToString();
  274. string unitCode = dvr.Cells[7].Value == null ? null : dvr.Cells[7].Value.ToString();
  275. string supplierCode = dvr.Cells[8].Value == null ? null : dvr.Cells[8].Value.ToString();
  276. string packageCode = dvr.Cells[9].Value == null ? null : dvr.Cells[9].Value.ToString();
  277. DateTime productTime = Convert.ToDateTime(dvr.Cells[10].Value);
  278. DateTime expTime = Convert.ToDateTime(dvr.Cells[11].Value);
  279. int billDtlId = dvr.Cells[12].Value == null ? 0 : Convert.ToInt32(dvr.Cells[12].Value);
  280. WmsInArrivalDtlResult mdResult = lstReceiptDtl.Find(x => x.ARRIVAL_DTL_ID == billDtlId);
  281. mdInspectionDtlList.Add(new WmsQaInspectionDtlResult
  282. {
  283. BILL_NO = mdResult.ARRIVAL_NO,
  284. BILL_DTL_ID = billDtlId,
  285. MATERIEL_CODE = materielCode,
  286. MATERIEL_NAME = materielName,
  287. MATERIEL_BARCODE = materielBarcode,
  288. BATCH_NO = batchNo,
  289. UNIT_CODE = unitCode,
  290. SUPPLIER_CODE = mdResult.SUPPLIER_CODE,
  291. SUPPLIER_NAME = mdResult.SUPPLIER_NAME,
  292. PACKAGE_CODE = packageCode,
  293. PRODUCT_DATE = productTime,
  294. EXP_DATE = expTime,
  295. INSPECTION_RESULT = inspectionResult,
  296. ITEM_STATUS = mdResult.ITEM_STATUS,
  297. INSPECTION_DTL_STATUS = (int)InspectionStatus.初始创建,
  298. CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId,
  299. UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId,
  300. DESCRIBE = null
  301. });
  302. }
  303. }
  304. #region 校验明细行 不能存在相同批次、物料条码的数据行
  305. var strList = mdInspectionDtlList.GroupBy(x => new { x.MATERIEL_CODE, x.BATCH_NO }).Select(x => new { Key = x.Count(), MATERIEL_CODE = x.Key.MATERIEL_CODE, BATCH_NO = x.Key.BATCH_NO }).ToList();
  306. foreach (var item in strList)
  307. {
  308. if (item.Key > 1)
  309. {
  310. KryptonMessageBox.Show($"相同的物料:【{item.MATERIEL_CODE}】,批次号:【{item.BATCH_NO}】只能添加一行数据,请修正输入数据行!");
  311. return;
  312. }
  313. }
  314. #endregion
  315. mdInspection.WmsQaInspectionDtlList = mdInspectionDtlList;
  316. var result = WmsInspectionService.wmsQaInspectionService.AddWmsQaInspectionData(mdInspection);
  317. if (result.Status == OperateStatus.Success)
  318. {
  319. KryptonMessageBox.Show(result.Message);
  320. frmWmsQaInspection.RefreshFrmHost();
  321. this.Close();
  322. }
  323. else
  324. {
  325. KryptonMessageBox.Show(result.Message);
  326. }
  327. }
  328. else
  329. {
  330. KryptonMessageBox.Show("请添加数据行!");
  331. }
  332. }
  333. /// <summary>
  334. /// 校验DataGridView输入行数据的正确性
  335. /// </summary>
  336. /// <param name="dvr">DataGridView输入行</param>
  337. /// <param name="OutMssg">校验结果信息</param>
  338. /// <returns></returns>
  339. private bool CheckDataGridViewRowFormat(DataGridViewRow dvr, ref string OutMssg)
  340. {
  341. if (dvr.Cells[1].Value == null)
  342. {
  343. OutMssg = $"第【{dvr.Index + 1}】行未输入物料编码!";
  344. return false;
  345. }
  346. if (dvr.Cells[2].Value == null)
  347. {
  348. OutMssg = $"第【{dvr.Index + 1}】行未输入物料编码!";
  349. return false;
  350. }
  351. if (dvr.Cells[3].Value == null)
  352. {
  353. OutMssg = $"第【{dvr.Index + 1}】行未输入物料名称!";
  354. return false;
  355. }
  356. if (dvr.Cells[7].Value == null)
  357. {
  358. OutMssg = $"第【{dvr.Index + 1}】行未选择单位信息!";
  359. return false;
  360. }
  361. if (dvr.Cells[8].Value == null)
  362. {
  363. OutMssg = $"第【{dvr.Index + 1}】行未选择供应商信息!";
  364. return false;
  365. }
  366. if (dvr.Cells[10].Value == null)
  367. {
  368. OutMssg = $"第【{dvr.Index + 1}】行未输入生产日期!";
  369. return false;
  370. }
  371. if (dvr.Cells[11].Value == null)
  372. {
  373. OutMssg = $"第【{dvr.Index + 1}】行未输入失效日期!";
  374. return false;
  375. }
  376. if (DateTime.Compare(Convert.ToDateTime(dvr.Cells[10].Value), Convert.ToDateTime(dvr.Cells[11].Value)) >= 0)
  377. {
  378. OutMssg = $"第【{dvr.Index + 1}】行未输入的生产日期大于失效日期,不符合实际情况,请重新输入!";
  379. return false;
  380. }
  381. OutMssg = "校验成功!";
  382. return true;
  383. }
  384. /// <summary>
  385. /// 取消按钮事件
  386. /// 退出新增页面
  387. /// </summary>
  388. /// <param name="sender"></param>
  389. /// <param name="e"></param>
  390. private void btnCancel_Click(object sender, EventArgs e)
  391. {
  392. this.Close();
  393. }
  394. private ListItem GetComboBoxItem(DataGridViewComboBoxCell dataGridViewComboBoxCell)
  395. {
  396. foreach (var item in dataGridViewComboBoxCell.Items)
  397. {
  398. if (((ListItem)item).Text == dataGridViewComboBoxCell.Value.ToString())
  399. {
  400. return (ListItem)item;
  401. }
  402. }
  403. return new ListItem();
  404. }
  405. private ListItem GetComboBoxItem(DataGridViewComboBoxCell dataGridViewComboBoxCell, string value)
  406. {
  407. foreach (var item in dataGridViewComboBoxCell.Items)
  408. {
  409. if (((ListItem)item).Value == value)
  410. {
  411. return (ListItem)item;
  412. }
  413. }
  414. return new ListItem();
  415. }
  416. #endregion
  417. #region DataGridView相关事件
  418. /// <summary>
  419. /// 编辑单元格控件时触发的事件
  420. /// </summary>
  421. /// <param name="sender"></param>
  422. /// <param name="e"></param>
  423. private void kdgv_InspectionDtlData_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  424. {
  425. if (e.Control is DataGridViewOfComoBoxCustom)
  426. {
  427. (e.Control as DataGridViewOfComoBoxCustom).AfterSelector -= new AfterSelectorEventHandler(SalePageAddOrEditForm_AfterSelector);
  428. (e.Control as DataGridViewOfComoBoxCustom).AfterSelector += new AfterSelectorEventHandler(SalePageAddOrEditForm_AfterSelector);
  429. }
  430. }
  431. /// <summary>
  432. /// 悬浮datagridview数据窗体,行选择后事件
  433. /// </summary>
  434. /// <param name="sender"></param>
  435. /// <param name="e"></param>
  436. void SalePageAddOrEditForm_AfterSelector(object sender, AfterSelectorEventArgs e)
  437. {
  438. try
  439. {
  440. DataGridViewRow row = e.Value as DataGridViewRow;
  441. DataRowView dataRow = row.DataBoundItem as DataRowView;
  442. int receiptDtlId = Convert.ToInt32(dataRow["到货通知单明细ID"].ToString().Trim());
  443. WmsInArrivalDtlResult receiptDtlResult = lstReceiptDtl.Find(x => x.ARRIVAL_DTL_ID == receiptDtlId);
  444. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[1].Value = dataRow["到货通知单号"].ToString().Trim();
  445. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[2].Value = dataRow["物料编码"].ToString().Trim();
  446. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[3].Value = dataRow["物料名称"].ToString().Trim();
  447. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[4].Value = dataRow["物料条码"].ToString().Trim();
  448. ListItem inspectionResultLstItm = GetComboBoxItem((DataGridViewComboBoxCell)kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[5], receiptDtlResult.INSPECTION_RESULT);
  449. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[5].Value = inspectionResultLstItm;
  450. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[6].Value = receiptDtlResult.BATCH_NO;
  451. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[7].Value = receiptDtlResult.UNIT_CODE;
  452. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[8].Value = receiptDtlResult.SUPPLIER_NAME;
  453. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[9].Value = receiptDtlResult.PACKAGE_CODE;
  454. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[10].Value = receiptDtlResult.PRODUCT_DATE;
  455. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[11].Value = receiptDtlResult.EXP_DATE;
  456. kdgv_InspectionDtlData.Rows[e.RowIndex].Cells[12].Value = receiptDtlResult.ARRIVAL_DTL_ID;
  457. kdgv_InspectionDtlData.CurrentCell = this.kdgv_InspectionDtlData[e.ColumnIndex, e.RowIndex + 1];
  458. }
  459. catch (Exception ex)
  460. {
  461. MessageBox.Show(ex.Message);
  462. }
  463. }
  464. /// <summary>
  465. /// 针对ComboBox下拉列表的DataGridView数据列单元格。
  466. /// 由于DataGridView的ComboBox列的Item至使用的是KeyValue形式的ListItem,
  467. /// 并且单元格刚开始进入编辑的时候,value值为null。如果后续不选择下拉列表的值,就切换编辑的单元格,就会触发DataError事件,警告数据格式错误。
  468. /// 所以单元格刚开始进入编辑的时候。需要设定一个默认值。默认值的类型为ListItem。一般设定为下拉列表值集合的第一个值。
  469. /// </summary>
  470. /// <param name="sender"></param>
  471. /// <param name="e"></param>
  472. private void kdgv_InspectionDtlData_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
  473. {
  474. int rowIndex = e.RowIndex;
  475. int columnIndex = e.ColumnIndex;
  476. if (kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex] is DataGridViewComboBoxCell)
  477. {
  478. if (kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex].Value == null)
  479. {
  480. DataGridViewComboBoxCell dataGridViewComboBoxCell = (DataGridViewComboBoxCell)kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex];
  481. ListItem tstlst = (ListItem)dataGridViewComboBoxCell.Items[0];
  482. kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex].Value = tstlst;
  483. }
  484. }
  485. }
  486. /// <summary>
  487. /// 针对ComboBox下拉列表的DataGridView数据列单元格。
  488. /// 由于DataGridView的ComboBox列的Item至使用的是KeyValue形式的ListItem,
  489. /// 所以单元格结束编辑的时候。需要给单元格设定一个类型为ListItem的值。
  490. /// </summary>
  491. /// <param name="sender"></param>
  492. /// <param name="e"></param>
  493. private void kdgv_InspectionDtlData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  494. {
  495. int rowIndex = e.RowIndex;
  496. int columnIndex = e.ColumnIndex;
  497. if (kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex] is DataGridViewComboBoxCell)
  498. {
  499. ListItem tstlst = GetComboBoxItem((DataGridViewComboBoxCell)kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex]);
  500. kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex].Value = tstlst;
  501. }
  502. }
  503. private void kdgv_InspectionDtlData_DataError(object sender, DataGridViewDataErrorEventArgs e)
  504. {
  505. }
  506. private void kdgv_InspectionDtlData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
  507. {
  508. int index = kdgv_InspectionDtlData.Rows.Count;
  509. kdgv_InspectionDtlData.Rows[index - 1].Cells[0].Value = index;
  510. }
  511. #endregion
  512. #region 鼠标右键单击事件
  513. /// <summary>
  514. /// 删除选中行事件
  515. /// </summary>
  516. /// <param name="sender"></param>
  517. /// <param name="e"></param>
  518. private void 删除选中行ToolStripMenuItem_Click(object sender, EventArgs e)
  519. {
  520. kdgv_InspectionDtlData.Rows.Remove(kdgv_InspectionDtlData.CurrentCell.OwningRow);
  521. foreach (DataGridViewRow item in kdgv_InspectionDtlData.Rows)
  522. {
  523. int index = item.Index;
  524. kdgv_InspectionDtlData.Rows[index].Cells[0].Value = index + 1;
  525. }
  526. }
  527. /// <summary>
  528. /// 删除全部行事件
  529. /// </summary>
  530. /// <param name="sender"></param>
  531. /// <param name="e"></param>
  532. private void 全部删除ToolStripMenuItem_Click(object sender, EventArgs e)
  533. {
  534. kdgv_InspectionDtlData.Rows.Clear();
  535. }
  536. #endregion
  537. }
  538. }