示例#1
0
        private static List <News> GetNewsBySql(string sql)
        {
            List <News> lists = new List <News>();

            DataTable dt = DBHelper.GetTable(sql);

            foreach (DataRow row in dt.Rows)
            {
                News news = new News();

                news.NewsId        = (int)row["NewsId"];
                news.Title         = row["Title"].ToString();
                news.PictureUrl    = row["PictureUrl"].ToString();
                news.PublishDate   = (DateTime)row["PublishDate"];
                news.PublisherName = row["PublisherName"].ToString();
                news.Clicks        = (int)row["Clicks"];
                news.State         = (int)row["State"];
                news.Contents      = row["Contents"].ToString();
                news.IsTop         = (int)row["IsTop"];
                //news.TypeId = (int)row["TypeId"];
                news.Type = NewsTypeService.GetNewsTypeByTypeId((int)row["typeId"]);
                lists.Add(news);
            }
            return(lists);
        }
示例#2
0
        private static List <News> GetNewsBySql(string sql, params SqlParameter[] values)
        {
            List <News> list = new List <News>();

            try
            {
                DataTable table = DBHelper.GetDataTable(sql, values);

                foreach (DataRow row in table.Rows)
                {
                    News news = new News();

                    news.NewsId        = (int)row["NewsId"];
                    news.Title         = (string)row["Title"];
                    news.PictureUrl    = (string)row["PictureUrl"];
                    news.PublishDate   = (DateTime)row["PublishDate"];
                    news.PublisherName = (string)row["PublisherName"];
                    news.Clicks        = (int)row["Clicks"];
                    news.State         = (int)row["State"];
                    news.Contents      = (string)row["Contents"];
                    news.IsTop         = (int)row["IsTop"];
                    news.Type          = NewsTypeService.GetNewsTypeByTypeId((int)row["TypeId"]);            //FK

                    list.Add(news);
                }

                return(list);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
示例#3
0
        public static News GetNewByNewsId(int newsId)
        {
            string sql = "SELECT * FROM News WHERE NewsId = @NewsId";

            int typeId;

            try
            {
                SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@NewsId", newsId));
                if (reader.Read())
                {
                    News news = new News();

                    news.NewsId        = (int)reader["NewsId"];
                    news.Title         = (string)reader["Title"];
                    news.PictureUrl    = (string)reader["PictureUrl"];
                    news.PublishDate   = (DateTime)reader["PublishDate"];
                    news.PublisherName = (string)reader["PublisherName"];
                    news.Clicks        = (int)reader["Clicks"];
                    news.State         = (int)reader["State"];
                    news.Contents      = (string)reader["Contents"];
                    news.IsTop         = (int)reader["IsTop"];
                    typeId             = (int)reader["TypeId"];         //FK

                    reader.Close();

                    news.Type = NewsTypeService.GetNewsTypeByTypeId(typeId);

                    return(news);
                }
                else
                {
                    reader.Close();
                    return(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
示例#4
0
        private static List <News> GetNewsBySql(string strsql)
        {
            DataTable   dt      = DBHelper.GetTable(strsql);
            List <News> allnews = new List <News>();

            foreach (DataRow row in dt.Rows)
            {
                News n = new News();
                n.NewsId = Convert.ToInt32(row["newsid"]);
                //n.TypeId = Convert.ToInt32(row["typeid"]);
                n.Type          = NewsTypeService.GetNewsTypeByTypeId((int)row["typeid"]);
                n.Title         = row["title"].ToString();
                n.PictureUrl    = row["pictureurl"].ToString();
                n.PublishDate   = Convert.ToDateTime(row["publishdate"]);
                n.PublisherName = row["publishername"].ToString();
                n.Clicks        = Convert.ToInt32(row["clicks"]);
                n.State         = Convert.ToInt32(row["state"]);
                n.Contents      = row["contents"].ToString();
                n.IsTop         = Convert.ToInt32(row["istop"]);

                allnews.Add(n);
            }
            return(allnews);
        }