예제 #1
0
        /// <summary>
        /// Loads and returns a record list of all News objects.
        /// Parameters: itemsPerPage = max records to fetch; pageNum = one based page number if multiple pages (otherwise itemsPerPage is effectively TOP)
        /// eg LoadActive() = returns all records; LoadActive(10) = returns top 10 records by default sort order; LoadActive(10, 2) = returns second page of 10 records by default sort order
        /// ("Default sort order" can be defined for each record type by overriding in the partial model file. By default it looks for fields: SortPosition,SortOrder,Position, DateAdded,CreateDate,DateCreated and NewsID desc.)
        /// </summary>
        public static NewsList LoadAll()
        {
            var result = new NewsList();

            result.LoadRecords(null);
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Returns a record list of News objects, given a SQL statement.
        /// </summary>
        /// <param name="sql">A SQL statement constructed using the Beweb.Sql class</param>
        /// <returns>A list of News records.</returns>
        public static NewsList Load(Sql sql)
        {
            var result = new NewsList();

            result.LoadRecords(sql);
            return(result);
        }
예제 #3
0
        /// <summary>
        /// Loads all records which are active plus the one with the given ID. For situations where you want to only show active records except you also want to include the record that is already current.
        /// </summary>
        public static NewsList LoadActivePlusExisting(object existingRecordID)
        {
            var result = new NewsList();
            var sql    = (new News()).GetSqlWhereActivePlusExisting(existingRecordID);

            result.LoadRecords(sql);
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Loads and returns a record list of all the "active" News objects.
        /// Parameters: itemsPerPage = max records to fetch; pageNum = one based page number if multiple pages (otherwise itemsPerPage is effectively TOP)
        /// eg LoadActive() = returns all active records; LoadActive(10) = returns top 10 active records by default sort order; LoadActive(10, 2) = returns second page of 10 active records by default sort order
        /// ("Active" can be defined for each record type by overriding in the partial model file. By default it looks for fields: PublishDate/ExpiryDate, IsActive,IsEnabled,IsPublished,Active,Enabled,Published,IsVisible,Visible.)
        /// </summary>
        public static NewsList LoadActive()
        {
            var result = new NewsList();
            var sql    = (new News()).GetSqlWhereActive();

            result.LoadRecords(sql);
            return(result);
        }
예제 #5
0
        public static NewsList LoadIDs(string[] ids, bool useDefaultOrderBy)
        {
            var sql    = new Sql("where NewsID in (", ids.SqlizeNumberList(), ")");
            var result = new NewsList();

            result.LoadRecords(sql, useDefaultOrderBy);
            return(result);
        }
예제 #6
0
        public static NewsList LoadActive(int itemsPerPage, int pageNum)
        {
            var result = new NewsList();
            var sql    = (new News()).GetSqlWhereActive();

            sql.Paging(itemsPerPage, pageNum);
            result.LoadRecords(sql);
            return(result);
        }
예제 #7
0
        public static NewsList LoadAll(int itemsPerPage, int pageNum)
        {
            var result = new NewsList();
            var sql    = new Sql("where 1=1");

            sql.Paging(itemsPerPage, pageNum);
            result.LoadRecords(sql);
            return(result);
        }
예제 #8
0
        private void GetNewsLink(int page)
        {
            string link;

            link = "https://tw.appledaily.com/new/realtime/";

            link = link + page.ToString();


            try
            {
                HtmlWeb      web = new HtmlWeb();
                HtmlDocument doc = web.Load(link);

                //項目名稱
                var nodeHead = doc.DocumentNode.SelectNodes("//div[@class='abdominis rlby clearmen']/h1[1]");
                //新聞標題資料
                var nodeData = doc.DocumentNode.SelectNodes("//div[@class='abdominis rlby clearmen']/ul[1]/li");

                NewsList newsList = new NewsList();

                foreach (var nsh in nodeHead)
                {
                    newsList.Days = nsh.InnerText;

                    List <NewsData> newsData = new List <NewsData>();
                    foreach (var nsd in nodeData)
                    {
                        NewsData news = new NewsData();

                        //建立key值
                        news.Id = Guid.NewGuid();

                        //抓取類型
                        news.Types = nsd.SelectSingleNode("./a/h2").InnerText;

                        //抓取網址
                        var newlinks = nsd.SelectSingleNode("./a").Attributes["href"].Value;
                        news.Links = newlinks;

                        //抓取內文
                        var DNC = GetNewsContent(newlinks);
                        news.Content = DNC["新聞內文"];

                        //新聞時間 -> 年/月/日 + 時:分
                        news.Time = Convert.ToDateTime(DNC["內文時間"].Substring(5));

                        //抓取標題
                        //news.Head = nsd.SelectSingleNode("./a/h1").InnerText;
                        news.Head = DNC["內文標題"];

                        newsData.Add(news);

                        Thread.Sleep(1);
                    }
                    newsList.GetList = newsData;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }