/// <summary> /// 初始化资讯 /// </summary> /// <param name="typeId"></param> protected void InitialPage(int page) { //更新置顶数据 var bll = new BLL.CCOM.News(); var list = bll.GetModelList("News_top=1"); for (int i = 0; i < list.Count; i++) { if (list[i].News_date != null) { DateTime date = Convert.ToDateTime(list[i].News_date); if (list[i].News_top_time != null) { if (date.AddDays((double)list[i].News_top_time) < DateTime.Now) { var model = bll.GetModel(list[i].News_id); model.News_top = false; model.News_top_time = 0; bll.Update(model); } } else { //若为空,默认为3天 if (date.AddDays(3.0) < DateTime.Now) { var model = bll.GetModel(list[i].News_id); model.News_top = false; model.News_top_time = 0; bll.Update(model); } } } } int start_index = 1; int end_index = 10; DataTable dt = bll.GetListByPage("", "News_top DESC ,News_date DESC ", start_index, end_index).Tables[0]; if (dt != null && dt.Rows.Count > 0) { string li = string.Empty; foreach (DataRow dr in dt.Rows) { bool top = false; try { top = Convert.ToBoolean(dr["News_top"]); } catch { top = false; } finally { DateTime date = Convert.ToDateTime(dr["News_date"]); string time = date.ToString("yyyy/MM/dd"); if (top) { li += "<li class=\"notice-li\">" + "<a href=\"" + dr["News_URL"] + "\" target=\"_blank\">" + "<img src=\"/images/news/news_logo2.png\" class=\"img_logo\"/>" + "<span style=\"color:red;\">[置顶] </span>" + dr["News_title"] + "</a>" + "<span class=\"date\">" + time + "</span>" + "</li>"; } else { li += "<li class=\"notice-li\">" + "<a href=\"" + dr["News_URL"] + "\" target=\"_blank\">" + "<img src=\"/images/news/news_logo2.png\" class=\"img_logo\"/>" + dr["News_title"] + "</a>" + "<span class=\"date\">" + time + "</span>" + "</li>"; } } } this.news_list.InnerHtml = li; } int newsNum = bll.GetRecordCount(""); int pageNum = 0; if (newsNum % 10 == 0) { pageNum = newsNum / 10; } else { pageNum = newsNum / 10 + 1; } this.page_num.Value = pageNum + ""; }
/// <summary> /// 绑定资讯内容 /// </summary> private void bindNewsData() { //更新置顶数据 var bll = new BLL.CCOM.News(); var list = bll.GetModelList("News_top=1"); for (int i = 0; i < list.Count; i++) { if (list[i].News_date != null) { DateTime date = Convert.ToDateTime(list[i].News_date); if (list[i].News_top_time != null) { if (date.AddDays((double)list[i].News_top_time) < DateTime.Now) { var model = bll.GetModel(list[i].News_id); model.News_top = false; model.News_top_time = 0; bll.Update(model); } } else { //若为空,默认为3天 if (date.AddDays(3.0) < DateTime.Now) { var model = bll.GetModel(list[i].News_id); model.News_top = false; model.News_top_time = 0; bll.Update(model); } } } } string strWhere = string.Empty; int pageSize = GetPageSize(15); //每页数量 int page = MyRequest.GetQueryInt("page", 1); keywords = MyRequest.GetQueryString("keywords"); string news_type_id = MyRequest.GetQueryString("news_type_id"); if (news_type_id != null && news_type_id.Length > 0) { string news_type = DESEncrypt.Decrypt(news_type_id); if (news_type != "0") { strWhere += " News_type_id=" + news_type; } } if (keywords != null && keywords.Length > 0) { if (strWhere != "") { strWhere = strWhere + " and News_title like '%" + keywords + "%' "; } else { strWhere = " News_title like '%" + keywords + "%' "; } } int start_index = pageSize * (page - 1) + 1; int end_index = pageSize * page; //计算数量 int totalCount = bll.GetRecordCount(""); //绑定当页 this.rptList.DataSource = bll.GetListByPage(strWhere, " News_date DESC ", start_index, end_index); this.rptList.DataBind(); //for (int i = 0; i < rptList.Items.Count; i++) //{ // LinkButton lbt = (LinkButton)rptList.Items[i].FindControl("lbtDelete"); // HiddenField hide = (HiddenField)rptList.Items[i].FindControl("hideCreatorId"); // int CreatorId = int.Parse(hide.Value); // if(CreatorId==GetAdminInfo_CCOM().User_id) // { // } //} //绑定页码 this.txtPageNum.Text = pageSize.ToString(); string pageUrl = Utils.CombUrlTxt("News_list_manager.aspx", "keywords={0}&page={1}&fun_id={2}", keywords, "__id__", DESEncrypt.Encrypt(this.fun_id)); this.PageContent.InnerHtml = Utils.OutPageList(pageSize, page, totalCount, pageUrl, 8, true); }