/// <summary> /// /// </summary> /// <param name="ID"></param> /// <param name="menuClass"></param> /// <param name="type"></param> /// <returns></returns> public static IEnumerable <Menu> GetChildren(long ID, int menuClass = 3) { if (ID == 0) { return(new List <Menu>()); } using (var conn = new SqlConnection(WebInfo.Conn)) { Dictionary <string, object> param = new Dictionary <string, object>(); param.Add("@ParentID", ID); string sql = ""; IEnumerable <Menu> retValue = new List <Menu>(); switch (menuClass) { case 1: long siteId = BackendMenuDAO.GetSiteId(ID); IEnumerable <MenusModels> submenu = MenusDAO.GetRootDataBySite(siteId); foreach (MenusModels item in submenu) { item.GetChildren(); } List <Menu> childMenu = new List <Menu>(); MenusModels lv1Menu = new MenusModels(); MenusModels lv2Menu = new MenusModels(); MenusModels lv3Menu = new MenusModels(); lv1Menu.Type = 1; lv1Menu.Title = "上導覽列"; lv1Menu.ID = long.MaxValue; lv1Menu.Children = submenu.Where(m => m.AreaID == 1); lv2Menu.Type = 1; lv2Menu.Title = "主選單"; lv2Menu.ID = long.MaxValue - 1; lv2Menu.Children = submenu.Where(m => m.AreaID == 2); lv3Menu.Type = 1; lv3Menu.Title = "下導覽列"; lv3Menu.ID = long.MaxValue - 2; lv3Menu.Children = submenu.Where(m => m.AreaID == 3); if (lv1Menu.Children.Count() > 0) { childMenu.Add(lv1Menu); } if (lv2Menu.Children.Count() > 0) { childMenu.Add(lv2Menu); } if (lv3Menu.Children.Count() > 0) { childMenu.Add(lv3Menu); } return(childMenu); case 2: case 3: default: sql = @" SELECT * FROM BackendMenu WHERE ParentID = @ParentID ORDER BY Sort "; retValue = conn.Query <BackendMenuModel>(sql, param); foreach (BackendMenuModel menu in retValue) { menu.GetChildren(); } return(retValue); } } }
/// <summary> /// 新增資料列表 /// </summary> /// <param name="search"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="recordCount"></param> /// <returns></returns> public static IEnumerable <CustomLineNewsDataModels> GetDataSearchItems(CustomLineNewsSearchModels search, int pageSize, int pageIndex, out int recordCount) { List <CustomLineNewsDataModels> items = new List <CustomLineNewsDataModels>(); recordCount = 0; if (search == null) { return(items); } #region 找資料 if (search.SiteID <= 0 | search.SelectMenuID <= 0) { return(items); } string DataType = ""; string sql; List <string> where = new List <string>(); where.Add("SiteID = " + search.SiteID); where.Add("MenuID = " + search.SelectMenuID); MenusModels M = MenusDAO.GetInfo(search.SiteID, search.SelectMenuID); if (M.DataType != null) { DataType = M.DataType; switch (DataType.ToLower()) { case "events": sql = "Select ID as SelectID, Title From Events Where {0} Order By sort Asc "; if (!string.IsNullOrWhiteSpace(search.Key)) { string key = string.Format("Like N'%{0}%'", search.Key.Replace("'", "''")); //where.Add(string.Format("(Title {0} OR Exists(Select 1 From Paragraph Where SourceNo = A.ID And (Title {0} OR Contents {0})))", key)); where.Add(string.Format("Title {0}", key)); } break; case "article": default: if (!string.IsNullOrWhiteSpace(search.Key)) { string key = string.Format("Like N'%{0}%'", search.Key.Replace("'", "''")); //where.Add(string.Format("(Title {0} OR Exists(Select 1 From Paragraph Where SourceNo = A.ID And (Title {0} OR Contents {0})))", key)); where.Add(string.Format("Title {0}", key)); } sql = "Select ID as SelectID, Title From Article Where {0} Order By sort Asc"; break; } SQLData.Database db = new SQLData.Database(WebInfo.Conn); DataTable datas = db.GetPageData(string.Format(sql, string.Join(" And ", where)), pageSize, pageIndex, out recordCount); if (datas != null) { foreach (DataRow dr in datas.Rows) { items.Add(new CustomLineNewsDataModels { SelectMenuID = M.ID, MenuTitle = M.Title, SelectID = (long)dr["SelectID"], Title = dr["Title"].ToString() }); } } } #endregion return(items); }