コード例 #1
0
        /// <summary>
        /// 按分类查看
        /// </summary>
        /// <param name="nstartIndex"></param>
        /// <param name="nendIndex"></param>
        /// <param name="nClassID"></param>
        /// <returns></returns>
        public List <News> Get_News(int nstartIndex, int nendIndex, int nClassID)
        {
            SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper();
            SqlParameter[]      ParamList =
            {
                sqlHelper.CreateInParam("@startIndex", SqlDbType.Int, 4, nstartIndex),
                sqlHelper.CreateInParam("@endIndex",   SqlDbType.Int, 4, nendIndex),
                sqlHelper.CreateInParam("@Classid",    SqlDbType.Int, 4, nClassID),
                sqlHelper.CreateInParam("@docount",    SqlDbType.Bit, 1, 0)
            };
            SqlDataReader rec = null;

            try
            {
                sqlHelper.RunProc("Get_ClassNews", ParamList, out rec);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
            List <News> List_News = new List <News>();

            while (rec.Read())
            {
                News        news        = new News();
                NewClass    newClass    = new NewClass();
                NewClassSQL newClassSQl = new NewClassSQL();
                newClass        = newClassSQl.Get_SintNewClass(Int32.Parse(rec["ClassID"].ToString()));
                news.NewClass   = newClass;
                news.ID         = Int32.Parse(rec["ID"].ToString());
                news.Title      = rec["Title"].ToString();
                news.Source     = rec["Source"].ToString();
                news.Author     = rec["Author"].ToString();
                news.Content    = rec["Content"].ToString();
                news.Updatatime = DateTime.Parse(rec["Updatatime"].ToString());
                news.Click      = Int32.Parse(rec["Click"].ToString());
                List_News.Add(news);
                news     = null;
                newClass = null;
            }
            return(List_News);
        }
コード例 #2
0
        /// <summary>
        /// 查看单条新闻
        /// </summary>
        /// <param name="nID"></param>
        /// <returns></returns>
        public News Get_SintNews(int nID)
        {
            SQLHelper.SQLHelper sqlHelper = new SQLHelper.SQLHelper();
            SqlParameter[]      ParamList =
            {
                sqlHelper.CreateInParam("@ID", SqlDbType.Int, 4, nID)
            };
            SqlDataReader rec = null;

            try
            {
                sqlHelper.RunProc("Get_SintNews", ParamList, out rec);
            }
            catch (Exception ex)
            {
                SystemError.CreateErrorLog(ex.Message);
                throw new Exception(ex.Message, ex);
            }
            News news = new News();

            while (rec.Read())
            {
                NewClass    newClass    = new NewClass();
                NewClassSQL newClassSQl = new NewClassSQL();
                newClass        = newClassSQl.Get_SintNewClass(Int32.Parse(rec["ClassID"].ToString()));
                news.NewClass   = newClass;
                news.ID         = Int32.Parse(rec["ID"].ToString());
                news.Title      = rec["Title"].ToString();
                news.Source     = rec["Source"].ToString();
                news.Author     = rec["Author"].ToString();
                news.Content    = rec["Content"].ToString();
                news.Updatatime = DateTime.Parse(rec["Updatatime"].ToString());
                news.Click      = Int32.Parse(rec["Click"].ToString());
            }
            return(news);
        }