/// <summary> /// 绑定父节点 /// </summary> private void Bind_Root(string ParentId, TreeView tv) { string sql = @"select c.CategoryName,c.CategoryGUID from Category c join CategoryNodePosition cn on c.CategoryGUID=cn.CategoryGUID where cn.CategoryPath like '%" + ParentId + "%' and YIndex=5 order by XIndex"; DataSet ds = new DataSet(); ds = DataQuery.SelectRows(ds, sql, "zjspccmConnectionString"); TreeNode tn; foreach (var c in ds.Tables[0].AsEnumerable()) { tn = new TreeNode(); tn.Text = c["CategoryName"].ToString(); tn.Value = c["CategoryGUID"].ToString(); tn.NavigateUrl = c["CategoryGUID"].ToString(); //判断是否有子节点 if (Check_Child(tn.Value, 4)) { tn.PopulateOnDemand = true; tn.Expanded = false; } tv.Nodes.Add(tn); } }
/// <summary> /// 绑定节点的子节点 /// </summary> /// <param name="treeNode"></param> /// <param name="p"></param> private void Bind_Child(TreeNode treeNode, string ParentId) { string sql = "select YIndex from CategoryNodePosition where CategoryGuid= '" + ParentId + "'"; DataSet ds = new DataSet(); ds = DataQuery.SelectRows(ds, sql, "zjspccmConnectionString"); int Yindex = Convert.ToInt16(ds.Tables[0].Rows[0][0].ToString()) + 1; sql = @"select c.CategoryName,c.CategoryGUID,cn.CategoryPath,cn.YIndex from Category c join CategoryNodePosition cn on c.CategoryGUID=cn.CategoryGUID where cn.CategoryPath like '%" + ParentId + "%' and YIndex=" + Yindex + "order by XIndex"; ds = new DataSet(); ds = DataQuery.SelectRows(ds, sql, "zjspccmConnectionString"); TreeNode tn; foreach (var c in ds.Tables[0].AsEnumerable()) { tn = new TreeNode(); tn.Text = c["CategoryName"].ToString(); tn.Value = c["CategoryGUID"].ToString(); tn.NavigateUrl = c["CategoryGUID"].ToString(); if (Check_Child(tn.Value, Yindex)) { tn.PopulateOnDemand = true; tn.Expanded = false; } treeNode.ChildNodes.Add(tn); } }
//树形菜单 #region sync public void tncRecursion(TreeNodeCollection tnc, string ParentId) { string sql = "select YIndex from CategoryNodePosition where CategoryGuid= '" + ParentId + "'"; DataSet ds = new DataSet(); ds = DataQuery.SelectRows(ds, sql, "zjspccmConnectionString"); int Yindex = Convert.ToInt16(ds.Tables[0].Rows[0][0].ToString()) + 1; sql = @"select c.CategoryName,c.CategoryGUID,cn.CategoryPath from Category c join CategoryNodePosition cn on c.CategoryGUID=cn.CategoryGUID where cn.CategoryPath like '%" + ParentId + "%' and YIndex=" + Yindex + "order by XIndex"; ds = new DataSet(); ds = DataQuery.SelectRows(ds, sql, "zjspccmConnectionString"); foreach (DataRow dr in ds.Tables[0].Rows) { string id = dr["CategoryGUID"].ToString(); string title = dr["CategoryName"].ToString(); TreeNode tn = new TreeNode(); tn.Text = title; tn.NavigateUrl = id; //tn.ImageUrl = "images/file.png";//默认图标为file.png tnc.Add(tn); int tncInt = ds.Tables[0].Rows.IndexOf(dr); tncRecursion(tnc[tncInt].ChildNodes, id); //----------递归调用 } //if (ds.Tables[0].Rows.Count > 0) //{ // tnc[0].Parent.ImageUrl = "images/openfoldericon.png";//设置父文件图标 //} //else //{ // tnc[0].Parent.ImageUrl = "images/file.png"; //} }
/// <summary> /// 判断是否有子节点 /// </summary> private bool Check_Child(string Id, int Yindex) { string sql = @"select Count(c.CategoryGUID) from Category c join CategoryNodePosition cn on c.CategoryGUID=cn.CategoryGUID where cn.CategoryPath like '%" + Id + "%' and YIndex =" + (Yindex + 1) + ""; DataSet ds = new DataSet(); ds = DataQuery.SelectRows(ds, sql, "zjspccmConnectionString"); int count = Convert.ToInt16(ds.Tables[0].Rows[0][0].ToString()); bool exist = (count > 0) ? true : false; return(exist); }