using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CTERP
{
public partial class FrmSysFunctionMenu : Form
{
public FrmSysFunctionMenu()
{
InitializeComponent();
}
LinkDataBase link = new LinkDataBase();
DataSet dsFunctionMenu = null;
private void FrmFunctionMenu_Load(object sender, EventArgs e)
{
dsFunctionMenu = new DataSet();
tvFunctionMenu.Nodes.Add("ERP系统功能菜单");
TreeNode rootNode = tvFunctionMenu.Nodes[0];
CreateChildTree(-1, rootNode);
rootNode.Expand();//展开根结点
}
//递归调用创建子树
private void CreateChildTree(int nparentid, TreeNode currentNode)
{
using (SqlConnection sqlCONN = new SqlConnection("server=.;uid=sa;database=cterp"))
{
string strSelect = "select id,title,parentid,sortid from sy_menu_wds where parentid=" + nparentid + " order by sortid";
SqlCommand sqlCMD = new SqlCommand(strSelect);
sqlCMD.Connection = sqlCONN;
sqlCONN.Open();
using (SqlDataReader sqlDR = sqlCMD.ExecuteReader())
{
while (sqlDR.Read())
{
TreeNode node = new TreeNode(sqlDR["title"].ToString().Trim());
CreateChildTree(int.Parse(sqlDR["id"].ToString().Trim()), node); //递归出子节点
currentNode.Nodes.Add(node);
}
}
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CTERP
{
public partial class FrmSysFunctionMenu : Form
{
public FrmSysFunctionMenu()
{
InitializeComponent();
}
LinkDataBase link = new LinkDataBase();
DataSet dsFunctionMenu = null;
private void FrmFunctionMenu_Load(object sender, EventArgs e)
{
dsFunctionMenu = new DataSet();
tvFunctionMenu.Nodes.Add("ERP系统功能菜单");
TreeNode rootNode = tvFunctionMenu.Nodes[0];
CreateChildTree(-1, rootNode);
rootNode.Expand();//展开根结点
}
//递归调用创建子树
private void CreateChildTree(int nparentid, TreeNode currentNode)
{
using (SqlConnection sqlCONN = new SqlConnection("server=.;uid=sa;database=cterp"))
{
string strSelect = "select id,title,parentid,sortid from sy_menu_wds where parentid=" + nparentid + " order by sortid";
SqlCommand sqlCMD = new SqlCommand(strSelect);
sqlCMD.Connection = sqlCONN;
sqlCONN.Open();
using (SqlDataReader sqlDR = sqlCMD.ExecuteReader())
{
while (sqlDR.Read())
{
TreeNode node = new TreeNode(sqlDR["title"].ToString().Trim());
CreateChildTree(int.Parse(sqlDR["id"].ToString().Trim()), node); //递归出子节点
currentNode.Nodes.Add(node);
}
}
}
}
}
}