/// <summary> /// 获取子节点ID /// </summary> /// <returns></returns> public string GetMenuSonList(string pid) { DataSet ds = this.GetList("Menu_ParentId=" + pid + " AND IsActive=1"); //获取激活状态的菜单栏 Dictionary <string, Model.yyyu.TreeObejct> dicTreeObejct = new Dictionary <string, Model.yyyu.TreeObejct>(); //数据存储 string strJson = ""; if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow item in ds.Tables[0].Rows) { Model.yyyu.TreeObejct mp = new Model.yyyu.TreeObejct(); mp.Menu_Id = item["Menu_Id"].ToString(); mp.Menu_ParentId = item["Menu_ParentId"].ToString(); mp.Name = item["Name"].ToString(); mp.ShowName = item["ShowName"].ToString(); mp.MeunNum = item["MeunNum"].ToString(); if (item["NodeUrl"] == null) { mp.NodeUrl = ""; } else { mp.NodeUrl = item["NodeUrl"].ToString(); } mp.IshasSon = item["IshasSon"].ToString(); mp.children = new List <Model.yyyu.TreeObejct>(); dicTreeObejct.Add(mp.Menu_Id, mp);//将数据插入到list中 } strJson = yyyu.Common.JsonHelper.SerializationStr(dicTreeObejct); } return(strJson); }
/// <summary> /// 分页获取数据列表 /// </summary> //public DataSet GetList(int PageSize,int PageIndex,string strWhere) //{ //return dal.GetList(PageSize,PageIndex,strWhere); //} #endregion BasicMethod #region ExtensionMethod /// <summary> /// 获取所有菜单 /// </summary> /// <returns></returns> public string GetMuenList() { //获取数据 DataSet ds = this.GetList("IsActive=1"); Dictionary <string, Model.yyyu.TreeObejct> dicTreeObejct = new Dictionary <string, Model.yyyu.TreeObejct>();//数据存储 string strJson = ""; //菜单数据大于0 if (ds.Tables[0].Rows.Count > 0) { //先获取添加父节点信息 DataView dv = ds.Tables[0].DefaultView;//获取视图 dv.RowFilter = "Menu_ParentId=-1 AND Menu_Level=1"; DataTable dt = dv.ToTable(); foreach (DataRow item in dt.Rows) { Model.yyyu.TreeObejct mp = new Model.yyyu.TreeObejct(); //添加父节点 if (item["Menu_ParentId"].ToString() == "-1") { mp.Menu_Id = item["Menu_Id"].ToString(); mp.Menu_ParentId = item["Menu_ParentId"].ToString(); mp.Name = item["Name"].ToString(); mp.ShowName = item["ShowName"].ToString(); mp.MeunNum = item["MeunNum"].ToString(); if (item["NodeUrl"] == null) { mp.NodeUrl = ""; } else { mp.NodeUrl = item["NodeUrl"].ToString(); } mp.IshasSon = item["IshasSon"].ToString(); mp.children = new List <Model.yyyu.TreeObejct>(); dicTreeObejct.Add(mp.Menu_Id, mp);//将数据插入到list中 } } //获取所有子节点的数据 DataView dv1 = ds.Tables[0].DefaultView;//获取子节点视图 dv1.RowFilter = "Menu_ParentId<>-1"; DataTable dt1 = dv1.ToTable(); if (dt1.Rows.Count > 0) { //根据父节点添加子节点 foreach (var dicTree in dicTreeObejct) { foreach (DataRow dr in dt1.Rows) { if (dicTree.Value.Menu_Id == dr["Menu_ParentId"].ToString()) { Model.yyyu.TreeObejct mp = new Model.yyyu.TreeObejct(); mp.Menu_Id = dr["Menu_Id"].ToString(); mp.Menu_ParentId = dr["Menu_ParentId"].ToString(); mp.Name = dr["Name"].ToString(); mp.ShowName = dr["ShowName"].ToString(); mp.MeunNum = dr["MeunNum"].ToString(); if (dr["NodeUrl"] == null) { mp.NodeUrl = ""; } else { mp.NodeUrl = dr["NodeUrl"].ToString(); } mp.IshasSon = dr["IshasSon"].ToString(); dicTreeObejct[dicTree.Value.Menu_Id].children.Add(mp); } } } } strJson = yyyu.Common.JsonHelper.SerializationStr(dicTreeObejct); } else { } return(strJson); }