frmPurUsePlan.cs 34 KB

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