frmPop_updPrice.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 Infragistics.Win.UltraWinGrid;
  10. using Infragistics.Win;
  11. using CoreFS.CA06;
  12. using Pur.Entity;
  13. using Core.Mes.Client.Comm.Control;
  14. using Core.Mes.Client.Comm;
  15. using Core.Mes.Client.Comm.Tool;
  16. using Pur.Entity.configureEntity;
  17. using Infragistics.Win.UltraWinTree;
  18. using Core.Mes.Client.Comm.Server;
  19. using Pur.Pop_upWindow;
  20. using com.hnshituo.pur.vo;
  21. using Pur.configure;
  22. using System.Collections;
  23. using Infragistics.Win.UltraWinToolTip;
  24. using Pur.require_plan;
  25. using Infragistics.Win.UltraWinEditors;
  26. using Pur.PublicTools;
  27. namespace Pur.Pop_upWindow
  28. {
  29. public partial class frmPop_updPrice : FrmPmsBase
  30. {
  31. public frmPop_updPrice(string strItemName,string strItemCode,string dPrice,OpeBase ob)
  32. {
  33. InitializeComponent();
  34. this.ob = ob;
  35. }
  36. public frmPop_updPrice()
  37. {
  38. InitializeComponent();
  39. }
  40. private void frmPop_updPrice_Load(object sender, EventArgs e)
  41. {
  42. PublicPur.InitCellEdit(new UltraGrid[] { GridMat }, new string[] { "Check", "newPrice" });
  43. PublicPur.InitCellPositionRight(new UltraGrid[] { GridMat }, new string[] { "newPrice" });
  44. PublicPur.InitColumnShowLength(new UltraGrid[] { GridMat }, 0, new string[] { "newPrice" }, 2, false);
  45. QtimeB.Value = System.DateTime.Now.AddYears(-1).AddDays(-3);
  46. QtimeE.Value = DateTime.Now.AddDays(-3);
  47. QueryNum.SelectedIndex = 0;//每页显示数量
  48. GridHelper.SetExcludeColumnsActive(GridMat.DisplayLayout.Bands[0], new string[] { "Check", "newPrice" });
  49. if (selectType == "1")
  50. {
  51. GridHelper.HidenColumns(GridMat.DisplayLayout.Bands[0], new string[] { "Check" });
  52. }
  53. //查询物料分类树
  54. GetPUR_MAT_Class();
  55. ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[0];
  56. }
  57. public double dPrice = 0;
  58. MatEntity Q_mat = null;
  59. String selectType = "0";//0:全选,1:单个选
  60. Boolean QClickCellOrQuery = false;//是否点击查询按钮或grid数据单元格,控制是否刷新右侧物料数据,true为不刷新
  61. DataTable dt_Purmatclass = null;
  62. UltraTreeNode qUltraNode = null;
  63. public ArrayList List_item=new ArrayList();
  64. public String selectedItemCode="";
  65. public String SelectedItemName="";
  66. public string tips="0";
  67. #region toolbar工具栏
  68. public override void ToolBar_Click(object sender, string ToolbarKey)
  69. {
  70. switch (ToolbarKey)
  71. {
  72. case "Query":
  73. doQuery();
  74. break;
  75. case "conFirmation":
  76. doSure();
  77. break;
  78. case "updByClass"://按分类修改
  79. {
  80. MessageUtil.ShowTips("无权限");
  81. return;
  82. GridMat.UpdateData();
  83. UltraTreeNode nd = ulTreeMat.ActiveNode;
  84. if (nd == null)
  85. {
  86. MessageUtil.ShowTips("请选择物料分类");
  87. return;
  88. }
  89. ArrayList a3 = new ArrayList();
  90. MatEntity m = new MatEntity();
  91. m.ArcCode = nd.Key;
  92. m.LastPrice = 1;
  93. if (QtimeB.Value != null)
  94. {
  95. m.UpdateTime = (DateTime)QtimeB.Value;
  96. }
  97. else
  98. {
  99. MessageUtil.ShowTips("请选择加权平均价格计算区间");
  100. return;
  101. }
  102. if (QtimeE.Value != null)
  103. {
  104. m.CreateTime = (DateTime)QtimeE.Value;
  105. }
  106. else
  107. {
  108. MessageUtil.ShowTips("请选择加权平均价格计算区间");
  109. return;
  110. }
  111. //m.BugPrice = double.Parse(a2[i].ToString());
  112. a3.Add(m);
  113. if (comm.ConfirmOption("注:修改新计划价格为到货合同加权平均价,如果合同加权平均价为空,则默认为原计划价。\n确定按物料分类【" + nd.Text + "】批量修改物料计划价"))
  114. {
  115. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.configure.service.MatService", "updateBugPrice", new object[] { a3 });//更新操作
  116. if (crt.Resultcode != 0)
  117. {
  118. MessageUtil.ShowTips("更新失败 " + crt.Resultmsg);
  119. return;
  120. }
  121. MessageUtil.ShowTips("更新成功");
  122. if (Q_mat != null)
  123. getMat(Q_mat);//刷新物料
  124. }
  125. break;
  126. }
  127. case "ESC":
  128. {
  129. this.Close();
  130. }
  131. break;
  132. case "doExcel":
  133. {
  134. doExcel();
  135. }
  136. break;
  137. }
  138. }
  139. private void doSure()
  140. {
  141. GridMat.UpdateData();
  142. ArrayList a3 = new ArrayList();
  143. DataRow[] arr = DTmat.Select("Check = 'True'");
  144. foreach (DataRow row in arr)
  145. {
  146. MatEntity m = new MatEntity();
  147. m.ItemCode = row["itemCode"].ToString().Trim();
  148. m.BugPrice = double.Parse(row["newPrice"].ToString().Trim());
  149. m.CreateName = UserInfo.GetUserName();
  150. m.CreateUserid = UserInfo.GetUserID();
  151. m.CreateTime = DateTime.Now;
  152. a3.Add(m);
  153. }
  154. if (comm.ConfirmOption("注:新计划价格为合同加权库存平均价,如果合同加权平均价为空,则默认为原计划价。\n确定修改物料计划价"))
  155. {
  156. CoreResult crt = this.execute<CoreResult>("com.hnshituo.pur.configure.service.MatService", "updateNewPrice", new object[] { a3 });//更新操作
  157. if (crt.Resultcode != 0)
  158. {
  159. MessageUtil.ShowTips("更新失败: " + crt.Resultmsg);
  160. return;
  161. }
  162. MessageUtil.ShowTips("更新成功");
  163. if (Q_mat != null)
  164. getMat(Q_mat);//刷新物料
  165. }
  166. }
  167. private void doQuery()
  168. {
  169. if (ultraTabControl1.SelectedTab.Key == "1")
  170. {
  171. QClickCellOrQuery = true;
  172. GetPUR_MAT_Class();
  173. if (GridMat.Rows.Count > 0)
  174. {
  175. ulTreeMat.CollapseAll();
  176. UltraTreeNode uttNode = ulTreeMat.GetNodeByKey(GridMat.Rows[0].Cells["ARCCODE"].Value.ToString());
  177. ulTreeMat.ActiveNode = uttNode;
  178. if (uttNode == null)
  179. {
  180. MessageUtil.ShowTips("物料名称:" + GridMat.Rows[0].Cells["ITEMNAME"].Value.ToString() + " 未找到相应的分类:" + GridMat.Rows[0].Cells["ARCCODE"].Value.ToString());
  181. }
  182. else
  183. {
  184. while (ulTreeMat.ActiveNode != uttNode)
  185. {
  186. ulTreeMat.ActiveNode = uttNode;
  187. }
  188. uttNode.Expanded = true;
  189. //展开分类
  190. while (uttNode.Parent != null)
  191. {
  192. uttNode = uttNode.Parent;
  193. uttNode.Expanded = true;
  194. }
  195. }
  196. QClickCellOrQuery = false;//设置未点击
  197. }
  198. }
  199. else
  200. {
  201. DTrecord.Clear();
  202. MatBugpirceRecord record = new MatBugpirceRecord();
  203. record.ItemCode = QitemCode_record.Text.Trim();
  204. record.ItemName = QitemName_record.Text.Trim();
  205. DataTable dt11 = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatBugpirceRecordService", "find", new object[] { record, 0, 0 });
  206. GridHelper.CopyDataToDatatable(ref dt11, ref DTrecord, true);//绑定物料分类表
  207. GridHelper.RefreshAndAutoSize(GridRecord);
  208. }
  209. }
  210. private void doExcel()
  211. {
  212. try
  213. {
  214. this.Cursor = Cursors.Default;
  215. if (ultraTabControl1.SelectedTab.Key == "1")
  216. {
  217. if (GridMat.ActiveRow == null)
  218. {
  219. MessageUtil.ShowTips("请选择需导出物料!");
  220. return;
  221. }
  222. String strclass = "";
  223. if (ulTreeMat.ActiveNode != null && !String.IsNullOrEmpty(ulTreeMat.ActiveNode.Text))
  224. {
  225. strclass = ulTreeMat.ActiveNode.Text + "_";
  226. }
  227. ArrayList alUltraGrid = new ArrayList();
  228. alUltraGrid.Add(GridMat);
  229. ArrayList alSheeft = new ArrayList();
  230. alSheeft.Add(strclass + "物料计划价格清单");
  231. GridHelper.ulGridToExcel(alUltraGrid, alSheeft, strclass + "物料计划价格清单");
  232. }
  233. else
  234. {
  235. if (GridRecord.Rows.Count <= 0)
  236. {
  237. MessageUtil.ShowTips("无可导出记录!");
  238. return;
  239. }
  240. ArrayList alUltraGrid = new ArrayList();
  241. alUltraGrid.Add(GridRecord);
  242. ArrayList alSheeft = new ArrayList();
  243. alSheeft.Add("计划价格修改记录");
  244. GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "计划价格修改记录");
  245. }
  246. }
  247. catch (Exception e)
  248. {
  249. MessageUtil.ShowTips("导出失败" + e.Message);
  250. }
  251. finally
  252. {
  253. this.Cursor = Cursors.Default;
  254. }
  255. }
  256. #endregion
  257. #region 加载物料分类树
  258. /// <summary>
  259. /// 查询物料分类和物料
  260. /// </summary>
  261. public void GetPUR_MAT_Class()
  262. {
  263. //查询物料分类
  264. PurmatclassEntity matclassEntity = new PurmatclassEntity();
  265. matclassEntity.Validflag = "1";
  266. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatClassService", "getMatClass", new object[] { matclassEntity });
  267. dt_Purmatclass = dt;
  268. getultree(dt);//绑定物料分类表
  269. //查询物料
  270. MatEntity mat = new MatEntity();
  271. mat.Validflag = "1";
  272. //物料分类
  273. if (checkBox1.Checked)
  274. {
  275. mat.UpdateName = txt_ARC_CODE.Text;
  276. }
  277. mat.ItemCode = txt_wlbm.Text;
  278. string strItemName = txt_wlmc.Text.Trim();
  279. while (strItemName.Contains(" "))
  280. {
  281. strItemName = strItemName.Replace(" ", " ");
  282. }
  283. mat.MatItems = strItemName.Split(' ');
  284. getMat(mat);
  285. }
  286. /// <summary>
  287. /// 获取物料分类树形结构
  288. /// </summary>
  289. public void getultree(DataTable dt)
  290. {
  291. ulTreeMat.Nodes.Clear();
  292. if (dt == null || dt.Rows.Count < 1)
  293. {
  294. return;
  295. }
  296. dt_Purmatclass = dt;//保存物料分类全局变量
  297. DataTable dt_A = new DataTable();//物料分类
  298. //筛选出根节点
  299. DataRow[] rows = dt.Select("PARENTCODE='' or PARENTCODE is null");
  300. dt_A = dt.Clone(); //克隆A的结构
  301. foreach (DataRow row in rows)
  302. {
  303. dt_A.ImportRow(row);//复制行数据
  304. }
  305. //添加物料大类
  306. for (int j = 0; j < dt_A.Rows.Count; j++)
  307. {
  308. UltraTreeNode Ultnode = ulTreeMat.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString());
  309. getChildNodes(Ultnode);
  310. }
  311. }
  312. /// <summary>
  313. /// 递归查询父节点下的所有子节点
  314. /// </summary>
  315. /// <param name="Tnode"></param>
  316. public void getChildNodes(UltraTreeNode Tnode)
  317. {
  318. DataTable dt_A = dt_Purmatclass.Clone();//物料分类
  319. DataRow[] rows = dt_Purmatclass.Select("PARENTCODE='" + Tnode.Key + "'");
  320. foreach (DataRow row in rows)
  321. {
  322. dt_A.ImportRow(row);//复制行数据
  323. }
  324. //添加物料分类
  325. for (int j = 0; j < dt_A.Rows.Count; j++)
  326. {
  327. UltraTreeNode Ultnode = Tnode.Nodes.Add(dt_A.Rows[j]["BASECODE"].ToString(), dt_A.Rows[j]["BASENAME"].ToString());
  328. getChildNodes(Ultnode);//利用递归将当前节点的子节点添加进去
  329. }
  330. }
  331. private void ulTreeMat_AfterActivate(object sender, NodeEventArgs e)
  332. {
  333. if (!QClickCellOrQuery)//如果不是点击查询按钮或单击grig行数据,刷新右侧数据
  334. {
  335. MatEntity eMat = new MatEntity();
  336. ulTreeMat.ActiveNode.Expanded = true;
  337. qUltraNode = ulTreeMat.ActiveNode;
  338. eMat.ArcCode = qUltraNode.Key;
  339. eMat.Validflag = "1";
  340. getMat(eMat);
  341. }
  342. txt_ARC_CODE.Text = ulTreeMat.ActiveNode.Key;
  343. txt_ARC_ITEM.Text = ulTreeMat.ActiveNode.Text;
  344. }
  345. #endregion
  346. #region 物料查询
  347. /// <summary>
  348. /// 查询物料
  349. /// </summary>
  350. private void getMat(MatEntity mat)
  351. {
  352. DTmat.Clear();
  353. //查询合同加权平均价
  354. if (QtimeB.Value != null)
  355. {
  356. mat.UpdateTime = (DateTime)QtimeB.Value;
  357. }
  358. if (QtimeE.Value != null)
  359. {
  360. mat.CreateTime = (DateTime)QtimeE.Value;
  361. }
  362. mat.LastPrice = 1;
  363. mat.ItemUomConefficient = double.Parse(QueryNum.Value.ToString());
  364. DataTable dt_mat = this.execute<DataTable>("com.hnshituo.pur.configure.service.MatService", "getMat", new object[] { mat });
  365. GridHelper.CopyDataToDatatable(ref dt_mat, ref DTmat, true);//绑定物料分类表
  366. GridHelper.RefreshAndAutoSize(GridMat);
  367. }
  368. #endregion
  369. private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
  370. {
  371. if (ultraTabControl1.SelectedTab.Key == "2")
  372. {
  373. this.ToolBarItemEnable(this, "conFirmation", false);
  374. this.ToolBarItemEnable(this, "updByClass", false);
  375. }
  376. else
  377. {
  378. this.ToolBarItemEnable(this, "conFirmation", true);
  379. this.ToolBarItemEnable(this, "updByClass", true);
  380. }
  381. }
  382. private void frmPop_updPrice_Shown(object sender, EventArgs e)
  383. {
  384. this.ToolBarItemEnable(this, "conFirmation", true);
  385. this.ToolBarItemEnable(this, "updByClass", true);
  386. }
  387. }
  388. }