FrmOrderRegion.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 Core.Mes.Client.Comm.Server;
  10. using CoreFS.CA06;
  11. using Core.Mes.Client.Comm.Tool;
  12. namespace Core.StlMes.Client.SaleOrder
  13. {
  14. public partial class FrmOrderRegion : FrmBase
  15. {
  16. string noDesID = "";
  17. string noDesName = "";
  18. TreeNode tNode = new TreeNode();
  19. public delegate void GetOrderLenHander(string ID_, string Name_);
  20. public event GetOrderLenHander GetOrderLen;
  21. OpeBase ob = new OpeBase();
  22. public FrmOrderRegion()
  23. {
  24. InitializeComponent();
  25. }
  26. public FrmOrderRegion(OpeBase obx)
  27. {
  28. this.ob = obx;
  29. InitializeComponent();
  30. }
  31. private void FrmOrderRegion_Load(object sender, EventArgs e)
  32. {
  33. QueryTree();
  34. }
  35. public void NameQueryTree(string name)
  36. {
  37. if (!string.IsNullOrEmpty(name))
  38. {
  39. for (int e = 0; e < this.treeRegion.Nodes.Count; e++)
  40. {
  41. //展开一级节点
  42. if (this.treeRegion.Nodes[e].Text.Trim().Equals(name))
  43. {
  44. noDesID = this.treeRegion.Nodes[e].Tag.ToString();
  45. noDesName = this.treeRegion.Nodes[e].Text.ToString();
  46. this.treeRegion.Nodes[e].Expand();
  47. return;
  48. }
  49. //展开二级节点
  50. for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
  51. {
  52. if (this.treeRegion.Nodes[e].Nodes[w].Text.Trim().Equals(name))
  53. {
  54. noDesID = this.treeRegion.Nodes[e].Nodes[w].Tag.ToString();
  55. noDesName = this.treeRegion.Nodes[e].Nodes[w].Text.ToString();
  56. this.treeRegion.Nodes[e].Expand();
  57. this.treeRegion.Nodes[e].Nodes[w].ExpandAll();
  58. return;
  59. }
  60. }
  61. //展开三级子节点
  62. for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
  63. {
  64. for (int r = 0; r < this.treeRegion.Nodes[e].Nodes[w].Nodes.Count; r++)
  65. {
  66. if (this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Text.Trim().Equals(name))
  67. {
  68. noDesID = this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Tag.ToString();
  69. noDesName = this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Text.ToString();
  70. this.treeRegion.Nodes[e].Expand();
  71. this.treeRegion.Nodes[e].Nodes[w].Expand();
  72. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].ExpandAll();
  73. return;
  74. }
  75. }
  76. }
  77. //展开四级子节点
  78. for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
  79. {
  80. for (int r = 0; r < this.treeRegion.Nodes[e].Nodes[w].Nodes.Count; r++)
  81. {
  82. for (int x = 0; x < this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes.Count; x++)
  83. {
  84. if (this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Text.Trim().Equals(name))
  85. {
  86. noDesID = this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Tag.ToString();
  87. noDesName = this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Text.ToString();
  88. this.treeRegion.Nodes[e].Expand();
  89. this.treeRegion.Nodes[e].Nodes[w].Expand();
  90. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Expand();
  91. this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].ExpandAll();
  92. return;
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }
  100. //查询树结构
  101. public void QueryTree()
  102. {
  103. this.treeRegion.Nodes.Clear();
  104. DataTable dt = new DataTable();
  105. dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreRegion.GetTivCode", new Object[] { }, this.ob);
  106. //树控件递归绑定方法。
  107. Bind_Tv(dt, treeRegion.Nodes, null, "REGION_NO", "P_REGION_NO", "REGION_NM");
  108. }
  109. /// <summary>
  110. /// 绑定TreeView(利用TreeNodeCollection)
  111. /// </summary>
  112. /// <param name="tnc">TreeNodeCollection(TreeView的节点集合)</param>
  113. /// <param name="pid_val">父id的值</param>
  114. /// <param name="id">数据库 id 字段名</param>
  115. /// <param name="pid">数据库 父id 字段名</param>
  116. /// <param name="text">数据库 文本 字段值</param>
  117. private void Bind_Tv(DataTable dt, TreeNodeCollection tnc, string pid_val, string id, string pid, string text)
  118. {
  119. DataView dv = new DataView(dt);//将DataTable存到DataView中,以便于筛选数据
  120. TreeNode tn;//建立TreeView的节点(TreeNode),以便将取出的数据添加到节点中
  121. //以下为三元运算符,如果父id为空,则为构建“父id字段 is null”的查询条件,否则构建“父id字段=父id字段值”的查询条件
  122. string filter = string.IsNullOrEmpty(pid_val) ? pid + " is null" : string.Format(pid + "='{0}'", pid_val);
  123. dv.RowFilter = filter;//利用DataView将数据进行筛选,选出相同 父id值 的数据
  124. foreach (DataRowView drv in dv)
  125. {
  126. tn = new TreeNode();//建立一个新节点(学名叫:一个实例)
  127. tn.Tag = drv[id].ToString();//节点的Value值,一般为数据库的id值
  128. tn.Text = drv[text].ToString().Substring(drv[text].ToString().IndexOf(' ')+1);//节点的Text,节点的文本显示
  129. tn.Name = drv["REGION_LVL_NO"].ToString();//区域属性代码
  130. tn.ImageKey = drv["REGION_LVL_NM"].ToString();
  131. if (!string.IsNullOrEmpty(drv["P_REGION_NO"].ToString()))
  132. {
  133. tn.ToolTipText = drv["P_REGION_NO"].ToString();
  134. }
  135. else
  136. {
  137. tn.ImageIndex = 0;
  138. }
  139. tnc.Add(tn);//将该节点加入到TreeNodeCollection(节点集合)中
  140. Bind_Tv(dt, tn.Nodes, tn.Tag.ToString(), id, pid, text);//递归(反复调用这个方法,直到把数据取完为止)
  141. }
  142. }
  143. private void ultraNodesName_ValueChanged(object sender, EventArgs e)
  144. {
  145. if (!string.IsNullOrEmpty(this.ultraNodesName.Text))
  146. {
  147. NameQueryTree(this.ultraNodesName.Text);
  148. }
  149. }
  150. private void buttonCom_Click(object sender, EventArgs e)
  151. {
  152. if (!string.IsNullOrEmpty(noDesID) && !string.IsNullOrEmpty(noDesName))
  153. {
  154. GetOrderLen(noDesID, noDesName);
  155. }
  156. else
  157. {
  158. MessageUtil.ShowTips("请选择树节点!");
  159. return;
  160. }
  161. }
  162. private void treeRegion_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  163. {
  164. //选择节点改变字体大小
  165. if (tNode.Text.Trim() != "")
  166. {
  167. tNode.NodeFont = new Font("宋体", 8F, System.Drawing.FontStyle.Bold);
  168. tNode.BackColor = Color.Empty;
  169. }
  170. e.Node.NodeFont = new Font("宋体", 9F, System.Drawing.FontStyle.Underline);
  171. e.Node.BackColor = Color.Empty;
  172. e.Node.BackColor = Color.LightBlue;
  173. tNode = e.Node;
  174. NameQueryTree(e.Node.Text.Trim());
  175. ultraNodesName.Text = e.Node.Text.Trim();
  176. }
  177. private void buttonEsc_Click(object sender, EventArgs e)
  178. {
  179. this.Close();
  180. }
  181. }
  182. }