frmChildInvoiceCheck.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Model.AppModels.Condition.Balance;
  3. using NXWMS.Client.Model.AppModels.Condition.Base;
  4. using NXWMS.Client.Model.AppModels.Result.Balance;
  5. using NXWMS.Client.Model.AppModels.Result.Base;
  6. using NXWMS.Client.Model.AppModels.Result.Common;
  7. using NXWMS.Client.Model.AppModels.Result.OutStock;
  8. using NXWMS.Client.Model.CoreModels;
  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.OutStock.frmOutstockChild
  20. {
  21. /// <summary>
  22. /// 发货审核
  23. /// </summary>
  24. public partial class frmChildInvoiceCheck : KryptonForm
  25. {
  26. /// <summary>
  27. /// 窗体构造函数
  28. /// </summary>
  29. public frmChildInvoiceCheck()
  30. {
  31. InitializeComponent();
  32. }
  33. #region 全局变量
  34. /// <summary>
  35. /// 发货单主键ID
  36. /// </summary>
  37. public string InvoiceId { get; set; }
  38. /// <summary>
  39. /// 数据库中的发货单所有数据(包括主、明细表)。
  40. /// 未进行编辑过。
  41. /// </summary>
  42. private WmsOutInvoiceResult InvoiceDataNotEdit = new WmsOutInvoiceResult();
  43. private WmsBalanceAllocateStatus AutoAllocateBalanceMsg = new WmsBalanceAllocateStatus();
  44. #endregion
  45. #region 初始化数据
  46. /// <summary>
  47. /// 窗体加载函数
  48. /// </summary>
  49. /// <param name="sender"></param>
  50. /// <param name="e"></param>
  51. private void frmChildInvoiceCheck_Load(object sender, EventArgs e)
  52. {
  53. InitComboBoxItemData();
  54. LoadWmsOutInvoiceDtlData();
  55. kcmb_AllocateType.SelectedIndex = 1;
  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. var regionResult = BaseServices.regionService.GetList(new RegionSearchCondition { IsUsed = true, ItemSQL = "REGION_CODE,REGION_NAME,AREA_NAME,AREA_CODE,WAREHOUSE_CODE,WAREHOUSE_NAME" });
  68. if (regionResult.Status == OperateStatus.Success)
  69. {
  70. kcmb_RegionMsg.Items.Clear();
  71. kcmb_RegionMsg.Items.Add(new ListItem
  72. {
  73. Value = "",
  74. Text = "请选择",
  75. });
  76. foreach (RegionResult item in regionResult.Data.RowData.ToList())
  77. {
  78. kcmb_RegionMsg.Items.Add(new ListItem
  79. {
  80. Value = item.REGION_CODE,
  81. Text = item.REGION_NAME,
  82. });
  83. }
  84. kcmb_RegionMsg.SelectedIndex = 0;
  85. }
  86. else
  87. {
  88. kcmb_RegionMsg.Items.Clear();
  89. KryptonMessageBox.Show(regionResult.Message);
  90. }
  91. #endregion
  92. }
  93. /// <summary>
  94. /// 调用服务端接口,请求发货单明细表数据
  95. /// </summary>
  96. /// <returns></returns>
  97. private string LoadWmsOutInvoiceDtlData()
  98. {
  99. var result = WmsInvoiceService.wmsOutInvoiceService.GetWmsOutInvoiceDtlListForId(new WmsOutInvoiceResult { INVOICE_ID = Convert.ToInt32(this.InvoiceId) });
  100. if (result.Status == OperateStatus.Success)
  101. {
  102. InvoiceDataNotEdit = result.Data;
  103. kdgv_InvoiceDtlData.Rows.Clear();
  104. foreach (WmsOutInvoiceDtlResult item in result.Data.WmsOutInvoiceDtlList)
  105. {
  106. int index = kdgv_InvoiceDtlData.Rows.Add();
  107. kdgv_InvoiceDtlData.Rows[index].Cells[0].Value = index + 1;
  108. kdgv_InvoiceDtlData.Rows[index].Cells[1].Value = item.MATERIEL_CODE;
  109. kdgv_InvoiceDtlData.Rows[index].Cells[2].Value = item.MATERIEL_NAME;
  110. kdgv_InvoiceDtlData.Rows[index].Cells[3].Value = item.MATERIEL_BARCODE;
  111. kdgv_InvoiceDtlData.Rows[index].Cells[4].Value = item.MATERIEL_SPEC;
  112. kdgv_InvoiceDtlData.Rows[index].Cells[5].Value = item.BATCH_NO;
  113. kdgv_InvoiceDtlData.Rows[index].Cells[6].Value = item.INVOICE_DEMAND_QTY;
  114. kdgv_InvoiceDtlData.Rows[index].Cells[7].Value = item.UNIT_CODE;
  115. kdgv_InvoiceDtlData.Rows[index].Cells[8].Value = item.PACKAGE_CODE;
  116. }
  117. kdgv_InvoiceDtlData.ClearSelection();
  118. return string.Empty;
  119. }
  120. else
  121. {
  122. return result.Message;
  123. }
  124. }
  125. #endregion
  126. #region 按钮事件
  127. private void kcmb_AllocateType_SelectionChangeCommitted(object sender, EventArgs e)
  128. {
  129. if (kcmb_AllocateType.Text == "自动分配")
  130. {
  131. AutoAllocateBalanceMsg = null;
  132. kdgv_AllowBalanceData.Columns[0].ReadOnly = true;
  133. kdgv_AllowBalanceData.Rows.Clear();
  134. foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
  135. {
  136. dvr.Cells[9].Value = null;
  137. dvr.Cells[10].Value = null;
  138. dvr.Cells[9].Style.BackColor = dvr.Cells[1].Style.BackColor;
  139. dvr.Cells[10].Style.BackColor = dvr.Cells[1].Style.BackColor;
  140. }
  141. var result = WmsInvoiceService.wmsOutInvoiceService.InvoiceAllocationBalanceAuto(InvoiceDataNotEdit);
  142. if (result.Status == OperateStatus.Success)
  143. {
  144. AutoAllocateBalanceMsg = result.Data;
  145. foreach (WmsStkBalanceDtlResult item in result.Data.BalanceDtlResultLst)
  146. {
  147. int index = kdgv_AllowBalanceData.Rows.Add();
  148. kdgv_AllowBalanceData.Rows[index].Cells[0].Value = true;
  149. kdgv_AllowBalanceData.Rows[index].Cells[1].Value = index + 1;
  150. kdgv_AllowBalanceData.Rows[index].Cells[2].Value = item.BALANCE_ID;
  151. kdgv_AllowBalanceData.Rows[index].Cells[3].Value = item.TRAY_ID;
  152. kdgv_AllowBalanceData.Rows[index].Cells[4].Value = item.TRAY_CODE;
  153. kdgv_AllowBalanceData.Rows[index].Cells[5].Value = item.PALLET_CODE;
  154. kdgv_AllowBalanceData.Rows[index].Cells[6].Value = item.TRAY_DTL_ID;
  155. kdgv_AllowBalanceData.Rows[index].Cells[7].Value = item.MATERIEL_CODE;
  156. kdgv_AllowBalanceData.Rows[index].Cells[8].Value = item.MATERIEL_NAME;
  157. kdgv_AllowBalanceData.Rows[index].Cells[9].Value = item.MATERIEL_BARCODE;
  158. kdgv_AllowBalanceData.Rows[index].Cells[10].Value = item.MATERIEL_SPEC;
  159. kdgv_AllowBalanceData.Rows[index].Cells[11].Value = item.BATCH_NO;
  160. kdgv_AllowBalanceData.Rows[index].Cells[12].Value = item.QTY;
  161. kdgv_AllowBalanceData.Rows[index].Cells[13].Value = item.UNIT_CODE;
  162. kdgv_AllowBalanceData.Rows[index].Cells[14].Value = item.PACKAGE_CODE;
  163. kdgv_AllowBalanceData.Rows[index].Cells[15].Value = item.PRODUCT_DATE;
  164. kdgv_AllowBalanceData.Rows[index].Cells[16].Value = item.EXP_DATE;
  165. kdgv_AllowBalanceData.Rows[index].DefaultCellStyle.BackColor = Color.LightGreen;
  166. foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
  167. {
  168. string materielCode = dvr.Cells[1].Value.ToString();
  169. string batchNo = dvr.Cells[5].Value.ToString();
  170. decimal invoiceQty = Convert.ToDecimal(dvr.Cells[6].Value);
  171. decimal allowQty = dvr.Cells[9].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[9].Value);
  172. if (item.MATERIEL_CODE == materielCode && item.BATCH_NO == batchNo)
  173. {
  174. dvr.Cells[9].Value = allowQty + item.QTY;
  175. string percentage = ((allowQty + item.QTY) / invoiceQty).ToString("0.00%");
  176. dvr.Cells[10].Value = "已分配:【" + percentage + "】";
  177. if ((allowQty + item.QTY) >= invoiceQty)
  178. {
  179. dvr.Cells[9].Style.BackColor = Color.LightGreen;
  180. dvr.Cells[10].Style.BackColor = Color.LightGreen;
  181. }
  182. break;
  183. }
  184. }
  185. kdgv_AllowBalanceData.ClearSelection();
  186. }
  187. }
  188. else
  189. {
  190. if ((result.Data != null && result.Data.BalanceDtlResultLst.Count > 0))
  191. {
  192. AutoAllocateBalanceMsg = result.Data;
  193. foreach (WmsStkBalanceDtlResult item in result.Data.BalanceDtlResultLst)
  194. {
  195. int index = kdgv_AllowBalanceData.Rows.Add();
  196. kdgv_AllowBalanceData.Rows[index].Cells[0].Value = true;
  197. kdgv_AllowBalanceData.Rows[index].Cells[1].Value = index + 1;
  198. kdgv_AllowBalanceData.Rows[index].Cells[2].Value = item.BALANCE_ID;
  199. kdgv_AllowBalanceData.Rows[index].Cells[3].Value = item.TRAY_ID;
  200. kdgv_AllowBalanceData.Rows[index].Cells[4].Value = item.TRAY_CODE;
  201. kdgv_AllowBalanceData.Rows[index].Cells[5].Value = item.PALLET_CODE;
  202. kdgv_AllowBalanceData.Rows[index].Cells[6].Value = item.TRAY_DTL_ID;
  203. kdgv_AllowBalanceData.Rows[index].Cells[7].Value = item.MATERIEL_CODE;
  204. kdgv_AllowBalanceData.Rows[index].Cells[8].Value = item.MATERIEL_NAME;
  205. kdgv_AllowBalanceData.Rows[index].Cells[9].Value = item.MATERIEL_BARCODE;
  206. kdgv_AllowBalanceData.Rows[index].Cells[10].Value = item.MATERIEL_SPEC;
  207. kdgv_AllowBalanceData.Rows[index].Cells[11].Value = item.BATCH_NO;
  208. kdgv_AllowBalanceData.Rows[index].Cells[12].Value = item.QTY;
  209. kdgv_AllowBalanceData.Rows[index].Cells[13].Value = item.UNIT_CODE;
  210. kdgv_AllowBalanceData.Rows[index].Cells[14].Value = item.PACKAGE_CODE;
  211. kdgv_AllowBalanceData.Rows[index].Cells[15].Value = item.PRODUCT_DATE;
  212. kdgv_AllowBalanceData.Rows[index].Cells[16].Value = item.EXP_DATE;
  213. kdgv_AllowBalanceData.Rows[index].DefaultCellStyle.BackColor = Color.LightGreen;
  214. foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
  215. {
  216. string materielCode = dvr.Cells[1].Value.ToString();
  217. string batchNo = dvr.Cells[5].Value.ToString();
  218. decimal invoiceQty = Convert.ToDecimal(dvr.Cells[6].Value);
  219. decimal allowQty = dvr.Cells[9].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[9].Value);
  220. if (item.MATERIEL_CODE == materielCode && item.BATCH_NO == batchNo)
  221. {
  222. dvr.Cells[9].Value = allowQty + item.QTY;
  223. string percentage = ((allowQty + item.QTY) / invoiceQty).ToString("0.00%");
  224. dvr.Cells[10].Value = "已分配:【" + percentage + "】";
  225. if ((allowQty + item.QTY) >= invoiceQty)
  226. {
  227. dvr.Cells[9].Style.BackColor = Color.LightGreen;
  228. dvr.Cells[10].Style.BackColor = Color.LightGreen;
  229. }
  230. break;
  231. }
  232. }
  233. kdgv_AllowBalanceData.ClearSelection();
  234. }
  235. }
  236. KryptonMessageBox.Show(result.Message);
  237. }
  238. }
  239. else
  240. {
  241. AutoAllocateBalanceMsg = null;
  242. kdgv_AllowBalanceData.Columns[0].ReadOnly = false;
  243. kdgv_AllowBalanceData.Rows.Clear();
  244. foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
  245. {
  246. dvr.Cells[9].Value = null;
  247. dvr.Cells[10].Value = null;
  248. dvr.Cells[9].Style.BackColor = dvr.Cells[1].Style.BackColor;
  249. dvr.Cells[10].Style.BackColor = dvr.Cells[1].Style.BackColor;
  250. }
  251. }
  252. }
  253. /// <summary>
  254. /// 手动分配模式下,查询库存信息。
  255. /// </summary>
  256. /// <param name="sender"></param>
  257. /// <param name="e"></param>
  258. private void kbtn_Search_Click(object sender, EventArgs e)
  259. {
  260. if (kcmb_AllocateType.Text != "自动分配")
  261. {
  262. kdgv_AllowBalanceData.Columns[0].ReadOnly = false;
  263. kdgv_AllowBalanceData.Rows.Clear();
  264. var result = WmsInvoiceService.wmsOutInvoiceService.InvoiceAllovationBalanceManual(new WmsStkBalanceDtlSearchMd {
  265. MaterielMsg = ktb_MaterielMsg.Text,
  266. BatchNoMsg = ktb_BatchNoMsg.Text,
  267. RegionMsg = ((ListItem)kcmb_RegionMsg.SelectedItem).Value,
  268. BinMsg = ktb_BinMsg.Text,
  269. PalletMsg = ktb_PalletNoMsg.Text,
  270. InvoiceMd = InvoiceDataNotEdit,
  271. });
  272. if (result.Status == OperateStatus.Success)
  273. {
  274. foreach (WmsStkBalanceDtlResult item in result.Data)
  275. {
  276. int index = kdgv_AllowBalanceData.Rows.Add();
  277. kdgv_AllowBalanceData.Rows[index].Cells[0].Value = false;
  278. kdgv_AllowBalanceData.Rows[index].Cells[1].Value = index + 1;
  279. kdgv_AllowBalanceData.Rows[index].Cells[2].Value = item.BALANCE_ID;
  280. kdgv_AllowBalanceData.Rows[index].Cells[3].Value = item.TRAY_ID;
  281. kdgv_AllowBalanceData.Rows[index].Cells[4].Value = item.TRAY_CODE;
  282. kdgv_AllowBalanceData.Rows[index].Cells[5].Value = item.PALLET_CODE;
  283. kdgv_AllowBalanceData.Rows[index].Cells[6].Value = item.TRAY_DTL_ID;
  284. kdgv_AllowBalanceData.Rows[index].Cells[7].Value = item.MATERIEL_CODE;
  285. kdgv_AllowBalanceData.Rows[index].Cells[8].Value = item.MATERIEL_NAME;
  286. kdgv_AllowBalanceData.Rows[index].Cells[9].Value = item.MATERIEL_BARCODE;
  287. kdgv_AllowBalanceData.Rows[index].Cells[10].Value = item.MATERIEL_SPEC;
  288. kdgv_AllowBalanceData.Rows[index].Cells[11].Value = item.BATCH_NO;
  289. kdgv_AllowBalanceData.Rows[index].Cells[12].Value = item.QTY;
  290. kdgv_AllowBalanceData.Rows[index].Cells[13].Value = item.UNIT_CODE;
  291. kdgv_AllowBalanceData.Rows[index].Cells[14].Value = item.PACKAGE_CODE;
  292. kdgv_AllowBalanceData.Rows[index].Cells[15].Value = item.PRODUCT_DATE;
  293. kdgv_AllowBalanceData.Rows[index].Cells[16].Value = item.EXP_DATE;
  294. kdgv_AllowBalanceData.ClearSelection();
  295. }
  296. }
  297. }
  298. }
  299. /// <summary>
  300. /// 重置查询条件
  301. /// </summary>
  302. /// <param name="sender"></param>
  303. /// <param name="e"></param>
  304. private void kbtn_Reset_Click(object sender, EventArgs e)
  305. {
  306. ktb_MaterielMsg.Text = "";
  307. ktb_BatchNoMsg.Text = "";
  308. ktb_BinMsg.Text = "";
  309. ktb_PalletNoMsg.Text = "";
  310. kcmb_RegionMsg.SelectedIndex = 0;
  311. }
  312. /// <summary>
  313. /// 提交发货审核结果数据。
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. private void kbtn_Confirm_Click(object sender, EventArgs e)
  318. {
  319. int index = 0;
  320. foreach (DataGridViewRow item in kdgv_InvoiceDtlData.Rows)
  321. {
  322. index++;
  323. decimal notInvoiceDtlQty = Convert.ToInt32(item.Cells[6].Value);
  324. decimal allocateQty = Convert.ToInt32(item.Cells[9].Value);
  325. if (allocateQty < notInvoiceDtlQty)
  326. {
  327. KryptonMessageBox.Show($"发货单明细第:【{index}】行分配数量小于未发货数量。目前版本不支持部分匹配出库,后续会添加该功能!");
  328. return;
  329. }
  330. }
  331. WmsOutInvoiceCheckResult checkResult = new WmsOutInvoiceCheckResult();
  332. checkResult.IsAutoAllocateBalance = kcmb_AllocateType.Text == "自动分配";
  333. checkResult.InvoiceMdResult = InvoiceDataNotEdit;
  334. checkResult.InvoiceMdResult.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
  335. checkResult.InvoiceMdResult.UPDATE_NAME = AppConfig.UserLoginResult.UserInfo.UserName;
  336. List<WmsStkTrayDtlRowsCountResultExt1> TrayIdLst = new List<WmsStkTrayDtlRowsCountResultExt1>();
  337. foreach (DataGridViewRow item in kdgv_AllowBalanceData.Rows)
  338. {
  339. bool isCheck = Convert.ToBoolean(item.Cells[0].Value);
  340. string TrayId = item.Cells[3].Value.ToString();
  341. if (isCheck)
  342. {
  343. if (TrayIdLst.FirstOrDefault(x => x.TRAY_ID == Convert.ToInt32(TrayId)) == null)
  344. {
  345. TrayIdLst.Add(new WmsStkTrayDtlRowsCountResultExt1 { TRAY_ID = Convert.ToInt32(TrayId) });
  346. }
  347. }
  348. }
  349. if (kcmb_AllocateType.Text == "自动分配")
  350. {
  351. checkResult.TrayIdLst = AutoAllocateBalanceMsg.PalletTaskResultTask;
  352. }
  353. else
  354. {
  355. checkResult.TrayIdLst = TrayIdLst;
  356. }
  357. var result = WmsInvoiceService.wmsOutInvoiceService.SubmitInvoiceCheckResult(checkResult);
  358. if (result.Status == OperateStatus.Success)
  359. {
  360. KryptonMessageBox.Show(result.Message);
  361. frmWmsOutInvoice.RefreshFrmHost();
  362. this.Close();
  363. }
  364. else
  365. {
  366. KryptonMessageBox.Show(result.Message);
  367. }
  368. }
  369. /// <summary>
  370. /// 取消按钮事件
  371. /// 关闭发货审核窗体
  372. /// </summary>
  373. /// <param name="sender"></param>
  374. /// <param name="e"></param>
  375. private void kbtn_Cancel_Click(object sender, EventArgs e)
  376. {
  377. this.Close();
  378. }
  379. #endregion
  380. #region DataGridView相关事件
  381. private void kdgv_AllowBalanceData_CellContentClick(object sender, DataGridViewCellEventArgs e)
  382. {
  383. if (e.ColumnIndex == 0)
  384. {
  385. DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)kdgv_AllowBalanceData.CurrentCell;
  386. if (Convert.ToBoolean(checkCell.EditedFormattedValue))
  387. {
  388. kdgv_AllowBalanceData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGreen;
  389. string materielCodeOfBalance = kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[7].Value.ToString();
  390. string bacthNoOfBalance = kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[11].Value.ToString();
  391. decimal qtyOfBalance = Convert.ToDecimal(kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[12].Value);
  392. foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
  393. {
  394. string materielCode = dvr.Cells[1].Value.ToString();
  395. string batchNo = dvr.Cells[5].Value.ToString();
  396. decimal invoiceQty = Convert.ToDecimal(dvr.Cells[6].Value);
  397. decimal allowQty = dvr.Cells[9].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[9].Value);
  398. if (materielCodeOfBalance == materielCode && bacthNoOfBalance == batchNo)
  399. {
  400. dvr.Cells[9].Value = allowQty + qtyOfBalance;
  401. string percentage = ((allowQty + qtyOfBalance) / invoiceQty).ToString("0.00%");
  402. dvr.Cells[10].Value = "已分配:【" + percentage + "】";
  403. if ((allowQty + qtyOfBalance) >= invoiceQty)
  404. {
  405. dvr.Cells[9].Style.BackColor = Color.LightGreen;
  406. dvr.Cells[10].Style.BackColor = Color.LightGreen;
  407. }
  408. else
  409. {
  410. dvr.Cells[9].Style.BackColor = Color.LightYellow;
  411. dvr.Cells[10].Style.BackColor = Color.LightYellow;
  412. }
  413. break;
  414. }
  415. }
  416. }
  417. else
  418. {
  419. kdgv_AllowBalanceData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Transparent;
  420. string materielCodeOfBalance = kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[7].Value.ToString();
  421. string bacthNoOfBalance = kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[11].Value.ToString();
  422. decimal qtyOfBalance = Convert.ToDecimal(kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[12].Value);
  423. foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
  424. {
  425. string materielCode = dvr.Cells[1].Value.ToString();
  426. string batchNo = dvr.Cells[5].Value.ToString();
  427. decimal invoiceQty = Convert.ToDecimal(dvr.Cells[6].Value);
  428. decimal allowQty = dvr.Cells[9].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[9].Value);
  429. if (materielCodeOfBalance == materielCode && bacthNoOfBalance == batchNo)
  430. {
  431. if ((allowQty - qtyOfBalance) <= 0)
  432. {
  433. dvr.Cells[9].Value = null;
  434. dvr.Cells[10].Value = null;
  435. dvr.Cells[9].Style.BackColor = Color.Transparent;
  436. dvr.Cells[10].Style.BackColor = Color.Transparent;
  437. break;
  438. }
  439. else
  440. {
  441. dvr.Cells[9].Value = allowQty - qtyOfBalance;
  442. string percentage = ((allowQty - qtyOfBalance) / invoiceQty).ToString("0.00%");
  443. dvr.Cells[10].Value = "已分配:【" + percentage + "】";
  444. if ((allowQty - qtyOfBalance) >= invoiceQty)
  445. {
  446. dvr.Cells[9].Style.BackColor = Color.LightGreen;
  447. dvr.Cells[10].Style.BackColor = Color.LightGreen;
  448. }
  449. else
  450. {
  451. dvr.Cells[9].Style.BackColor = Color.LightYellow;
  452. dvr.Cells[10].Style.BackColor = Color.LightYellow;
  453. }
  454. break;
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }
  461. #endregion
  462. #region 鼠标右键单击事件
  463. #endregion
  464. }
  465. }