FrmBaseInfoNew.cs 30 KB

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