FrmPurRePlanChangeNew.cs 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  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;using Pur.Entity;
  10. using Infragistics.Win.UltraWinGrid;
  11. using Infragistics.Win;
  12. using Core.Mes.Client.Comm.Control;
  13. using Core.Mes.Client.Comm;
  14. using Core.Mes.Client.Comm.Tool;
  15. using Pur.Entity.configureEntity;
  16. using System.Collections;
  17. using Pur.Entity.require_planEntiy;
  18. using com.hnshituo.pur.vo;
  19. using Infragistics.Win.UltraWinEditors;
  20. using CoreFS.SA06;
  21. namespace Pur.require_plan
  22. {
  23. public partial class FrmPurRePlanChangeNew: FrmPmsBase
  24. {
  25. private string tips1="0";
  26. ArrayList list = new ArrayList();//待编制的需求行
  27. ArrayList listItemAttr = new ArrayList();//待编制的物料属性
  28. DataTable dtAttr = new DataTable();
  29. DataTable dtUom = new DataTable();
  30. DataTable dtStandards = new DataTable();
  31. public string Tips //是否需要刷新界面
  32. {
  33. get { return tips1; }
  34. set { tips1 = value; }
  35. }
  36. public FrmPurRePlanChangeNew()
  37. {
  38. InitializeComponent();
  39. }
  40. public FrmPurRePlanChangeNew(OpeBase ob, ArrayList str)
  41. {
  42. this.ob = ob;
  43. this.list = str;
  44. InitializeComponent();
  45. }
  46. private void FrmPurRePlanChangeNew_Load(object sender, EventArgs e)
  47. {
  48. dtAttr.Columns.AddRange(new DataColumn[] { new DataColumn("Code"), new DataColumn("Desc") });
  49. dtAttr.PrimaryKey = new DataColumn[] { dtAttr.Columns["Code"] };
  50. dtUom.Columns.AddRange(new DataColumn[] { new DataColumn("Code"), new DataColumn("Desc") });
  51. dtUom.PrimaryKey = new DataColumn[] { dtUom.Columns["Code"] };
  52. dtStandards.Columns.AddRange(new DataColumn[] { new DataColumn("Code"), new DataColumn("Desc") });
  53. dtStandards.PrimaryKey = new DataColumn[] { dtStandards.Columns["Code"] };
  54. //ultraPanel2.Visible = false;
  55. ck_ftime.Checked = false;
  56. txt_ForcasTimeEnd.Enabled = false;
  57. txt_ForcasTimeStart.Enabled = false;
  58. txt_ForcasTimeEnd.Value = DateTime.Now.AddMonths(-2);
  59. txt_ForcasTimeStart.Value = DateTime.Now.AddDays(1);
  60. txt_UrgencyType.SelectedIndex = 0;
  61. //data_MrPeriodEnd.Enabled = false;
  62. if (DateTime.Now.Month == 2)
  63. {
  64. data_MrPeriodEnd.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/28")) ? DateTime.Parse(DateTime.Now.ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM"));
  65. }
  66. else
  67. {
  68. data_MrPeriodEnd.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/30")) ? DateTime.Parse(DateTime.Now.ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM"));
  69. }
  70. GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { "newitemUom", "newitemattr", "newitemStandardsCode", "CHECK", "LASTDELIVERYDATE" });
  71. GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[1], new string[] { });
  72. GridHelper.SetExcludeColumnsActive(ultraGrid2.DisplayLayout.Bands[0], new string[] { "UseQty","CHK" });
  73. GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], new string[] { "CHK" });
  74. ultraExpandableGroupBox1.Expanded = false;
  75. ck_hasOrderQty.Checked = true;
  76. initM();
  77. }
  78. #region 初始化区域
  79. //重新组合数据
  80. private void reConfig(DataTable dt)
  81. {
  82. try
  83. {
  84. dataSet1.Clear();
  85. dataSet2.Clear();
  86. dataSet3.Clear();
  87. DataTable dttest = dt.Copy();
  88. DataTable dt1 = dt.Copy();
  89. //删除父表中没有的需求订单行
  90. for (int i = 0; i < dttest.Rows.Count; i++)
  91. {
  92. String StrItemUnique = dttest.Rows[i]["newItemUnique"].ToString().Trim();
  93. int cou = 0;
  94. for (int j = dt.Rows.Count - 1; j >= 0; j--)
  95. {
  96. //DataRow rowt = dt.Rows[j];
  97. if (dt.Rows[j]["newItemUnique"].ToString().Trim() == StrItemUnique)
  98. {
  99. cou = cou + 1;
  100. if (cou == 1)
  101. {
  102. //rowt = dt.Rows[j];
  103. }
  104. if (cou >= 2)
  105. {
  106. //rowt["SQTYPUR"] = Convert.ToDouble(rowt["SQTYPUR"])+ Convert.ToDouble(dt.Rows[j]["SQTYPUR"]);
  107. //rowt["Num"] = Convert.ToDouble(rowt["Num"]) + Convert.ToDouble(dt.Rows[j]["Num"]);
  108. dt.Rows.RemoveAt(j);
  109. }
  110. }
  111. }
  112. }
  113. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  114. foreach (DataRow rows in dt1.Rows)
  115. {
  116. rows["qtypur"]=rows["qty"];
  117. }
  118. GridHelper.CopyDataToDatatable(dt1, dataTable2, true);
  119. foreach (UltraGridRow rowg in ultraGrid1.Rows)
  120. {
  121. if (rowg.HasChild())
  122. {
  123. double numall = 0;
  124. //double SQTYPURall = 0;
  125. foreach (UltraGridRow rowc in rowg.ChildBands[0].Rows)
  126. {
  127. numall = numall + Convert.ToDouble(rowc.GetCellValue("Qty"));
  128. //SQTYPURall = Convert.ToDouble(rowc.GetCellValue("SQTYPUR"));
  129. }
  130. rowg.Cells["Num"].Value = numall;
  131. rowg.Cells["SQTYPUR"].Value = numall;
  132. }
  133. }
  134. GridHelper.RefreshAndAutoSize(ultraGrid1);
  135. }
  136. catch (Exception ex)
  137. {
  138. MessageUtil.ShowTips("初始化或刷新界面失败:" + ex);
  139. }
  140. }
  141. #endregion
  142. #region 界面事件
  143. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  144. {
  145. if (ultraGrid1.ActiveRow != null && !ultraGrid1.ActiveRow.HasParent())
  146. {
  147. UltraGridRow row = ultraGrid1.ActiveRow;
  148. //非激活本行
  149. foreach (UltraGridRow rows in ultraGrid1.DisplayLayout.Bands[0].GetRowEnumerator(GridRowType.DataRow))
  150. {
  151. if (rows.GetCellValue("id").ToString() != row.GetCellValue("id").ToString())
  152. {
  153. rows.Cells["newitemStandardsCode"].Value = rows.Cells["newitemStandardsCode"].Text;
  154. rows.Cells["newitemAttr"].Value = rows.Cells["newitemAttr"].Text;
  155. rows.Cells["newItemUom"].Value = rows.Cells["newItemUom"].Text;
  156. }
  157. }
  158. //更具子行调整填写dt
  159. dtAttr.Clear();
  160. dtStandards.Clear();
  161. dtUom.Clear();
  162. foreach (UltraGridRow rowc in row.ChildBands[0].Rows)
  163. {
  164. //填充dropDownlist源数据
  165. if (!dtAttr.Rows.Contains(rowc.GetCellValue("itemAttrId")) && rowc.GetCellValue("itemAttrId").ToString().Trim() != "")
  166. {
  167. dtAttr.Rows.Add(rowc.GetCellValue("itemAttrId"), rowc.GetCellValue("itemAttr"));
  168. }
  169. if (!dtUom.Rows.Contains(rowc.GetCellValue("itemUomId")) && rowc.GetCellValue("itemUomId").ToString().Trim() != "")
  170. {
  171. dtUom.Rows.Add(rowc.GetCellValue("itemUomId"), rowc.GetCellValue("itemUom"));
  172. }
  173. if (!dtStandards.Rows.Contains(rowc.GetCellValue("itemStandardsId")) && rowc.GetCellValue("itemStandardsId").ToString().Trim() != "")
  174. {
  175. dtStandards.Rows.Add(rowc.GetCellValue("itemStandardsId"), rowc.GetCellValue("itemStandardsCode"));
  176. }
  177. }
  178. //激活本行
  179. String strItemCode = row.GetCellValue("itemCode").ToString().Trim();
  180. String strnewitemAttr = row.GetCellValue("newitemAttr").ToString().Trim();
  181. String strnewitemStandardsCode = row.GetCellValue("newitemStandardsCode").ToString().Trim();
  182. String strnewItemUom = row.GetCellValue("newItemUom").ToString().Trim();
  183. String strnewitemStandardsId = row.GetCellValue("newitemStandardsId").ToString().Trim();
  184. String strnewitemAttrId = row.GetCellValue("newitemAttrId").ToString().Trim();
  185. String strnewitemUomId = row.GetCellValue("newitemUomId").ToString().Trim();
  186. getDropDownListData(strItemCode);
  187. //row.Cells["newitemStandardsCode"].Value = row.GetCellValue("newitemStandardsId").ToString().Trim();
  188. //row.Cells["newitemAttr"].Value = row.GetCellValue("newitemAttrId").ToString().Trim();
  189. //row.Cells["newItemUom"].Value = row.GetCellValue("newitemUomId").ToString().Trim();
  190. row.Cells["newitemStandardsCode"].Value = strnewitemStandardsCode;
  191. row.Cells["newitemAttr"].Value = strnewitemAttr;
  192. row.Cells["newItemUom"].Value = strnewItemUom;
  193. ultraGrid1.UpdateData();
  194. }
  195. }
  196. // 数量输入
  197. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  198. {
  199. if (e.Cell.Column.Key.Equals("newItemAttr") && !e.Cell.Row.HasParent())
  200. {
  201. itemAttrValueChange();
  202. }
  203. if (e.Cell.Column.Key.Equals("newItemUom") && !e.Cell.Row.HasParent())
  204. {
  205. itemUomValueChange();
  206. }
  207. if (e.Cell.Column.Key.Equals("newItemStandardsCode") && !e.Cell.Row.HasParent())
  208. {
  209. standardsValueChange();
  210. }
  211. //采购数据计算
  212. double qt = 0;
  213. if (e.Cell.Column.Key.Equals("qtyPur") && e.Cell.Row.HasParent())
  214. {
  215. object oldv = e.Cell.Row.Cells["qtyPur"].Value;
  216. ultraGrid1.UpdateData();
  217. object newv = e.Cell.Row.Cells["qtyPur"].Value;
  218. double reqty = Convert.ToDouble(e.Cell.Row.Cells["qty"].Value);
  219. if (newv != DBNull.Value)
  220. {
  221. if (Convert.ToDouble(newv) > reqty)
  222. {
  223. e.Cell.Row.Cells["qtyPur"].Value = oldv;
  224. return;
  225. }
  226. }
  227. string str = e.Cell.Row.Cells["newItemUnique"].Value.ToString();
  228. foreach (UltraGridRow cRow in e.Cell.Row.ParentRow.ChildBands[0].Rows)
  229. {
  230. if (cRow.Cells["qtyPur"].Value != DBNull.Value)
  231. {
  232. qt = qt + Convert.ToDouble(cRow.Cells["qtyPur"].Value);
  233. }
  234. }
  235. qt = qt + (e.Cell.Row.ParentRow.Cells["qtyYc"].Value == DBNull.Value ? 0 : Convert.ToDouble(e.Cell.Row.ParentRow.Cells["qtyYc"].Value));
  236. e.Cell.Row.ParentRow.Cells["SQTYPUR"].Value = qt;
  237. return;
  238. }
  239. ////利库计算
  240. //if (e.Cell.Column.Key.Equals("qtyLk") && !e.Cell.Row.HasParent())
  241. //{
  242. // object oldv = e.Cell.Row.Cells["qtyLk"].Value;
  243. // ultraGrid1.UpdateData();
  244. // object newlk = e.Cell.Row.Cells["qtyLk"].Value;
  245. // object newYc = e.Cell.Row.Cells["qtyYc"].Value;
  246. // foreach (UltraGridRow cRow in e.Cell.Row.ChildBands[0].Rows)
  247. // {
  248. // if (cRow.Cells["qtyPur"].Value != DBNull.Value)
  249. // {
  250. // qt = qt + Convert.ToDouble(cRow.Cells["qtyPur"].Value);
  251. // }
  252. // }
  253. // // object purqty = e.Cell.Row.Cells["SQTYPUR"].Value;
  254. // qt = qt - (newlk == DBNull.Value ? 0 : Convert.ToDouble(newlk)) + (newYc == DBNull.Value ? 0 : Convert.ToDouble(newYc));
  255. // if (qt < 0)
  256. // {
  257. // e.Cell.Row.Cells["qtyLk"].Value = oldv;
  258. // return;
  259. // }
  260. // e.Cell.Row.Cells["SQTYPUR"].Value = qt;
  261. // return;
  262. //}
  263. if (e.Cell.Column.Key.Equals("qtyYc") && !e.Cell.Row.HasParent())
  264. {
  265. ultraGrid1.UpdateData();
  266. //object newlk = e.Cell.Row.Cells["qtyLk"].Value;
  267. object newYc = e.Cell.Row.Cells["qtyYc"].Value;
  268. foreach (UltraGridRow cRow in e.Cell.Row.ChildBands[0].Rows)
  269. {
  270. if (cRow.Cells["qtyPur"].Value != DBNull.Value)
  271. {
  272. qt = qt + Convert.ToDouble(cRow.Cells["qtyPur"].Value);
  273. }
  274. }
  275. // object purqty = e.Cell.Row.Cells["SQTYPUR"].Value;
  276. qt = qt + (newYc == DBNull.Value ? 0 : Convert.ToDouble(newYc));
  277. e.Cell.Row.Cells["SQTYPUR"].Value = qt;
  278. return;
  279. }
  280. }
  281. // 数量输入
  282. //private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  283. //{
  284. // ultraGrid1.UpdateData();
  285. // if (e.Cell.Column.Key.Equals("qtyPur"))
  286. // {
  287. // double qt = 0;
  288. // string str = e.Cell.Row.Cells["ITEMCODE"].Value.ToString();
  289. // foreach (UltraGridRow uRows in ultraGrid1.Rows)
  290. // {
  291. // if (uRows.Cells["ITEMCODE"].Value.ToString() == str)
  292. // {
  293. // foreach (UltraGridRow cRow in uRows.ChildBands[0].Rows)
  294. // {
  295. // if (cRow.Cells["qtyPur"].Value.ToString() != "")
  296. // {
  297. // qt = qt + Convert.ToDouble(cRow.Cells["qtyPur"].Value);
  298. // }
  299. // }
  300. // uRows.Cells["SQTYPUR"].Value = qt;
  301. // return;
  302. // }
  303. // }
  304. // }
  305. //}
  306. // 物料属性选择事件
  307. private void cmb_itemAttr_ValueChanged(object sender, EventArgs e)
  308. {
  309. itemAttrValueChange();
  310. }
  311. private void itemAttrValueChange()
  312. {
  313. //根据获取来得改变新属性编码
  314. if (ultraGrid1.ActiveRow != null && !ultraGrid1.ActiveRow.HasParent())
  315. {
  316. ultraGrid1.UpdateData();
  317. UltraGridRow uge = ultraGrid1.ActiveRow;
  318. string strnewItemAttrId = uge.GetCellValue("newItemAttr").ToString().Trim();
  319. uge.Cells["newItemAttrId"].Value = strnewItemAttrId;
  320. //生成新unique
  321. //uge.Cells["newItemStandardsId"].Value = uge.GetCellValue("newItemStandardsCode").ToString().Trim();
  322. uge.Cells["newItemUnique"].Value = uge.GetCellValue("itemCode").ToString().Trim() + "@" + strnewItemAttrId + "@" + uge.GetCellValue("newItemStandardsId").ToString().Trim() + "@" + uge.GetCellValue("newItemUomId").ToString().Trim();
  323. ultraGrid1.UpdateData();
  324. }
  325. }
  326. // 物料采购单位选择事件
  327. private void cmb_Uom_ValueChanged(object sender, EventArgs e)
  328. {
  329. itemUomValueChange();
  330. }
  331. private void itemUomValueChange()
  332. {
  333. //根据获取来得改变新单位编码,库存单位,转化系数
  334. if (ultraGrid1.ActiveRow != null && !ultraGrid1.ActiveRow.HasParent())
  335. {
  336. UltraGridRow uge = ultraGrid1.ActiveRow;
  337. //获取改变之前的转化系数
  338. double oldCon = Convert.ToDouble(uge.GetCellValue("ItemUomConefficient").ToString().Trim());
  339. ultraGrid1.UpdateData();
  340. String strnewItemUomId = uge.GetCellValue("newItemUom").ToString().Trim();
  341. //需改变数量
  342. PurMatUomsEntity dt_matUOM = this.execute<PurMatUomsEntity>("com.hnshituo.pur.configure.service.MatUomsService", "findById", new object[] { strnewItemUomId });
  343. if (dt_matUOM == null)
  344. {
  345. return;
  346. }
  347. double newCon = (double)dt_matUOM.ItemUomConefficient;
  348. double oldQtyPur = Convert.ToDouble(uge.GetCellValue("QtyPur").ToString().Trim());
  349. double newQtyPur=0;
  350. if (oldCon != newCon)
  351. {
  352. newQtyPur = oldQtyPur * oldCon / newCon;
  353. uge.Cells["QtyPur"].Value = newQtyPur;
  354. uge.Cells["ItemUomConefficient"].Value = newCon;
  355. }
  356. uge.Cells["newItemUomId"].Value = strnewItemUomId;//记录新的单位换算ID
  357. //uge.Cells["newItemStandardsId"].Value = uge.GetCellValue("newItemStandardsCode").ToString().Trim();
  358. uge.Cells["newItemUnique"].Value = uge.GetCellValue("itemCode").ToString().Trim() + "@" + uge.GetCellValue("newItemAttrId").ToString().Trim() + "@" + uge.GetCellValue("newItemStandardsId").ToString().Trim() + "@" + strnewItemUomId;
  359. ultraGrid1.UpdateData();
  360. }
  361. }
  362. // 物料标准值选择事件
  363. private void cmb_standard_ValueChanged(object sender, EventArgs e)
  364. {
  365. standardsValueChange();
  366. }
  367. private void standardsValueChange()
  368. {
  369. //根据获取来得改变新编制编码
  370. if (ultraGrid1.ActiveRow != null && !ultraGrid1.ActiveRow.HasParent())
  371. {
  372. ultraGrid1.UpdateData();
  373. UltraGridRow uge = ultraGrid1.ActiveRow;
  374. String strnewItemStandardsId = uge.GetCellValue("newItemStandardsCode").ToString().Trim();
  375. uge.Cells["newItemStandardsId"].Value = strnewItemStandardsId;
  376. uge.Cells["newItemUnique"].Value = uge.GetCellValue("itemCode").ToString().Trim() + "@" + uge.GetCellValue("newItemAttrId").ToString().Trim() + "@" + strnewItemStandardsId + "@" + uge.GetCellValue("newItemUomId").ToString().Trim();
  377. ultraGrid1.UpdateData();
  378. }
  379. }
  380. #endregion
  381. #region 工具栏事件
  382. //展开
  383. private void btn_doExit_Click(object sender, EventArgs e)
  384. {
  385. ultraGrid1.Rows.ExpandAll(true);
  386. }
  387. //刷新界面
  388. private void btn_doRefash_Click(object sender, EventArgs e)
  389. {
  390. initM();
  391. }
  392. //初始化
  393. private void initM()
  394. {
  395. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "getReceivedReqByList", new object[] { list });
  396. foreach (DataRow row in dt.Rows)
  397. {
  398. row["itemDescE"] = Convert.ToDateTime(row["itemDescE"]).ToString("yyyy/MM");
  399. }
  400. dt.Columns.Add("newItemUom", Type.GetType("System.String"));
  401. dt.Columns.Add("newWeightUnit", Type.GetType("System.String"));
  402. dt.Columns.Add("newITEMUOMCONEFFICIENT", Type.GetType("System.String"));
  403. dt.Columns.Add("newItemUomId", Type.GetType("System.String"));
  404. dt.Columns.Add("newItemStandardsCode", Type.GetType("System.String"));
  405. dt.Columns.Add("newItemStandardsId", Type.GetType("System.String"));
  406. dt.Columns.Add("newItemAttrId", Type.GetType("System.String"));
  407. dt.Columns.Add("newItemAttr", Type.GetType("System.String"));
  408. dt.Columns.Add("newItemUnique", Type.GetType("System.String"));
  409. foreach (DataRow rows in dt.Rows)
  410. {
  411. rows["newItemUnique"] = rows["itemUnique"];
  412. rows["newItemUomId"] = rows["itemUomId"];
  413. rows["newItemUom"] = rows["itemUom"];
  414. rows["newWeightUnit"] = rows["weightUnit"];
  415. rows["newITEMUOMCONEFFICIENT"] = rows["ITEMUOMCONEFFICIENT"];
  416. rows["newItemStandardsCode"] = rows["itemStandardsCode"];
  417. rows["newItemStandardsId"] = rows["itemStandardsId"];
  418. rows["newItemAttrId"] = rows["itemAttrId"];
  419. rows["newItemAttr"] = rows["itemAttr"];
  420. }
  421. reConfig(dt);
  422. }
  423. //确定按钮
  424. private void btn_doSaveChange_Click(object sender, EventArgs e)
  425. {
  426. ultraGrid1.UpdateData();
  427. doChange();
  428. }
  429. //调整
  430. private void doChange()
  431. {
  432. if (ultraGrid1.Rows.Count > 0)
  433. {
  434. try
  435. {
  436. //调整前数据判定
  437. int i = 0;
  438. string strItemCode = "";
  439. foreach (UltraGridRow rows in ultraGrid1.Rows)
  440. {
  441. if (Convert.ToBoolean(rows.GetCellValue("CHECK")))
  442. {
  443. i = i + 1;
  444. if (i != 1)
  445. {
  446. if (rows.GetCellValue("itemCode").ToString().Trim() != strItemCode)
  447. {
  448. MessageUtil.ShowTips("只能合并相同物料!");
  449. rows.Activate();
  450. return;
  451. }
  452. }
  453. else
  454. {
  455. strItemCode = rows.GetCellValue("itemCode").ToString().Trim();
  456. }
  457. }
  458. }
  459. if (i == 0)
  460. {
  461. MessageUtil.ShowTips("请选择需调整的需求行");
  462. return;
  463. }
  464. //保存调整数据
  465. DataTable dtC = dataTable2.Copy();
  466. //调整数据
  467. int j = 0;
  468. String strnewitemAttr = "";
  469. String strnewitemStandardsCode = "";
  470. String strnewItemUom = "";
  471. String strnewWeightUnit = "";
  472. String strnewITEMUOMCONEFFICIENT = "";
  473. String strnewitemStandardsId = "";
  474. String strnewitemAttrId = "";
  475. String strnewitemUomId = "";
  476. String strnewItemUnique = "";
  477. foreach (UltraGridRow row in ultraGrid1.Rows)
  478. {
  479. if (Convert.ToBoolean(row.GetCellValue("CHECK")))
  480. {
  481. j = j + 1;
  482. if (j == 1)
  483. {
  484. strnewitemStandardsId = row.GetCellValue("newitemStandardsId").ToString().Trim();
  485. strnewitemStandardsCode = row.GetCellValue("newitemStandardsCode").ToString().Trim();
  486. strnewItemUom = row.GetCellValue("newItemUom").ToString().Trim();
  487. strnewWeightUnit = row.GetCellValue("newWeightUnit").ToString().Trim();
  488. strnewITEMUOMCONEFFICIENT = row.GetCellValue("newITEMUOMCONEFFICIENT").ToString().Trim();
  489. strnewitemUomId = row.GetCellValue("newitemUomId").ToString().Trim();
  490. strnewitemStandardsId = row.GetCellValue("newitemStandardsId").ToString().Trim();
  491. strnewitemAttrId = row.GetCellValue("newitemAttrId").ToString().Trim();
  492. strnewitemAttr = row.GetCellValue("newitemAttr").ToString().Trim();
  493. strnewitemUomId = row.GetCellValue("newitemUomId").ToString().Trim();
  494. strnewItemUnique = row.GetCellValue("newItemUnique").ToString().Trim();
  495. }
  496. //开始调整操作---对所有的子行进行调整
  497. foreach (UltraGridRow rowChild in row.ChildBands[0].Rows)
  498. {
  499. String strId = rowChild.GetCellValue("id").ToString().Trim();
  500. //DataRow[] rows = dt_Purmatclass.Select("PID='" + Tnode.Key + "'");
  501. DataRow[] roww = dtC.Select("id='" + strId + "'");
  502. if (roww.Count() != 1)
  503. {
  504. MessageUtil.ShowTips("发现" + roww.Count()+"条" + strId + "接收需求计划行,数据异常!");
  505. }
  506. roww[0]["newitemStandardsId"] = strnewitemStandardsId;
  507. roww[0]["newitemStandardsCode"] = strnewitemStandardsCode;
  508. roww[0]["newItemUom"] = strnewItemUom;
  509. roww[0]["newWeightUnit"] = strnewWeightUnit;
  510. roww[0]["newITEMUOMCONEFFICIENT"] = strnewITEMUOMCONEFFICIENT;
  511. roww[0]["newitemUomId"] = strnewitemUomId;
  512. roww[0]["newitemStandardsId"] = strnewitemStandardsId;
  513. roww[0]["newitemAttrId"] = strnewitemAttrId;
  514. roww[0]["newitemAttr"] = strnewitemAttr;
  515. roww[0]["newitemUomId"] = strnewitemUomId;
  516. roww[0]["newItemUnique"] = strnewItemUnique;
  517. roww[0]["itemUnique"] = strnewItemUnique;
  518. }
  519. }
  520. }
  521. //重组数据
  522. if (MessageUtil.ShowYesNoAndQuestion("确定调整?") != DialogResult.Yes)
  523. {
  524. return;
  525. }
  526. reConfig(dtC);
  527. ultraGrid1.Refresh();
  528. }
  529. catch (Exception ex)
  530. {
  531. MessageUtil.ShowTips("调整失败:" + ex);
  532. }
  533. }
  534. }
  535. //编制采购计划
  536. private void doCreate()
  537. {
  538. //校验月份
  539. if (data_MrPeriodEnd.Text == "")
  540. {
  541. MessageUtil.ShowTips("计划月份不能为空");
  542. data_MrPeriodEnd.Focus();
  543. return;
  544. }
  545. if (txt_UrgencyType.SelectedIndex == -1)
  546. {
  547. MessageUtil.ShowTips("请选择采购计划紧急程度类型!");
  548. txt_UrgencyType.Focus();
  549. return;
  550. }
  551. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "getReceivedReqByList", new object[] { list });
  552. if (txt_UrgencyType.Value.ToString().Trim() != "1")
  553. {
  554. foreach (DataRow rr in dt.Rows)
  555. {
  556. if (Convert.ToDateTime(rr["itemDescE"]) > Convert.ToDateTime(data_MrPeriodEnd.Value))
  557. {
  558. MessageUtil.ShowTips("需求计划行:" + rr["mrLineId"] + "的计划月份需小于待生成采购计划的计划月份!");
  559. data_MrPeriodEnd.Focus();
  560. return;
  561. }
  562. }
  563. }
  564. string strPurId = "";//采购单号
  565. string strYcMrId = "";//预采需求单号
  566. int tips = 0; //生成预采需求单行号
  567. try
  568. {
  569. strPurId = this.execute<string>("com.hnshituo.pur.utils.service.UtilsService", "genMrId", new object[] { 2 });
  570. EntityPurPlanM PPM_Entity = new EntityPurPlanM();
  571. PPM_Entity.MrId = strPurId;
  572. PPM_Entity.CreateName = UserInfo.GetUserName();
  573. PPM_Entity.CreateTime = DateTime.Now;
  574. PPM_Entity.CreateUserid = UserInfo.GetUserID();
  575. PPM_Entity.Validflag = "1";
  576. PPM_Entity.Status = "1";
  577. PPM_Entity.PlanType = "2";
  578. PPM_Entity.MrPeriodEnd = DateTime.Parse(Convert.ToDateTime(data_MrPeriodEnd.Value).ToString("yyyy/MM"));
  579. //PPM_Entity.MrPeriodEnd = Convert.ToDateTime(data_MrPeriodEnd.Value);
  580. PPM_Entity.ReqOrgName = UserInfo.GetDepartment();
  581. PPM_Entity.ReqOrgId = UserInfo.GetDeptid();
  582. PPM_Entity.UrgencyType = txt_UrgencyType.Value.ToString().Trim();
  583. PPM_Entity.PurType = "2";//采购类型,1预采,2普采
  584. IQueryable<UltraGridRow> uge = ultraGrid1.Rows.AsQueryable().Where("itemUnique != null");
  585. int i = 1;
  586. int j = 1;
  587. ArrayList listRpD = new ArrayList();//需求计划行
  588. ArrayList listReceiveRpD = new ArrayList();//接收需求计划行
  589. ArrayList listPpd = new ArrayList();//采购计划行
  590. //ArrayList ListYcReq = new ArrayList();//预采需求计划行
  591. //RequirePlanM rem = new RequirePlanM();//预采需求计划头
  592. foreach (UltraGridRow uRows in uge)
  593. {
  594. double b = 0;
  595. string mu = "";
  596. string u = i.ToString();
  597. while (u.Length < 3)
  598. {
  599. u = "0" + u;
  600. }
  601. mu += u;
  602. i++;
  603. //string mid = this.execute<string>("com.hnshituo.pur.utils.service.UtilsService", "getOddNumber", new object[] { "PUR_PUR_PLAN_D", "MR_LINE_ID", str+"-", "3" });
  604. MatEntity Mat = new MatEntity();
  605. EntityPurPlanD EppD = new EntityPurPlanD();
  606. EppD.MrId = strPurId;
  607. EppD.MrLineId = strPurId + "-" + mu;
  608. EppD.CreateName = UserInfo.GetUserName();
  609. EppD.CreateUserid = UserInfo.GetUserID();
  610. EppD.Validflag = "1";
  611. EppD.CreateTime = DateTime.Now;
  612. EppD.QtyYc = uRows.Cells["QtyYc"].Value == DBNull.Value ? b : (Convert.ToDouble(uRows.Cells["QtyYc"].Value));
  613. EppD.QtyYcUseable = EppD.QtyYc;//可分配数量
  614. EppD.QtyYcUsed = 0;//已分配数量
  615. EppD.PaymentCode = "110402";//默认付款方式
  616. EppD.PackageType = "110702";//默认包装方式
  617. EppD.ItemCode = uRows.Cells["ItemCode"].Value.ToString();
  618. EppD.ItemName = uRows.Cells["ItemName"].Value.ToString();
  619. EppD.ItemUom = uRows.Cells["newItemUom"].Text.ToString();
  620. EppD.ItemAttrId = uRows.Cells["newITEMATTRID"].Value.ToString();//物料属性编码
  621. EppD.ItemAttr = uRows.Cells["newITEMATTR"].Text.ToString();//物料属性名称
  622. EppD.ItemUomConefficient = Convert.ToDouble(uRows.Cells["newItemUomConefficient"].Value);
  623. EppD.WeightUnit = uRows.Cells["newWeightUnit"].Value.ToString();
  624. EppD.BugPrice = uRows.Cells["BugPrice"].Value == DBNull.Value ? b : Convert.ToDouble(uRows.Cells["BugPrice"].Value);
  625. EppD.Qty = uRows.Cells["SQTYPUR"].Value == DBNull.Value ? b : (Convert.ToDouble(uRows.Cells["SQTYPUR"].Value));
  626. EppD.QtyPur = EppD.Qty;
  627. EppD.BudgetAmt = EppD.BugPrice * EppD.Qty * EppD.ItemUomConefficient;
  628. EppD.AskDeliverDate = Convert.ToDateTime(uRows.Cells["LASTDELIVERYDATE"].Value.ToString().Trim());
  629. //2016年3月1号的新增leitao
  630. EppD.ItemStandardsCode =uRows.Cells["newItemStandardsCode"].Text.ToString().Trim();
  631. EppD.ItemStandardsId = uRows.Cells["newItemStandardsId"].Value.ToString().Trim();
  632. EppD.ItemUnique = uRows.Cells["newItemUnique"].Value.ToString().Trim();
  633. EppD.ItemUomId = uRows.Cells["newItemUomId"].Value.ToString().Trim();
  634. if ((EppD.Qty) > 0)
  635. {
  636. listPpd.Add(EppD);
  637. }
  638. //关系表和更新接收需求计划行
  639. //IQueryable<UltraGridRow> checkRow = uRows.ChildBands[0].Rows.AsQueryable().Where("itemUnique != null ");
  640. foreach (UltraGridRow cRow in uRows.ChildBands[0].Rows)
  641. {
  642. double db=cRow.Cells["qtyPur"].Value == DBNull.Value ? 0 : Convert.ToDouble(cRow.Cells["qtyPur"].Value);
  643. if (db > 0)
  644. {
  645. ////插入关系表
  646. //ReqPurPlanR ReqR = new ReqPurPlanR();
  647. //ReqR.PurLineId = EppD.MrLineId;
  648. //ReqR.CreateTime = DateTime.Now;
  649. //ReqR.RequireLineId = cRow.Cells["Id"].Value.ToString();//接收需求计划行信息
  650. //ReqR.ID = cRow.Cells["Id"].Value.ToString() + EppD.MrLineId;
  651. //listRr.Add(ReqR);
  652. //更新接收需求表
  653. RequireReceive ReqRev = new RequireReceive();
  654. ReqRev.MrLineId = cRow.Cells["MrLineId"].Value.ToString();
  655. ReqRev.Id = cRow.Cells["id"].Value.ToString();
  656. ReqRev.QtyPur = cRow.Cells["qtyPur"].Value == DBNull.Value ? 0 : Convert.ToDouble(cRow.Cells["qtyPur"].Value);//默认的需求数量
  657. ReqRev.Status = "2";//已编制
  658. ReqRev.PurLineId = EppD.MrLineId;//绑定采购计划行
  659. ReqRev.LjhTime = DateTime.Now;
  660. listReceiveRpD.Add(ReqRev);
  661. //更新需求计划
  662. RequirePlanD ReqD = new RequirePlanD();
  663. ReqD.MrLineId = cRow.Cells["MrLineId"].Value.ToString();
  664. ReqD.FlagGeneratedPurPlan = "4";
  665. listRpD.Add(ReqD);
  666. //校验接收需求计划行
  667. //校验需求计划行
  668. }
  669. }
  670. //生成预采需求计划
  671. //if (EppD.QtyYc > 0)
  672. //{
  673. // if (tips == 0)
  674. // {
  675. // //生成需求单号
  676. // strYcMrId = this.execute<string>("com.hnshituo.pur.utils.service.UtilsService", "genMrId", new object[] { 1 });
  677. // rem.CreateName = UserInfo.GetUserName();
  678. // rem.CreateUserid = UserInfo.GetUserID();
  679. // rem.CreateTime = DateTime.Now;
  680. // rem.Status = "1";
  681. // //ReqM.ReqOrgId = txt_REQ_ORG_ID.Text;
  682. // //ReqM.ReqOrgName = txt_REQORGNAME.Text;
  683. // //rem.MrPeriodEnd = Convert.ToDateTime(txt_MRPERIODEND.Text).Date;
  684. // //rem.MrPeriodStart = Convert.ToDateTime(txt_MRPERIODSTART.Text).Date;
  685. // rem.UrgencyType = "1";
  686. // rem.ReqOrgName = UserInfo.GetDepartment();//申请者机构名称
  687. // rem.ReqOrgId = UserInfo.GetDeptid();//申请者机构ID
  688. // rem.Validflag = "1";
  689. // rem.RequireType = "122102";//生产性物料预采,系统自动生成
  690. // rem.MrId = strYcMrId;
  691. // }
  692. // tips = tips + 1;
  693. // RequirePlanD ReqD = new RequirePlanD();
  694. // string mu1 = "";
  695. // string u1 = j.ToString();
  696. // while (u1.Length < 3)
  697. // {
  698. // u1 = "0" + u1;
  699. // }
  700. // mu1 += u1;
  701. // j++;
  702. // //ReqD.MrLineId = this.execute<string>("com.hnshituo.pur.requireplan.service.RequirePlanDService", "ReqMrLineId", new object[] { strYcMrId + "-" });//需求单行号//getCodeId(ultraGrid1.ActiveRow.Cells["mrId"].Value.ToString());
  703. // ReqD.MrLineId = strYcMrId + "-" + mu1;
  704. // ReqD.MrId = strYcMrId;
  705. // ReqD.ItemCode = EppD.ItemCode;
  706. // ReqD.ItemName = EppD.ItemName;
  707. // ReqD.Remark = "由预采补充需求计划行信息";
  708. // ReqD.BugPrice = EppD.BugPrice;
  709. // ReqD.ItemAttr = EppD.ItemAttr;//属性名称
  710. // ReqD.ItemUom = EppD.ItemUom;
  711. // ReqD.WeightUnit = EppD.WeightUnit;
  712. // ReqD.ItemUomConefficient = EppD.ItemUomConefficient;
  713. // ReqD.BuyerDeptCode = "";
  714. // ReqD.BuyerDeptDesc = "";
  715. // ReqD.BuyerUnitCode = "";
  716. // ReqD.BuyerUnitDesc = "";
  717. // ReqD.Validflag = "1";
  718. // ReqD.Qty = EppD.QtyYc;
  719. // ReqD.QtyPur = EppD.QtyYc;
  720. // ReqD.BudgetAmt = EppD.QtyYc * (ReqD.BugPrice == null ? 0 : ReqD.BugPrice);
  721. // ReqD.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
  722. // ReqD.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
  723. // ReqD.CreateTime = DateTime.Now;
  724. // ReqD.FlagGeneratedPurPlan = "1";
  725. // //ReqD.LastDeliveryDate = EppD.;
  726. // //2016年2月28新增leitao
  727. // ReqD.DeliveryLocationFlag = "0";
  728. // ReqD.DeliveryLocation = "";
  729. // ReqD.DeliveryLocationCode = "";
  730. // ReqD.ItemStandardsCode = EppD.ItemStandardsCode;
  731. // ReqD.ItemStandardsId = EppD.ItemStandardsId;
  732. // ReqD.ItemUomId = EppD.ItemUomId;
  733. // ReqD.ItemAttrId = EppD.ItemAttrId;
  734. // ReqD.ItemUnique = EppD.ItemUnique;
  735. // ReqD.AuditFlag = "1";
  736. // ReqD.AuditMsg = "默认审批通过";
  737. // ListYcReq.Add(ReqD);
  738. // //插入关系表
  739. // ReqPurPlanR ReqR = new ReqPurPlanR();
  740. // ReqR.PurLineId = EppD.MrLineId;
  741. // ReqR.CreateTime = DateTime.Now;
  742. // ReqR.RequireLineId = ReqD.MrLineId;
  743. // ReqR.ID = ReqD.MrLineId + EppD.MrLineId;
  744. // listRr.Add(ReqR);
  745. //}
  746. }
  747. if (MessageUtil.ShowYesNoAndQuestion("确定生成采购计划?") != DialogResult.Yes)
  748. {
  749. return;
  750. }
  751. CoreResult rt = this.execute<CoreResult>("com.hnshituo.pur.purplan.service.PurPlanDService", "insert_four_New", new object[] { PPM_Entity, listRpD, listPpd,listReceiveRpD });
  752. if (rt.Resultcode != 0)
  753. {
  754. Core.Mes.Client.Comm.Tool.MessageUtil.ShowWarning("生成采购计划失败! " + rt.Resultmsg);
  755. return;
  756. }
  757. if (tips > 0)
  758. {
  759. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("成功,已生成采购计划: " + strPurId + " 和需求计划(预采-系统):" + strYcMrId + "");
  760. tips1 = "1";
  761. this.Close();
  762. }
  763. else
  764. {
  765. Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("操作成功,已生成采购计划: " + strPurId + " ");
  766. tips1 = "1";
  767. this.Close();
  768. }
  769. }
  770. catch (Exception e1)
  771. {
  772. Core.Mes.Client.Comm.Tool.MessageUtil.ShowWarning("制单失败!" + e1);
  773. return;
  774. }
  775. }
  776. #endregion
  777. #region 公共函数
  778. // 填充物料属性、标准值、单位dropDownList数据
  779. private void getDropDownListData(String strItemCode)
  780. {
  781. getItemAttr(strItemCode);
  782. getMatStandard(strItemCode);
  783. getMatUOM(strItemCode);
  784. }
  785. // 获取物料属性
  786. private void getItemAttr(String strItemCode)
  787. {
  788. if (!string.IsNullOrEmpty(strItemCode))
  789. {
  790. cmb_itemAttr.DataSource = dtAttr;
  791. cmb_itemAttr.ValueMember = "Code";
  792. cmb_itemAttr.DisplayMember = "Desc";
  793. }
  794. }
  795. // 获取物料标准编号
  796. private void getMatStandard(String strItemCode)
  797. {
  798. if (!string.IsNullOrEmpty(strItemCode))
  799. {
  800. cmb_standard.DataSource = dtStandards;
  801. cmb_standard.ValueMember = "Code";
  802. cmb_standard.DisplayMember = "Desc";
  803. }
  804. }
  805. // 获取单位转换
  806. private void getMatUOM(String strItemCode)
  807. {
  808. if (!string.IsNullOrEmpty(strItemCode))
  809. {
  810. cmb_Uom.DataSource = dtUom;
  811. cmb_Uom.ValueMember = "Code";
  812. cmb_Uom.DisplayMember = "Desc";
  813. }
  814. }
  815. private string createUnique(UltraGridRow uge)
  816. {
  817. String ItemUnique = uge.GetCellValue("itemCode").ToString().Trim() + uge.GetCellValue("newItemAttrId").ToString().Trim() + uge.GetCellValue("newItemStandardsId").ToString().Trim() + uge.GetCellValue("newItemUomId").ToString().Trim();
  818. return ItemUnique;
  819. }
  820. #endregion
  821. private void btn_Create_Click(object sender, EventArgs e)
  822. {
  823. doCreate();
  824. }
  825. private void ck_ftime_CheckedChanged(object sender, EventArgs e)
  826. {
  827. txt_ForcasTimeEnd.Enabled = ck_ftime.Checked;
  828. txt_ForcasTimeStart.Enabled = ck_ftime.Checked;
  829. }
  830. private void ultraGrid1_ClickCell(object sender, ClickCellEventArgs e)
  831. {
  832. UltraGridRow row = e.Cell.Row;
  833. string strMrLineId = row.GetCellValue("mrlineid").ToString().Trim();
  834. string strItemCode = row.GetCellValue("itemCode").ToString().Trim();
  835. //string strItemUniuqe = row.GetCellValue("ItemUnique").ToString().Trim();
  836. //String strNewItemUniuqe=row.GetCellValue("newItemUnique").ToString().Trim();
  837. //if (row.HasParent())//子行查询可利资源
  838. //{
  839. // getCanUsePlan(strMrLineId, strItemUniuqe);
  840. //}
  841. //else//调整后数据查询
  842. //{
  843. // getCanUsePlan(strMrLineId, strNewItemUniuqe);
  844. //}
  845. getCanUsePlan(strMrLineId, strItemCode);
  846. }
  847. private void getCanUsePlan(String strMrLineId, String strItemCode)
  848. {
  849. dataTable3.Clear();
  850. dataTable4.Clear();
  851. if (string.IsNullOrEmpty(strMrLineId) || string.IsNullOrEmpty(strItemCode))
  852. {
  853. return;
  854. }
  855. //查询可利计划资源
  856. Dictionary<string, object> param = new Dictionary<string, object>();
  857. param.Add("itemCode", strItemCode);
  858. if (ck_ftime.Checked)
  859. {
  860. if (txt_ForcasTimeStart.Text != "")
  861. {
  862. param.Add("forcastTimeStart", Convert.ToDateTime(txt_ForcasTimeStart.Value));
  863. }
  864. if (txt_ForcasTimeEnd.Text != "")
  865. {
  866. param.Add("forcastTimeEnd", Convert.ToDateTime(txt_ForcasTimeEnd.Value));
  867. }
  868. }
  869. if (ck_hasOrderQty.Checked)
  870. {
  871. param.Add("hasOrderQty", "1");
  872. }
  873. param.Add("orderLineSqe",txt_orderNo.Text.Trim());
  874. DataTable dt5 = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "findcanUseBenefitReceivePlan", new object[] { param });
  875. GridHelper.CopyDataToDatatable(dt5, dataTable3, true);
  876. foreach(UltraGridRow rows in ultraGrid2.Rows)
  877. {
  878. double orderCanUse=0;
  879. double planCanUse=0;
  880. double.TryParse(rows.Cells["qtyOrderRemain"].Value.ToString(), out orderCanUse);
  881. double.TryParse(rows.Cells["qtyCanUsePlan"].Value.ToString(), out planCanUse);
  882. rows.Cells["useQty"].Value = Math.Min(orderCanUse, planCanUse);
  883. rows.Cells["canUseQty"].Value = Math.Min(orderCanUse, planCanUse);
  884. //rows.Cells["CHK"].Value = true;
  885. }
  886. GridHelper.RefreshAndAutoSize(ultraGrid2);
  887. //查询已利计划资源
  888. Dictionary<string, object> ReqPnew = new Dictionary<string, object>();
  889. ReqPnew["mrLineId"] = strMrLineId;
  890. ReqPnew["style"] = "1";//有效数据
  891. ReqPnew["dStatus"] = "2";//已编制数据
  892. ReqPnew["lineSeq"] = "2";//走利计划类型
  893. DataTable dt3 = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "get_canUse", new object[] { ReqPnew });
  894. GridHelper.CopyDataToDatatable(dt3, dataTable4, true);
  895. GridHelper.RefreshAndAutoSize(ultraGrid3);
  896. }
  897. private void btn_QueryLi_Click(object sender, EventArgs e)
  898. {
  899. UltraGridRow row = ultraGrid1.ActiveRow;
  900. if (row == null)
  901. {
  902. MessageUtil.ShowTips("请选择需要利计划的行信息!");
  903. return;
  904. }
  905. string strMrLineId = row.GetCellValue("mrlineid").ToString().Trim();
  906. string strItemCode = row.GetCellValue("itemCode").ToString().Trim();
  907. //string strItemUniuqe = row.GetCellValue("ItemUnique").ToString().Trim();
  908. //String strNewItemUniuqe = row.GetCellValue("newItemUnique").ToString().Trim();
  909. //if (row.HasParent())//子行查询可利资源
  910. //{
  911. // getCanUsePlan(strMrLineId, strItemUniuqe);
  912. //}
  913. //else//调整后数据查询
  914. //{
  915. // getCanUsePlan(strMrLineId, strItemUniuqe);
  916. //}
  917. getCanUsePlan(strMrLineId, strItemCode);
  918. }
  919. private void btn_CreateLi_Click(object sender, EventArgs e)
  920. {
  921. try
  922. {
  923. if (ultraGrid1.ActiveRow == null||ultraGrid1.ActiveRow.HasChild())
  924. {
  925. MessageUtil.ShowTips("需选择利计划的需求计划行!");
  926. return;
  927. }
  928. UltraGridRow rowP = ultraGrid1.ActiveRow;
  929. String strMrLineId = rowP.GetCellValue("mrlineid").ToString().Trim();
  930. String strItemUnique = rowP.GetCellValue("itemUnique").ToString().Trim();
  931. String strItemCode = rowP.GetCellValue("itemCode").ToString().Trim();
  932. String strId = rowP.GetCellValue("Id").ToString().Trim();
  933. Double canLiQty=Convert.ToDouble(rowP.GetCellValue("Qty"));
  934. if (testStatus(strMrLineId, 2) == false)
  935. {
  936. return;
  937. }
  938. ultraGrid2.UpdateData();
  939. IQueryable<UltraGridRow> checkRows = ultraGrid2.Rows.AsQueryable().Where(a => a.GetValue("CHK") == "True" && a.GetValue("UseQty") != "" && double.Parse(a.GetValue("UseQty")) > 0); //("CHK = 'True' and QTYLJHTemp='0'");
  940. if (checkRows.Count() == 0)
  941. {
  942. MessageUtil.ShowWarning("无可利对象,请选择可利计划资源!");
  943. return;
  944. }
  945. ArrayList list = new ArrayList();
  946. double liQty=0;
  947. foreach (UltraGridRow uRows in checkRows)
  948. {
  949. //减少接收表数据
  950. //插入接收表数据
  951. //更新需求计划行行状态
  952. RequireReceive rr = new RequireReceive();
  953. rr.Id = strId;
  954. rr.IdOld = uRows.GetCellValue("id").ToString().Trim();
  955. rr.Qty = Convert.ToDouble(uRows.GetCellValue("UseQty"));
  956. liQty=liQty+(double)rr.Qty;
  957. rr.CreateUserid = UserInfo.GetUserID();
  958. rr.CreateTime = DateTime.Now;
  959. rr.CreateName = UserInfo.GetUserName();
  960. list.Add(rr);
  961. }
  962. if (liQty > canLiQty)
  963. {
  964. MessageUtil.ShowTips("需求计划行:" + strMrLineId + "最大可利计划量为:" + canLiQty);
  965. return;
  966. }
  967. if (MessageUtil.ShowYesNoAndQuestion("确定对需求计划行:" + strMrLineId + "进行利计划操作?") != DialogResult.Yes)
  968. {
  969. return;
  970. }
  971. CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "doBenefit", new object[] { list, "1" });
  972. if (re.Resultcode == 0)
  973. {
  974. MessageUtil.ShowTips("利计划成功!");
  975. getCanUsePlan(strMrLineId, strItemUnique);
  976. rowP.Cells["qtyPur"].Value=Convert.ToDouble(rowP.GetCellValue("qtyPur")) - liQty;
  977. //更新到dateTable
  978. DataRow[] roww = dataTable2.Select("id='" + strId + "'");
  979. if (roww.Count() != 1)
  980. {
  981. MessageUtil.ShowTips("发现" + roww.Count() + "条" + strId + "接收需求计划行,数据异常!");
  982. }
  983. roww[0]["qty"] = Convert.ToDouble(roww[0]["qty"]) - liQty;
  984. rowP.Cells["Qty"].Value = Convert.ToDouble(rowP.GetCellValue("Qty"));
  985. rowP.ParentRow.Cells["SQTYPUR"].Value = Convert.ToDouble(rowP.ParentRow.Cells["SQTYPUR"].Value) - liQty;
  986. rowP.ParentRow.Cells["Num"].Value = Convert.ToDouble(rowP.ParentRow.Cells["Num"].Value) - liQty;
  987. return;
  988. }
  989. else
  990. {
  991. MessageUtil.ShowTips("操作失败:" + re.Resultmsg + "!");
  992. return;
  993. }
  994. }
  995. catch (Exception ex)
  996. {
  997. MessageUtil.ShowTips("操作失败:" + ex.Message + "!");
  998. }
  999. }
  1000. private void btn_cancelLi_Click(object sender, EventArgs e)
  1001. {
  1002. try
  1003. {
  1004. if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.HasChild())
  1005. {
  1006. MessageUtil.ShowTips("请选择撤销利计划的需求计划行!");
  1007. return;
  1008. }
  1009. UltraGridRow rowP = ultraGrid1.ActiveRow;
  1010. String strMrLineId = rowP.GetCellValue("mrlineid").ToString().Trim();
  1011. String strItemUnique = rowP.GetCellValue("itemUnique").ToString().Trim();
  1012. string strId = rowP.GetCellValue("id").ToString().Trim();
  1013. if (testStatus(strMrLineId, 3) == false)
  1014. {
  1015. return;
  1016. }
  1017. ultraGrid3.UpdateData();
  1018. IQueryable<UltraGridRow> checkRows = ultraGrid3.Rows.AsQueryable().Where(a => a.GetValue("CHK") == "True"); //("CHK = 'True' and QTYLJHTemp='0'");
  1019. if (checkRows.Count() == 0)
  1020. {
  1021. MessageUtil.ShowWarning("未勾选需撤销利计划的计划行!");
  1022. return;
  1023. }
  1024. double cancelLiQty = 0;
  1025. ArrayList list = new ArrayList();
  1026. foreach (UltraGridRow uRows in checkRows)
  1027. {
  1028. //减少接收表数据
  1029. //插入接收表数据
  1030. //更新需求计划行行状态
  1031. RequireReceive rr = new RequireReceive();
  1032. rr.Id = uRows.GetCellValue("id").ToString().Trim();
  1033. rr.MrLineId = strMrLineId;
  1034. rr.PurLineId = uRows.GetCellValue("mrLineId").ToString().Trim();
  1035. cancelLiQty = cancelLiQty + Convert.ToDouble(uRows.GetCellValue("qty"));
  1036. //rr.Qty = Convert.ToDouble(uRows.GetCellValue("QTYLJHTemp"));
  1037. rr.CreateUserid = UserInfo.GetUserID();
  1038. rr.CreateTime = DateTime.Now;
  1039. rr.CreateName = UserInfo.GetUserName();
  1040. list.Add(rr);
  1041. }
  1042. if (MessageUtil.ShowYesNoAndQuestion("确定对需求计划行:" + strMrLineId + "进行撤销利计划操作?") != DialogResult.Yes)
  1043. {
  1044. return;
  1045. }
  1046. CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "doBenefit", new object[] { list, "2" });
  1047. if (re.Resultcode == 0)
  1048. {
  1049. MessageUtil.ShowTips("撤销成功!");
  1050. getCanUsePlan(strMrLineId, strItemUnique);
  1051. rowP.Cells["qtyPur"].Value = Convert.ToDouble(rowP.GetCellValue("qtyPur")) + cancelLiQty;
  1052. //更新到dateTable
  1053. DataRow[] roww = dataTable2.Select("id='" + strId + "'");
  1054. if (roww.Count() != 1)
  1055. {
  1056. MessageUtil.ShowTips("发现" + roww.Count() + "条" + strId + "接收需求计划行,数据异常!");
  1057. }
  1058. roww[0]["qty"] = Convert.ToDouble(roww[0]["qty"]) + cancelLiQty;
  1059. rowP.Cells["Qty"].Value = Convert.ToDouble(rowP.GetCellValue("Qty"));
  1060. rowP.ParentRow.Cells["SQTYPUR"].Value = Convert.ToDouble(rowP.ParentRow.Cells["SQTYPUR"].Value) + cancelLiQty;
  1061. rowP.ParentRow.Cells["Num"].Value = Convert.ToDouble(rowP.ParentRow.Cells["Num"].Value) + cancelLiQty;
  1062. return;
  1063. }
  1064. else
  1065. {
  1066. MessageUtil.ShowTips("操作失败:" + re.Resultmsg + "!");
  1067. return;
  1068. }
  1069. }
  1070. catch (Exception ex)
  1071. {
  1072. MessageUtil.ShowTips("操作失败:" + ex.Message + "!");
  1073. }
  1074. }
  1075. private void ultraGrid2_CellChange(object sender, CellEventArgs e)
  1076. {
  1077. if (e.Cell.Column.Key == "UseQty")
  1078. {
  1079. double oldQty = e.Cell.Row.GetCellValue("UseQty") == DBNull.Value ? 0 : Convert.ToDouble(e.Cell.Row.GetCellValue("UseQty"));
  1080. ultraGrid2.UpdateData();
  1081. double newQty = e.Cell.Row.GetCellValue("UseQty") == DBNull.Value ? 0 : Convert.ToDouble(e.Cell.Row.GetCellValue("UseQty"));
  1082. if (!ultraGrid1.ActiveRow.HasParent()||ultraGrid1.ActiveRow==null)
  1083. {
  1084. MessageUtil.ShowTips("请选择需求计划行利计划!");
  1085. e.Cell.Row.Cells["UseQty"].Value = oldQty;
  1086. return;
  1087. }
  1088. double canmaxLi = 0;
  1089. double canUseLi = e.Cell.Row.GetCellValue("canUseQty") == DBNull.Value ? 0 : Convert.ToDouble(e.Cell.Row.GetCellValue("canUseQty"));
  1090. canmaxLi = ultraGrid1.ActiveRow.GetCellValue("Qty") == DBNull.Value ? 0 : Convert.ToDouble(ultraGrid1.ActiveRow.GetCellValue("Qty"));
  1091. if (newQty > canUseLi || newQty > canmaxLi)
  1092. {
  1093. e.Cell.Row.Cells["UseQty"].Value = oldQty;
  1094. }
  1095. }
  1096. }
  1097. private bool testStatus(string mrlineId, int p2)//校验状态
  1098. {
  1099. if (String.IsNullOrEmpty(mrlineId))
  1100. {
  1101. MessageUtil.ShowTips("为获取到需求计划行号!");
  1102. return false;
  1103. }
  1104. if (p2 == 1)
  1105. {
  1106. RequireReceive rr = new RequireReceive();
  1107. rr.MrLineId = mrlineId;
  1108. rr.Validflag = "1";
  1109. DataTable dt2 = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "find", new object[] { rr, 0, 0 });
  1110. if (dt2.Rows.Count == 0)
  1111. {
  1112. MessageUtil.ShowTips("需求计划行:" + mrlineId + "已退回或已删除!");
  1113. comm.doActiveSelRow(ultraGrid2, "mrlineId", mrlineId);
  1114. return false;
  1115. }
  1116. if (dt2.Rows.Count > 1)
  1117. {
  1118. MessageUtil.ShowTips("需求计划行:" + mrlineId + "已利计划,请先撤销利计划再操作!");
  1119. comm.doActiveSelRow(ultraGrid2, "mrlineId", mrlineId);
  1120. return false;
  1121. }
  1122. if (dt2.Rows[0]["status"].ToString().Trim() == "2")
  1123. {
  1124. MessageUtil.ShowTips("需求计划行:" + mrlineId + "已编制汇总,请先撤销编制汇总再操作!");
  1125. comm.doActiveSelRow(ultraGrid2, "mrlineId", mrlineId);
  1126. return false;
  1127. }
  1128. }
  1129. //是否可以利计划判断
  1130. else if (p2 == 2)
  1131. {
  1132. RequireReceive rr = new RequireReceive();
  1133. rr.MrLineId = mrlineId;
  1134. rr.Purtype = "1";//编制类型
  1135. rr.Validflag = "1";//有效数据
  1136. List<RequireReceive> listR = this.execute<List<RequireReceive>>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "find", new object[] { rr, 0, 0 });
  1137. if (listR.Count() == 0)
  1138. {
  1139. MessageUtil.ShowTips("未发现接收需求计划行:" + mrlineId + "信息记录,可能已被删除或退回,或请刷新重新操作!");
  1140. return false;
  1141. }
  1142. else if (listR.Count() > 1)
  1143. {
  1144. MessageUtil.ShowTips("接收需求计划行:" + mrlineId + "数据异常,或请刷新重新操作!");
  1145. return false;
  1146. }
  1147. else
  1148. {
  1149. rr = listR[0];
  1150. if (rr.Status == "2")
  1151. {
  1152. MessageUtil.ShowTips("该接收需求计划行:" + mrlineId + "已编制汇总!");
  1153. return false;
  1154. }
  1155. if (rr.Qty <= 0)
  1156. {
  1157. MessageUtil.ShowTips("该接收需求计划行:" + mrlineId + "剩余最大可利计划量【" + rr.Qty + rr.ItemUom + "】!");
  1158. return false;
  1159. }
  1160. }
  1161. }
  1162. //是否可以利计划判断
  1163. else if (p2 == 3)
  1164. {
  1165. RequireReceive rr = new RequireReceive();
  1166. rr.MrLineId = mrlineId;
  1167. rr.Purtype = "1";//编制类型
  1168. rr.Validflag = "1";//有效数据
  1169. List<RequireReceive> listR = this.execute<List<RequireReceive>>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "find", new object[] { rr, 0, 0 });
  1170. if (listR.Count() == 0)
  1171. {
  1172. MessageUtil.ShowTips("未发现接收需求计划行:" + mrlineId + "信息记录,可能已被删除或退回,或请刷新重新操作!");
  1173. return false;
  1174. }
  1175. else if (listR.Count() > 1)
  1176. {
  1177. MessageUtil.ShowTips("接收需求计划行:" + mrlineId + "数据异常,或请刷新重新操作!");
  1178. return false;
  1179. }
  1180. else
  1181. {
  1182. rr = listR[0];
  1183. if (rr.Status == "2")
  1184. {
  1185. MessageUtil.ShowTips("该接收需求计划行:" + mrlineId + "已编制汇总!");
  1186. return false;
  1187. }
  1188. }
  1189. }
  1190. else
  1191. {
  1192. MessageUtil.ShowTips("未知验证参数!");
  1193. return false;
  1194. }
  1195. return true;
  1196. }
  1197. private void txt_UrgencyType_ValueChanged(object sender, EventArgs e)
  1198. {
  1199. if (txt_UrgencyType.SelectedIndex == 1)
  1200. {
  1201. //data_MrPeriodEnd.Enabled = true;
  1202. }
  1203. else
  1204. {
  1205. //data_MrPeriodEnd.Enabled = false;
  1206. if (DateTime.Now.Month == 2)
  1207. {
  1208. data_MrPeriodEnd.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/28")) ? DateTime.Now : DateTime.Now.AddMonths(1);
  1209. }
  1210. else
  1211. {
  1212. data_MrPeriodEnd.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/30")) ? DateTime.Now : DateTime.Now.AddMonths(1);
  1213. }
  1214. }
  1215. }
  1216. private void doExcel_Click(object sender, EventArgs e)
  1217. {
  1218. try
  1219. {
  1220. //获取导出的采购计划行表
  1221. ultraGrid1.DisplayLayout.Bands[0].Columns["CHECK"].Hidden = true;
  1222. ultraGrid1.DisplayLayout.Bands[1].Hidden = true;
  1223. ArrayList alUltraGrid = new ArrayList();
  1224. alUltraGrid.Add(ultraGrid1);
  1225. ArrayList alSheeft = new ArrayList();
  1226. alSheeft.Add("需求计划合计");
  1227. if (ultraGrid1.Rows.Count > 0)
  1228. {
  1229. GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "采购计划编制");//导出excel
  1230. }
  1231. }
  1232. catch (Exception ex)
  1233. {
  1234. MessageUtil.ShowTips("导出失败" + ex.Message);
  1235. }
  1236. finally
  1237. {
  1238. ultraGrid1.DisplayLayout.Bands[0].Columns["CHECK"].Hidden = false;//显示复选框
  1239. ultraGrid1.DisplayLayout.Bands[1].Hidden = false;
  1240. }
  1241. }
  1242. }
  1243. }