FrmRePlanChange.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using com.hnshituo.pur.vo;
  11. using Core.Mes.Client.Comm.Control;
  12. using Core.Mes.Client.Comm.Tool;
  13. using CoreFS.CA06;using Pur.Entity;
  14. using Infragistics.Win;
  15. using Infragistics.Win.UltraWinGrid;
  16. using Pur.Entity.configureEntity;
  17. using Pur.Entity.require_planEntiy;
  18. using Pur.Pop_upWindow;
  19. namespace Pur.require_plan
  20. {
  21. public partial class FrmRePlanChange : FrmPmsBase
  22. {
  23. //变量
  24. public ArrayList list;//变更的需求行信息
  25. public DataTable dtOld;//变更前数据备份
  26. public DataTable dtNew;//变更后的数据备份
  27. public FrmRePlanChange()
  28. {
  29. InitializeComponent();
  30. }
  31. public FrmRePlanChange(ArrayList List, OpeBase Ob)
  32. {
  33. InitializeComponent();
  34. this.ob = Ob;
  35. this.list = List;
  36. }
  37. private void FrmRePlanChange_Load(object sender, EventArgs e)
  38. {
  39. init();
  40. }
  41. /// <summary>
  42. /// 加载需要变更的数据
  43. /// </summary>
  44. private void init()
  45. {
  46. //加载待编辑数据
  47. if (list.Count > 0)
  48. {
  49. dtOld = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.RequirePlanDService", "getJoinedByIds", new object[] { list });
  50. GridHelper.CopyDataToDatatable(dtOld, dataTable1, true);
  51. ultraGrid1.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;
  52. ultraGrid2.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;
  53. }
  54. else
  55. {
  56. MessageUtil.ShowTips("无待修改数据");
  57. }
  58. }
  59. /// <summary>
  60. /// 加载物料信息
  61. /// </summary>
  62. /// <param name="sender"></param>
  63. /// <param name="e"></param>
  64. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  65. {
  66. clearTab();
  67. if (ultraGrid1.ActiveRow != null)
  68. {
  69. UltraGridRow uge = ultraGrid1.ActiveRow;
  70. String strmatCode = uge.GetCellValue("itemCode").ToString();
  71. txt_matCode.Text = strmatCode;
  72. String strmatName = uge.GetCellValue("itemName").ToString();
  73. txt_matName.Text = strmatName;
  74. getItemAttr();//获取物料属性
  75. getMatStandard();// 获取物料标准编号
  76. getMatUOM();// 获取单位转换
  77. string stritemUomId = uge.GetCellValue("itemUomId").ToString();
  78. string stritemStandardsId = uge.GetCellValue("itemStandardsId").ToString();
  79. string stritemAttrId = uge.GetCellValue("itemAttrId").ToString();
  80. setGridCheck(ultraGrid5, "itemUomId", stritemUomId);
  81. setGridCheck(ultraGrid3, "itemAttrId", stritemAttrId);
  82. setGridCheck(ultraGrid4, "itemStandardsId", stritemStandardsId);
  83. }
  84. }
  85. /// <summary>
  86. /// 清楚编辑区信息
  87. /// </summary>
  88. private void clearTab()
  89. {
  90. txt_matCode.Text = "";
  91. txt_matName.Text = "";
  92. dataTable5.Clear();
  93. dataTable6.Clear();
  94. dataTable7.Clear();
  95. }
  96. /// <summary>
  97. /// 获取物料属性
  98. /// </summary>
  99. /// <param name="parm"></param>
  100. private void getItemAttr()
  101. {
  102. dataTable5.Rows.Clear();
  103. Dictionary<string, object> param = new Dictionary<string, object>();
  104. param.Add("ItemCode", ultraGrid1.ActiveRow.Cells["ITEMCODE"].Value.ToString());
  105. param.Add("Validflag", "1");
  106. DataTable dt_mat = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatAttrsService", "find", new object[] { param, 0, 0 });
  107. GridHelper.CopyDataToDatatable(ref dt_mat, ref dataTable5, true);//获取物料属性
  108. }
  109. /// <summary>
  110. /// 获取物料标准编号
  111. /// </summary>
  112. private void getMatStandard()
  113. {
  114. dataTable6.Rows.Clear();
  115. if (ultraGrid1.ActiveRow != null)
  116. {
  117. PurMatStandardsEntity PurMatStandards_Entity = new PurMatStandardsEntity();
  118. PurMatStandards_Entity.Validflag = "1";
  119. PurMatStandards_Entity.ItemCode = ultraGrid1.ActiveRow.Cells["ITEMCODE"].Value.ToString();
  120. DataTable dt_matStandards = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatStandardsService", "find", new object[] { PurMatStandards_Entity, 0, 0 });
  121. GridHelper.CopyDataToDatatable(ref dt_matStandards, ref dataTable6, true);//绑定物料规格
  122. }
  123. }
  124. /// <summary>
  125. /// 获取单位转换
  126. /// </summary>
  127. private void getMatUOM()
  128. {
  129. dataTable7.Rows.Clear();
  130. if (ultraGrid1.ActiveRow != null)
  131. {
  132. PurMatUomsEntity MatUomsEntity = new PurMatUomsEntity();
  133. MatUomsEntity.ItemCode = ultraGrid1.ActiveRow.Cells["ITEMCODE"].Value.ToString();
  134. MatUomsEntity.Validflag = "1";
  135. DataTable dt_matUOM = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatUomsService", "find", new object[] { MatUomsEntity, 0, 0 });
  136. GridHelper.CopyDataToDatatable(ref dt_matUOM, ref dataTable7, true);//绑定物料规格
  137. }
  138. }
  139. /// <summary>
  140. /// 设置Check点击
  141. /// </summary>
  142. /// <param name="ultraGrid1"></param>
  143. /// <param name="p"></param>
  144. /// <param name="stritemUomId"></param>
  145. private void setGridCheck(UltraGrid ultraGrid, string p, string stritemUomId)
  146. {
  147. foreach (UltraGridRow row in ultraGrid.Rows)
  148. {
  149. if (row.GetCellValue(p).ToString() == stritemUomId)
  150. {
  151. row.Cells["Check"].Value = true;
  152. row.Activated = true;
  153. }
  154. else
  155. {
  156. row.Cells["Check"].Value = false;
  157. row.Activated = false;
  158. }
  159. }
  160. }
  161. /// <summary>
  162. /// ultraGrid3的Check选择事件1
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. private void ultraGrid3_CellChange(object sender, CellEventArgs e)
  167. {
  168. foreach (UltraGridRow row in ultraGrid3.Rows)
  169. {
  170. if (row == e.Cell.Row)
  171. {
  172. row.Cells["Check"].Value = true;
  173. }
  174. else
  175. {
  176. row.Cells["Check"].Value = false;
  177. }
  178. }
  179. ultraGrid3.UpdateData();
  180. }
  181. /// <summary>
  182. /// ultraGrid4的Check选择事件1
  183. /// </summary>
  184. /// <param name="sender"></param>
  185. /// <param name="e"></param>
  186. private void ultraGrid4_CellChange(object sender, CellEventArgs e)
  187. {
  188. foreach (UltraGridRow row in ultraGrid4.Rows)
  189. {
  190. if (row == e.Cell.Row)
  191. {
  192. row.Cells["Check"].Value = true;
  193. }
  194. else
  195. {
  196. row.Cells["Check"].Value = false;
  197. }
  198. }
  199. ultraGrid4.UpdateData();
  200. }
  201. /// <summary>
  202. /// ultraGrid5的Check选择事件1
  203. /// </summary>
  204. /// <param name="sender"></param>
  205. /// <param name="e"></param>
  206. private void ultraGrid5_CellChange(object sender, CellEventArgs e)
  207. {
  208. foreach (UltraGridRow row in ultraGrid5.Rows)
  209. {
  210. if (row == e.Cell.Row)
  211. {
  212. row.Cells["Check"].Value = true;
  213. }
  214. else
  215. {
  216. row.Cells["Check"].Value = false;
  217. }
  218. }
  219. ultraGrid5.UpdateData();
  220. }
  221. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  222. {
  223. switch (e.Tool.Key)
  224. {
  225. case "doSure": // ButtonTool
  226. doSure();
  227. break;
  228. case "doCancel": // ButtonTool
  229. this.Close();
  230. break;
  231. case "doChage": // ButtonTool
  232. doChange();
  233. break;
  234. }
  235. }
  236. /// <summary>
  237. ///
  238. /// </summary>
  239. private void doSure()
  240. {
  241. if (ultraGrid2.Rows.Count >= 1)
  242. {
  243. UltraGridRow uge=ultraGrid2.Rows[0];
  244. RequirePlanD rd = new RequirePlanD();
  245. rd.MrLineId = uge.GetCellValue("mrLineId").ToString().Trim();
  246. rd.NewItemUnique=uge.GetCellValue("newItemUnique").ToString().Trim();
  247. rd.NewItemUomId=uge.GetCellValue("newItemUomId").ToString().Trim();
  248. rd.NewItemStandardsId=uge.GetCellValue("newItemStandardsId").ToString().Trim();
  249. rd.NewItemStandardsCode=uge.GetCellValue("newItemStandardsCode").ToString().Trim();
  250. rd.NewItemAttrId=uge.GetCellValue("newItemAttrId").ToString().Trim();
  251. rd.ItemAttr=uge.GetCellValue("itemAttr").ToString().Trim();
  252. rd.WeightUnit=uge.GetCellValue("weightUnit").ToString().Trim();
  253. rd.ItemUomConefficient=Convert.ToDouble(uge.GetCellValue("itemUomConefficient"));
  254. rd.ItemUom=uge.GetCellValue("itemUom").ToString().Trim();
  255. rd.UpdateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
  256. rd.UpdateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
  257. rd.UpdateTime = DateTime.Now;
  258. if (MessageUtil.ShowYesNoAndQuestion("是否确定要修改?") == DialogResult.No)
  259. {
  260. return;
  261. }
  262. CoreResult rt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.RequirePlanDService", "doUpdate", new object[] { rd });
  263. if (rt.Resultcode != 0)
  264. {
  265. MessageUtil.ShowTips("修改失败!" + rt.Resultmsg);
  266. return;
  267. }
  268. else
  269. {
  270. MessageUtil.ShowTips("修改成功!" + rt.Resultmsg);
  271. this.Close();
  272. return;
  273. }
  274. }
  275. else
  276. {
  277. MessageUtil.ShowTips("无待提交的修改数据");
  278. return;
  279. }
  280. }
  281. /// <summary>
  282. ///
  283. /// </summary>
  284. private void doChange()
  285. {
  286. if (ultraGrid1.ActiveRow == null)
  287. {
  288. MessageUtil.ShowTips("请选择需要修改的行");
  289. return;
  290. }
  291. ultraGrid3.UpdateData();
  292. ultraGrid4.UpdateData();
  293. ultraGrid5.UpdateData();
  294. UltraGridRow uge3 = ultraGrid3.ActiveRow;//属性
  295. UltraGridRow uge4 = ultraGrid4.ActiveRow;//标准编号
  296. UltraGridRow uge5 = ultraGrid5.ActiveRow;//单位
  297. String itemCode = ultraGrid1.ActiveRow.Cells["itemCode"].Value.ToString().Trim();
  298. String itemUniqueOld = ultraGrid1.ActiveRow.Cells["itemUnique"].Value.ToString().Trim();
  299. String newitemUniqueOld = ultraGrid1.ActiveRow.Cells["newItemUnique"].Value.ToString().Trim();
  300. String itemAttrId="";
  301. String itemStandardsId="";
  302. String itemUomId="";
  303. String itemAttr = "";
  304. String itemAttrCode = "";
  305. String standardsId = "";
  306. String standardsCode = "";
  307. String weightUnit="";
  308. String weightUnitCode ="";
  309. String itemUomConefficient = "";
  310. String uomCode = "";
  311. String uomName = "";
  312. if (uge3 != null)//属性
  313. {
  314. itemAttr = uge3.Cells["itemAttr"].Value.ToString().Trim();
  315. itemAttrCode = uge3.Cells["ITEMATTRCODE"].Value.ToString().Trim();
  316. itemAttrId = uge3.Cells["itemAttrId"].Value.ToString().Trim();
  317. }
  318. if (uge4 != null)//标准编号
  319. {
  320. itemStandardsId = uge4.Cells["itemStandardsId"].Value.ToString().Trim();
  321. standardsId = uge4.Cells["standardsId"].Value.ToString().Trim();
  322. standardsCode = uge4.Cells["standardsCode"].Value.ToString().Trim();
  323. }
  324. if (uge5 != null)//采购单位
  325. {
  326. itemUomId = uge5.Cells["itemUomId"].Value.ToString().Trim();
  327. weightUnit = uge5.Cells["weightUnit"].Value.ToString().Trim();
  328. weightUnitCode = uge5.Cells["weightUnitCode"].Value.ToString().Trim();
  329. itemUomConefficient = uge5.Cells["itemUomConefficient"].Value.ToString();
  330. uomCode = uge5.Cells["uomCode"].Value.ToString().Trim();
  331. uomName = uge5.Cells["uomName"].Value.ToString().Trim();
  332. }
  333. //所选物料唯一标识值
  334. String ItemUnique = itemCode + itemAttrId + itemStandardsId + itemUomId;
  335. if (itemUniqueOld == ItemUnique || newitemUniqueOld == ItemUnique)
  336. {
  337. MessageUtil.ShowTips("未发现有修改,请确定");
  338. return;
  339. }
  340. DataTable dtOld1 = dtOld.Copy();
  341. DataRow myDr = dtOld1.Rows[0];
  342. myDr["newItemUnique"] = ItemUnique;
  343. myDr["newItemUomId"] = itemUomId;
  344. myDr["newItemStandardsId"] = itemStandardsId;
  345. myDr["newItemStandardsCode"] = standardsCode;
  346. myDr["newItemAttrId"] = itemAttrId;
  347. myDr["itemAttr"] = itemAttr;
  348. myDr["weightUnit"] = weightUnit;
  349. myDr["itemUomConefficient"] = itemUomConefficient;
  350. myDr["itemUom"] = uomName;
  351. //删除重复行
  352. if (dtNew == null)
  353. {
  354. dtNew = dtOld.Clone();
  355. dtNew.Rows.Add(myDr.ItemArray);
  356. }
  357. else
  358. {
  359. if (dtNew.Rows.Count > 0)
  360. {
  361. for (int i = dtNew.Rows.Count - 1; i >= 0; i--)
  362. {
  363. if (dtNew.Rows[i]["itemUnique"] == myDr["itemUnique"])
  364. {
  365. dtNew.Rows.RemoveAt(i);
  366. }
  367. }
  368. }
  369. //加行
  370. dtNew.Rows.Add(myDr.ItemArray);
  371. }
  372. GridHelper.CopyDataToDatatable(dtNew, dataTable2, true);
  373. }
  374. }
  375. }