博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
winform窗体树结构
阅读量:6154 次
发布时间:2019-06-21

本文共 2499 字,大约阅读时间需要 8 分钟。

private void InitDataTable()

{
string sql = @"select distinct ECGCODE
from ICSTSERRORCODE
where RCARD='" + txtRCARD.Text + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
sql = string.Format(sql);
DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];

BindRoot(data);

}

private void BindRoot(DataTable data)
{
//取根
foreach (DataRow dr in data.Rows)
{
TreeNode rootNode = new TreeNode();
rootNode.Tag = dr;
rootNode.Text = dr["ECGCODE"].ToString();
treeView1.Nodes.Add(rootNode);
BindChildAreas(rootNode, data);
}
}

//递归绑定子区域

private void BindChildAreas(TreeNode fNode, DataTable data)
{
string sql = @"select ECODE
from ICSTSERRORCODE
where RCARD='" + txtRCARD.Text + "' and ECGCODE='" + fNode .Text+ "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
sql = string.Format(sql);
DataTable data1 = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
//DataRow dr = (DataRow)fNode.Tag;
父节点数据关联的数据行
//string fid = (string)dr["ECGCODE"];
父节点ID
//DataRow[] rows = data1.Rows;//子区域
if (data1.Rows.Count == 0) //递归终止,区域不包含子区域时
{ return; }
foreach (DataRow dr in data1.Rows)
{
TreeNode node = new TreeNode();
node.Tag = dr;
node.Text = dr["ECODE"].ToString(); //添加子点
fNode.Nodes.Add(node); //递归
//BindChildAreas(node, data);
}
}
private void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
foreach (TreeNode node in treeView1.Nodes)
{
if (node.IsSelected)
{
return;
}
foreach (TreeNode childnode in node.Nodes)
{
if (childnode.IsSelected)
{
fnode = node.Text;
snode = childnode.Text;
groupBox1.Visible = true;
string sql = @"select ECGDESC
from ICSECG
where ECGCODE='" + fnode + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
sql = string.Format(sql);
DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
foreach (DataRow dr in data.Rows)
{
txtECGDESC.Text = dr["ECGDESC"].ToString();

}

string sql2 = @"select ECDESC
from ICSEC
where ECODE='" + snode + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
sql2 = string.Format(sql2);
DataTable data2 = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql2).Tables[0];
foreach (DataRow dr2 in data2.Rows)
{
txtECDESC.Text = dr2["ECDESC"].ToString();

}

txtEPART.Text = "";
txtECSCODE.Text = "";
txtECSGCODE.Text = "";
txtDUTYCODE.Text = "";
txtSOLCODE.Text = "";
txtPREVENTION.Text = "";
txtELOC.Text = "";
}
}
}
}

转载于:https://www.cnblogs.com/smallsunand/p/7018782.html

你可能感兴趣的文章
非nodejs方式的vue.js的使用
查看>>
Effective JavaScript Item 33 让构造函数不再依赖newkeyword
查看>>
What you should know about .so files
查看>>
【剑指offer】字符串的排列
查看>>
dedecms首页怎么调用公司简介的内容
查看>>
微信公众号获取acess_token并存储(php)
查看>>
深入学习 History 对象管理浏览器会话历史
查看>>
resteasy经验谈
查看>>
MyEclipse中快捷键
查看>>
天津政府应急系统之GIS一张图(arcgis api for flex)解说(二)鹰眼模块
查看>>
ZOJ 3201
查看>>
leetcode第一刷_Search in Rotated Sorted Array
查看>>
《textanalytics》课程简单总结(1):两种word relations——Paradigmatic vs. Syntagmatic...
查看>>
POJ 3070 Fibonacci
查看>>
bloom
查看>>
maven 常用插件3
查看>>
单词数 (STL set集合)
查看>>
Codeforces Round #168 (Div. 2)---A. Lights Out
查看>>
探讨一下Java单例设计模式
查看>>
VIM下的可视模式的相关知识
查看>>