/// <summary> /// 得到该分中心图片新闻列表 /// </summary> /// <param name="SQLWhere"></param> private void GetPicNewsList(string SubCenterID) { try { List<NewsContent> gotNewsList = new List<NewsContent>(); List<NewsModule> gotNewsModule = NewsModule.GetNewsModuleList("Center='2' and Site='" + SubCenterID + "'") as List<NewsModule>; if (gotNewsModule != null && gotNewsModule.Count != 0) { for (int i = 0; i < gotNewsModule.Count; i++) { string sqlwhere = "ModuleID ='" + gotNewsModule[i].Id + "'"; sqlwhere = sqlwhere + " and Status = '2'"; gotNewsList.AddRange(NewsContent.GetSqlWhere(sqlwhere) as List<NewsContent>); } } if (gotNewsList != null) { List<SubImgNew> needNewsPhoto = new List<SubImgNew>(); for (int z = 0; z < gotNewsList.Count; z++) { string needimgurl = GetPhotoSrc(gotNewsList[z].Content); if (needimgurl != string.Empty) { SubImgNew imgnews = new SubImgNew(); imgnews.NewsImgurl = needimgurl; imgnews.NewsId = gotNewsList[z].Id.ToString(); imgnews.NewsTitle = gotNewsList[z].Title; imgnews.PublishTime = gotNewsList[z].PublishTime; imgnews.NewsModule = (NewsModule.Load(gotNewsList[z].ModuleID)).Name; needNewsPhoto.Add(imgnews); } } if (needNewsPhoto != null && needNewsPhoto.Count != 0) { needNewsPhoto.Sort((x, y) => x.PublishTime.CompareTo(y.PublishTime)); needNewsPhoto = needNewsPhoto.Take(8).ToList(); for (int j = 0; j < needNewsPhoto.Count; j++) { if (imgfiles != "") { imgfiles += "|"; } string srcImgPath = needNewsPhoto[j].NewsImgurl; int Picwidth = 238; int picheight = 230; string strFileName = ""; int location = srcImgPath.LastIndexOf("/"); int length = srcImgPath.Length; strFileName = srcImgPath.Substring(location + 1, length - location - 1); strFileName = needNewsPhoto[j].NewsId.ToString() + "_" + Picwidth.ToString() + "_" + picheight + "_" + strFileName; srcImgPath = srcImgPath.Replace("../", ""); try { if (!srcImgPath.StartsWith("/")) srcImgPath = "/" + srcImgPath; string PhysicPath = Server.MapPath(srcImgPath); string serverPath = Server.MapPath("/preview/" + strFileName); if (!System.IO.File.Exists(Server.MapPath("/preview/" + strFileName))) { if (System.IO.File.Exists(PhysicPath)) { if (!System.IO.File.Exists(serverPath)) { CY.Utility.Common.PicProcess.MakeThumbnail(PhysicPath, serverPath, (int)Picwidth, (int)picheight, "Cut", ""); } srcImgPath = "/preview/" + strFileName; } else { srcImgPath = needNewsPhoto[j].NewsImgurl; } } else { srcImgPath = "/preview/" + strFileName; } } catch { srcImgPath = needNewsPhoto[j].NewsImgurl; } imgfiles += srcImgPath; if (newslinks != "") { newslinks += "|"; } newslinks += "newsshow.aspx?SUBID=" + SubCenterID + "^" + needNewsPhoto[j].NewsId; if (newsnames != "") { newsnames += "|"; } newsnames += "[" + needNewsPhoto[j].NewsModule + "]" + needNewsPhoto[j].NewsTitle; } } } } catch (Exception ex) { //throw ex; Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('参数错误!');window.location = '../Default.aspx'</script>"); return; } }
private void BindImgNews() { List<NewsContent> gotNewsList = new List<NewsContent>(); List<NewsModule> gotNewsModule = NewsModule.GetNewsModuleList("Center=2 and Site='" + SubCenterID + "'") as List<NewsModule>; if (gotNewsModule != null && gotNewsModule.Count!=0) { for (int i = 0; i < gotNewsModule.Count; i++) { string sqlwhere = "ModuleID ='" + gotNewsModule[i].Id + "'"; sqlwhere = sqlwhere + " and Status = 2 "; gotNewsList.AddRange( NewsContent.GetSqlWhere(sqlwhere) as List<NewsContent>); } } if (gotNewsList != null) { List<SubImgNew> needNewsPhoto = new List<SubImgNew>(); for (int z = 0; z < gotNewsList.Count; z++) { string needimgurl = GetPhotoSrc(gotNewsList[z].Content); if (needimgurl != string.Empty) { SubImgNew imgnews = new SubImgNew(); imgnews.NewsImgurl = needimgurl; imgnews.NewsId = gotNewsList[z].Id.ToString(); imgnews.NewsTitle = gotNewsList[z].Title; imgnews.PublishTime = gotNewsList[z].PublishTime; imgnews.NewsModule = (NewsModule.Load(gotNewsList[z].ModuleID)).Name; needNewsPhoto.Add(imgnews); } } if (needNewsPhoto.Count != 0) { needNewsPhoto.Sort((x, y) => x.PublishTime.CompareTo(y.PublishTime)); needNewsPhoto = needNewsPhoto.Take(8).ToList(); RpImgNews.DataSource = needNewsPhoto; RpImgNews.DataBind(); } } }