frmUsePlanYBNew.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. using com.hnshituo.pur.vo;
  2. using CoreFS.CA06;
  3. using Infragistics.Win.UltraWinEditors;
  4. using Infragistics.Win.UltraWinGrid;
  5. using Pur.Entity.configureEntity;
  6. using Pur.Entity.require_planEntiy;
  7. using Pur.require_plan;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Windows.Forms;
  17. using Pur.PublicTools;
  18. using Pur.configure;
  19. using Pur.Pop_upWindow;
  20. using Pur.Entity;
  21. using Core.Mes.Client.Comm.Control;
  22. using Core.Mes.Client.Comm.Tool;
  23. namespace Pur.ck
  24. {
  25. public partial class frmUsePlanYBNew: FrmPmsBase
  26. {
  27. DataTable Qdt = null;//库区
  28. private string req_org_id = "";
  29. public frmUsePlanYBNew()
  30. {
  31. InitializeComponent();
  32. this.IsLoadUserView = true;
  33. }
  34. private void frmUsePlanYBNew_Load(object sender, EventArgs e)
  35. {
  36. txt_status.SelectedIndex = 1;
  37. ck_ctime.Checked = true;
  38. txtCreateTimeStart.Value = DateTime.Now.AddMonths(-1);
  39. txtCreateTimeEnd.Value = DateTime.Now.AddDays(2);
  40. GridHelper.SetColumnsActive(ultraGrid1.DisplayLayout.Bands[0]);
  41. GridHelper.SetColumnsActive(ultraGrid2.DisplayLayout.Bands[0]);
  42. GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], new String[] { "Check", "OUTNUM", "OUTNUM1" });
  43. GridHelper.SetExcludeColumnsActive(ultraGrid4.DisplayLayout.Bands[0], new String[] { "Check" });
  44. do_outBill.Enabled = true;
  45. cancel_outBill.Enabled = false;
  46. }
  47. #region toolbar工具栏
  48. public override void ToolBar_Click(object sender, string ToolbarKey)
  49. {
  50. switch (ToolbarKey)
  51. {
  52. case "Query":
  53. getUserPlanM("");
  54. break;
  55. case "doReceive":
  56. receiveUserPlanM();
  57. break;
  58. case "dofinish":
  59. finishUserPlanM();
  60. break;
  61. case "doReturn":
  62. returnUserPlanM();
  63. break;
  64. case "doExcel":
  65. doExcel();
  66. break;
  67. case "close":
  68. CloPUR_SUPP();
  69. break;
  70. }
  71. }
  72. /// 导出Excel
  73. /// </summary>
  74. private void doExcel()
  75. {
  76. try
  77. {
  78. this.Cursor = Cursors.Default;
  79. if (ultraGrid1.ActiveRow == null)
  80. {
  81. MessageUtil.ShowTips("请选择需导出明细的领用单头!");
  82. return;
  83. }
  84. //获取导出的采购计划行表
  85. ArrayList alUltraGrid = new ArrayList();
  86. alUltraGrid.Add(ultraGrid2);
  87. ArrayList alSheeft = new ArrayList();
  88. alSheeft.Add("物料明细");
  89. if (ultraGrid2.Rows.Count > 0)
  90. {
  91. GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "领用单[" + ultraGrid1.ActiveRow.GetCellValue("mrId") + "]明细表");//导出excel
  92. }
  93. else
  94. {
  95. MessageUtil.ShowTips("领用单:" + ultraGrid1.ActiveRow.GetCellValue("mrId") + "无可导出明细!");
  96. }
  97. }
  98. catch (Exception e)
  99. {
  100. MessageUtil.ShowTips("导出失败" + e.Message);
  101. }
  102. finally
  103. {
  104. this.Cursor = Cursors.Default;
  105. }
  106. }
  107. /// <summary>
  108. /// 退回
  109. /// </summary>
  110. private void returnUserPlanM()
  111. {
  112. UltraGridRow uge = ultraGrid1.ActiveRow;
  113. if (uge == null)
  114. return;
  115. String strMrId = uge.Cells["MRID"].Value.ToString();
  116. if (String.IsNullOrEmpty(strMrId))
  117. {
  118. return;
  119. }
  120. if (testStatusM(strMrId, 2) == false)
  121. {
  122. return;
  123. }
  124. String strReason = "";
  125. frmPopReason frm = new frmPopReason(this.ob);
  126. frm.ShowDialog();
  127. if (frm.Tips == "1")
  128. {
  129. strReason = frm.Reason;
  130. }
  131. else
  132. {
  133. return;
  134. }
  135. UsePlanM um = new UsePlanM();
  136. um.MrId = strMrId;
  137. um.Status = "9";
  138. um.Quitreson = "[退回] "+strReason;
  139. um.UpdateName = UserInfo.GetUserName();
  140. um.UpdateUserid = UserInfo.GetUserID();
  141. um.UpdateTime = DateTime.Now;
  142. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um });
  143. if (crt.Resultcode != 0)
  144. {
  145. MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
  146. return;
  147. }
  148. MessageUtil.ShowTips("操作成功");
  149. getUserPlanM(strMrId);
  150. }
  151. /// <summary>
  152. /// 查询领用单主表
  153. /// </summary>
  154. private void getUserPlanM(String strMrId)
  155. {
  156. LYM.Clear();
  157. LYD.Clear();
  158. stockPos.Clear();
  159. outStockDt.Clear();
  160. UsePlanM pupe = new UsePlanM();
  161. pupe.DeleteUserid = txt_status.Value == null ? "" : txt_status.Value.ToString().Trim();
  162. pupe.MrId = ultraTextEditor1.Text.Trim();
  163. pupe.ReqOrgId = req_org_id;
  164. if (ck_ctime.Checked == true)
  165. {
  166. if (txtCreateTimeStart.Text != "")
  167. {
  168. pupe.CreateTime = Convert.ToDateTime(txtCreateTimeStart.Value);
  169. }
  170. if (txtCreateTimeEnd.Text != "")
  171. {
  172. pupe.DeleteTime = Convert.ToDateTime(txtCreateTimeEnd.Value);
  173. }
  174. }
  175. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.UsePlanMService", "find_UsePlanM", new object[] { pupe });
  176. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  177. GridHelper.RefreshAndAutoSize(ultraGrid1);
  178. if (!String.IsNullOrEmpty(strMrId))
  179. {
  180. publicPms.doActiveSelRow(ultraGrid1, "mrId", strMrId);
  181. }
  182. }
  183. /// <summary>
  184. /// 完成领用
  185. /// </summary>
  186. private void finishUserPlanM()
  187. {
  188. UltraGridRow uge = ultraGrid1.ActiveRow;
  189. if (uge == null)
  190. return;
  191. String strMrId = uge.Cells["MRID"].Value.ToString();
  192. if (String.IsNullOrEmpty(strMrId))
  193. {
  194. return;
  195. }
  196. UsePlanM um = new UsePlanM();
  197. um.MrId = strMrId;
  198. um.Status = "5";
  199. um.UpdateName = UserInfo.GetUserName();
  200. um.UpdateUserid = UserInfo.GetUserID();
  201. um.UpdateTime = DateTime.Now;
  202. if(testStatusM(strMrId,1)==false)
  203. {
  204. return;
  205. }
  206. if (MessageUtil.ShowYesNoAndQuestion("确定完成该领用单出库:" + strMrId + "?") != DialogResult.Yes)
  207. {
  208. return;
  209. }
  210. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um });
  211. if (crt.Resultcode != 0)
  212. {
  213. MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
  214. return;
  215. }
  216. MessageUtil.ShowTips("操作成功");
  217. getUserPlanM(strMrId);
  218. }
  219. /// <summary>
  220. /// 确认领用单
  221. /// </summary>
  222. private void receiveUserPlanM()
  223. {
  224. throw new NotImplementedException();
  225. }
  226. /// <summary>
  227. /// 关闭
  228. /// </summary>
  229. private void CloPUR_SUPP()
  230. {
  231. this.Close();
  232. }
  233. #endregion
  234. #region 库存操作
  235. /// <summary>
  236. /// 重新匹配
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void query_ckPos_Click(object sender, EventArgs e)
  241. {
  242. }
  243. /// <summary>
  244. /// 出库操作
  245. /// </summary>
  246. /// <param name="sender"></param>
  247. /// <param name="e"></param>
  248. private void do_outBill_Click(object sender, EventArgs e)
  249. {
  250. setOutCkBill();
  251. }
  252. /// <summary>
  253. /// 生成出库单
  254. /// </summary>
  255. private void setOutCkBill()
  256. {
  257. UltraGrid grid = new UltraGrid();
  258. String isNor = "1";//是否为有主需求出库
  259. if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[0])
  260. {
  261. grid = ultraGrid3;
  262. isNor = "1";
  263. }
  264. else if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[1])
  265. {
  266. grid = ultraGrid5;
  267. isNor = "0";
  268. }
  269. else
  270. {
  271. MessageUtil.ShowTips("请选择可出库数据");
  272. return;
  273. }
  274. grid.UpdateData();
  275. if (ultraGrid2.ActiveRow == null)
  276. {
  277. MessageUtil.ShowTips("请选择领用单行进行操作");
  278. return;
  279. }
  280. String strUseLineId = ultraGrid2.ActiveRow.Cells["MrLineId"].Value.ToString().Trim();
  281. if (String.IsNullOrEmpty(strUseLineId))
  282. {
  283. MessageUtil.ShowTips("请选择领用单行号为空");
  284. return;
  285. }
  286. CkOutBill cob = new CkOutBill();
  287. UsePlanD pupe = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strUseLineId });
  288. if (pupe == null)
  289. {
  290. MessageUtil.ShowTips("未发现领用单行:" + strUseLineId + " 信息记录");
  291. return;
  292. }
  293. if (pupe.Validflag != "1")
  294. {
  295. MessageUtil.ShowTips("领用单行:" + strUseLineId + " 信息记录已经作废");
  296. return;
  297. }
  298. UsePlanM pm = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { pupe.MrId });
  299. if (pm == null)
  300. {
  301. MessageUtil.ShowTips("未发现领料单头:" + pupe.MrId + "信息记录");
  302. return;
  303. }
  304. if (pm.Validflag != "1")
  305. {
  306. MessageUtil.ShowTips("领料单头:" + pupe.MrId + "信息记录可能已作废");
  307. return;
  308. }
  309. if (pm.Status != "2" && pm.Status != "3")
  310. {
  311. MessageUtil.ShowTips("领料单头:" + pupe.MrId + "当前状态无法执行出库");
  312. return;
  313. }
  314. cob = EntityHelper.CopyEntity<CkOutBill>(pupe);
  315. cob.DeliverAddress = pm.DeliveryLocationCode;
  316. cob.Status = "1";
  317. if (isNor == "1")
  318. {
  319. cob.OutstockType = "4";//非JIT有主
  320. }
  321. else
  322. {
  323. cob.OutstockType = "6";//非JIT无主
  324. }
  325. cob.RefeId = strUseLineId;
  326. cob.CreateName = UserInfo.GetUserName();
  327. cob.CreateUserid = UserInfo.GetUserID();
  328. cob.CreateTime = DateTime.Now;
  329. cob.Validflag = "1";
  330. cob.ReleaseQty = 0;
  331. double bQTYUSE = 0;
  332. ArrayList al = new ArrayList();
  333. for (int i = 0; i < grid.Rows.Count; i++)
  334. {
  335. UltraGridRow row = grid.Rows[i];
  336. if (Convert.ToBoolean(row.GetCellValue("Check")) == true)
  337. {
  338. double b_OutNum = 0;//出库量
  339. if (row.GetCellValue("itemUom").ToString() == "基吨")
  340. {
  341. double.TryParse(grid.Rows[i].Cells["OUTNUM1"].Value.ToString(), out b_OutNum);//铁合金出库存
  342. if (b_OutNum <= 0)
  343. {
  344. MessageUtil.ShowTips("储位【" + row.Cells["INVPOS"].Value.ToString() + "】的出库量必须>0");
  345. return;
  346. }
  347. }
  348. else
  349. {
  350. double.TryParse(grid.Rows[i].Cells["OUTNUM"].Value.ToString(), out b_OutNum);//非铁合金出采购
  351. if (b_OutNum <= 0)
  352. {
  353. MessageUtil.ShowTips("储位【" + row.Cells["INVPOS"].Value.ToString() + "】的出库量必须>0");
  354. return;
  355. }
  356. }
  357. CkOutbillPosition cobp = new CkOutbillPosition();
  358. bQTYUSE += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);
  359. cobp.OutNum = Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);//出库量
  360. //cob.ReleaseQty += b_OutNum;
  361. //cobp.Id = ultraGrid1.Rows[i].Cells["INVPOSID"].Value.ToString();
  362. //cobp.InvId = ultraGrid5.Rows[i].Cells["InvId"].Value.ToString();
  363. cobp.InvPhysic = grid.Rows[i].Cells["INVPHYSIC"].Value.ToString();
  364. if (cobp.InvPhysic != pm.InvPhysic)
  365. {
  366. MessageUtil.ShowTips("请选择仓库:" + pm.InvPhysic + " 物料进行出库");
  367. return;
  368. }
  369. cobp.InvPosId = grid.Rows[i].Cells["InvPosId"].Value.ToString();
  370. cobp.InvId = grid.Rows[i].Cells["InvId"].Value.ToString();
  371. if (String.IsNullOrEmpty(cobp.InvId))
  372. {
  373. MessageUtil.ShowTips("选择的出库信息的送货单行不能为空");
  374. return;
  375. }
  376. al.Add(cobp);
  377. }
  378. }
  379. if (al.Count == 0)
  380. {
  381. MessageUtil.ShowTips("至少有一个库位出库量>0");
  382. return;
  383. }
  384. cob.ReleaseQty = Math.Round(bQTYUSE, 4, MidpointRounding.AwayFromZero);
  385. double canUse1=Math.Round((double)pupe.Qty-(double)pupe.QtyPur,4);
  386. if (cob.ReleaseQty > canUse1)
  387. {
  388. MessageUtil.ShowTips("总出库数量:" + cob.ReleaseQty + "已经大于该领用单行可编制量:" + canUse1);
  389. return;
  390. }
  391. if (MessageUtil.ShowYesNoAndQuestion("确定对领用单行:" + strUseLineId + " 进行出库(备货)操作?") != DialogResult.Yes)
  392. {
  393. return;
  394. }
  395. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutBillService", "doInsert_UpdateNew", new object[] {cob, al,isNor});
  396. if (crt.Resultcode != 0)
  397. {
  398. MessageUtil.ShowTips("出库单生成失败!" + crt.Resultmsg);
  399. return;
  400. }
  401. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("出库成功!单号:" + crt.Resultmsg);
  402. getUserPlanM(pupe.MrId);
  403. publicPms.doActiveSelRow(ultraGrid2, "MrLineId", strUseLineId);
  404. }
  405. /// <summary>
  406. /// 取消出库操作
  407. /// </summary>
  408. /// <param name="sender"></param>
  409. /// <param name="e"></param>
  410. private void cancel_outBill_Click(object sender, EventArgs e)
  411. {
  412. ultraGrid3.UpdateData();
  413. if (ultraGrid2.ActiveRow == null)
  414. {
  415. MessageUtil.ShowTips("请选择领用单行进行操作");
  416. return;
  417. }
  418. String strUseLineId = ultraGrid2.ActiveRow.Cells["MrLineId"].Value.ToString().Trim();
  419. if (String.IsNullOrEmpty(strUseLineId))
  420. {
  421. MessageUtil.ShowTips("请选择领用单行号为空");
  422. return;
  423. }
  424. ArrayList al = new ArrayList();
  425. for (int i = 0; i < ultraGrid4.Rows.Count; i++)
  426. {
  427. UltraGridRow row = ultraGrid4.Rows[i];
  428. if (Convert.ToBoolean(row.GetCellValue("Check")) == true)
  429. {
  430. CkOutbillPosition cobp = new CkOutbillPosition();
  431. cobp.OutStockNo = row.Cells["outStockno"].Value.ToString();
  432. cobp.Id = row.Cells["id"].Value.ToString();
  433. if (String.IsNullOrEmpty(cobp.Id))
  434. {
  435. MessageUtil.ShowTips("选择的撤销的出库单行行号不能为空");
  436. return;
  437. }
  438. cobp.DeleteName = UserInfo.GetUserName();
  439. cobp.DeleteUserid = UserInfo.GetUserID();
  440. cobp.DeleteTime= DateTime.Now;
  441. al.Add(cobp);
  442. }
  443. }
  444. if (al.Count == 0)
  445. {
  446. MessageUtil.ShowTips("至少有一个出库记录");
  447. return;
  448. }
  449. if (MessageUtil.ShowYesNoAndQuestion("确定对领用单行:" + strUseLineId + " 进行撤销出库(备货)操作?") != DialogResult.Yes)
  450. {
  451. return;
  452. }
  453. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutBillService", "doCancel_OutStock", new object[] { strUseLineId, al });
  454. if (crt.Resultcode != 0)
  455. {
  456. MessageUtil.ShowTips("撤销出库!" + crt.Resultmsg);
  457. return;
  458. }
  459. getUserPlanM(strUseLineId);
  460. }
  461. #endregion
  462. #region 公共函数
  463. /// <summary>
  464. /// 查询领用单行表
  465. /// </summary>
  466. private void getUserPlanD()
  467. {
  468. LYD.Clear();
  469. stockPos.Clear();
  470. outStockDt.Clear();
  471. UltraGridRow uge = ultraGrid1.ActiveRow;
  472. if (uge == null)
  473. return;
  474. UsePlanD pupe = new UsePlanD();
  475. pupe.MrId = uge.Cells["MRID"].Value.ToString();
  476. if (String.IsNullOrEmpty(pupe.MrId))
  477. {
  478. return;
  479. }
  480. pupe.Validflag = "1";
  481. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.UsePlanDService", "getUsePlanD", new object[] { pupe });
  482. foreach (DataRow row in dt.Rows)
  483. {
  484. if (row["ITEMUOM"].ToString() == "基吨")
  485. {
  486. row["ITEMUOM"] = "吨";
  487. }
  488. }
  489. GridHelper.CopyDataToDatatable(dt, dataTable2, true);
  490. GridHelper.RefreshAndAutoSize(ultraGrid2);
  491. }
  492. /// <summary>
  493. /// 查询有主出库库位
  494. /// </summary>
  495. private void getInvPhysicNor()
  496. {
  497. stockPos.Clear();
  498. UltraGridRow ugr = ultraGrid2.ActiveRow;
  499. if (ugr == null)
  500. {
  501. MessageUtil.ShowTips("请选择需出库的物料");
  502. return;
  503. }
  504. String strMrLineId=ugr.Cells["MRLINEID"].Value.ToString().Trim();
  505. if ( String.IsNullOrEmpty(strMrLineId))
  506. {
  507. MessageUtil.ShowTips("该领用单行号为空");
  508. return;
  509. }
  510. UsePlanD ud = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId });
  511. UsePlanM um = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { ud.MrId });
  512. if (String.IsNullOrEmpty(ud.PurLineId))
  513. {
  514. MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联采购计划号,无法查询库存信息");
  515. return;
  516. }
  517. if (String.IsNullOrEmpty(ud.PurRequireLineId))
  518. {
  519. MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联需求接收号,无法查询库存占用信息");
  520. return;
  521. }
  522. PurCkStoragePosEntity ckp = new PurCkStoragePosEntity();
  523. ckp.UpdateName = ud.PurLineId;
  524. ckp.DeleteName = ud.ReceiveId;
  525. ckp.InvPhysic = um.InvPhysic;
  526. ckp.UpdateUserid = "nor";//查询有主需求
  527. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.ck.service.CkStoragePosService", "getCkStoragePosUse", new object[] { ckp });
  528. if (dt == null || dt.Rows.Count <= 0)
  529. {
  530. ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[1];
  531. }
  532. else
  533. {
  534. ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[0];
  535. }
  536. GridHelper.CopyDataToDatatable(ref dt, ref dataTable3, true);
  537. double canOutNum = (double)ud.Qty - (ud.QtyPur == null ? 0 : (double)ud.QtyPur);
  538. double canOutNum1 = (ud.QtyUnnormal == null ? 0 : (double)ud.QtyUnnormal) - (ud.QtyUnnormalPur == null ? 0 : (double)ud.QtyUnnormalPur);
  539. if (canOutNum1 > 0)
  540. {
  541. canOutNum = canOutNum - canOutNum1;
  542. }
  543. double tempCanUseQty = canOutNum;
  544. Hashtable table = new Hashtable();
  545. double norQtyNor = 0;
  546. double norQtyNorWeight = 0;
  547. foreach (UltraGridRow row in ultraGrid3.Rows)
  548. {
  549. String strInvId = row.GetCellValue("invId").ToString().Trim();
  550. double.TryParse(row.GetCellValue("qtyNor").ToString(), out norQtyNor);
  551. double.TryParse(row.GetCellValue("qtyNorWeight").ToString(), out norQtyNorWeight);
  552. double UseQtyInInv = 0;
  553. double createQty=0;
  554. if (table.ContainsKey(strInvId))
  555. {
  556. UseQtyInInv = (double)table[strInvId];
  557. }
  558. if (String.IsNullOrEmpty(strInvId))
  559. {
  560. continue;
  561. }
  562. if (row.GetCellValue("itemUom").ToString() == "基吨")
  563. {
  564. //row.Cells["itemUom"].Value = "吨";
  565. double needQty = 0;
  566. double dbItemUomConefficient = 1;
  567. double.TryParse(row.GetCellValue("INVQTYWEIGHT").ToString(), out needQty);//库存需出库量
  568. double.TryParse(row.GetCellValue("itemUomConefficient").ToString(), out dbItemUomConefficient);
  569. if (tempCanUseQty > 0 && needQty > 0)
  570. {
  571. if (needQty >= tempCanUseQty)
  572. {
  573. if (tempCanUseQty <= norQtyNorWeight - UseQtyInInv)
  574. {
  575. createQty=tempCanUseQty;
  576. row.Cells["OUTNUM1"].Value =createQty ;//库存出库量
  577. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  578. tempCanUseQty = 0;
  579. row.Cells["Check"].Value = true;
  580. }
  581. else
  582. {
  583. createQty = (norQtyNorWeight - UseQtyInInv) < 0 ? 0 : (norQtyNorWeight - UseQtyInInv);
  584. if(createQty>0)
  585. {
  586. row.Cells["OUTNUM1"].Value = createQty;//库存出库量
  587. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  588. tempCanUseQty = tempCanUseQty - createQty;
  589. row.Cells["Check"].Value = true;
  590. }
  591. }
  592. if (table.ContainsKey(strInvId))
  593. {
  594. table[strInvId] = UseQtyInInv + createQty;
  595. }
  596. }
  597. else//需要的小
  598. {
  599. if (needQty <= norQtyNorWeight - UseQtyInInv)
  600. {
  601. createQty = needQty;
  602. row.Cells["OUTNUM1"].Value = createQty;//库存出库量
  603. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  604. tempCanUseQty = tempCanUseQty - createQty;
  605. row.Cells["Check"].Value = true;
  606. }
  607. else
  608. {
  609. createQty = (norQtyNorWeight - UseQtyInInv) < 0 ? 0 : (norQtyNorWeight - UseQtyInInv);
  610. if (createQty > 0)
  611. {
  612. row.Cells["OUTNUM1"].Value = createQty;//库存出库量
  613. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  614. tempCanUseQty = tempCanUseQty - createQty;
  615. row.Cells["Check"].Value = true;
  616. }
  617. }
  618. if (table.ContainsKey(strInvId))
  619. {
  620. table[strInvId] = UseQtyInInv + createQty;
  621. }
  622. }
  623. }
  624. }
  625. else {
  626. double needQty = 0;
  627. double dbItemUomConefficient = 1;
  628. double.TryParse(row.GetCellValue("invqty").ToString(), out needQty);//采购需出库量
  629. double.TryParse(row.GetCellValue("itemUomConefficient").ToString(), out dbItemUomConefficient);
  630. if (tempCanUseQty > 0 && needQty > 0)
  631. {
  632. if (needQty >= tempCanUseQty)
  633. {
  634. if (tempCanUseQty <= norQtyNor - UseQtyInInv)
  635. {
  636. createQty = tempCanUseQty;
  637. row.Cells["OUTNUM"].Value = createQty;
  638. row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
  639. tempCanUseQty = 0;
  640. row.Cells["Check"].Value = true;
  641. }
  642. else
  643. {
  644. createQty = (norQtyNor - UseQtyInInv) < 0 ? 0 : (norQtyNor - UseQtyInInv);
  645. if (createQty > 0)
  646. {
  647. row.Cells["OUTNUM"].Value = createQty;//库存出库量
  648. row.Cells["OUTNUM1"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  649. tempCanUseQty = tempCanUseQty - createQty;
  650. row.Cells["Check"].Value = true;
  651. }
  652. }
  653. if (table.ContainsKey(strInvId))
  654. {
  655. table[strInvId] = UseQtyInInv + createQty;
  656. }
  657. }
  658. else
  659. {
  660. if (needQty <= norQtyNor - UseQtyInInv)
  661. {
  662. createQty = needQty;
  663. row.Cells["OUTNUM"].Value = needQty;
  664. row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
  665. tempCanUseQty = tempCanUseQty - createQty;
  666. row.Cells["Check"].Value = true;
  667. }
  668. else
  669. {
  670. createQty = (norQtyNor - UseQtyInInv) < 0 ? 0 : (norQtyNor - UseQtyInInv);
  671. if (createQty > 0)
  672. {
  673. row.Cells["OUTNUM1"].Value = createQty;//库存出库量
  674. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  675. tempCanUseQty = tempCanUseQty - createQty;
  676. row.Cells["Check"].Value = true;
  677. }
  678. }
  679. if (table.ContainsKey(strInvId))
  680. {
  681. table[strInvId] = UseQtyInInv + createQty;
  682. }
  683. }
  684. }
  685. }
  686. }
  687. GridHelper.RefreshAndAutoSize(ultraGrid3);
  688. }
  689. /// <summary>
  690. /// 查询无主出库库位
  691. /// </summary>
  692. private void getInvPhysicUnnor()
  693. {
  694. stockPosUnnor.Clear();
  695. UltraGridRow ugr = ultraGrid2.ActiveRow;
  696. if (ugr == null)
  697. {
  698. MessageUtil.ShowTips("请选择需出库的物料");
  699. return;
  700. }
  701. String strMrLineId = ugr.Cells["MRLINEID"].Value.ToString().Trim();
  702. if (String.IsNullOrEmpty(strMrLineId))
  703. {
  704. MessageUtil.ShowTips("该领用单行号为空");
  705. return;
  706. }
  707. UsePlanD ud = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId });
  708. UsePlanM um = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { ud.MrId });
  709. if (String.IsNullOrEmpty(ud.PurLineId))
  710. {
  711. MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联采购计划号,无法查询库存信息");
  712. return;
  713. }
  714. if (String.IsNullOrEmpty(ud.PurRequireLineId))
  715. {
  716. MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联需求接收号,无法查询库存占用信息");
  717. return;
  718. }
  719. PurCkStoragePosEntity ckp = new PurCkStoragePosEntity();
  720. ckp.UpdateName = ud.PurLineId;
  721. ckp.DeleteName = ud.ReceiveId;
  722. ckp.InvPhysic = um.InvPhysic;
  723. ckp.UpdateUserid = "unNor";//查询有主需求
  724. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.ck.service.CkStoragePosService", "getCkStoragePosUse", new object[] { ckp });
  725. GridHelper.CopyDataToDatatable(ref dt, ref dataTable5, true);
  726. double canOutNum = (ud.QtyUnnormal == null ? 0 : (double)ud.QtyUnnormal) - (ud.QtyUnnormalPur == null ? 0 : (double)ud.QtyUnnormalPur);
  727. canOutNum = canOutNum < 0 ? 0 : canOutNum;
  728. double tempCanUseQty = canOutNum;
  729. Hashtable table = new Hashtable();
  730. double unnorQtyNor = 0;
  731. double unnorQtyNorWeight = 0;
  732. foreach (UltraGridRow row in ultraGrid5.Rows)
  733. {
  734. String strInvId = row.GetCellValue("invId").ToString().Trim();
  735. double.TryParse(row.GetCellValue("qtyUnnor").ToString(), out unnorQtyNor);
  736. double.TryParse(row.GetCellValue("qtyUnnorWeight").ToString(), out unnorQtyNorWeight);
  737. double UseQtyInInv = 0;
  738. double createQty = 0;
  739. if (table.ContainsKey(strInvId))
  740. {
  741. UseQtyInInv = (double)table[strInvId];
  742. }
  743. if (row.GetCellValue("itemUom").ToString() == "基吨")
  744. {
  745. //row.Cells["itemUom"].Value = "吨";
  746. double needQty = 0;
  747. double dbItemUomConefficient = 1;
  748. double.TryParse(row.GetCellValue("INVQTYWEIGHT").ToString(), out needQty);//库存需出库量
  749. double.TryParse(row.GetCellValue("itemUomConefficient").ToString(), out dbItemUomConefficient);
  750. if (tempCanUseQty > 0 && needQty > 0)
  751. {
  752. if (needQty >= tempCanUseQty)
  753. {
  754. if (tempCanUseQty <= unnorQtyNorWeight - UseQtyInInv)
  755. {
  756. createQty = tempCanUseQty;
  757. row.Cells["OUTNUM1"].Value = createQty;//库存出库量
  758. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  759. tempCanUseQty = 0;
  760. row.Cells["Check"].Value = true;
  761. }
  762. else
  763. {
  764. createQty = (unnorQtyNorWeight - UseQtyInInv) < 0 ? 0 : (unnorQtyNorWeight - UseQtyInInv);
  765. if (createQty > 0)
  766. {
  767. row.Cells["OUTNUM1"].Value = createQty;//库存出库量
  768. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  769. tempCanUseQty = tempCanUseQty - createQty;
  770. row.Cells["Check"].Value = true;
  771. }
  772. }
  773. if (table.ContainsKey(strInvId))
  774. {
  775. table[strInvId] = UseQtyInInv + createQty;
  776. }
  777. }
  778. else
  779. {
  780. if (needQty <= unnorQtyNorWeight - UseQtyInInv)
  781. {
  782. createQty = needQty;
  783. row.Cells["OUTNUM1"].Value = createQty;//库存出库量
  784. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  785. tempCanUseQty = tempCanUseQty - createQty;
  786. row.Cells["Check"].Value = true;
  787. }
  788. else
  789. {
  790. createQty = (unnorQtyNorWeight - UseQtyInInv) < 0 ? 0 : (unnorQtyNorWeight - UseQtyInInv);
  791. if (createQty > 0)
  792. {
  793. row.Cells["OUTNUM1"].Value = createQty;//库存出库量
  794. row.Cells["OUTNUM"].Value = Math.Round(createQty * dbItemUomConefficient, 4);//采购出库量
  795. tempCanUseQty = tempCanUseQty - createQty;
  796. row.Cells["Check"].Value = true;
  797. }
  798. }
  799. if (table.ContainsKey(strInvId))
  800. {
  801. table[strInvId] = UseQtyInInv + createQty;
  802. }
  803. }
  804. }
  805. }
  806. else
  807. {
  808. double needQty = 0;
  809. double dbItemUomConefficient = 1;
  810. double.TryParse(row.GetCellValue("invqty").ToString(), out needQty);//采购需出库量
  811. double.TryParse(row.GetCellValue("itemUomConefficient").ToString(), out dbItemUomConefficient);
  812. if (tempCanUseQty > 0 && needQty > 0)
  813. {
  814. if (needQty >= tempCanUseQty)
  815. {
  816. if (tempCanUseQty <= unnorQtyNor - UseQtyInInv)
  817. {
  818. createQty = tempCanUseQty;
  819. row.Cells["OUTNUM"].Value = createQty;
  820. row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
  821. tempCanUseQty = 0;
  822. row.Cells["Check"].Value = true;
  823. }
  824. else
  825. {
  826. createQty = (unnorQtyNor - UseQtyInInv) < 0 ? 0 : (unnorQtyNor - UseQtyInInv);
  827. if (createQty > 0)
  828. {
  829. row.Cells["OUTNUM"].Value = createQty;
  830. row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
  831. tempCanUseQty = tempCanUseQty - createQty;
  832. row.Cells["Check"].Value = true;
  833. }
  834. }
  835. if (table.ContainsKey(strInvId))
  836. {
  837. table[strInvId] = UseQtyInInv + createQty;
  838. }
  839. }
  840. else
  841. {
  842. if (needQty <= unnorQtyNor - UseQtyInInv)
  843. {
  844. createQty = needQty;
  845. row.Cells["OUTNUM"].Value = createQty;
  846. row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
  847. tempCanUseQty = tempCanUseQty - createQty;
  848. row.Cells["Check"].Value = true;
  849. }
  850. else
  851. {
  852. createQty = (unnorQtyNor - UseQtyInInv) < 0 ? 0 : (unnorQtyNor - UseQtyInInv);
  853. if (createQty > 0)
  854. {
  855. row.Cells["OUTNUM"].Value = createQty;
  856. row.Cells["OUTNUM1"].Value = Math.Round(createQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
  857. tempCanUseQty = tempCanUseQty - createQty;
  858. row.Cells["Check"].Value = true;
  859. }
  860. }
  861. if (table.ContainsKey(strInvId))
  862. {
  863. table[strInvId] = UseQtyInInv + createQty;
  864. }
  865. }
  866. }
  867. }
  868. }
  869. GridHelper.RefreshAndAutoSize(ultraGrid5);
  870. }
  871. private void getOutBillPos()
  872. {
  873. try
  874. {
  875. outStockDt.Clear();
  876. UltraGridRow ugr = ultraGrid2.ActiveRow;
  877. if (ugr == null)
  878. {
  879. MessageUtil.ShowTips("请选择需出库的物料");
  880. return;
  881. }
  882. String strMrLineId = ugr.Cells["MRLINEID"].Value.ToString().Trim();
  883. if (String.IsNullOrEmpty(strMrLineId))
  884. {
  885. MessageUtil.ShowTips("该领用单行号为空");
  886. return;
  887. }
  888. UsePlanD ud = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId });
  889. UsePlanM um = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { ud.MrId });
  890. if (String.IsNullOrEmpty(ud.PurLineId))
  891. {
  892. MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联采购计划号,无法查询库存信息");
  893. return;
  894. }
  895. CkOutbillPosition cp = new CkOutbillPosition();
  896. cp.UpdateName = strMrLineId;
  897. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.ck.service.CkOutbillPositionService", "doQueryCkOutbillPosition", new object[] { cp });
  898. if (dt != null && dt.Rows.Count >= 1)
  899. {
  900. GridHelper.CopyDataToDatatable(ref dt, ref dataTable4, true);
  901. GridHelper.RefreshAndAutoSize(ultraGrid4);
  902. }
  903. }
  904. catch (Exception ex)
  905. {
  906. MessageBox.Show("操作失败:" + ex.Message, "提示");
  907. }
  908. }
  909. /// <summary>
  910. /// 校验状态
  911. /// </summary>
  912. /// <param name="strMrId"></param>
  913. /// <returns></returns>
  914. private bool testStatusM(string strMrId, int i)
  915. {
  916. UsePlanM up = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { strMrId });
  917. if (up == null)
  918. {
  919. MessageUtil.ShowTips("未发现领料单头:" + strMrId + "信息记录");
  920. return false;
  921. }
  922. if (up.Validflag != "1")
  923. {
  924. MessageUtil.ShowTips("领料单头:" + strMrId + "信息记录可能已作废");
  925. return false;
  926. }
  927. //完成领用
  928. if (i == 1)
  929. {
  930. if (up.Status == "2" || up.Status == "1" || up.Status=="9")
  931. {
  932. MessageUtil.ShowTips("还未备货,无法确认出库");
  933. return false;
  934. }
  935. else if (up.Status == "5" || up.Status == "6")
  936. {
  937. MessageUtil.ShowTips("已出库,无需重复操作");
  938. return false;
  939. }
  940. else if (up.Status == "3")
  941. {
  942. if (MessageUtil.ShowYesNoAndQuestion("还未全部备货,确定执行出库?") != DialogResult.Yes)
  943. {
  944. return false;
  945. }
  946. }
  947. }
  948. else if (i == 2)
  949. {
  950. if (up.Status!= "2")
  951. {
  952. MessageUtil.ShowTips("不在待确认状态,无法退回!若有出库(备货),请先取消出库(备货)!");
  953. return false;
  954. }
  955. }
  956. else
  957. {
  958. MessageUtil.ShowTips("参数异常");
  959. }
  960. return true;
  961. }
  962. #endregion
  963. #region 界面事件
  964. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  965. {
  966. getUserPlanD();
  967. }
  968. /// <summary>
  969. /// 填写出库量
  970. /// </summary>
  971. /// <param name="sender"></param>
  972. /// <param name="e"></param>
  973. private void ultraGrid5_CellChange(object sender, CellEventArgs e)
  974. {
  975. object o = e.Cell.Value;
  976. ultraGrid5.UpdateData();
  977. double canUse = 0;
  978. double canUseUom = 0;
  979. double canUseWeight = 0;
  980. double conf = 0;
  981. double norQtyNor = 0;
  982. double norQtyNorWeight = 0;
  983. if (ultraGrid2.ActiveRow != null)
  984. {
  985. double b_QTY = 0;//领用量
  986. double.TryParse(ultraGrid2.ActiveRow.Cells["QTY"].Value.ToString(), out b_QTY);
  987. double b_QTY_pur = 0;//领用量
  988. double.TryParse(ultraGrid2.ActiveRow.Cells["QTYPUR"].Value.ToString(), out b_QTY_pur);
  989. canUse = Math.Round((b_QTY - b_QTY_pur), 4, MidpointRounding.AwayFromZero);
  990. }
  991. else
  992. {
  993. MessageUtil.ShowTips("请选择待出库物料");
  994. e.Cell.Value = o;
  995. return;
  996. }
  997. double.TryParse(e.Cell.Row.GetCellValue("invqty").ToString(), out canUseUom);
  998. double.TryParse(e.Cell.Row.GetCellValue("INVQTYWEIGHT").ToString(), out canUseWeight);
  999. double.TryParse(e.Cell.Row.GetCellValue("itemUomConefficient").ToString(), out conf);
  1000. double.TryParse(e.Cell.Row.GetCellValue("qtyUnnor").ToString(), out norQtyNor);
  1001. double.TryParse(e.Cell.Row.GetCellValue("qtyUnnorWeight").ToString(), out norQtyNorWeight);
  1002. String strInvId = e.Cell.Row.GetCellValue("invId").ToString().Trim();
  1003. if (String.IsNullOrEmpty(strInvId))
  1004. {
  1005. MessageUtil.ShowTips("请选择待出库库存的库存记录号不能为空");
  1006. e.Cell.Value = o;
  1007. return;
  1008. }
  1009. if (e.Cell.Column.Key == "OUTNUM")//采购数量
  1010. {
  1011. double b_OutNum_nor_q = 0;//库存有主需求出库量总
  1012. double b_OutNum_q = 0;//出库总量
  1013. double OutNum = 0;//出库量
  1014. double.TryParse(e.Cell.Row.GetCellValue("OUTNUM").ToString(), out OutNum);
  1015. for (int i = 0; i < ultraGrid5.Rows.Count; i++)
  1016. {
  1017. double b_OutNum = 0;//出库量
  1018. double.TryParse(ultraGrid5.Rows[i].Cells["OUTNUM"].Value.ToString(), out b_OutNum);
  1019. b_OutNum_q += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);
  1020. if (ultraGrid5.Rows[i].Cells["invId"].Value.ToString().Trim() == strInvId)
  1021. {
  1022. b_OutNum_nor_q = b_OutNum_nor_q + b_OutNum;
  1023. }
  1024. }
  1025. if (b_OutNum_q > canUse)
  1026. {
  1027. MessageUtil.ShowTips("已大于领用单可编制量:" + canUse + "");
  1028. e.Cell.Value = o;
  1029. return;
  1030. }
  1031. if (b_OutNum_nor_q > norQtyNor)
  1032. {
  1033. MessageUtil.ShowTips("库存记录总编制量已大于该单位在该库存记录下的无主库存量(采购单位)");
  1034. e.Cell.Value = o;
  1035. return;
  1036. }
  1037. if (OutNum > canUseUom)
  1038. {
  1039. MessageUtil.ShowTips("已大于在库量(采购单位):" + canUseUom + "");
  1040. e.Cell.Value = o;
  1041. return;
  1042. }
  1043. if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨")
  1044. {
  1045. e.Cell.Row.Cells["OUTNUM1"].Value = Math.Round(OutNum / conf, 4, MidpointRounding.AwayFromZero);
  1046. }
  1047. else
  1048. {
  1049. e.Cell.Row.Cells["OUTNUM1"].Value = Math.Round(conf * OutNum, 4, MidpointRounding.AwayFromZero);
  1050. }
  1051. }
  1052. else if (e.Cell.Column.Key == "OUTNUM1")//库存数量
  1053. {
  1054. double OutNum1 = 0;//库存单位出库量
  1055. double.TryParse(e.Cell.Row.GetCellValue("OUTNUM1").ToString(), out OutNum1);
  1056. double b_OutNum_nor_q = 0;//库存有主需求出库量总
  1057. for (int i = 0; i < ultraGrid5.Rows.Count; i++)
  1058. {
  1059. double b_OutNum = 0;//出库量
  1060. double.TryParse(ultraGrid5.Rows[i].Cells["OUTNUM1"].Value.ToString(), out b_OutNum);
  1061. if (ultraGrid5.Rows[i].Cells["invId"].Value.ToString().Trim() == strInvId)
  1062. {
  1063. b_OutNum_nor_q = b_OutNum_nor_q + b_OutNum;
  1064. }
  1065. }
  1066. if (OutNum1 > canUseWeight)
  1067. {
  1068. MessageUtil.ShowTips("已大于在库量(库存单位):" + canUseWeight + "");
  1069. e.Cell.Value = o;
  1070. return;
  1071. }
  1072. if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨")
  1073. {
  1074. e.Cell.Row.Cells["OUTNUM"].Value = Math.Round(OutNum1 * conf, 4, MidpointRounding.AwayFromZero);
  1075. }
  1076. else
  1077. {
  1078. e.Cell.Row.Cells["OUTNUM"].Value = Math.Round(OutNum1 / conf, 4, MidpointRounding.AwayFromZero);
  1079. }
  1080. }
  1081. ultraGrid5.UpdateData();
  1082. }
  1083. /// <summary>
  1084. /// 填写出库量
  1085. /// </summary>
  1086. /// <param name="sender"></param>
  1087. /// <param name="e"></param>
  1088. private void ultraGrid3_CellChange(object sender, CellEventArgs e)
  1089. {
  1090. object o = e.Cell.Value;
  1091. ultraGrid3.UpdateData();
  1092. double canUse=0;
  1093. double canUseUom = 0;
  1094. double canUseWeight = 0;
  1095. double conf = 0;
  1096. double norQtyNor = 0;
  1097. double norQtyNorWeight = 0;
  1098. if (ultraGrid2.ActiveRow != null)
  1099. {
  1100. double b_QTY = 0;//领用量
  1101. double.TryParse(ultraGrid2.ActiveRow.Cells["QTY"].Value.ToString(), out b_QTY);
  1102. double b_QTY_pur = 0;//领用量
  1103. double.TryParse(ultraGrid2.ActiveRow.Cells["QTYPUR"].Value.ToString(), out b_QTY_pur);
  1104. canUse = Math.Round((b_QTY - b_QTY_pur), 4, MidpointRounding.AwayFromZero);
  1105. }
  1106. else
  1107. {
  1108. MessageUtil.ShowTips("请选择待出库物料");
  1109. e.Cell.Value = o;
  1110. return;
  1111. }
  1112. double.TryParse(e.Cell.Row.GetCellValue("invqty").ToString(), out canUseUom);
  1113. double.TryParse(e.Cell.Row.GetCellValue("INVQTYWEIGHT").ToString(), out canUseWeight);
  1114. double.TryParse(e.Cell.Row.GetCellValue("itemUomConefficient").ToString(), out conf);
  1115. double.TryParse(e.Cell.Row.GetCellValue("qtyNor").ToString(), out norQtyNor);
  1116. double.TryParse(e.Cell.Row.GetCellValue("qtyNorWeight").ToString(), out norQtyNorWeight);
  1117. String strInvId = e.Cell.Row.GetCellValue("invId").ToString().Trim();
  1118. if (String.IsNullOrEmpty(strInvId))
  1119. {
  1120. MessageUtil.ShowTips("请选择待出库库存的库存记录号不能为空");
  1121. e.Cell.Value = o;
  1122. return;
  1123. }
  1124. if(e.Cell.Column.Key=="OUTNUM")//采购数量
  1125. {
  1126. double b_OutNum_nor_q = 0;//库存有主需求出库量总
  1127. double b_OutNum_q = 0;//出库总量
  1128. double OutNum = 0;//出库量
  1129. double.TryParse(e.Cell.Row.GetCellValue("OUTNUM").ToString(), out OutNum);
  1130. for(int i=0;i<ultraGrid3.Rows.Count;i++)
  1131. {
  1132. double b_OutNum = 0;//出库量
  1133. double.TryParse(ultraGrid3.Rows[i].Cells["OUTNUM"].Value.ToString(), out b_OutNum);
  1134. b_OutNum_q += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);
  1135. if (ultraGrid3.Rows[i].Cells["invId"].Value.ToString().Trim() == strInvId)
  1136. {
  1137. b_OutNum_nor_q = b_OutNum_nor_q + b_OutNum_q;
  1138. }
  1139. }
  1140. if (b_OutNum_nor_q > norQtyNor)
  1141. {
  1142. MessageUtil.ShowTips("库存记录总编制量已大于该单位在该库存记录下的占用量(计量单位)");
  1143. e.Cell.Value = o;
  1144. return;
  1145. }
  1146. if (OutNum > canUseUom)
  1147. {
  1148. MessageUtil.ShowTips("已大于在库量(采购单位):" + canUseUom + "");
  1149. e.Cell.Value = o;
  1150. return;
  1151. }
  1152. if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨")
  1153. {
  1154. e.Cell.Row.Cells["OUTNUM1"].Value = Math.Round(OutNum/conf , 4, MidpointRounding.AwayFromZero);
  1155. }
  1156. else {
  1157. if (b_OutNum_q > canUse)
  1158. {
  1159. MessageUtil.ShowTips("已大于领用单可编制量:" + canUse + "");
  1160. e.Cell.Value = o;
  1161. return;
  1162. }
  1163. e.Cell.Row.Cells["OUTNUM1"].Value = Math.Round(conf * OutNum, 4, MidpointRounding.AwayFromZero);
  1164. }
  1165. }
  1166. else if (e.Cell.Column.Key == "OUTNUM1")//库存数量
  1167. {
  1168. double OutNum1 = 0;//库存单位出库量
  1169. double.TryParse(e.Cell.Row.GetCellValue("OUTNUM1").ToString(), out OutNum1);
  1170. double b_OutNum_nor_q = 0;//库存有主需求出库量总(库存)
  1171. double b_OutNum_q = 0;//出库总量(库存)
  1172. for (int i = 0; i < ultraGrid3.Rows.Count; i++)
  1173. {
  1174. double b_OutNum = 0;//出库量
  1175. double.TryParse(ultraGrid3.Rows[i].Cells["OUTNUM1"].Value.ToString(), out b_OutNum);
  1176. b_OutNum_q += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);
  1177. if (ultraGrid3.Rows[i].Cells["invId"].Value.ToString().Trim() == strInvId)
  1178. {
  1179. b_OutNum_nor_q = b_OutNum_nor_q + b_OutNum_q;
  1180. }
  1181. }
  1182. if (b_OutNum_nor_q > norQtyNorWeight)
  1183. {
  1184. MessageUtil.ShowTips("库存记录总编制量已大于该单位在该库存记录下的占用量(库存单位)");
  1185. e.Cell.Value = o;
  1186. return;
  1187. }
  1188. //校验编制量不能大于库存量
  1189. if (OutNum1 > canUseWeight)
  1190. {
  1191. MessageUtil.ShowTips("已大于在库量(库存单位):" + canUseWeight + "");
  1192. e.Cell.Value = o;
  1193. return;
  1194. }
  1195. if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨")
  1196. {
  1197. if (b_OutNum_q > canUse)
  1198. {
  1199. MessageUtil.ShowTips("已大于领用单可编制量:" + canUse + "");
  1200. e.Cell.Value = o;
  1201. return;
  1202. }
  1203. e.Cell.Row.Cells["OUTNUM"].Value = Math.Round(OutNum1*conf, 4, MidpointRounding.AwayFromZero);
  1204. }
  1205. else
  1206. {
  1207. e.Cell.Row.Cells["OUTNUM"].Value = Math.Round(OutNum1 / conf, 4, MidpointRounding.AwayFromZero);
  1208. }
  1209. }
  1210. ultraGrid3.UpdateData();
  1211. }
  1212. /// <summary>
  1213. /// 激活领用单行
  1214. /// </summary>
  1215. /// <param name="sender"></param>
  1216. /// <param name="e"></param>
  1217. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  1218. {
  1219. getInvPhysicNor();
  1220. getInvPhysicUnnor();
  1221. getOutBillPos();
  1222. }
  1223. private void ultraGrid2_InitializeLayout(object sender, InitializeLayoutEventArgs e)
  1224. {
  1225. }
  1226. private void ck_ctime_CheckedChanged(object sender, EventArgs e)
  1227. {
  1228. if (ck_ctime.Checked == false)
  1229. {
  1230. txtCreateTimeEnd.Enabled = false;
  1231. txtCreateTimeStart.Enabled = false;
  1232. }
  1233. else
  1234. {
  1235. txtCreateTimeEnd.Enabled = true;
  1236. txtCreateTimeStart.Enabled = true;
  1237. }
  1238. }
  1239. private void txt_REQ_ORG_EditorButtonClick(object sender, EditorButtonEventArgs e)
  1240. {
  1241. frmdepartment frm = new frmdepartment(this.ob);
  1242. frm.StartPosition = FormStartPosition.Manual;
  1243. frm.Location = publicPms.getShowLocation(frm);
  1244. frm.ShowDialog();
  1245. String strdeptId = frm.BuyerUnitCode;
  1246. String strDeptName = frm.Fulltext;
  1247. if (!String.IsNullOrEmpty(strdeptId) && !String.IsNullOrEmpty(strDeptName))
  1248. {
  1249. txt_REQ_ORG.Text = strDeptName;
  1250. req_org_id = strdeptId;
  1251. }
  1252. }
  1253. #endregion
  1254. private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
  1255. {
  1256. if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[2])
  1257. {
  1258. do_outBill.Enabled = false;
  1259. cancel_outBill.Enabled = true;
  1260. }
  1261. else
  1262. {
  1263. do_outBill.Enabled = true;
  1264. cancel_outBill.Enabled = false;
  1265. }
  1266. }
  1267. }
  1268. }