FrmRegion.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  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;
  10. using Core.Mes.Client.Comm.Server;
  11. using Infragistics.Win.UltraWinGrid;
  12. using System.Collections;
  13. using Core.Mes.Client.Comm.Tool;
  14. using Core.Mes.Client.Comm.Control;
  15. namespace Pur.configure
  16. {
  17. public partial class FrmRegion : FrmBase
  18. {
  19. TreeNode tNode = new TreeNode();//保存上一次树点
  20. string strShift = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserOrder();
  21. string strTerm = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserGroup();
  22. string strOperator = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
  23. string regIonID = "";
  24. string nodeId = "";
  25. string region_no = "";
  26. DataTable isx = new DataTable();
  27. DataTable unLoad = new DataTable();
  28. protected override void OnLoad(EventArgs e)
  29. {
  30. try
  31. {
  32. base.OnLoad(e);
  33. ultraGridRegion.DisplayLayout.Override.FilterUIType = Infragistics.Win.UltraWinGrid.FilterUIType.FilterRow;
  34. ultraGridRegion.DisplayLayout.Override.FilterOperatorDefaultValue = Infragistics.Win.UltraWinGrid.FilterOperatorDefaultValue.Contains;
  35. //ultraGridRegion.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect;
  36. }
  37. catch (System.Exception ex)
  38. { }
  39. }
  40. public FrmRegion()
  41. {
  42. InitializeComponent();
  43. }
  44. /// <summary>
  45. /// 重写基类方法
  46. /// </summary>
  47. /// <param name="sender"></param>
  48. /// <param name="ToolbarKey"></param>
  49. public override void ToolBar_Click(object sender, string ToolbarKey)
  50. {
  51. switch (ToolbarKey)
  52. {
  53. case "doQuery":
  54. doQuery();
  55. break;
  56. case "doAdd":
  57. if (string.IsNullOrEmpty(txtName.Text))
  58. {
  59. MessageUtil.ShowTips("区域名称不允许为空!");
  60. return;
  61. }
  62. if (string.IsNullOrEmpty(ComboEdiRegPro.Text))
  63. {
  64. MessageUtil.ShowTips("区域属性不允许为空!");
  65. return;
  66. }
  67. if (string.IsNullOrEmpty(ComboEditorPro.Text))
  68. {
  69. MessageUtil.ShowTips("上级区域不允许为空!");
  70. return;
  71. }
  72. if (comboRegIon.SelectedItem == null || comboRegIon.Text.Equals(""))
  73. {
  74. MessageUtil.ShowWarning("请选择[行政片区]!");
  75. return ;
  76. }
  77. if (MessageUtil.ShowQuestion("是否新增数据?").ToString().ToLower().Equals("yes"))
  78. {
  79. string dosave = doSave();
  80. if (dosave.Equals("doAddTrue"))
  81. {
  82. MessageUtil.ShowTips("添加成功!");
  83. }
  84. else if (dosave.Equals("doAddFalse"))
  85. {
  86. MessageUtil.ShowTips("添加失败!");
  87. return;
  88. }
  89. else if (dosave.Equals("saveCoint"))
  90. {
  91. MessageUtil.ShowTips("已经维护!");
  92. return;
  93. }
  94. else if (dosave.Equals("updateTrue"))
  95. {
  96. MessageUtil.ShowTips("添加成功!");
  97. }
  98. else if (dosave.Equals("updateFalse"))
  99. {
  100. MessageUtil.ShowTips("添加失败!");
  101. return;
  102. }
  103. regIonCode();
  104. try {
  105. doQueryClick(ComboEditorPro.Value.ToString());
  106. }catch(Exception){}
  107. QueryTree();
  108. }
  109. break;
  110. case "doDelete":
  111. if (ultraGridRegion.ActiveRow == null)
  112. {
  113. MessageUtil.ShowTips("未找到需要操作的数据!");
  114. return;
  115. }
  116. if (string.IsNullOrEmpty(regIonID))
  117. {
  118. MessageUtil.ShowTips("请选择需要作废的数据!");
  119. return;
  120. }
  121. foreach (UltraGridRow ugr in this.ultraGridRegion.Rows)
  122. {
  123. if (ugr.Cells["REGION_NO"].Value.ToString().Equals(regIonID))
  124. {
  125. if (ugr.Cells["VALIDFLAG"].Value.ToString().Equals("无效"))
  126. {
  127. MessageUtil.ShowTips("数据无效不能重复操作!");
  128. return;
  129. }
  130. }
  131. }
  132. if (MessageUtil.ShowQuestion("是否作废数据?").ToString().ToLower().Equals("yes"))
  133. {
  134. if (doDelete())
  135. {
  136. MessageUtil.ShowTips("作废成功!");
  137. }
  138. else
  139. {
  140. MessageUtil.ShowTips("作废失败!");
  141. return;
  142. }
  143. regIonCode();
  144. try
  145. {
  146. doQueryClick(ComboEditorPro.Value.ToString());
  147. }catch( Exception){
  148. }
  149. QueryTree();
  150. //doQuery();
  151. }
  152. break;
  153. //case "doRecovery":
  154. // if (ultraGridRegion.ActiveRow == null)
  155. // {
  156. // MessageUtil.ShowTips("未找到需要操作的数据!");
  157. // return;
  158. // }
  159. // if (string.IsNullOrEmpty(regIonID))
  160. // {
  161. // MessageUtil.ShowTips("请选择需要恢复的数据!");
  162. // return;
  163. // }
  164. // foreach (UltraGridRow ugr in this.ultraGridRegion.Rows)
  165. // {
  166. // if (ugr.Cells["REGION_NO"].Value.ToString().Equals(regIonID))
  167. // {
  168. // if (ugr.Cells["VALIDFLAG"].Value.ToString().Equals("有效"))
  169. // {
  170. // MessageUtil.ShowTips("数据有效不能恢复!");
  171. // return;
  172. // }
  173. // }
  174. // }
  175. // if (MessageUtil.ShowQuestion("是否恢复数据?").ToString().ToLower().Equals("yes"))
  176. // {
  177. // if (doResume())
  178. // {
  179. // MessageUtil.ShowTips("恢复成功!");
  180. // }
  181. // else
  182. // {
  183. // MessageUtil.ShowTips("恢复失败!");
  184. // return;
  185. // }
  186. // doQueryClick(ComboEditorPro.Value == null ? "" : ComboEditorPro.Value.ToString());
  187. // }
  188. // break;
  189. case "doUpdate":
  190. if (ultraGridRegion.ActiveRow == null)
  191. {
  192. MessageUtil.ShowWarning("请选择一行您要修改的数据!");
  193. return ;
  194. }
  195. if (string.IsNullOrEmpty(txtName.Text))
  196. {
  197. MessageUtil.ShowTips("区域名称不允许为空!");
  198. return;
  199. }
  200. if (string.IsNullOrEmpty(ComboEdiRegPro.Text))
  201. {
  202. MessageUtil.ShowTips("区域属性不允许为空!");
  203. return;
  204. }
  205. if (string.IsNullOrEmpty(ComboEditorPro.Text))
  206. {
  207. MessageUtil.ShowTips("上级区域不允许为空!");
  208. return;
  209. }
  210. if (string.IsNullOrEmpty(comboRegIon.Text))
  211. {
  212. MessageUtil.ShowTips("行政片区不允许为空!");
  213. return;
  214. }
  215. if (string.IsNullOrEmpty(regIonID))
  216. {
  217. MessageUtil.ShowTips("请选择需要修改的数据!");
  218. return;
  219. }
  220. if (MessageUtil.ShowQuestion("是否修改数据?").ToString().ToLower().Equals("yes"))
  221. {
  222. if (doUpdate())
  223. {
  224. MessageUtil.ShowTips("修改成功!");
  225. }
  226. else
  227. {
  228. //MessageUtil.ShowTips("修改失败!");
  229. return;
  230. }
  231. regIonCode();
  232. try
  233. {
  234. doQueryClick(ComboEditorPro.Value.ToString());
  235. }
  236. catch (Exception)
  237. {
  238. }
  239. QueryTree();
  240. }
  241. break;
  242. case "doClose":
  243. this.Close();
  244. break;
  245. }
  246. }
  247. //查询
  248. public void doQuery()
  249. {
  250. QueryTree();
  251. //if (nodeId != "")
  252. //{
  253. // doQueryClick(nodeId);
  254. // return;
  255. //}
  256. DataTable dts = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetQueryReg", new Object[] { }, this.ob);
  257. uldtsCoupling.Tables[0].Clear();
  258. foreach (DataRow dr in dts.Rows)
  259. {
  260. DataRow _dr = uldtsCoupling.Tables[0].NewRow();
  261. foreach (DataColumn dc in uldtsCoupling.Tables[0].Columns)
  262. {
  263. _dr[dc.ColumnName] = dr[dc.ColumnName];
  264. }
  265. uldtsCoupling.Tables[0].Rows.Add(_dr);
  266. }
  267. foreach (UltraGridRow ugr in this.ultraGridRegion.Rows)
  268. {
  269. if (ugr.Cells["VALIDFLAG"].Value.ToString().ToLower() == "0")
  270. {
  271. ugr.Cells["VALIDFLAG"].Value = "无效";
  272. this.ultraGridRegion.Rows[ugr.Index].CellAppearance.ForeColor = Color.Red;
  273. }
  274. if (ugr.Cells["VALIDFLAG"].Value.ToString().ToLower() == "1")
  275. {
  276. ugr.Cells["VALIDFLAG"].Value = "有效";
  277. }
  278. if (ugr.Cells["REGION_NM"].Value.ToString().Equals(region_no))
  279. {
  280. ugr.Activate();
  281. }
  282. else if (ugr.Cells["REGION_NO"].Value.ToString().Equals(region_no))
  283. {
  284. ugr.Activate();
  285. }
  286. }
  287. //内容自适应
  288. GridHelper.RefreshAndAutoSizeExceptRows(ultraGridRegion, new UltraGridColumn[] {
  289. ultraGridRegion.DisplayLayout.Bands[0].Columns["MEMO"]
  290. });
  291. }
  292. //单击树形视图查询
  293. public void doQueryClick(string regIon)
  294. {
  295. DataTable dts = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetQueryRegIonCode", new Object[] { regIon }, this.ob);
  296. uldtsCoupling.Tables[0].Clear();
  297. foreach (DataRow dr in dts.Rows)
  298. {
  299. DataRow _dr = uldtsCoupling.Tables[0].NewRow();
  300. foreach (DataColumn dc in uldtsCoupling.Tables[0].Columns)
  301. {
  302. _dr[dc.ColumnName] = dr[dc.ColumnName];
  303. }
  304. uldtsCoupling.Tables[0].Rows.Add(_dr);
  305. }
  306. foreach (UltraGridRow ugr in this.ultraGridRegion.Rows)
  307. {
  308. if (ugr.Cells["VALIDFLAG"].Value.ToString().ToLower() == "0")
  309. {
  310. ugr.Cells["VALIDFLAG"].Value = "无效";
  311. this.ultraGridRegion.Rows[ugr.Index].CellAppearance.ForeColor = Color.Red;
  312. }
  313. if (ugr.Cells["VALIDFLAG"].Value.ToString().ToLower() == "1")
  314. {
  315. ugr.Cells["VALIDFLAG"].Value = "有效";
  316. }
  317. if (ugr.Cells["REGION_NM"].Value.ToString().Equals(region_no))
  318. {
  319. ugr.Activate();
  320. }
  321. else if (ugr.Cells["REGION_NO"].Value.ToString().Equals(region_no))
  322. {
  323. ugr.Activate();
  324. }
  325. }
  326. //内容自适应
  327. GridHelper.RefreshAndAutoSizeExceptRows(ultraGridRegion, new UltraGridColumn[] {
  328. ultraGridRegion.DisplayLayout.Bands[0].Columns["MEMO"]
  329. });
  330. }
  331. //保存
  332. public string doSave()
  333. {
  334. if (string.IsNullOrEmpty(ComboEditorPro.Text))
  335. {
  336. MessageUtil.ShowTips("请选择[上级区域],不允许为空!");
  337. return "xxx";
  338. }
  339. if (string.IsNullOrEmpty(ComboEdiRegPro.Text))
  340. {
  341. MessageUtil.ShowTips("请选择[区域属性],不允许为空!");
  342. return "xxx";
  343. }
  344. if (string.IsNullOrEmpty(txtName.Text))
  345. {
  346. MessageUtil.ShowTips("请选择[区域名称],不允许为空!");
  347. return "xxx";
  348. }
  349. if (txtName.Text.Equals("/"))
  350. {
  351. MessageUtil.ShowTips("请选择[区域名称],不允许填 / !");
  352. return "xxx";
  353. }
  354. //if (string.IsNullOrEmpty(comboRegIon.Text))
  355. //{
  356. // MessageUtil.ShowTips("行政片区不允许为空!");
  357. // return "xxx";
  358. //}
  359. //区域名称
  360. string regName = txtName.Text;
  361. //属性区域
  362. string regionno = ComboEdiRegPro.Text;
  363. string regionnm = ComboEdiRegPro.Value.ToString();
  364. //上级区域
  365. string pregionno = ComboEditorPro.Text == "" ? " " : ComboEditorPro.Text;
  366. string regiontype = ComboEditorPro.Value == null? " " : ComboEditorPro.Value.ToString();
  367. //行政片区
  368. string bigareaName = comboRegIon.Text == "" ? " " : comboRegIon.Text.ToString();
  369. string bigareaCode = comboRegIon.Value == null ? " " : comboRegIon.Value.ToString();
  370. //根据名称查找数据,如果有数据,而且是有效的,提示不允许新增。
  371. DataTable countDb = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.saveQueryName", new Object[] { regName }, this.ob);
  372. if (countDb.Rows.Count > 0)
  373. {
  374. MessageUtil.ShowTips("请重新输入[区域名称],区域名称存在!");
  375. return "xxx";
  376. }
  377. DataTable dts = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetSaveQuery", new Object[] { regName, regiontype }, this.ob);
  378. ArrayList parm = new ArrayList();
  379. CoreClientParam ccp = new CoreClientParam();
  380. if (dts.Rows.Count > 0)
  381. {
  382. if (dts.Rows[0]["VALIDFLAG"].ToString().Equals("1"))
  383. {
  384. return "saveCoint";
  385. }
  386. else if (dts.Rows[0]["VALIDFLAG"].ToString().Equals("0"))
  387. {
  388. parm = new ArrayList();
  389. parm.Add("1"); //0恢复
  390. parm.Add(dts.Rows[0]["REGION_NO"].ToString()); //ID
  391. ccp = new CoreClientParam();
  392. ccp.ServerName = "com.hnshituo.pur.configure.service.impl.CoreRegion";
  393. ccp.MethodName = "SetResumeIon";
  394. ccp.ServerParams = new object[] { parm };
  395. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  396. if (ccp.ReturnCode == -1)
  397. {
  398. return "updateFalse";
  399. }
  400. region_no = regName;
  401. return "updateTrue";
  402. }
  403. }
  404. parm = new ArrayList();
  405. parm.Add(regiontype); //如果是区域首次默认上级+01.
  406. parm.Add(regiontype); //如果是区域首次默认Where.
  407. parm.Add(regName); //区域名称
  408. parm.Add(regiontype); //上级区域代码
  409. parm.Add(regionnm);
  410. parm.Add(regiontype); //上级区域代码
  411. parm.Add(this.textBoxMemo.Text);
  412. parm.Add(strOperator);
  413. parm.Add(bigareaCode);//行政片区
  414. ccp = new CoreClientParam();
  415. ccp.ServerName = "com.hnshituo.pur.configure.service.impl.CoreRegion";
  416. ccp.MethodName = "SetAddRegion";
  417. ccp.ServerParams = new object[] { parm };
  418. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  419. if (ccp.ReturnCode == -1)
  420. {
  421. return "doAddFalse";
  422. }
  423. region_no = regName;
  424. return "doAddTrue";
  425. }
  426. //0删除,1恢复
  427. public bool doDelete()
  428. {
  429. if (string.IsNullOrEmpty(regIonID))
  430. {
  431. MessageUtil.ShowTips("请选择需要修改的数据!");
  432. return false;
  433. }
  434. ArrayList parm = new ArrayList();
  435. parm.Add("0"); //0删除
  436. parm.Add(strOperator);//删除人
  437. parm.Add(regIonID); //ID
  438. CoreClientParam ccp = new CoreClientParam();
  439. ccp.ServerName = "com.hnshituo.pur.configure.service.impl.CoreRegion";
  440. ccp.MethodName = "SetDleteRegion";
  441. ccp.ServerParams = new object[] { parm };
  442. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  443. if (ccp.ReturnCode == -1)
  444. {
  445. return false;
  446. }
  447. return true;
  448. }
  449. //恢复
  450. public bool doResume()
  451. {
  452. if (string.IsNullOrEmpty(regIonID))
  453. {
  454. MessageUtil.ShowTips("请选择需要修改的数据!");
  455. return false;
  456. }
  457. ArrayList parm = new ArrayList();
  458. parm.Add("1"); //0恢复
  459. parm.Add(regIonID); //ID
  460. CoreClientParam ccp = new CoreClientParam();
  461. ccp.ServerName = "com.hnshituo.pur.configure.service.impl.CoreRegion";
  462. ccp.MethodName = "SetResumeIon";
  463. ccp.ServerParams = new object[] { parm };
  464. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  465. if (ccp.ReturnCode == -1)
  466. {
  467. return false;
  468. }
  469. return true;
  470. }
  471. //修改
  472. public bool doUpdate()
  473. {
  474. if (string.IsNullOrEmpty(regIonID))
  475. {
  476. MessageUtil.ShowTips("请选择需要修改的数据!");
  477. return false;
  478. }
  479. if (string.IsNullOrEmpty(txtName.Text))
  480. {
  481. MessageUtil.ShowTips("区域名称不允许为空!");
  482. return false;
  483. }
  484. if (string.IsNullOrEmpty(ComboEdiRegPro.Text))
  485. {
  486. MessageUtil.ShowTips("属性区域不允许为空!");
  487. return false;
  488. }
  489. if (string.IsNullOrEmpty(ComboEditorPro.Text))
  490. {
  491. MessageUtil.ShowTips("上级区域不允许为空!");
  492. return false;
  493. }
  494. if (string.IsNullOrEmpty(comboRegIon.Text))
  495. {
  496. MessageUtil.ShowTips("行政区域不允许为空!");
  497. return false;
  498. }
  499. if (ultraGridRegion.ActiveRow != null && !ultraGridRegion.ActiveRow.Cells["REGION_NM"].Value.ToString().Equals(txtName.Text))
  500. {
  501. DataTable dts = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetSaveQuery", new Object[] { txtName.Text, ComboEditorPro.Value }, this.ob);
  502. if (dts.Rows.Count > 0)
  503. {
  504. MessageUtil.ShowTips("城市名称已存在,不能修改!");
  505. return false;
  506. }
  507. }
  508. ArrayList parm = new ArrayList();
  509. parm.Add(txtName.Text); //0恢复
  510. parm.Add(ComboEdiRegPro.Value); //type
  511. parm.Add(textBoxMemo.Text);//备注
  512. parm.Add(strOperator);//修改人
  513. parm.Add(comboRegIon.Value == null ? " " : comboRegIon.Value.ToString());//行政片区
  514. parm.Add(ComboEditorPro.Value);
  515. parm.Add(regIonID);//ID
  516. CoreClientParam ccp = new CoreClientParam();
  517. ccp.ServerName = "com.hnshituo.pur.configure.service.impl.CoreRegion";
  518. ccp.MethodName = "SetUpdateIon";
  519. ccp.ServerParams = new object[] { parm };
  520. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  521. if (ccp.ReturnCode == -1)
  522. {
  523. return false;
  524. }
  525. region_no = regIonID;
  526. return true;
  527. }
  528. private void frmRegion_Load(object sender, EventArgs e)
  529. {
  530. regIonCode();
  531. //this.treeRegion.Parent.Font = new Font("宋体", 8F, System.Drawing.FontStyle.Bold);
  532. //this.treeRegion.BackColor = Color.Empty;
  533. QueryTree();//刷新树结构
  534. ClsBaseInfo.SetComboItemHeight(ComboEditorPro);
  535. ClsBaseInfo.SetComboItemHeight(ComboEdiRegPro);
  536. ClsBaseInfo.SetComboItemHeight(comboRegIon);
  537. }
  538. //加载区域和上级区域属性
  539. private void regIonCode()
  540. {
  541. unLoad = new DataTable();
  542. unLoad.Columns.Add("Name", typeof(System.String));
  543. unLoad.Columns.Add("Code", typeof(System.String));
  544. //查询区域属性
  545. isx = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetRegIonCodeS", new Object[] { }, this.ob);
  546. for (int i = 0; i < isx.Rows.Count; i++)
  547. {
  548. unLoad.Rows.Add(isx.Rows[i]["REGION_TYPE_NM"].ToString(), isx.Rows[i]["REGION_TYPE_NO"].ToString());
  549. }
  550. ComboEdiRegPro.DataSource = unLoad;
  551. ComboEdiRegPro.DisplayMember = "Name";
  552. ComboEdiRegPro.ValueMember = "Code";
  553. //查询上级区域属性
  554. isx = new DataTable();
  555. unLoad = new DataTable();
  556. unLoad.Columns.Add("Name", typeof(System.String));
  557. unLoad.Columns.Add("Code", typeof(System.String));
  558. isx = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetSelAdminRegion", new Object[] { }, this.ob);
  559. for (int i = 0; i < isx.Rows.Count; i++)
  560. {
  561. unLoad.Rows.Add(isx.Rows[i]["REGION_NM"].ToString(), isx.Rows[i]["REGION_NO"].ToString());
  562. }
  563. ComboEditorPro.DataSource = unLoad;
  564. ComboEditorPro.DisplayMember = "Name";
  565. ComboEditorPro.ValueMember = "Code";
  566. //行政片区
  567. isx = new DataTable();
  568. unLoad = new DataTable();
  569. unLoad.Columns.Add("BASENAME", typeof(System.String));
  570. unLoad.Columns.Add("BASECODE", typeof(System.String));
  571. isx = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreBaseInfoNew.doQuery", new Object[] { "1216" }, this.ob);
  572. //DataView dv = isx.DefaultView;
  573. //dv.RowFilter = "VALIDFLAG = '1'";
  574. //DataTable newTable1 = dv.ToTable();
  575. //unLoad = new DataTable();
  576. for (int i = 0; i < isx.Rows.Count; i++)
  577. {
  578. if (isx.Rows[i]["VALIDFLAG"].ToString().Trim() == "1")
  579. {
  580. unLoad.Rows.Add(isx.Rows[i]["BASENAME"].ToString(), isx.Rows[i]["BASECODE"].ToString());
  581. }
  582. }
  583. DataRow dr = unLoad.NewRow();
  584. unLoad.Rows.Add(dr);
  585. comboRegIon.DataSource = unLoad;
  586. comboRegIon.DisplayMember = "BASENAME";
  587. comboRegIon.ValueMember = "BASECODE";
  588. }
  589. //刷新Tree
  590. public void QueryTree()
  591. {
  592. this.treeRegion.Nodes.Clear();
  593. DataTable dt = new DataTable();
  594. dt = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetTivCode", new Object[] { }, this.ob);
  595. //树控件递归绑定方法。
  596. Bind_Tv(dt, treeRegion.Nodes, null, "REGION_NO", "P_REGION_NO", "REGION_NM");
  597. if (!string.IsNullOrEmpty(tNode.Name))
  598. {
  599. for (int e = 0; e < this.treeRegion.Nodes.Count; e++)
  600. {
  601. //展开一级节点
  602. //if (this.treeRegion.Nodes[e].Name.Equals(tNode.Name))
  603. //{
  604. // this.treeRegion.Nodes[e].Expand();
  605. // return;
  606. //}
  607. //展开二级节点
  608. for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
  609. {
  610. if (this.treeRegion.Nodes[e].Nodes[w].Name.Equals(tNode.Name))
  611. {
  612. this.treeRegion.Nodes[e].Expand();
  613. this.treeRegion.Nodes[e].Nodes[w].ExpandAll();
  614. return;
  615. }
  616. }
  617. //展开三级子节点
  618. for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
  619. {
  620. for (int r = 0; r < this.treeRegion.Nodes[e].Nodes[w].Nodes.Count; r++)
  621. {
  622. if (this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Name.Equals(tNode.Name))
  623. {
  624. this.treeRegion.Nodes[e].Expand();
  625. this.treeRegion.Nodes[e].Nodes[w].Expand();
  626. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].ExpandAll();
  627. return;
  628. }
  629. }
  630. }
  631. //展开四级子节点
  632. for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
  633. {
  634. for (int r = 0; r < this.treeRegion.Nodes[e].Nodes[w].Nodes.Count; r++)
  635. {
  636. for (int x = 0; x < this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes.Count; x++)
  637. {
  638. if (this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Name.Equals(tNode.Name))
  639. {
  640. this.treeRegion.Nodes[e].Expand();
  641. this.treeRegion.Nodes[e].Nodes[w].Expand();
  642. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Expand();
  643. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].ExpandAll();
  644. return;
  645. }
  646. }
  647. }
  648. }
  649. //展开五级子节点
  650. for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
  651. {
  652. for (int r = 0; r < this.treeRegion.Nodes[e].Nodes[w].Nodes.Count; r++)
  653. {
  654. for (int x = 0; x < this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes.Count; x++)
  655. {
  656. for (int j = 0; j < this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Nodes.Count; j++)
  657. {
  658. if (this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Nodes[j].Name.Equals(tNode.Name))
  659. {
  660. this.treeRegion.Nodes[e].Expand();
  661. this.treeRegion.Nodes[e].Nodes[w].Expand();
  662. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Expand();
  663. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].ExpandAll();
  664. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[j].ExpandAll();
  665. return;
  666. }
  667. }
  668. }
  669. }
  670. }
  671. }
  672. }
  673. }
  674. /// <summary>
  675. /// 绑定TreeView(利用TreeNodeCollection)
  676. /// </summary>
  677. /// <param name="tnc">TreeNodeCollection(TreeView的节点集合)</param>
  678. /// <param name="pid_val">父id的值</param>
  679. /// <param name="id">数据库 id 字段名</param>
  680. /// <param name="pid">数据库 父id 字段名</param>
  681. /// <param name="text">数据库 文本 字段值</param>
  682. private void Bind_Tv(DataTable dt, TreeNodeCollection tnc, string pid_val, string id, string pid, string text)
  683. {
  684. DataView dv = new DataView(dt);//将DataTable存到DataView中,以便于筛选数据
  685. TreeNode tn;//建立TreeView的节点(TreeNode),以便将取出的数据添加到节点中
  686. //以下为三元运算符,如果父id为空,则为构建“父id字段 is null”的查询条件,否则构建“父id字段=父id字段值”的查询条件
  687. string filter = string.IsNullOrEmpty(pid_val) ? pid + " is null" : string.Format(pid + "='{0}'", pid_val);
  688. dv.RowFilter = filter;//利用DataView将数据进行筛选,选出相同 父id值 的数据
  689. foreach (DataRowView drv in dv)
  690. {
  691. tn = new TreeNode();//建立一个新节点(学名叫:一个实例)
  692. tn.Tag = drv[id].ToString();//节点的Value值,一般为数据库的id值
  693. tn.Text = drv[text].ToString();//节点的Text,节点的文本显示
  694. tn.Name = drv["REGION_LVL_NO"].ToString();//区域属性代码
  695. tn.ImageKey = drv["REGION_LVL_NM"].ToString();
  696. if (!string.IsNullOrEmpty(drv["P_REGION_NO"].ToString()))
  697. {
  698. tn.ToolTipText = drv["P_REGION_NO"].ToString();
  699. }
  700. else
  701. {
  702. tn.ImageIndex = 0;
  703. }
  704. tnc.Add(tn);//将该节点加入到TreeNodeCollection(节点集合)中
  705. Bind_Tv(dt, tn.Nodes, tn.Tag.ToString(), id, pid, text);//递归(反复调用这个方法,直到把数据取完为止)
  706. }
  707. }
  708. private void treeRegion_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  709. {
  710. //选择节点改变字体大小
  711. if (tNode.Text.Trim() != "")
  712. {
  713. tNode.NodeFont = new Font("宋体", 8F, System.Drawing.FontStyle.Bold);
  714. tNode.BackColor = Color.Empty;
  715. }
  716. e.Node.NodeFont = new Font("宋体", 9F, System.Drawing.FontStyle.Underline);
  717. e.Node.BackColor = Color.Empty;
  718. e.Node.BackColor = Color.LightBlue;
  719. tNode = e.Node;
  720. //查询上级区域属性
  721. isx = new DataTable();
  722. unLoad = new DataTable();
  723. unLoad.Columns.Add("Name", typeof(System.String));
  724. unLoad.Columns.Add("Code", typeof(System.String));
  725. isx = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetSelAdminRegionFilter", new Object[] { tNode.Tag.ToString() }, this.ob);
  726. for (int i = 0; i < isx.Rows.Count; i++)
  727. {
  728. unLoad.Rows.Add(isx.Rows[i]["REGION_NM"].ToString(), isx.Rows[i]["REGION_NO"].ToString());
  729. }
  730. ComboEditorPro.DataSource = unLoad;
  731. ComboEditorPro.DisplayMember = "Name";
  732. ComboEditorPro.ValueMember = "Code";
  733. ////保存上一级区域属性信息
  734. //if (!string.IsNullOrEmpty(e.Node.ImageKey))
  735. //{
  736. // ComboEditorPro.Text = e.Node.ImageKey;
  737. // ComboEditorPro.Value = e.Node.ToolTipText;
  738. //}
  739. //保存上一级区域属性信息
  740. if (unLoad.Rows.Count > 0)
  741. {
  742. ComboEditorPro.Text = unLoad.Rows[0][0].ToString();
  743. ComboEditorPro.Value = unLoad.Rows[0][1].ToString();
  744. }
  745. //查询区域属性
  746. //string indexCode = "";
  747. //string indexName = e.Node.Text.Substring(0, e.Node.Text.IndexOf(" ")).Trim();
  748. //ComboEdiRegPro.Text = indexName;
  749. txtName.Text = e.Node.Text.Substring(e.Node.Text.IndexOf(" ")).Trim();
  750. DataTable countDb = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.saveQueryName", new Object[] { txtName.Text }, this.ob);
  751. if (countDb.Rows.Count > 0)
  752. {
  753. comboRegIon.Value = countDb.Rows[0]["BIGAREA"].ToString();
  754. }
  755. doQueryClick(e.Node.Tag.ToString());
  756. nodeId = e.Node.Tag.ToString();
  757. }
  758. private void ultraGridRegion_Click(object sender, EventArgs e)
  759. {
  760. DataTable unLoad = new DataTable();
  761. unLoad.Columns.Add("Name", typeof(System.String));
  762. unLoad.Columns.Add("Code", typeof(System.String));
  763. if (this.ultraGridRegion.Rows.Count > 0)
  764. {
  765. //查询区域属性
  766. ComboEdiRegPro.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_TYPE_NM"].Text.Trim();
  767. ComboEdiRegPro.Value = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_TYPE_NO"].Value.ToString();
  768. regIonID = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_NO"].Value.ToString(); //修改使用的id
  769. this.txtName.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_NM"].Text.Trim();
  770. textBoxMemo.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["MEMO"].Text.Trim();
  771. this.comboRegIon.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["BIGAREA"].Text.Trim();
  772. //保存上一级区域属性信息
  773. if (!string.IsNullOrEmpty(this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NO"].Value.ToString()))
  774. {
  775. ComboEditorPro.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NM"].Value.ToString();
  776. ComboEditorPro.Value = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NO"].Value.ToString();
  777. }
  778. }
  779. }
  780. private void ComboEditorPro_TextChanged(object sender, EventArgs e)
  781. {
  782. if (!string.IsNullOrEmpty(ComboEditorPro.Text))
  783. {
  784. DataTable unLoad = new DataTable();
  785. unLoad.Columns.Add("Name", typeof(System.String));
  786. unLoad.Columns.Add("Code", typeof(System.String));
  787. //查询区域属性
  788. isx = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreRegion.GetRegIonCodeNo", new Object[] { ComboEditorPro.Value }, this.ob);
  789. for (int i = 0; i < isx.Rows.Count; i++)
  790. {
  791. unLoad.Rows.Add(isx.Rows[i]["REGION_TYPE_NM"].ToString(), isx.Rows[i]["REGION_TYPE_NO"].ToString());
  792. }
  793. ComboEdiRegPro.DataSource = unLoad;
  794. ComboEdiRegPro.DisplayMember = "Name";
  795. ComboEdiRegPro.ValueMember = "Code";
  796. }
  797. }
  798. private void txtName_TextChanged(object sender, EventArgs e)
  799. {
  800. if (this.txtName.Text.Length > 40)
  801. {
  802. MessageUtil.ShowTips("长度过长!");
  803. this.txtName.Text = this.txtName.Text.Substring(0,40);
  804. }
  805. }
  806. private void textBoxMemo_TextChanged(object sender, EventArgs e)
  807. {
  808. if (this.textBoxMemo.Text.Length > 180)
  809. {
  810. MessageUtil.ShowTips("长度过长!");
  811. this.textBoxMemo.Text = this.textBoxMemo.Text.Substring(0, 180);
  812. }
  813. }
  814. private void ultraGridRegion_AfterCellActivate(object sender, EventArgs e)
  815. {
  816. if (this.ultraGridRegion.ActiveRow!=null)
  817. {
  818. //查询区域属性
  819. ComboEdiRegPro.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_TYPE_NM"].Text.Trim();
  820. ComboEdiRegPro.Value = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_TYPE_NO"].Value.ToString();
  821. regIonID = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_NO"].Value.ToString(); //修改使用的id
  822. this.txtName.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_NM"].Text.Trim();
  823. textBoxMemo.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["MEMO"].Text.Trim();
  824. this.comboRegIon.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["BIGAREA"].Text.Trim();
  825. //保存上一级区域属性信息
  826. if (!string.IsNullOrEmpty(this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NO"].Value.ToString()))
  827. {
  828. ComboEditorPro.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NM"].Value.ToString();
  829. ComboEditorPro.Value = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NO"].Value.ToString();
  830. }
  831. }
  832. }
  833. private void ultraGridRegion_AfterRowActivate(object sender, EventArgs e)
  834. {
  835. if (this.ultraGridRegion.ActiveRow != null)
  836. {
  837. //查询区域属性
  838. ComboEdiRegPro.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_TYPE_NM"].Text.Trim();
  839. ComboEdiRegPro.Value = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_TYPE_NO"].Text.Trim();
  840. regIonID = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_NO"].Value.ToString(); //修改使用的id
  841. this.txtName.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["REGION_NM"].Text.Trim();
  842. textBoxMemo.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["MEMO"].Text.Trim();
  843. this.comboRegIon.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["BIGAREA"].Value.ToString();
  844. //保存上一级区域属性信息
  845. if (!string.IsNullOrEmpty(this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NO"].Value.ToString()))
  846. {
  847. ComboEditorPro.Text = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NM"].Value.ToString();
  848. ComboEditorPro.Value = this.ultraGridRegion.DisplayLayout.ActiveRow.Cells["P_REGION_NO"].Value.ToString();
  849. }
  850. }
  851. }
  852. }
  853. }