Example #1
0
        /// <summary>
        /// 已加入資料列表
        /// </summary>
        /// <param name="search"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public static IEnumerable <CustomLineNewsDataModels> GetDataItems(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      = "Select M.Title MenuTitle,M.DataType," +
                              " Case M.DataType " +
                              " WHEN 'Article' " +
                              " THEN (Select Title from Article A Where LND.SelectID = A.ID And LND.SiteID = A.SiteID And LND.SelectMenuID = A.MenuID) " +
                              " WHEN 'Event' " +
                              " THEN (Select Title from[Events] A Where LND.SelectID = A.ID And LND.SiteID = A.SiteID And LND.SelectMenuID = A.MenuID) " +
                              " ELSE " +
                              " '' " +
                              " End Title " +
                              " , LND.* " +
                              " From CustomLINENewsData LND " +
                              " Inner Join Menus M On LND.SelectMenuID= M.ID " +


                              " Where SourceID = {}; ";
            List <string> where = new List <string>();
            where.Add("SourceID = " + 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);
        }