Beispiel #1
0
        internal List <S_TreeInfoViewModel> GetListByRoleId(int roleID)
        {
            List <S_TreeInfoViewModel> resultList = new List <S_TreeInfoViewModel>();
            StringBuilder cmdText = new StringBuilder();

            if (roleID == -1)
            {
                cmdText.AppendFormat("SELECT * FROM S_TreeInfo WHERE ISNULL(TreeUrl,'')!=''  ORDER BY TreeSort ASC", roleID);
            }
            else
            {
                cmdText.AppendFormat("SELECT * FROM S_TreeInfo WHERE TreeID IN ( SELECT TreeID FROM S_TreeRole WHERE RoleID={0} ) ORDER BY TreeSort ASC", roleID);
            }
            DataSet data = db.Query(cmdText.ToString());

            if (data != null && data.Tables[0].Rows.Count > 0)
            {
                DataRowCollection rows = data.Tables[0].Rows;
                foreach (DataRow row in rows)
                {
                    S_TreeInfoViewModel tree = new S_TreeInfoViewModel();
                    tree.TreeId       = Convert.IsDBNull(row["TreeId"]) ? 0 : Convert.ToInt32(row["TreeId"]);
                    tree.TreeName     = Convert.IsDBNull(row["TreeName"]) ? "" : Convert.ToString(row["TreeName"]);
                    tree.ParentID     = Convert.IsDBNull(row["ParentID"]) ? 0 : Convert.ToInt32(row["ParentID"]);
                    tree.TreeSort     = Convert.IsDBNull(row["TreeSort"]) ? 0 : Convert.ToInt32(row["TreeSort"]);
                    tree.TreeUrl      = Convert.IsDBNull(row["TreeUrl"]) ? "" : Convert.ToString(row["TreeUrl"]);
                    tree.TreeNote     = Convert.IsDBNull(row["TreeNote"]) ? "" : Convert.ToString(row["TreeNote"]);
                    tree.TreeCode     = Convert.IsDBNull(row["TreeCode"]) ? "" : Convert.ToString(row["TreeCode"]);
                    tree.TreePageCode = Convert.IsDBNull(row["TreePageCode"]) ? "" : Convert.ToString(row["TreePageCode"]);
                    tree.TreeDesc     = Convert.IsDBNull(row["TreeDesc"]) ? "" : Convert.ToString(row["TreeDesc"]);
                    resultList.Add(tree);
                }
            }
            return(resultList);
        }
Beispiel #2
0
        /// <summary>
        /// 获取所有菜单
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public List <S_TreeInfoViewModel> GetTreeList()
        {
            var           resultList = new List <S_TreeInfoViewModel>();
            StringBuilder strSql     = new StringBuilder();

            strSql.Append("select  t.TreeID,t.TreeName,t.ParentID,t.TreeSort from S_TreeInfo t WHERE ISNULL(T.TreeUrl,'')!='' ORDER BY t.TreeSort");

            var ds = db.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var model = new S_TreeInfoViewModel();
                    var row   = ds.Tables[0].Rows[i];
                    if (row["TreeID"] != null && row["TreeID"].ToString() != "")
                    {
                        model.TreeId = int.Parse(row["TreeID"].ToString());
                    }
                    if (row["TreeName"] != null)
                    {
                        model.TreeName = row["TreeName"].ToString();
                    }
                    if (row["ParentID"] != null)
                    {
                        model.ParentID = Convert.ToInt32(row["ParentID"]);
                    }
                    if (row["TreeSort"] != null && row["TreeSort"].ToString() != "")
                    {
                        model.TreeSort = Convert.ToDecimal(row["TreeSort"].ToString());
                    }
                    resultList.Add(model);
                }
            }
            else
            {
                return(null);
            }
            return(resultList);
        }