frmUsePlanYB.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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 frmUsePlanYB : FrmPmsBase
  26. {
  27. DataTable Qdt = null;//库区
  28. private string req_org_id = "";
  29. public frmUsePlanYB()
  30. {
  31. InitializeComponent();
  32. }
  33. private void frmUsePlanYB_Load(object sender, EventArgs e)
  34. {
  35. ck_attr.Checked = true;
  36. ck_Uom.Checked = true;
  37. ck_standard.Checked = true;
  38. txt_status.SelectedIndex = 1;
  39. ck_ctime.Checked = true;
  40. txtCreateTimeStart.Value = DateTime.Now.AddMonths(-1);
  41. txtCreateTimeEnd.Value = DateTime.Now.AddDays(2);
  42. GridHelper.SetColumnsActive(ultraGrid1.DisplayLayout.Bands[0]);
  43. GridHelper.SetColumnsActive(ultraGrid2.DisplayLayout.Bands[0]);
  44. GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], new String[] { "Check", "OUTNUM", "OUTNUM1" });
  45. GridHelper.SetExcludeColumnsActive(ultraGrid4.DisplayLayout.Bands[0], new String[] { "Check" });
  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. String strReason = "";
  121. frmPopReason frm = new frmPopReason(this.ob);
  122. frm.ShowDialog();
  123. if (frm.Tips == "1")
  124. {
  125. strReason = frm.Reason;
  126. }
  127. UsePlanM um = new UsePlanM();
  128. um.MrId = strMrId;
  129. um.Status = "9";
  130. um.Quitreson = "[退回] "+strReason;
  131. um.UpdateName = UserInfo.GetUserName();
  132. um.UpdateUserid = UserInfo.GetUserID();
  133. um.UpdateTime = DateTime.Now;
  134. if (MessageUtil.ShowYesNoAndQuestion("确定退回领用单:" + strMrId + "?") != DialogResult.Yes)
  135. {
  136. return;
  137. }
  138. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um });
  139. if (crt.Resultcode != 0)
  140. {
  141. MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
  142. return;
  143. }
  144. MessageUtil.ShowTips("操作成功");
  145. getUserPlanM(strMrId);
  146. }
  147. /// <summary>
  148. /// 查询领用单主表
  149. /// </summary>
  150. private void getUserPlanM(String strMrId)
  151. {
  152. LYM.Clear();
  153. LYD.Clear();
  154. stockPos.Clear();
  155. outStockDt.Clear();
  156. UsePlanM pupe = new UsePlanM();
  157. pupe.DeleteUserid = txt_status.Value == null ? "" : txt_status.Value.ToString().Trim();
  158. pupe.MrId = ultraTextEditor1.Text.Trim();
  159. pupe.ReqOrgId = req_org_id;
  160. if (ck_ctime.Checked == true)
  161. {
  162. if (txtCreateTimeStart.Text != "")
  163. {
  164. pupe.CreateTime = Convert.ToDateTime(txtCreateTimeStart.Value);
  165. }
  166. if (txtCreateTimeEnd.Text != "")
  167. {
  168. pupe.DeleteTime = Convert.ToDateTime(txtCreateTimeEnd.Value);
  169. }
  170. }
  171. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.UsePlanMService", "find_UsePlanM", new object[] { pupe });
  172. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  173. GridHelper.RefreshAndAutoSize(ultraGrid1);
  174. if (!String.IsNullOrEmpty(strMrId))
  175. {
  176. publicPms.doActiveSelRow(ultraGrid1, "mrId", strMrId);
  177. }
  178. }
  179. /// <summary>
  180. /// 完成领用
  181. /// </summary>
  182. private void finishUserPlanM()
  183. {
  184. UltraGridRow uge = ultraGrid1.ActiveRow;
  185. if (uge == null)
  186. return;
  187. String strMrId = uge.Cells["MRID"].Value.ToString();
  188. if (String.IsNullOrEmpty(strMrId))
  189. {
  190. return;
  191. }
  192. UsePlanM um = new UsePlanM();
  193. um.MrId = strMrId;
  194. um.Status = "5";
  195. um.UpdateName = UserInfo.GetUserName();
  196. um.UpdateUserid = UserInfo.GetUserID();
  197. um.UpdateTime = DateTime.Now;
  198. if (MessageUtil.ShowYesNoAndQuestion("确定完成该领用单出库:" + strMrId + "?") != DialogResult.Yes)
  199. {
  200. return;
  201. }
  202. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um });
  203. if (crt.Resultcode != 0)
  204. {
  205. MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
  206. return;
  207. }
  208. MessageUtil.ShowTips("操作成功");
  209. getUserPlanM(strMrId);
  210. }
  211. /// <summary>
  212. /// 确认领用单
  213. /// </summary>
  214. private void receiveUserPlanM()
  215. {
  216. throw new NotImplementedException();
  217. }
  218. /// <summary>
  219. /// 关闭
  220. /// </summary>
  221. private void CloPUR_SUPP()
  222. {
  223. this.Close();
  224. }
  225. #endregion
  226. #region 库存操作
  227. /// <summary>
  228. /// 重新匹配
  229. /// </summary>
  230. /// <param name="sender"></param>
  231. /// <param name="e"></param>
  232. private void query_ckPos_Click(object sender, EventArgs e)
  233. {
  234. }
  235. /// <summary>
  236. /// 出库操作
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void do_outBill_Click(object sender, EventArgs e)
  241. {
  242. setOutCkBill();
  243. }
  244. /// <summary>
  245. /// 生成出库单
  246. /// </summary>
  247. private void setOutCkBill()
  248. {
  249. ultraGrid3.UpdateData();
  250. if (ultraGrid2.ActiveRow == null)
  251. {
  252. MessageUtil.ShowTips("请选择领用单行进行操作");
  253. return;
  254. }
  255. String strUseLineId = ultraGrid2.ActiveRow.Cells["MrLineId"].Value.ToString().Trim();
  256. if (String.IsNullOrEmpty(strUseLineId))
  257. {
  258. MessageUtil.ShowTips("请选择领用单行号为空");
  259. return;
  260. }
  261. CkOutBill cob = new CkOutBill();
  262. UsePlanD pupe = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strUseLineId });
  263. if (pupe == null)
  264. {
  265. MessageUtil.ShowTips("未发现领用单行:" + strUseLineId + " 信息记录");
  266. return;
  267. }
  268. if (pupe.Validflag != "1")
  269. {
  270. MessageUtil.ShowTips("领用单行:" + strUseLineId + " 信息记录已经作废");
  271. return;
  272. }
  273. UsePlanM pm = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { pupe.MrId });
  274. cob = EntityHelper.CopyEntity<CkOutBill>(pupe);
  275. cob.DeliverAddress = pm.DeliveryLocationCode;
  276. cob.Status = "1";
  277. cob.OutstockType = "6";//非JIT
  278. cob.RefeId = strUseLineId;
  279. cob.CreateName = UserInfo.GetUserName();
  280. cob.CreateUserid = UserInfo.GetUserID();
  281. cob.CreateTime = DateTime.Now;
  282. cob.Validflag = "1";
  283. cob.ReleaseQty = 0;
  284. double bQTYUSE = 0;
  285. ArrayList al = new ArrayList();
  286. for (int i = 0; i < ultraGrid3.Rows.Count; i++)
  287. {
  288. UltraGridRow row = ultraGrid3.Rows[i];
  289. if (Convert.ToBoolean(row.GetCellValue("Check")) == true)
  290. {
  291. double b_OutNum = 0;//出库量
  292. if (row.GetCellValue("itemUom").ToString() == "基吨")
  293. {
  294. double.TryParse(ultraGrid3.Rows[i].Cells["OUTNUM1"].Value.ToString(), out b_OutNum);//铁合金出库存
  295. if (b_OutNum <= 0)
  296. {
  297. MessageUtil.ShowTips("储位【" + row.Cells["INVPOS"].Value.ToString() + "】的出库量必须>0");
  298. return;
  299. }
  300. }
  301. else
  302. {
  303. double.TryParse(ultraGrid3.Rows[i].Cells["OUTNUM"].Value.ToString(), out b_OutNum);//非铁合金出采购
  304. if (b_OutNum <= 0)
  305. {
  306. MessageUtil.ShowTips("储位【" + row.Cells["INVPOS"].Value.ToString() + "】的出库量必须>0");
  307. return;
  308. }
  309. }
  310. CkOutbillPosition cobp = new CkOutbillPosition();
  311. bQTYUSE += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);
  312. cobp.OutNum = Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);//出库量
  313. //cob.ReleaseQty += b_OutNum;
  314. //cobp.Id = ultraGrid1.Rows[i].Cells["INVPOSID"].Value.ToString();
  315. //cobp.InvId = ultraGrid5.Rows[i].Cells["InvId"].Value.ToString();
  316. cobp.InvPhysic = ultraGrid3.Rows[i].Cells["INVPHYSIC"].Value.ToString();
  317. if (cobp.InvPhysic != pm.InvPhysic)
  318. {
  319. MessageUtil.ShowTips("请选择仓库:" + pm.InvPhysic + " 物料进行出库");
  320. return;
  321. }
  322. cobp.InvPosId = ultraGrid3.Rows[i].Cells["InvPosId"].Value.ToString();
  323. cobp.InvId = ultraGrid3.Rows[i].Cells["InvId"].Value.ToString();
  324. if (String.IsNullOrEmpty(cobp.InvId))
  325. {
  326. MessageUtil.ShowTips("选择的出库信息的送货单行不能为空");
  327. return;
  328. }
  329. al.Add(cobp);
  330. }
  331. }
  332. if (al.Count == 0)
  333. {
  334. MessageUtil.ShowTips("至少有一个库位出库量>0");
  335. return;
  336. }
  337. cob.ReleaseQty = Math.Round(bQTYUSE, 4, MidpointRounding.AwayFromZero);
  338. double canUse1=Math.Round((double)pupe.Qty-(double)pupe.QtyPur,4);
  339. if (cob.ReleaseQty > canUse1)
  340. {
  341. MessageUtil.ShowTips("总出库数量:" + cob.ReleaseQty + "已经大于该领用单行可编制量:" + canUse1);
  342. return;
  343. }
  344. if (MessageUtil.ShowYesNoAndQuestion("确定对领用单行:" + strUseLineId + " 进行出库(备货)操作?") != DialogResult.Yes)
  345. {
  346. return;
  347. }
  348. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutBillService", "doInsert_Update", new object[] {cob, al });
  349. if (crt.Resultcode != 0)
  350. {
  351. MessageUtil.ShowTips("出库单生成失败!" + crt.Resultmsg);
  352. return;
  353. }
  354. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("出库成功!单号:" + crt.Resultmsg);
  355. getUserPlanM(pupe.MrId);
  356. publicPms.doActiveSelRow(ultraGrid2, "MrLineId", strUseLineId);
  357. }
  358. /// <summary>
  359. /// 取消出库操作
  360. /// </summary>
  361. /// <param name="sender"></param>
  362. /// <param name="e"></param>
  363. private void cancel_outBill_Click(object sender, EventArgs e)
  364. {
  365. ultraGrid3.UpdateData();
  366. if (ultraGrid2.ActiveRow == null)
  367. {
  368. MessageUtil.ShowTips("请选择领用单行进行操作");
  369. return;
  370. }
  371. String strUseLineId = ultraGrid2.ActiveRow.Cells["MrLineId"].Value.ToString().Trim();
  372. if (String.IsNullOrEmpty(strUseLineId))
  373. {
  374. MessageUtil.ShowTips("请选择领用单行号为空");
  375. return;
  376. }
  377. ArrayList al = new ArrayList();
  378. for (int i = 0; i < ultraGrid4.Rows.Count; i++)
  379. {
  380. UltraGridRow row = ultraGrid4.Rows[i];
  381. if (Convert.ToBoolean(row.GetCellValue("Check")) == true)
  382. {
  383. CkOutbillPosition cobp = new CkOutbillPosition();
  384. cobp.OutStockNo = row.Cells["outStockno"].Value.ToString();
  385. cobp.Id = row.Cells["id"].Value.ToString();
  386. if (String.IsNullOrEmpty(cobp.Id))
  387. {
  388. MessageUtil.ShowTips("选择的撤销的出库单行行号不能为空");
  389. return;
  390. }
  391. cobp.DeleteName = UserInfo.GetUserName();
  392. cobp.DeleteUserid = UserInfo.GetUserID();
  393. cobp.DeleteTime= DateTime.Now;
  394. al.Add(cobp);
  395. }
  396. }
  397. if (al.Count == 0)
  398. {
  399. MessageUtil.ShowTips("至少有一个出库记录");
  400. return;
  401. }
  402. if (MessageUtil.ShowYesNoAndQuestion("确定对领用单行:" + strUseLineId + " 进行撤销出库(备货)操作?") != DialogResult.Yes)
  403. {
  404. return;
  405. }
  406. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.ck.service.CkOutBillService", "doCancel_OutStock", new object[] { strUseLineId, al });
  407. if (crt.Resultcode != 0)
  408. {
  409. MessageUtil.ShowTips("撤销出库!" + crt.Resultmsg);
  410. return;
  411. }
  412. getUserPlanM(strUseLineId);
  413. }
  414. #endregion
  415. #region 公共函数
  416. /// <summary>
  417. /// 查询领用单行表
  418. /// </summary>
  419. private void getUserPlanD()
  420. {
  421. LYD.Clear();
  422. stockPos.Clear();
  423. outStockDt.Clear();
  424. UltraGridRow uge = ultraGrid1.ActiveRow;
  425. if (uge == null)
  426. return;
  427. UsePlanD pupe = new UsePlanD();
  428. pupe.MrId = uge.Cells["MRID"].Value.ToString();
  429. if (String.IsNullOrEmpty(pupe.MrId))
  430. {
  431. return;
  432. }
  433. pupe.Validflag = "1";
  434. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.UsePlanDService", "getUsePlanD", new object[] { pupe });
  435. foreach (DataRow row in dt.Rows)
  436. {
  437. if (row["ITEMUOM"].ToString() == "基吨")
  438. {
  439. row["ITEMUOM"] = "吨";
  440. }
  441. }
  442. GridHelper.CopyDataToDatatable(dt, dataTable2, true);
  443. GridHelper.RefreshAndAutoSize(ultraGrid2);
  444. }
  445. /// <summary>
  446. /// 查询出库库位
  447. /// </summary>
  448. private void getInvPhysic()
  449. {
  450. stockPos.Clear();
  451. UltraGridRow ugr = ultraGrid2.ActiveRow;
  452. if (ugr == null)
  453. {
  454. MessageUtil.ShowTips("请选择需出库的物料");
  455. return;
  456. }
  457. String strMrLineId=ugr.Cells["MRLINEID"].Value.ToString().Trim();
  458. if ( String.IsNullOrEmpty(strMrLineId))
  459. {
  460. MessageUtil.ShowTips("该领用单行号为空");
  461. return;
  462. }
  463. UsePlanD ud = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId });
  464. UsePlanM um = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { ud.MrId });
  465. if (String.IsNullOrEmpty(ud.PurLineId))
  466. {
  467. MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联采购计划号,无法查询库存信息");
  468. return;
  469. }
  470. PurCkStoragePosEntity ckp = new PurCkStoragePosEntity();
  471. ckp.UpdateName = ud.PurLineId;
  472. ckp.InvPhysic = um.InvPhysic;
  473. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.ck.service.CkStoragePosService", "getCkStoragePos", new object[] { ckp });
  474. GridHelper.CopyDataToDatatable(ref dt, ref dataTable3, true);
  475. double canOutNum = (double)ud.Qty - (ud.QtyPur == null ? 0 : (double)ud.QtyPur);
  476. double tempCanUseQty = canOutNum;
  477. foreach (UltraGridRow row in ultraGrid3.Rows)
  478. {
  479. if (row.GetCellValue("itemUom").ToString() == "基吨")
  480. {
  481. //row.Cells["itemUom"].Value = "吨";
  482. double needQty = 0;
  483. double dbItemUomConefficient = 1;
  484. double.TryParse(row.GetCellValue("INVQTYWEIGHT").ToString(), out needQty);//库存需出库量
  485. double.TryParse(row.GetCellValue("itemUomConefficient").ToString(), out dbItemUomConefficient);
  486. if (tempCanUseQty > 0 && needQty > 0)
  487. {
  488. if (needQty >= tempCanUseQty)
  489. {
  490. row.Cells["OUTNUM1"].Value = tempCanUseQty;//库存出库量
  491. row.Cells["OUTNUM"].Value = Math.Round(tempCanUseQty*dbItemUomConefficient,4);//采购出库量
  492. tempCanUseQty = 0;
  493. row.Cells["Check"].Value = true;
  494. }
  495. else
  496. {
  497. row.Cells["OUTNUM1"].Value = needQty;//库存出库量
  498. row.Cells["OUTNUM"].Value = Math.Round(needQty*dbItemUomConefficient, 4);//采购出库量
  499. tempCanUseQty = tempCanUseQty - needQty;
  500. row.Cells["Check"].Value = true;
  501. }
  502. }
  503. }
  504. else {
  505. double needQty = 0;
  506. double dbItemUomConefficient = 1;
  507. double.TryParse(row.GetCellValue("invqty").ToString(), out needQty);//采购需出库量
  508. double.TryParse(row.GetCellValue("itemUomConefficient").ToString(), out dbItemUomConefficient);
  509. if (tempCanUseQty > 0 && needQty > 0)
  510. {
  511. if (needQty >= tempCanUseQty)
  512. {
  513. row.Cells["OUTNUM"].Value = tempCanUseQty;
  514. row.Cells["OUTNUM1"].Value = Math.Round(tempCanUseQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
  515. tempCanUseQty = 0;
  516. row.Cells["Check"].Value = true;
  517. }
  518. else
  519. {
  520. row.Cells["OUTNUM"].Value = needQty;
  521. row.Cells["OUTNUM1"].Value = Math.Round(needQty / dbItemUomConefficient, 4, MidpointRounding.AwayFromZero);//采购出库量
  522. tempCanUseQty = tempCanUseQty - needQty;
  523. row.Cells["Check"].Value = true;
  524. }
  525. }
  526. }
  527. }
  528. GridHelper.RefreshAndAutoSize(ultraGrid3);
  529. }
  530. private void getOutBillPos()
  531. {
  532. try
  533. {
  534. outStockDt.Clear();
  535. UltraGridRow ugr = ultraGrid2.ActiveRow;
  536. if (ugr == null)
  537. {
  538. MessageUtil.ShowTips("请选择需出库的物料");
  539. return;
  540. }
  541. String strMrLineId = ugr.Cells["MRLINEID"].Value.ToString().Trim();
  542. if (String.IsNullOrEmpty(strMrLineId))
  543. {
  544. MessageUtil.ShowTips("该领用单行号为空");
  545. return;
  546. }
  547. UsePlanD ud = this.execute<UsePlanD>("com.hnshituo.pur.requireplan.service.UsePlanDService", "findById", new object[] { strMrLineId });
  548. UsePlanM um = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { ud.MrId });
  549. if (String.IsNullOrEmpty(ud.PurLineId))
  550. {
  551. MessageUtil.ShowTips("领用单行:" + strMrLineId + "未关联采购计划号,无法查询库存信息");
  552. return;
  553. }
  554. CkOutbillPosition cp = new CkOutbillPosition();
  555. cp.UpdateName = strMrLineId;
  556. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.ck.service.CkOutbillPositionService", "doQueryCkOutbillPosition", new object[] { cp });
  557. if (dt != null && dt.Rows.Count >= 1)
  558. {
  559. GridHelper.CopyDataToDatatable(ref dt, ref dataTable4, true);
  560. GridHelper.RefreshAndAutoSize(ultraGrid4);
  561. }
  562. }
  563. catch (Exception ex)
  564. {
  565. MessageBox.Show("操作失败:" + ex.Message, "提示");
  566. }
  567. }
  568. #endregion
  569. #region 界面事件
  570. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  571. {
  572. getUserPlanD();
  573. }
  574. /// <summary>
  575. /// 填写出库量
  576. /// </summary>
  577. /// <param name="sender"></param>
  578. /// <param name="e"></param>
  579. private void ultraGrid3_CellChange(object sender, CellEventArgs e)
  580. {
  581. object o = e.Cell.Value;
  582. ultraGrid3.UpdateData();
  583. double canUse=0;
  584. double canUseUom = 0;
  585. double canUseWeight = 0;
  586. double conf = 0;
  587. if (ultraGrid2.ActiveRow != null)
  588. {
  589. double b_QTY = 0;//领用量
  590. double.TryParse(ultraGrid2.ActiveRow.Cells["QTY"].Value.ToString(), out b_QTY);
  591. double b_QTY_pur = 0;//领用量
  592. double.TryParse(ultraGrid2.ActiveRow.Cells["QTYPUR"].Value.ToString(), out b_QTY_pur);
  593. canUse = Math.Round((b_QTY - b_QTY_pur), 4, MidpointRounding.AwayFromZero);
  594. }
  595. else
  596. {
  597. MessageUtil.ShowTips("请选择待出库物料");
  598. return;
  599. }
  600. double.TryParse(e.Cell.Row.GetCellValue("invqty").ToString(), out canUseUom);
  601. double.TryParse(e.Cell.Row.GetCellValue("INVQTYWEIGHT").ToString(), out canUseWeight);
  602. double.TryParse(e.Cell.Row.GetCellValue("itemUomConefficient").ToString(), out conf);
  603. if(e.Cell.Column.Key=="OUTNUM")//采购数量
  604. {
  605. double b_OutNum_q = 0;//出库总量
  606. double OutNum = 0;//出库量
  607. double.TryParse(e.Cell.Row.GetCellValue("OUTNUM").ToString(), out OutNum);
  608. for(int i=0;i<ultraGrid3.Rows.Count;i++)
  609. {
  610. double b_OutNum = 0;//出库量
  611. double.TryParse(ultraGrid3.Rows[i].Cells["OUTNUM"].Value.ToString(), out b_OutNum);
  612. b_OutNum_q += Math.Round(b_OutNum, 4, MidpointRounding.AwayFromZero);
  613. }
  614. if (b_OutNum_q > canUse)
  615. {
  616. MessageUtil.ShowTips("已大于领用单可编制量:"+canUse+"");
  617. e.Cell.Value = o;
  618. return;
  619. }
  620. if (OutNum > canUseUom)
  621. {
  622. MessageUtil.ShowTips("已大于在库量(采购单位):" + canUseUom + "");
  623. e.Cell.Value = o;
  624. return;
  625. }
  626. if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨")
  627. {
  628. e.Cell.Row.Cells["OUTNUM1"].Value = Math.Round(OutNum/conf , 4, MidpointRounding.AwayFromZero);
  629. }
  630. else {
  631. e.Cell.Row.Cells["OUTNUM1"].Value = Math.Round(conf * OutNum, 4, MidpointRounding.AwayFromZero);
  632. }
  633. }
  634. else if (e.Cell.Column.Key == "OUTNUM1")//库存数量
  635. {
  636. double OutNum1 = 0;//库存单位出库量
  637. double.TryParse(e.Cell.Row.GetCellValue("OUTNUM1").ToString(), out OutNum1);
  638. if (OutNum1 > canUseWeight)
  639. {
  640. MessageUtil.ShowTips("已大于在库量(库存单位):" + canUseWeight + "");
  641. e.Cell.Value = o;
  642. return;
  643. }
  644. if (e.Cell.Row.GetCellValue("itemUom").ToString() == "基吨")
  645. {
  646. e.Cell.Row.Cells["OUTNUM"].Value = Math.Round(OutNum1*conf, 4, MidpointRounding.AwayFromZero);
  647. }
  648. else
  649. {
  650. e.Cell.Row.Cells["OUTNUM"].Value = Math.Round(OutNum1 / conf, 4, MidpointRounding.AwayFromZero);
  651. }
  652. }
  653. ultraGrid3.UpdateData();
  654. }
  655. /// <summary>
  656. /// 激活领用单行
  657. /// </summary>
  658. /// <param name="sender"></param>
  659. /// <param name="e"></param>
  660. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  661. {
  662. getInvPhysic();
  663. getOutBillPos();
  664. }
  665. private void ultraGrid2_InitializeLayout(object sender, InitializeLayoutEventArgs e)
  666. {
  667. }
  668. private void ck_ctime_CheckedChanged(object sender, EventArgs e)
  669. {
  670. if (ck_ctime.Checked == false)
  671. {
  672. txtCreateTimeEnd.Enabled = false;
  673. txtCreateTimeStart.Enabled = false;
  674. }
  675. else
  676. {
  677. txtCreateTimeEnd.Enabled = true;
  678. txtCreateTimeStart.Enabled = true;
  679. }
  680. }
  681. private void txt_REQ_ORG_EditorButtonClick(object sender, EditorButtonEventArgs e)
  682. {
  683. frmdepartment frm = new frmdepartment(this.ob);
  684. frm.StartPosition = FormStartPosition.Manual;
  685. frm.Location = publicPms.getShowLocation(frm);
  686. frm.ShowDialog();
  687. String strdeptId = frm.BuyerUnitCode;
  688. String strDeptName = frm.Fulltext;
  689. if (!String.IsNullOrEmpty(strdeptId) && !String.IsNullOrEmpty(strDeptName))
  690. {
  691. txt_REQ_ORG.Text = strDeptName;
  692. req_org_id = strdeptId;
  693. }
  694. }
  695. #endregion
  696. }
  697. }