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");
}
///
/// 绑定TreeView(利用TreeNodeCollection)
///
/// TreeNodeCollection(TreeView的节点集合)
/// 父id的值
/// 数据库 id 字段名
/// 数据库 父id 字段名
/// 数据库 文本 字段值
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();
}
}
}