frmPurUsePlanNew.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;
  10. using Pur.Entity.require_planEntiy;
  11. using Core.Mes.Client.Comm.Control;
  12. using Core.Mes.Client.Comm.Tool;
  13. using Infragistics.Win.UltraWinGrid;
  14. using com.hnshituo.pur.vo;
  15. using System.Collections;
  16. using Pur.Entity.configureEntity;
  17. using Pur.configure;
  18. using Pur.require_plan;
  19. using Pur.PublicTools;
  20. using Pur.Pop_upWindow;
  21. using Pur.Entity;
  22. namespace Pur.ck
  23. {
  24. public partial class frmPurUsePlanNew : FrmPmsBase
  25. {
  26. private string showType="1";//默认生产厂
  27. public frmPurUsePlanNew()
  28. {
  29. InitializeComponent();
  30. this.IsLoadUserView = true;
  31. }
  32. /// <summary>
  33. /// 界面初始化
  34. /// </summary>
  35. /// <param name="sender"></param>
  36. /// <param name="e"></param>
  37. private void frmPurUsePlanNew_Load(object sender, EventArgs e)
  38. {
  39. showType = this.CustomInfo;
  40. if (String.IsNullOrEmpty(showType))
  41. {
  42. MessageUtil.ShowTips("界面配置错误,请指定界面使用者[1:生产厂,2:供应部]");
  43. return;
  44. }
  45. txt_status_LY.SelectedIndex = 1;
  46. ck_ctime.Checked = true;
  47. txtCreateTimeStart.Value = DateTime.Now.AddMonths(-1);
  48. txtCreateTimeEnd.Value = DateTime.Now.AddDays(2);
  49. GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { "check", "REMARKUSE" });
  50. GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[1], new string[] { "useQtyReq" });
  51. GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], new string[] { "CHK"});
  52. GridHelper.SetExcludeColumnsActive(ultraGrid2.DisplayLayout.Bands[0], new string[] { });
  53. getUserPlanM("");
  54. }
  55. #region toolbar事件
  56. /// <summary>
  57. /// toolbar
  58. /// </summary>
  59. /// <param name="sender"></param>
  60. /// <param name="ToolbarKey"></param>
  61. public override void ToolBar_Click(object sender, string ToolbarKey)//菜单toolbar按钮
  62. {
  63. switch (ToolbarKey)
  64. {
  65. case "Query":
  66. getUserPlan("");
  67. break;
  68. case "addPlanUserMD"://生成领用单
  69. addPlanProgram();
  70. break;
  71. case "sendPlanUserMD"://提交领用单
  72. sendPlanProgram();
  73. break;
  74. case "backPlanUserMD"://撤回领用单
  75. backPlanProgram();
  76. break;
  77. case "surePlanUserMD"://确认领用
  78. surePlanProgram();
  79. break;
  80. case "cancelPlanUserMD"://删除领用单
  81. cancelPlanProgram();
  82. break;
  83. case "printPlanUserMD"://删除领用单
  84. printPlanProgram();
  85. break;
  86. case "Quit"://退出
  87. this.Close();
  88. break;
  89. case "doExcel"://退出
  90. doExcel();
  91. break;
  92. }
  93. }
  94. /// <summary>
  95. /// 确认领用
  96. /// </summary>
  97. private void surePlanProgram()
  98. {
  99. UltraGridRow uge = ultraGrid2.ActiveRow;
  100. if (uge == null)
  101. return;
  102. String strMrId = uge.Cells["MRID"].Value.ToString();
  103. if (String.IsNullOrEmpty(strMrId))
  104. {
  105. return;
  106. }
  107. if (testStatusM(strMrId, 6) == false)
  108. {
  109. return;
  110. }
  111. UsePlanM um = new UsePlanM();
  112. um.MrId = strMrId;
  113. um.Status = "6";
  114. um.UpdateName = UserInfo.GetUserName();
  115. um.UpdateUserid = UserInfo.GetUserID();
  116. um.UpdateTime = DateTime.Now;
  117. if (MessageUtil.ShowYesNoAndQuestion("已完成领用单:" + strMrId + "物料领用?") != DialogResult.Yes)
  118. {
  119. return;
  120. }
  121. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um });
  122. if (crt.Resultcode != 0)
  123. {
  124. MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
  125. return;
  126. }
  127. MessageUtil.ShowTips("操作成功");
  128. getUserPlanM(strMrId);
  129. }
  130. /// <summary>
  131. /// 导出Excel
  132. /// </summary>
  133. private void doExcel()
  134. {
  135. try
  136. {
  137. this.Cursor = Cursors.Default;
  138. if (ultraGrid2.ActiveRow == null)
  139. {
  140. MessageUtil.ShowTips("请选择需导出明细的领用单头!");
  141. return;
  142. }
  143. //获取导出的采购计划行表
  144. ArrayList alUltraGrid = new ArrayList();
  145. alUltraGrid.Add(ultraGrid3);
  146. ArrayList alSheeft = new ArrayList();
  147. alSheeft.Add("物料明细");
  148. if (ultraGrid2.Rows.Count > 0)
  149. {
  150. GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "领用单[" + ultraGrid2.ActiveRow.GetCellValue("mrId") + "]明细表");//导出excel
  151. }
  152. else
  153. {
  154. MessageUtil.ShowTips("领用单:" + ultraGrid2.ActiveRow.GetCellValue("mrId") + "无可导出明细!");
  155. }
  156. }
  157. catch (Exception e)
  158. {
  159. MessageUtil.ShowTips("导出失败" + e.Message);
  160. }
  161. finally
  162. {
  163. this.Cursor = Cursors.Default;
  164. }
  165. }
  166. /// <summary>
  167. /// 添加领用单头
  168. /// </summary>
  169. private void addPlanProgram()
  170. {
  171. try
  172. {
  173. frmUsePlanMAdd frm = new frmUsePlanMAdd(this.ob, showType);
  174. frm.ShowDialog();
  175. if (frm.tips == "1")
  176. {
  177. string StrMrId = frm.mrId;
  178. getUserPlanM(StrMrId);
  179. }
  180. }
  181. catch (Exception e)
  182. {
  183. MessageUtil.ShowTips("新增失败!" + e);
  184. return;
  185. }
  186. }
  187. /// <summary>
  188. /// 查询领用计划
  189. /// </summary>
  190. private void getUserPlan(String strMrId)
  191. {
  192. getUserPlanM(strMrId);
  193. }
  194. /// <summary>
  195. /// 打印领用单
  196. /// </summary>
  197. private void printPlanProgram()
  198. {
  199. MessageUtil.ShowTips("开发中");
  200. }
  201. /// <summary>
  202. /// 撤回领用大
  203. /// </summary>
  204. private void backPlanProgram()
  205. {
  206. UltraGridRow uge = ultraGrid2.ActiveRow;
  207. if (uge == null)
  208. return;
  209. String strMrId = uge.Cells["MRID"].Value.ToString();
  210. if (String.IsNullOrEmpty(strMrId))
  211. {
  212. return;
  213. }
  214. if (testStatusM(strMrId, 11) == false)
  215. {
  216. return;
  217. }
  218. UsePlanM um = new UsePlanM();
  219. um.MrId = strMrId;
  220. um.Status = "1";
  221. um.UpdateName = UserInfo.GetUserName();
  222. um.UpdateUserid = UserInfo.GetUserID();
  223. um.UpdateTime = DateTime.Now;
  224. if (MessageUtil.ShowYesNoAndQuestion("确定撤回领用单:" + strMrId + "?") != DialogResult.Yes)
  225. {
  226. return;
  227. }
  228. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um });
  229. if (crt.Resultcode != 0)
  230. {
  231. MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
  232. return;
  233. }
  234. MessageUtil.ShowTips("操作成功");
  235. getUserPlanM(strMrId);
  236. }
  237. /// <summary>
  238. /// 取消提报领用单
  239. /// </summary>
  240. private void cancelPlanProgram()
  241. {
  242. UltraGridRow uge = ultraGrid2.ActiveRow;
  243. if (uge == null)
  244. return;
  245. String strMrId = uge.Cells["MRID"].Value.ToString();
  246. if (String.IsNullOrEmpty(strMrId))
  247. {
  248. return;
  249. }
  250. if (testStatusM(strMrId, 10) == false)
  251. {
  252. return;
  253. }
  254. UsePlanM um = new UsePlanM();
  255. um.MrId = strMrId;
  256. um.Status = "-1";
  257. um.UpdateName = UserInfo.GetUserName();
  258. um.UpdateUserid = UserInfo.GetUserID();
  259. um.UpdateTime = DateTime.Now;
  260. if (MessageUtil.ShowYesNoAndQuestion("确定删除领用单:" + strMrId + "?") != DialogResult.Yes)
  261. {
  262. return;
  263. }
  264. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um });
  265. if (crt.Resultcode != 0)
  266. {
  267. MessageUtil.ShowTips("操作失败:" + crt.Resultmsg);
  268. return;
  269. }
  270. MessageUtil.ShowTips("操作成功");
  271. getUserPlan(strMrId);
  272. }
  273. /// <summary>
  274. /// 发送领用单
  275. /// </summary>
  276. private void sendPlanProgram()
  277. {
  278. UltraGridRow uge = ultraGrid2.ActiveRow;
  279. if (uge == null)
  280. return;
  281. String strMrId = uge.Cells["MRID"].Value.ToString();
  282. if (String.IsNullOrEmpty(strMrId))
  283. {
  284. return;
  285. }
  286. if (testStatusM(strMrId, 2) == false)
  287. {
  288. return;
  289. }
  290. UsePlanM um = new UsePlanM();
  291. um.MrId = strMrId;
  292. um.Status = "2";
  293. um.UpdateName = UserInfo.GetUserName();
  294. um.UpdateUserid = UserInfo.GetUserID();
  295. um.UpdateTime = DateTime.Now;
  296. if (MessageUtil.ShowYesNoAndQuestion("确定提报领用单:" + strMrId + "?") != DialogResult.Yes)
  297. {
  298. return;
  299. }
  300. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanMService", "doHandleM", new object[] { um });
  301. if (crt.Resultcode != 0)
  302. {
  303. MessageUtil.ShowTips("操作失败:"+crt.Resultmsg);
  304. return;
  305. }
  306. MessageUtil.ShowTips("操作成功");
  307. getUserPlanM(strMrId);
  308. }
  309. #endregion
  310. #region 界面事件
  311. /// <summary>
  312. /// 输入领用数量,计算总价
  313. /// </summary>
  314. /// <param name="sender"></param>
  315. /// <param name="e"></param>
  316. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  317. {
  318. UltraGridRow row = e.Cell.Row;
  319. if (e.Cell.Column.Key == "useQtyReq" && e.Cell.Row.HasParent())
  320. {
  321. double bQtyOld = 0;
  322. double.TryParse(e.Cell.Value.ToString(), out bQtyOld);
  323. ultraGrid1.UpdateData();
  324. //if (txt_InvPhysic.SelectedIndex==-1||txt_InvPhysic.SelectedIndex==0)
  325. //{
  326. // MessageUtil.ShowTips("请选择待领料的仓库");
  327. // txt_InvPhysic.Focus();
  328. // e.Cell.Value = bQtyOld;
  329. // return;
  330. //}
  331. //if (txt_ItemClass.SelectedIndex == -1 || txt_ItemClass.SelectedIndex ==0)
  332. //{
  333. // MessageUtil.ShowTips("请选择待领用物料中类");
  334. // txt_ItemClass.Focus();
  335. // e.Cell.Value = bQtyOld;
  336. // return;
  337. //}
  338. double canUseQty = 0;
  339. double canUseQty1 = 0;
  340. double noticeQtyReq = 0;
  341. double singleNormalQty = 0;
  342. double.TryParse(row.ParentRow.GetCellValue("canUseQty").ToString(), out canUseQty);
  343. double.TryParse(row.ParentRow.GetCellValue("canUseQtyUnnor").ToString(), out canUseQty1);
  344. double.TryParse(row.GetCellValue("QTYYCUSEABLE").ToString(), out noticeQtyReq);
  345. double.TryParse(row.GetCellValue("normalQty").ToString(), out singleNormalQty);
  346. double bQtyNew = 0;
  347. double.TryParse(e.Cell.Value.ToString(), out bQtyNew);
  348. //if (noticeQtyReq < bQtyNew)
  349. //{
  350. // MessageUtil.ShowTips("不能大于需求计划的可领用量");
  351. // e.Cell.Value = bQtyOld;
  352. // return;
  353. //}
  354. double allUseQty = 0;//全部编制量
  355. double allUseQty1 = 0;//无主需求总编制量
  356. foreach (UltraGridRow row1 in row.ParentRow.ChildBands[0].Rows)
  357. {
  358. double singleQty = 0;//编制量
  359. //double singleUnQty=0;//无主需求量
  360. double singlenorQty = 0;//有主需求量
  361. //double.TryParse(row1.GetCellValue("QTYYCUSEABLE").ToString(), out singleCanUseQty);
  362. double.TryParse(row1.GetCellValue("useQtyReq").ToString(), out singleQty);
  363. //double.TryParse(row1.GetCellValue("unNormalQty").ToString(), out singleUnQty);
  364. double.TryParse(row1.GetCellValue("normalQty").ToString(), out singlenorQty);
  365. if (singlenorQty - singleQty < 0)
  366. {
  367. allUseQty1 = allUseQty1 + singleQty - singlenorQty;
  368. }
  369. allUseQty = allUseQty + singleQty;
  370. }
  371. //if (canUseQty < allUseQty)
  372. //{
  373. // MessageUtil.ShowTips("不能大于采购计划的最大可编制量");
  374. // e.Cell.Value = bQtyOld;
  375. // return;
  376. //}
  377. if (canUseQty1 < allUseQty1)
  378. {
  379. MessageUtil.ShowTips("无主库存编制量不能大于采购计划的无主需求量");
  380. e.Cell.Value = bQtyOld;
  381. return;
  382. }
  383. if (singleNormalQty - bQtyNew < 0)
  384. {
  385. row.Cells["unNormalQtyUse"].Value = bQtyNew - singleNormalQty;
  386. }
  387. row.ParentRow.Cells["UseQty"].Value = allUseQty;
  388. row.ParentRow.Cells["UseQty1"].Value = allUseQty1;
  389. double bBugprice = 0;//计划价
  390. double.TryParse(row.ParentRow.Cells["Bugprice"].Value.ToString(), out bBugprice);
  391. double bPriceaverage = 0;//采购平均价
  392. double.TryParse(row.ParentRow.Cells["BUDGETAMT"].Value.ToString(), out bPriceaverage);
  393. row.ParentRow.Cells["bugpriceamt"].Value = allUseQty * bBugprice;
  394. row.ParentRow.Cells["priceaverageAMT"].Value = allUseQty * bPriceaverage;
  395. }
  396. else if (e.Cell.Column.Key == "REMARKUSE")
  397. {
  398. //if (txt_InvPhysic.Value == null)
  399. //{
  400. // MessageUtil.ShowTips("请选择待领料的仓库");
  401. // txt_InvPhysic.Focus();
  402. // return;
  403. //}
  404. //if (txt_ItemClass.SelectedIndex == -1)
  405. //{
  406. // MessageUtil.ShowTips("请选择待领用物料中类");
  407. // txt_ItemClass.Focus();
  408. // return;
  409. //}
  410. }
  411. e.Cell.Row.Activated = true;
  412. }
  413. /// <summary>
  414. /// 查询领用单数据
  415. /// </summary>
  416. /// <param name="sender"></param>
  417. /// <param name="e"></param>
  418. private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
  419. {
  420. UltraGridRow uge = ultraGrid2.ActiveRow;
  421. if (uge == null)
  422. return;
  423. UsePlanD pupe = new UsePlanD();
  424. pupe.MrId = uge.Cells["MRID"].Value.ToString();
  425. pupe.Validflag = "1";
  426. if (String.IsNullOrEmpty(pupe.MrId))
  427. {
  428. return;
  429. }
  430. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.UsePlanDService", "getUsePlanD", new object[] { pupe });
  431. foreach (DataRow row in dt.Rows)
  432. {
  433. if (row["ITEMUOM"].ToString() == "基吨")
  434. {
  435. row["ITEMUOM"] = "吨";
  436. }
  437. }
  438. GridHelper.CopyDataToDatatable(dt, dataTable3, true);
  439. GridHelper.RefreshAndAutoSize(ultraGrid3);
  440. //UsePlanM up = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { pupe.MrId });
  441. //if (up == null)
  442. //{
  443. // MessageUtil.ShowTips("未发现领料单头:" + pupe.MrId + "信息记录");
  444. // return;
  445. //}
  446. //txt_InvPhysic.Value = up.InvPhysic;
  447. //txt_ItemClass.Value = up.ItemClass;
  448. getCanUseData();
  449. }
  450. /// <summary>
  451. /// 查询时间控制
  452. /// </summary>
  453. /// <param name="sender"></param>
  454. /// <param name="e"></param>
  455. private void ck_ctime_CheckedChanged(object sender, EventArgs e)
  456. {
  457. if (ck_ctime.Checked == false)
  458. {
  459. txtCreateTimeEnd.Enabled = false;
  460. txtCreateTimeStart.Enabled = false;
  461. }
  462. else
  463. {
  464. txtCreateTimeEnd.Enabled = true;
  465. txtCreateTimeStart.Enabled = true;
  466. }
  467. }
  468. #endregion
  469. #region 公共函数
  470. /// <summary>
  471. /// 查询可领用数据
  472. /// </summary>
  473. private void getCanUseData()
  474. {
  475. dataSet1.Clear();
  476. UltraGridRow uge = ultraGrid2.ActiveRow;
  477. if (uge == null)
  478. return;
  479. UsePlanD pupe = new UsePlanD();
  480. String strMrid = uge.Cells["MRID"].Value.ToString();
  481. UsePlanM up = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { strMrid });
  482. if (up == null)
  483. {
  484. MessageUtil.ShowTips("未发现领料单头:" + strMrid + "信息记录");
  485. return;
  486. }
  487. //txt_InvPhysic.Value = up.InvPhysic;
  488. //txt_ItemClass.Value = up.ItemClass;
  489. EntityPurPlanD pd = new EntityPurPlanD();
  490. if (String.IsNullOrEmpty(up.ItemClass))
  491. {
  492. //MessageUtil.ShowTips("领用单物料类别不能为空");
  493. return;
  494. }
  495. if (String.IsNullOrEmpty(up.InvPhysic))
  496. {
  497. MessageUtil.ShowTips("领用单库区不能为空");
  498. return;
  499. }
  500. if (String.IsNullOrEmpty(up.ReqOrgId))
  501. {
  502. MessageUtil.ShowTips("领用单需求部门不能为空");
  503. return;
  504. }
  505. if (showType == "1")
  506. {
  507. pd.UpdateName = up.ReqOrgId;
  508. }
  509. pd.ItemDescE = up.ItemClass;
  510. pd.DeleteName = up.InvPhysic;
  511. pd.ItemCode = txt_itemCode.Text.Trim();
  512. pd.ItemName = txt_itemName.Text.Trim();
  513. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.purplan.service.PurPlanDService", "getCanOutBillPlanDNew", new object[] { pd });
  514. DataTable dt2 = this.execute<DataTable>("com.hnshituo.pur.purplan.service.PurPlanDService", "getCanOutBillPlanRe1New", new object[] { pd });
  515. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  516. GridHelper.CopyDataToDatatable(dt2, dataTable4, true);
  517. foreach (DataRow rowq in dataTable1.Rows)
  518. {
  519. double QtyPur = 0;
  520. double QtyInstock = 0;
  521. double QtyNormal = 0;
  522. double QtyUnNormal = 0;
  523. double QtyUse = 0;
  524. double QtyWill = 0;
  525. double.TryParse(rowq["qty"].ToString(), out QtyPur);//采购计划数量
  526. double.TryParse(rowq["instockQty"].ToString(), out QtyInstock);//库存量
  527. double.TryParse(rowq["normalQty"].ToString(), out QtyNormal);//有主需求
  528. double.TryParse(rowq["unNormalQty"].ToString(), out QtyUnNormal);//无主需求
  529. double.TryParse(rowq["qtyYcUsed"].ToString(), out QtyUse);//已经领用量(所有部门)
  530. double.TryParse(rowq["QTYPURED"].ToString(), out QtyWill);//待领用量(所有部门)
  531. //double.TryParse(rowq["QTYLK"].ToString(), out QtyReqPur);//采购核准量
  532. double canUseQty = QtyInstock - QtyWill;//------供应部可以全部编制
  533. if (canUseQty <= 0)
  534. {
  535. rowq["canUseQty"] = 0;
  536. }
  537. else
  538. {
  539. rowq["canUseQty"] = canUseQty;
  540. }
  541. if (rowq["itemuom"].ToString() == "基吨")
  542. {
  543. rowq["itemuom"] = "吨";
  544. }
  545. }
  546. GridHelper.RefreshAndAutoSizeExceptColumns(ultraGrid1, new UltraGridColumn[] { ultraGrid1.DisplayLayout.Bands[0].Columns["check"], ultraGrid1.DisplayLayout.Bands[0].Columns["UseQty"], ultraGrid1.DisplayLayout.Bands[0].Columns["REMARKUSE"] });
  547. }
  548. /// <summary>
  549. /// 查询领用单主表
  550. /// </summary>
  551. private void getUserPlanM(String strMrId)
  552. {
  553. dataSet1.Clear();
  554. LYM.Clear();
  555. LYC.Clear();
  556. UsePlanM pupe = new UsePlanM();
  557. pupe.Status = txt_status_LY.Value == null ? "" : txt_status_LY.Value.ToString().Trim();
  558. pupe.MrId = txt_mrId_LY.Text.Trim();
  559. if (showType == "1")
  560. {
  561. pupe.ApplyReqOrgId = UserInfo.GetDeptid();
  562. }
  563. if (ck_ctime.Checked == true)
  564. {
  565. if (txtCreateTimeStart.Text != "")
  566. {
  567. pupe.CreateTime = Convert.ToDateTime(txtCreateTimeStart.Value);
  568. }
  569. if (txtCreateTimeEnd.Text != "")
  570. {
  571. pupe.DeleteTime = Convert.ToDateTime(txtCreateTimeEnd.Value);
  572. }
  573. }
  574. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.UsePlanMService", "find_UsePlanM", new object[] { pupe });
  575. GridHelper.CopyDataToDatatable(dt, dataTable2, true);
  576. GridHelper.RefreshAndAutoSize(ultraGrid2);
  577. if (!String.IsNullOrEmpty(strMrId))
  578. {
  579. publicPms.doActiveSelRow(ultraGrid2, "mrId", strMrId);
  580. }
  581. }
  582. /// <summary>
  583. /// 校验状态
  584. /// </summary>
  585. /// <param name="strMrId"></param>
  586. /// <returns></returns>
  587. private bool testStatusM(string strMrId, int i)
  588. {
  589. UsePlanM up = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { strMrId });
  590. if (up == null)
  591. {
  592. MessageUtil.ShowTips("未发现领料单头:" + strMrId + "信息记录");
  593. return false;
  594. }
  595. if (up.Validflag != "1")
  596. {
  597. MessageUtil.ShowTips("领料单头:" + strMrId + "信息记录可能已作废");
  598. return false;
  599. }
  600. if (up.CreateUserid != UserInfo.GetUserID())
  601. {
  602. MessageUtil.ShowTips("非本人创建领料单,无权限进行操作");
  603. return false;
  604. }
  605. //新增行
  606. if (i == 1)
  607. {
  608. if (up.Status != "1" && up.Status != "9")
  609. {
  610. MessageUtil.ShowTips("非提报和退回状态无法增删改");
  611. return false;
  612. }
  613. //UltraGridRow uge = ultraGrid2.ActiveRow;
  614. //if (uge == null)
  615. //{
  616. // MessageUtil.ShowTips("请选择领料单头");
  617. // return false;
  618. //}
  619. //String strinv = uge.Cells["invPhysic"].Value.ToString();
  620. //String strclass = uge.Cells["ITEMCLASS"].Value.ToString();
  621. //if (up.InvPhysic != strInvPhysic)
  622. //{
  623. // MessageUtil.ShowTips("非库区:" + strinv + "[" + up.InvPhysic + "] 物料,无法添加");
  624. // return false;
  625. //}
  626. //if (up.ItemClass != strItemClass)
  627. //{
  628. // MessageUtil.ShowTips("非物料类别:" + strclass + "[" + up.ItemClass + "] 物料,无法添加");
  629. // return false;
  630. //}
  631. }
  632. //完成移库操作
  633. else if (i == 6)
  634. {
  635. if (up.Status != "5")
  636. {
  637. MessageUtil.ShowTips("库房未出库,无法确认领用");
  638. return false;
  639. }
  640. }
  641. //撤回操作
  642. else if (i == 11)
  643. {
  644. if (up.Status != "2")
  645. {
  646. MessageUtil.ShowTips("不在待确认状态,无法撤回");
  647. return false;
  648. }
  649. }
  650. //删除操作
  651. else if (i == 10)
  652. {
  653. if (up.Status != "1" && up.Status != "9")
  654. {
  655. MessageUtil.ShowTips("不在待提报或者退回状态,无法删除");
  656. return false;
  657. }
  658. }
  659. //提报
  660. else if (i == 2)
  661. {
  662. if (up.Status != "1" && up.Status != "9")
  663. {
  664. MessageUtil.ShowTips("不在待提报状态,无法删除");
  665. return false;
  666. }
  667. UsePlanD pupe = new UsePlanD();
  668. pupe.MrId = strMrId;
  669. pupe.Validflag = "1";
  670. int count = this.execute<int>("com.hnshituo.pur.requireplan.service.UsePlanDService", "count", new object[] { pupe });
  671. if (count <= 0)
  672. {
  673. MessageUtil.ShowTips("请编制有效的行信息,无法删除");
  674. return false;
  675. }
  676. }
  677. else
  678. {
  679. MessageUtil.ShowTips("未知参数");
  680. return false;
  681. }
  682. return true;
  683. }
  684. #endregion
  685. #region 领用单行编辑区
  686. /// <summary>
  687. /// 查询按钮
  688. /// </summary>
  689. /// <param name="sender"></param>
  690. /// <param name="e"></param>
  691. private void btn_doQuery_canUse_Click(object sender, EventArgs e)
  692. {
  693. getCanUseData();
  694. }
  695. /// <summary>
  696. /// 添加按钮
  697. /// </summary>
  698. /// <param name="sender"></param>
  699. /// <param name="e"></param>
  700. private void btn_add_d_Click(object sender, EventArgs e)
  701. {
  702. try
  703. {
  704. UltraGridRow row = ultraGrid2.ActiveRow;
  705. if (row == null)
  706. return;
  707. String strMrId = row.Cells["MRID"].Value.ToString();
  708. if (String.IsNullOrEmpty(strMrId))
  709. {
  710. return;
  711. }
  712. UsePlanM up = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { strMrId });
  713. if (up == null)
  714. {
  715. MessageUtil.ShowTips("未发现领料单头:" + strMrId + "信息记录");
  716. return;
  717. }
  718. if (testStatusM(strMrId, 1)==false)
  719. {
  720. return;
  721. }
  722. ultraGrid1.UpdateData();
  723. //领用计划主表
  724. ArrayList al = new ArrayList();
  725. foreach (UltraGridRow uge in ultraGrid1.Rows)
  726. {
  727. if (!(bool)uge.Cells["Check"].Value)
  728. {
  729. continue;
  730. }
  731. int i = 0;
  732. foreach (UltraGridRow ugc in uge.ChildBands[0].Rows)
  733. {
  734. String strpurlineid = uge.Cells["mrLineId"].Value.ToString();
  735. String strReceiveId = ugc.Cells["ITEMSTANDARDSID"].Value.ToString();
  736. String strRequireId = ugc.Cells["ITEMUOMID"].Value.ToString();
  737. if (String.IsNullOrEmpty(strpurlineid))
  738. {
  739. MessageUtil.ShowTips("物料【" + uge.Cells["ITEMNAME"].Value.ToString() + "】的采购计划行为空");
  740. return;
  741. }
  742. if (String.IsNullOrEmpty(strRequireId))
  743. {
  744. MessageUtil.ShowTips("物料【" + uge.Cells["ITEMNAME"].Value.ToString() + "】的需求计划行号为空");
  745. return;
  746. }
  747. if (String.IsNullOrEmpty(strReceiveId))
  748. {
  749. MessageUtil.ShowTips("物料【" + uge.Cells["ITEMNAME"].Value.ToString() + "】的需求标识为空");
  750. return;
  751. }
  752. double bQty = 0;
  753. double.TryParse(ugc.Cells["useQtyReq"].Value.ToString(), out bQty);
  754. if (bQty <= 0)
  755. {
  756. continue;
  757. }
  758. double bQtyUnnor = 0;
  759. double.TryParse(ugc.Cells["unNormalQtyUse"].Value.ToString(), out bQtyUnnor);
  760. i = i + 1;
  761. double bBugprice = 0;//计划价
  762. double.TryParse(uge.Cells["Bugprice"].Value.ToString(), out bBugprice);
  763. double bPriceaverage = 0;//采购平均价
  764. double.TryParse(uge.Cells["BUDGETAMT"].Value.ToString(), out bPriceaverage);
  765. UsePlanD Upd = new UsePlanD();
  766. Upd.PurLineId = strpurlineid;
  767. Upd.Qty = bQty;//申请量
  768. Upd.QtyUnnormal = bQtyUnnor;//无主需求
  769. Upd.QtyUnnormalPur = 0;
  770. Upd.QtyUse = bQty;//统计量
  771. Upd.QtyPur = 0;//领用量
  772. Upd.Status = "1";//未出库
  773. Upd.PriceWithoutTaxAverage = bPriceaverage;
  774. Upd.ReceiveId = strReceiveId;
  775. Upd.PurRequireLineId = strRequireId;
  776. Upd.Validflag = "1";
  777. Upd.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
  778. Upd.CreateTime = DateTime.Now;
  779. Upd.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
  780. Upd.RemarkUse = uge.Cells["RemarkUse"].Value.ToString();
  781. al.Add(Upd);//添加领用单行标
  782. }
  783. if (i <= 0)
  784. {
  785. MessageUtil.ShowTips("物料【" + uge.Cells["ITEMNAME"].Value.ToString() + "】的未编制有效需求领用量");
  786. return;
  787. }
  788. }
  789. if (al.Count < 1)
  790. {
  791. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("请勾选需领用的物料");
  792. return;
  793. }
  794. if (MessageUtil.ShowYesNoAndQuestion("确定给领用单:" + strMrId + " 新增物料?") != DialogResult.Yes)
  795. {
  796. return;
  797. }
  798. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanDService", "insert_D", new object[] { strMrId,al });
  799. if (crt.Resultcode != 0)
  800. {
  801. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("添加失败:" + crt.Resultmsg);
  802. return;
  803. }
  804. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("添加成功!");
  805. getUserPlan(strMrId);
  806. getCanUseData();
  807. }
  808. catch (Exception ex)
  809. {
  810. MessageUtil.ShowTips("领用单生成失败!" + ex);
  811. return;
  812. }
  813. }
  814. /// <summary>
  815. /// 删除按钮
  816. /// </summary>
  817. /// <param name="sender"></param>
  818. /// <param name="e"></param>
  819. private void btn_delete_d_Click(object sender, EventArgs e)
  820. {
  821. try
  822. {
  823. UltraGridRow row = ultraGrid2.ActiveRow;
  824. if (row == null)
  825. return;
  826. String strMrId = row.Cells["MRID"].Value.ToString();
  827. UsePlanM up = this.execute<UsePlanM>("com.hnshituo.pur.requireplan.service.UsePlanMService", "findById", new object[] { strMrId });
  828. if (up == null)
  829. {
  830. MessageUtil.ShowTips("未发现领料单头:" + strMrId + "信息记录");
  831. return;
  832. }
  833. if (String.IsNullOrEmpty(strMrId))
  834. {
  835. return;
  836. }
  837. ultraGrid3.UpdateData();
  838. //领用计划主表
  839. ArrayList al = new ArrayList();
  840. foreach (UltraGridRow uge in ultraGrid3.Rows)
  841. {
  842. if (!(bool)uge.Cells["CHK"].Value)
  843. {
  844. continue;
  845. }
  846. String strpurlineid = uge.Cells["mrLineId"].Value.ToString();
  847. if (String.IsNullOrEmpty(strpurlineid))
  848. {
  849. MessageUtil.ShowTips("物料【" + uge.Cells["ITEMNAME"].Value.ToString() + "】的领用单行号为空");
  850. return;
  851. }
  852. UsePlanD Upd = new UsePlanD();
  853. Upd.MrLineId = strpurlineid;
  854. Upd.Validflag = "0";
  855. Upd.DeleteName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
  856. Upd.DeleteTime = DateTime.Now;
  857. Upd.DeleteUserid= CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
  858. al.Add(Upd);//添加领用单行标
  859. }
  860. if (al.Count < 1)
  861. {
  862. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("请勾选需领用的物料");
  863. return;
  864. }
  865. if (MessageUtil.ShowYesNoAndQuestion("确定删除上述共:"+al.Count+"条行信息?") != DialogResult.Yes)
  866. {
  867. return;
  868. }
  869. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.UsePlanDService", "delete_D", new object[] { strMrId,al });
  870. if (crt.Resultcode != 0)
  871. {
  872. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("删除失败!" + crt.Resultmsg);
  873. return;
  874. }
  875. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("删除成功!");
  876. getUserPlan(strMrId);
  877. getCanUseData();
  878. }
  879. catch (Exception ex)
  880. {
  881. MessageUtil.ShowTips("删除领用单行失败!" + ex);
  882. return;
  883. }
  884. }
  885. #endregion
  886. }
  887. }