| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Core.Mes.Client.Comm.Server;
- using CoreFS.CA06;
- using Core.Mes.Client.Comm.Tool;
- namespace Core.StlMes.Client.SaleOrder
- {
- public partial class FrmOrderRegion : FrmBase
- {
- string noDesID = "";
- string noDesName = "";
- TreeNode tNode = new TreeNode();
- public delegate void GetOrderLenHander(string ID_, string Name_);
- public event GetOrderLenHander GetOrderLen;
- OpeBase ob = new OpeBase();
- public FrmOrderRegion()
- {
- InitializeComponent();
- }
- public FrmOrderRegion(OpeBase obx)
- {
- this.ob = obx;
- InitializeComponent();
- }
- private void FrmOrderRegion_Load(object sender, EventArgs e)
- {
- QueryTree();
- }
- public void NameQueryTree(string name)
- {
- if (!string.IsNullOrEmpty(name))
- {
- for (int e = 0; e < this.treeRegion.Nodes.Count; e++)
- {
- //展开一级节点
- if (this.treeRegion.Nodes[e].Text.Trim().Equals(name))
- {
- noDesID = this.treeRegion.Nodes[e].Tag.ToString();
- noDesName = this.treeRegion.Nodes[e].Text.ToString();
- this.treeRegion.Nodes[e].Expand();
- return;
- }
- //展开二级节点
- for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
- {
- if (this.treeRegion.Nodes[e].Nodes[w].Text.Trim().Equals(name))
- {
- noDesID = this.treeRegion.Nodes[e].Nodes[w].Tag.ToString();
- noDesName = this.treeRegion.Nodes[e].Nodes[w].Text.ToString();
- this.treeRegion.Nodes[e].Expand();
- this.treeRegion.Nodes[e].Nodes[w].ExpandAll();
- return;
- }
- }
- //展开三级子节点
- for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
- {
- for (int r = 0; r < this.treeRegion.Nodes[e].Nodes[w].Nodes.Count; r++)
- {
- if (this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Text.Trim().Equals(name))
- {
- noDesID = this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Tag.ToString();
- noDesName = this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Text.ToString();
- this.treeRegion.Nodes[e].Expand();
- this.treeRegion.Nodes[e].Nodes[w].Expand();
- this.treeRegion.Nodes[e].Nodes[w].Nodes[r].ExpandAll();
- return;
- }
- }
- }
- //展开四级子节点
- for (int w = 0; w < this.treeRegion.Nodes[e].Nodes.Count; w++)
- {
- for (int r = 0; r < this.treeRegion.Nodes[e].Nodes[w].Nodes.Count; r++)
- {
- for (int x = 0; x < this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes.Count; x++)
- {
- if (this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Text.Trim().Equals(name))
- {
- noDesID = this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Tag.ToString();
- noDesName = this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].Text.ToString();
- this.treeRegion.Nodes[e].Expand();
- this.treeRegion.Nodes[e].Nodes[w].Expand();
- this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Expand();
- this.treeRegion.Nodes[e].Nodes[w].Nodes[r].Nodes[x].ExpandAll();
- return;
- }
- }
- }
- }
- }
- }
- }
- //查询树结构
- public void QueryTree()
- {
- this.treeRegion.Nodes.Clear();
- DataTable dt = new DataTable();
- dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreRegion.GetTivCode", new Object[] { }, this.ob);
- //树控件递归绑定方法。
- Bind_Tv(dt, treeRegion.Nodes, null, "REGION_NO", "P_REGION_NO", "REGION_NM");
- }
- /// <summary>
- /// 绑定TreeView(利用TreeNodeCollection)
- /// </summary>
- /// <param name="tnc">TreeNodeCollection(TreeView的节点集合)</param>
- /// <param name="pid_val">父id的值</param>
- /// <param name="id">数据库 id 字段名</param>
- /// <param name="pid">数据库 父id 字段名</param>
- /// <param name="text">数据库 文本 字段值</param>
- private void Bind_Tv(DataTable dt, TreeNodeCollection tnc, string pid_val, string id, string pid, string text)
- {
- DataView dv = new DataView(dt);//将DataTable存到DataView中,以便于筛选数据
- TreeNode tn;//建立TreeView的节点(TreeNode),以便将取出的数据添加到节点中
- //以下为三元运算符,如果父id为空,则为构建“父id字段 is null”的查询条件,否则构建“父id字段=父id字段值”的查询条件
- string filter = string.IsNullOrEmpty(pid_val) ? pid + " is null" : string.Format(pid + "='{0}'", pid_val);
- dv.RowFilter = filter;//利用DataView将数据进行筛选,选出相同 父id值 的数据
- foreach (DataRowView drv in dv)
- {
- tn = new TreeNode();//建立一个新节点(学名叫:一个实例)
- tn.Tag = drv[id].ToString();//节点的Value值,一般为数据库的id值
- tn.Text = drv[text].ToString().Substring(drv[text].ToString().IndexOf(' ')+1);//节点的Text,节点的文本显示
- tn.Name = drv["REGION_LVL_NO"].ToString();//区域属性代码
- tn.ImageKey = drv["REGION_LVL_NM"].ToString();
- if (!string.IsNullOrEmpty(drv["P_REGION_NO"].ToString()))
- {
- tn.ToolTipText = drv["P_REGION_NO"].ToString();
- }
- else
- {
- tn.ImageIndex = 0;
- }
- tnc.Add(tn);//将该节点加入到TreeNodeCollection(节点集合)中
- Bind_Tv(dt, tn.Nodes, tn.Tag.ToString(), id, pid, text);//递归(反复调用这个方法,直到把数据取完为止)
- }
- }
- private void ultraNodesName_ValueChanged(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(this.ultraNodesName.Text))
- {
- NameQueryTree(this.ultraNodesName.Text);
- }
- }
- private void buttonCom_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(noDesID) && !string.IsNullOrEmpty(noDesName))
- {
- GetOrderLen(noDesID, noDesName);
- }
- else
- {
- MessageUtil.ShowTips("请选择树节点!");
- return;
- }
- }
- private void treeRegion_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- //选择节点改变字体大小
- if (tNode.Text.Trim() != "")
- {
- tNode.NodeFont = new Font("宋体", 8F, System.Drawing.FontStyle.Bold);
- tNode.BackColor = Color.Empty;
- }
- e.Node.NodeFont = new Font("宋体", 9F, System.Drawing.FontStyle.Underline);
- e.Node.BackColor = Color.Empty;
- e.Node.BackColor = Color.LightBlue;
- tNode = e.Node;
- NameQueryTree(e.Node.Text.Trim());
- ultraNodesName.Text = e.Node.Text.Trim();
- }
- private void buttonEsc_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }
|