FrmAttrs.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;using Pur.Entity;
  10. using System.Collections;
  11. using Infragistics.Win.UltraWinGrid;
  12. using Core.Mes.Client.Comm.Server;
  13. using Core.Mes.Client.Comm.Control;
  14. using Core.Mes.Client.Comm.Tool;
  15. namespace Pur.configure
  16. {
  17. public partial class FrmAttrs : FrmPmsBase
  18. {
  19. public FrmAttrs()
  20. {
  21. InitializeComponent();
  22. ExceptionHelper.RegistException();
  23. }
  24. public override void ToolBar_Click(object sender, string ToolbarKey)
  25. {
  26. switch (ToolbarKey)
  27. {
  28. case "doQuery":
  29. try
  30. {
  31. this.Cursor = Cursors.WaitCursor;
  32. doQuery();
  33. }
  34. finally
  35. {
  36. this.Cursor = Cursors.Default;
  37. }
  38. break;
  39. case "doAdd":
  40. doAdd();
  41. break;
  42. case "doModify":
  43. doModify();
  44. break;
  45. case "doDelete":
  46. this.doDeleteOrResume(true);
  47. break;
  48. case "doResume":
  49. this.doDeleteOrResume(false);
  50. break;
  51. case "Close":
  52. this.Close();
  53. break;
  54. }
  55. }
  56. /// <summary>
  57. /// 树节点选中事件触发时,存储父节点id,防止当父节点选中项转移到其他焦点时,无法获取数据。
  58. /// </summary>
  59. private static string parentCode = "";
  60. /// <summary>
  61. /// 用于修改时验证重复项
  62. /// </summary>
  63. private static string VName = "";
  64. private bool IsExistValidChild(string baseCode)
  65. {
  66. DataTable dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.isExistValidChild", new object[] { baseCode }, ob);
  67. if (dt != null && dt.Rows[0][0].ToString() != "0")
  68. {
  69. return true;
  70. }
  71. return false;
  72. }
  73. private bool IsExistValidParent(string sortCode)
  74. {
  75. DataTable dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.isExistValidParent", new object[] { sortCode }, ob);
  76. if (dt != null && dt.Rows[0][0].ToString() != "0")
  77. {
  78. return true;
  79. }
  80. return false;
  81. }
  82. /// <summary>
  83. /// 作废或恢复
  84. /// </summary>
  85. /// <param name="isDelete">true作废 false恢复</param>
  86. private void doDeleteOrResume(bool isDelete)
  87. {
  88. //已经没有批量作废功能,单表作废功能实现。
  89. ArrayList param = new ArrayList();
  90. if (ultraGrid1.ActiveRow == null)
  91. {
  92. MessageBox.Show("请选择需要" + (isDelete ? "作废" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  93. return;
  94. }
  95. string validflagStr = ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
  96. //无效数据不允许作废
  97. if ("0".Equals(validflagStr))
  98. {
  99. if (isDelete)
  100. {
  101. MessageBox.Show("无效数据不支持作废操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  102. return;
  103. }
  104. }
  105. else
  106. {
  107. //有效数据不允许恢复
  108. if (!isDelete)
  109. {
  110. MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  111. return;
  112. }
  113. }
  114. string baseCode = ultraGrid1.ActiveRow.Cells["BASECODE"].Value.ToString();
  115. string parentCode = ultraGrid1.ActiveRow.Cells["SORTCODE"].Value.ToString();
  116. if (isDelete && IsExistValidChild(baseCode))
  117. {
  118. MessageUtil.ShowWarning("该节点包含有效的子节点,不能作废!");
  119. return;
  120. }
  121. if (isDelete == false && IsExistValidParent(parentCode) == false)
  122. {
  123. MessageUtil.ShowWarning("该节点没有有效的父节点,不能恢复!");
  124. return;
  125. }
  126. ArrayList parm = new ArrayList();
  127. param.Add(baseCode);
  128. if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "作废" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  129. {
  130. try
  131. {
  132. int count = ServerHelper.SetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
  133. if (count > 0)
  134. {
  135. binUltraGrid(parentCode);
  136. //作废聚焦
  137. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  138. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  139. {
  140. row = ultraGrid1.Rows[i];
  141. if (row.Cells["BASECODE"].Value.ToString().Equals(baseCode))
  142. {
  143. row.Activate();
  144. break;
  145. }
  146. }
  147. }
  148. }
  149. catch (Exception ex)
  150. {
  151. MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  152. }
  153. }
  154. }
  155. /// <summary>
  156. /// 验证必填项
  157. /// </summary>
  158. /// <returns></returns>
  159. private bool ValidInput()
  160. {
  161. if (string.IsNullOrEmpty(txtName.Text.Trim()))
  162. {
  163. MessageBox.Show("请输入基础分类名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  164. return false;
  165. }
  166. return true;
  167. }
  168. /// <summary>
  169. /// 修改操作
  170. /// </summary>
  171. private void doModify()
  172. {
  173. //判断当前树节点是否有选中项,如果没有则不允许新增。 || !(treeView1.SelectedNode.Nodes.Count > 0)
  174. //if (treeView1.SelectedNode == null)
  175. //{
  176. // MessageBox.Show("请先选中左侧基础分类树节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  177. // return;
  178. //}
  179. if (parentCode == "")
  180. {
  181. MessageBox.Show("请先选中左侧基础分类树节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  182. return;
  183. }
  184. //BASECODE,BASENAME,SORTCODE,ISVISIBLE,MNEMONIC_CODE,SEQ,FLAG
  185. //基础分类编码,基础分类名称,快速检索码,可编辑标志(1:可编辑,0:不可编辑),拼音助记码,序号(排序用),
  186. //是否允许增加子类(1:允许,0:不允许)
  187. if (ultraGrid1.ActiveRow == null)
  188. {
  189. MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  190. return;
  191. }
  192. string validflagStr = ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
  193. //无效数据不允许修改
  194. if ("0".Equals(validflagStr))
  195. {
  196. MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  197. return;
  198. }
  199. if (ValidInput())
  200. {
  201. ArrayList parm = new ArrayList();
  202. //父节点的编号+当前手动输入的后半段编号,需要提供验证功能。
  203. string baseCode = this.ultraGrid1.ActiveRow.Cells["baseCode"].Value.ToString();
  204. //先判断基础分类名称是否重复,如果重复则return,并提示他。
  205. string name = txtName.Text.Trim();
  206. //验证是否修改了name
  207. if (!VName.Equals(name))
  208. {
  209. //验证名称是否重复。
  210. if (isRepeatName(parentCode, name))
  211. {
  212. MessageBox.Show("基础分类名称\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  213. return;
  214. }
  215. }
  216. if (MessageBox.Show("是否确认修改?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  217. {
  218. return;
  219. }
  220. //基础分类名称
  221. parm.Add(name);
  222. //快速检索码,父节点编号
  223. //string parentCode = this.parentCode;
  224. //parm.Add(parentCode);
  225. //可编辑标识
  226. //parm.Add(cmbEdit.Value.ToString().Trim());
  227. //拼音助记码
  228. parm.Add("");
  229. //序号也应该是自动生成的
  230. //parm.Add(txtSEQ.Text.Trim());
  231. //是否允许添加子类,因此,实际上在新增时,还需要判断该字段,假设为否,则提示他不可以新增子类。
  232. if (chbxAddChild.Checked)
  233. {
  234. parm.Add(1);
  235. }
  236. else
  237. {
  238. parm.Add(0);
  239. }
  240. //admin
  241. parm.Add(this.UserInfo.GetUserName());
  242. //备注
  243. parm.Add(txtMemo.Text);
  244. //id最后加入
  245. parm.Add(baseCode);
  246. CoreClientParam ccp = new CoreClientParam();
  247. ccp.ServerName = "com.hnshituo.pur.configure.service.impl.CoreAttrs";
  248. ccp.MethodName = "doModify";
  249. ccp.ServerParams = new object[] { parm };
  250. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  251. if (ccp.ReturnCode == -1) return;
  252. //刷新Grid数据
  253. binUltraGrid(parentCode);
  254. //刷新树节点数据
  255. //treeView1.SelectedNode.Nodes.Find(baseCode,false) = name;
  256. //修改树节点数据
  257. foreach (TreeNode anode in treeView1.SelectedNode.Nodes)
  258. {
  259. if (baseCode.Equals(anode.Tag.ToString()))
  260. {
  261. anode.Text = name;
  262. }
  263. }
  264. //高亮显示新增的数据
  265. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  266. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  267. {
  268. row = ultraGrid1.Rows[i];
  269. if (row.Cells["BASECODE"].Value.ToString().Equals(baseCode))
  270. {
  271. row.Activate();
  272. break;
  273. }
  274. }
  275. }
  276. }
  277. /// <summary>
  278. /// 查找树节点根据tag
  279. /// </summary>
  280. /// <param name="treeview">要查找的树</param>
  281. /// <param name="treeTag">treetag</param>
  282. /// <returns></returns>
  283. public TreeNode[] FindTreeNodeByNodeTag(TreeView treeview, string treeTag)
  284. {
  285. if (treeview.Nodes == null)
  286. {
  287. return null;
  288. }
  289. TreeNode[] treeNodeList = null;
  290. ArrayList treelist = new ArrayList();
  291. foreach (TreeNode trnode in treeview.Nodes)
  292. {
  293. FindTreeNodeFromTag(trnode, treeTag, ref treelist);
  294. }
  295. if (treelist.Count > 0)
  296. {
  297. treeNodeList = new TreeNode[treelist.Count];
  298. for (int i = 0; i < treelist.Count; i++)
  299. {
  300. treeNodeList[i] = (TreeNode)treelist[i];
  301. }
  302. }
  303. return treeNodeList;
  304. }
  305. /// <summary>
  306. /// 查找具体的tag
  307. /// </summary>
  308. /// <param name="trnode"></param>
  309. /// <param name="treeTag"></param>
  310. /// <param name="treelist"></param>
  311. private void FindTreeNodeFromTag(TreeNode trnode, string treeTag, ref ArrayList treelist)
  312. {
  313. if (trnode.Tag != null && trnode.Tag.ToString() == treeTag)
  314. {
  315. treelist.Add(trnode);
  316. }
  317. foreach (TreeNode anode in trnode.Nodes)
  318. {
  319. FindTreeNodeFromTag(anode, treeTag, ref treelist);
  320. }
  321. }
  322. /// <summary>
  323. /// 验证名称是否重复。
  324. /// </summary>
  325. /// <param name="name"></param>
  326. /// <returns></returns>
  327. private bool isRepeatName(string sortCode, string baseName)
  328. {
  329. DataTable dt = new DataTable();
  330. dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.GetName", new Object[] { sortCode, baseName }, this.ob);
  331. if (dt.Rows.Count > 0)
  332. {
  333. return true;
  334. }
  335. else
  336. {
  337. return false;
  338. }
  339. }
  340. /// <summary>
  341. /// 验证是否允许添加子项
  342. /// </summary>
  343. /// <param name="parentCode"></param>
  344. /// <returns></returns>
  345. private bool isAddChild(string baseCode)
  346. {
  347. DataTable dt = new DataTable();
  348. dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.isAddChild", new Object[] { baseCode }, this.ob);
  349. if ("1".Equals(dt.Rows[0]["FLAG"].ToString()))
  350. {
  351. return true;
  352. }
  353. else
  354. {
  355. return false;
  356. }
  357. }
  358. /// <summary>
  359. /// 新增操作
  360. /// </summary>
  361. private void doAdd()
  362. {
  363. //判断当前树节点是否有选中项,如果没有则不允许新增。
  364. //单击新增时,树节点势必没有选中。
  365. //if (treeView1.SelectedNode == null || !(treeView1.SelectedNode.Nodes.Count > 0))
  366. //{
  367. // MessageBox.Show("请先选中树节点!", "提示");
  368. // return;
  369. //}
  370. if (parentCode == "")
  371. {
  372. MessageBox.Show("请先选中左侧基础分类树节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  373. return;
  374. }
  375. if (ValidInput())
  376. {
  377. //基础分类名称
  378. string name = txtName.Text.Trim();
  379. if (isRepeatName(parentCode, name))
  380. {
  381. MessageBox.Show("基础分类名称\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  382. return;
  383. }
  384. //string parentCode = parentCode;
  385. //判断当前父类是否允许增加子类
  386. if (!isAddChild(parentCode))
  387. {
  388. MessageBox.Show("当前父类基础信息不允许增加子类!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  389. return;
  390. }
  391. if (MessageBox.Show("是否确认新增?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  392. {
  393. return;
  394. }
  395. ArrayList parm = new ArrayList();
  396. //BASECODE,BASENAME,SORTCODE,ISVISIBLE,MNEMONIC_CODE,SEQ,FLAG
  397. //基础分类编码,基础分类名称,快速检索码,可编辑标志(1:可编辑,0:不可编辑),拼音助记码,序号(排序用),
  398. //是否允许增加子类(1:允许,0:不允许)
  399. //自动生成编号,需要查询出当前父节点下最大编号。
  400. DataTable dt = new DataTable();
  401. dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.GetMaxBaseCode", new Object[] { parentCode }, this.ob);
  402. string baseCode = "";
  403. if (dt.Rows.Count > 0 && !"".Equals(dt.Rows[0][0].ToString()))
  404. {
  405. baseCode = (Convert.ToInt32(dt.Rows[0][0]) + 1).ToString();
  406. }
  407. else
  408. {
  409. if (parentCode.Length > 1)
  410. {
  411. baseCode = parentCode + "001";
  412. }
  413. else
  414. {
  415. baseCode = parentCode + "001";
  416. }
  417. }
  418. parm.Add(baseCode);
  419. parm.Add(name);
  420. //快速检索码,父节点编号
  421. parm.Add(parentCode);
  422. //可编辑标识
  423. //parm.Add(cmbEdit.Value.ToString());
  424. //拼音助记码
  425. parm.Add("");
  426. //序号也应该是自动生成的
  427. //parm.Add(txtSEQ.Text.Trim());
  428. //是否允许添加子类,因此,实际上在新增时,还需要判断该字段,假设为否,则提示他不可以新增子类。
  429. if (chbxAddChild.Checked)
  430. {
  431. parm.Add(1);
  432. }
  433. else
  434. {
  435. parm.Add(0);
  436. }
  437. //admin
  438. parm.Add(this.UserInfo.GetUserName());
  439. //备注
  440. parm.Add(txtMemo.Text);
  441. CoreClientParam ccp = new CoreClientParam();
  442. ccp.ServerName = "com.hnshituo.pur.configure.service.impl.CoreAttrs";
  443. ccp.MethodName = "doAdd";
  444. ccp.ServerParams = new object[] { parm };
  445. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  446. if (ccp.ReturnCode == -1) return;
  447. //刷新数据源
  448. binUltraGrid(parentCode);
  449. //树节点刷新,树节点会折叠起来。
  450. //bandTreeView();
  451. //当前父节点新增一个子节点
  452. TreeNode tn = new TreeNode();
  453. tn.Text = name;
  454. tn.Tag = baseCode;
  455. treeView1.SelectedNode.Nodes.Add(tn);
  456. //高亮显示新增的数据
  457. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  458. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  459. {
  460. row = ultraGrid1.Rows[i];
  461. if (row.Cells["BASECODE"].Value.ToString().Equals(baseCode))
  462. {
  463. row.Activate();
  464. break;
  465. }
  466. }
  467. }
  468. }
  469. /// <summary>
  470. /// 刷新操作
  471. /// </summary>
  472. private void doQuery()
  473. {
  474. //查询按钮就当刷新功能。
  475. bandTreeView();
  476. }
  477. /// <summary>
  478. /// 刷新树控件
  479. /// </summary>
  480. /// <param name="sender"></param>
  481. /// <param name="e"></param>
  482. private void FrmAttrs_Load(object sender, EventArgs e)
  483. {
  484. //绑定是否可编辑控件
  485. //bandCmbEdit();
  486. //根据已选择的项,绑定树控件。
  487. bandTreeView();
  488. }
  489. /// <summary>
  490. /// //绑定是否可编辑控件
  491. /// </summary>
  492. //public void bandCmbEdit()
  493. //{
  494. // DataTable dt = new DataTable();
  495. // dt.Columns.Add("display");
  496. // dt.Columns.Add("value");
  497. // DataRow dr = dt.NewRow();
  498. // dr["display"] = "是";
  499. // dr["value"] = "1";
  500. // DataRow drB = dt.NewRow();
  501. // drB["display"] = "否";
  502. // drB["value"] = "0";
  503. // dt.Rows.Add(dr);
  504. // dt.Rows.Add(drB);
  505. // cmbEdit.DataSource = dt;
  506. // cmbEdit.DisplayMember = "display";
  507. // cmbEdit.ValueMember = "value";
  508. //}
  509. /// <summary>
  510. /// 树控件绑定数据源
  511. /// </summary>
  512. public void bandTreeView()
  513. {
  514. ArrayList parms = new ArrayList();
  515. //if (chbxXS.Checked)
  516. //{
  517. // parms.Add("1");
  518. //}
  519. //else
  520. //{
  521. // parms.Add("");
  522. //}
  523. //采购管理
  524. if (chbxCG.Checked)
  525. {
  526. parms.Add("1");
  527. }
  528. else
  529. {
  530. parms.Add("");
  531. }
  532. if (chbxSC.Checked)
  533. {
  534. parms.Add("2");
  535. }
  536. else
  537. {
  538. parms.Add("");
  539. }
  540. if (chbxLG.Checked)
  541. {
  542. parms.Add("3");
  543. }
  544. else
  545. {
  546. parms.Add("");
  547. }
  548. if (chbxZL.Checked)
  549. {
  550. parms.Add("4");
  551. }
  552. else
  553. {
  554. parms.Add("");
  555. }
  556. if (chbxZG.Checked)
  557. {
  558. parms.Add("5");
  559. }
  560. else
  561. {
  562. parms.Add("");
  563. }
  564. if (chbxRCL.Checked)
  565. {
  566. parms.Add("6");
  567. }
  568. else
  569. {
  570. parms.Add("");
  571. }
  572. if (chbxGJG.Checked)
  573. {
  574. parms.Add("7");
  575. }
  576. else
  577. {
  578. parms.Add("");
  579. }
  580. if (chbxWL.Checked)
  581. {
  582. parms.Add("8");
  583. }
  584. else
  585. {
  586. parms.Add("");
  587. }
  588. if (chbxQT.Checked)
  589. {
  590. parms.Add("9");
  591. }
  592. else
  593. {
  594. parms.Add("");
  595. }
  596. //DataTable treeViewdt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.getTreeData", new Object[] { parms }, this.ob);
  597. //binUltraGrid("2001");
  598. treeView1.Nodes.Clear();
  599. DataTable dt = new DataTable();
  600. dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.getTreeData", new Object[] { parms }, this.ob);
  601. //树控件递归绑定方法。
  602. Bind_Tv(dt, treeView1.Nodes, null, "BASECODE", "SORTCODE", "BASENAME");
  603. }
  604. /// <summary>
  605. /// top复选框选中事件触发,更新树控件数据源
  606. /// </summary>
  607. /// <param name="sender"></param>
  608. /// <param name="e"></param>
  609. private void chbx_CheckedChanged(object sender, EventArgs e)
  610. {
  611. //刷新功能。
  612. bandTreeView();
  613. }
  614. /// <summary>
  615. /// terrView1选择内容更改时触发。
  616. /// </summary>
  617. /// <param name="sender"></param>
  618. /// <param name="e"></param>
  619. private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  620. {
  621. try
  622. {
  623. this.Cursor = Cursors.WaitCursor;
  624. //给编辑区域控件赋值。
  625. //基础分类编码
  626. //txtCodePart1.Text = e.Node.Tag.ToString();
  627. //快速检索码
  628. //txtSCode.Text = e.Node.Tag.ToString();
  629. //刷新Grid数据源,将父节点等于当前选中节点的数据全部取出来,构建数据源。
  630. parentCode = e.Node.Tag.ToString();
  631. binUltraGrid(parentCode);
  632. }
  633. finally
  634. {
  635. this.Cursor = Cursors.Default;
  636. }
  637. }
  638. /// <summary>
  639. /// 刷新Grid数据源
  640. /// </summary>
  641. /// <param name="basecode"></param>
  642. private void binUltraGrid(string basecode)
  643. {
  644. this.dataTable1.Clear();
  645. DataTable dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreAttrs.doQuery", new Object[] { basecode }, this.ob);
  646. GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
  647. //不同颜色区分是否有效数据
  648. Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
  649. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  650. {
  651. row = ultraGrid1.Rows[i];
  652. if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
  653. {
  654. row.Appearance.ForeColor = Color.Red;
  655. }
  656. else
  657. {
  658. row.Appearance.ForeColor = Color.Black;
  659. }
  660. }
  661. //内容自适应
  662. GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, new UltraGridColumn[] {
  663. ultraGrid1.DisplayLayout.Bands[0].Columns["MEMO"]
  664. });
  665. }
  666. /// <summary>
  667. /// 绑定TreeView(利用TreeNodeCollection)
  668. /// </summary>
  669. /// <param name="tnc">TreeNodeCollection(TreeView的节点集合)</param>
  670. /// <param name="pid_val">父id的值</param>
  671. /// <param name="id">数据库 id 字段名</param>
  672. /// <param name="pid">数据库 父id 字段名</param>
  673. /// <param name="text">数据库 文本 字段值</param>
  674. private void Bind_Tv(DataTable dt, TreeNodeCollection tnc, string pid_val, string id, string pid, string text)
  675. {
  676. DataView dv = new DataView(dt);//将DataTable存到DataView中,以便于筛选数据
  677. TreeNode tn;//建立TreeView的节点(TreeNode),以便将取出的数据添加到节点中
  678. //以下为三元运算符,如果父id为空,则为构建“父id字段 is null”的查询条件,否则构建“父id字段=父id字段值”的查询条件
  679. string filter = string.IsNullOrEmpty(pid_val) ? pid + " is null" : string.Format(pid + "='{0}'", pid_val);
  680. dv.RowFilter = filter;//利用DataView将数据进行筛选,选出相同 父id值 的数据
  681. foreach (DataRowView drv in dv)
  682. {
  683. tn = new TreeNode();//建立一个新节点(学名叫:一个实例)
  684. tn.Tag = drv[id].ToString();//节点的Value值,一般为数据库的id值
  685. tn.Text = drv[text].ToString();//节点的Text,节点的文本显示
  686. tnc.Add(tn);//将该节点加入到TreeNodeCollection(节点集合)中
  687. Bind_Tv(dt, tn.Nodes, tn.Tag.ToString(), id, pid, text);//递归(反复调用这个方法,直到把数据取完为止)
  688. }
  689. }
  690. /// <summary>
  691. /// 为编辑区域赋值
  692. /// </summary>
  693. /// <param name="sender"></param>
  694. /// <param name="e"></param>
  695. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  696. {
  697. //BASECODE,BASENAME,SORTCODE,ISVISIBLE,MNEMONIC_CODE,SEQ,FLAG
  698. //基础分类编码,基础分类名称,快速检索码,可编辑标志(1:可编辑,0:不可编辑),拼音助记码,序号(排序用),
  699. //是否允许增加子类(1:允许,0:不允许)
  700. Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid1.ActiveRow;
  701. if (row != null)
  702. {
  703. //基础分类编码
  704. //txtCodePart2.Text = row.Cells["BASECODE"].Value.ToString();
  705. //基础分类名称
  706. txtName.Text = row.Cells["BASENAME"].Value.ToString();
  707. //存储name,用于修改时验证重复项。
  708. VName = row.Cells["BASENAME"].Value.ToString();
  709. //快速检索码,进入Grid之前就已经进行赋值。
  710. //txtCodePart2.Text = row.Cells["SORTCODE"].Value.ToString();
  711. //可编辑标志
  712. //cmbEdit.Value = row.Cells["ISVISIBLE"].Value.ToString();
  713. //拼音助记码
  714. //txtPym.Text = row.Cells["MNEMONIC_CODE"].Value.ToString();
  715. //序号
  716. //txtSEQ.Text = row.Cells["SEQ"].Value.ToString();
  717. //是否允许增加子类
  718. if ("1".Equals(row.Cells["FLAG"].Value.ToString()))
  719. {
  720. chbxAddChild.Checked = true;
  721. }
  722. else
  723. {
  724. chbxAddChild.Checked = false;
  725. }
  726. //备注
  727. txtMemo.Text = row.Cells["MEMO"].Value.ToString();
  728. }
  729. }
  730. }
  731. }