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 = ""; } } } }