public DataSet GetAllMenu()
{
//ManagerMenu.aspx
//get all menu info
DataSet ds = new DataSet();
//选取用户的所有权限菜单
string str00="select * from quan_menut order by menu_type,menu_seq";
OracleDataAdapter da = new OracleDataAdapter(str00,MyConnection);
da.Fill(ds,"tree");
return ds;
}
页面
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
CreateDataSet();
InitTree(TreeViewMenu.Nodes,"0");
}
//取数据到TreeView控件中
//建立数据集
private DataSet CreateDataSet()
{
// string cmdSelect="select * from quan_menut order by menu_type,menu_seq";
// OracleDataAdapter myCmd=new OracleDataAdapter(cmdSelect,MyConnection);
// ds=new DataSet();
// myCmd.Fill(ds,"tree");
// return ds;
DataSelectStr DSTR = new DataSelectStr();
ds = DSTR.GetAllMenu();
return ds;
}
//建树的基本思路是:从根节点开始递归调用显示子树
private void InitTree(TreeNodeCollection Nds,string parentId)
{
DataView dv=new DataView();
TreeNode tmpNd;
string intId;
dv.Table=ds.Tables["tree"];
dv.RowFilter="menu_parentid="+parentId+"" ;
foreach(DataRowView drv in dv)
{
tmpNd=new TreeNode();
tmpNd.ID=drv["menu_noteid"].ToString();
tmpNd.Text=drv["menu_noteid_name"].ToString();
// tmpNd.ImageUrl="../images/"+drv["Icon"].ToString();
// tmpNd.NavigateUrl="../"+drv["Address"].ToString();
Nds.Add(tmpNd);
intId=drv["menu_parentid"].ToString();
InitTree(tmpNd.Nodes,tmpNd.ID);
}
}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
// 在此处放置用户代码以初始化页面
CreateDataSet();
InitTree(TreeViewMenu.Nodes,"0");
BindGrid();
}
}
private void CreateDataSet()
{
DataAccess.Database data = new DataAccess.Database();
OracleDataReader dataReader;
string userid = "1418";
string groupid ="1";
OracleParameter[] param = {
data.MakeInParam("userid",OracleType.VarChar,8,userid),
data.MakeInParam("groupid",OracleType.VarChar,6,groupid),
data.MakeOutParam("RetCursor",OracleType.Cursor,0)
};
data.RunProc("chmcoa_package_t.infousermenu",param,out dataReader);
dataTbl1 = ConvertDataReaderToDataTable(dataReader);
dataTbl1.TableName = "TreeView";
}
#region 将DataReader 转为 DataTable
/// <summary>
/// 将DataReader 转为 DataTable
/// </summary>
/// <param name="DataReader">DataReader</param>
public DataTable ConvertDataReaderToDataTable(OracleDataReader dataReader)
{
//WebUI.ClassFile.Database data = new WebUI.ClassFile.Database();
DataTable datatable = new DataTable();
DataTable schemaTable = dataReader.GetSchemaTable();
//动态添加列
foreach(DataRow myRow in schemaTable.Rows)
{
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = myRow[0].ToString();
datatable.Columns.Add(myDataColumn);
}
//添加数据
while(dataReader.Read())
{
DataRow myDataRow = datatable.NewRow();
for(int i=0;i<schemaTable.Rows.Count;i++)
{
myDataRow[i] = dataReader[i].ToString();
}
datatable.Rows.Add(myDataRow);
myDataRow = null;
}
schemaTable = null;
dataReader.Close();
return datatable;
}
#endregion
private void InitTree(TreeNodeCollection Nds,string parentId)
{
DataView dv=new DataView();
TreeNode tmpNd;
string intId;
dv = dataTbl1.Copy().DefaultView;
dv.RowFilter="menu_parentid="+parentId+"" ;
foreach(DataRowView drv in dv)
{
tmpNd=new TreeNode();
tmpNd.ID=drv["menu_noteid"].ToString();
tmpNd.Text=drv["menu_noteid_name"].ToString();
// tmpNd.ImageUrl="../images/"+drv["Icon"].ToString();
// tmpNd.NavigateUrl="../"+drv["prog_address"].ToString();
Nds.Add(tmpNd);
intId=drv["menu_parentid"].ToString();
InitTree(tmpNd.Nodes,tmpNd.ID);
}
}