/// <summary> /// Adds the contents of another <see cref="AdShowInfoCollection">AdShowInfoCollection</see> to the end of the collection. /// </summary> /// <param name="value">A <see cref="AdShowInfoCollection">AdShowInfoCollection</see> containing the Components to add to the collection. </param> public void AddRange(AdShowInfoCollection value) { for (int i = 0; (i < value.Count); i = (i + 1)) { this.Add((AdShowInfo)value.List[i]); } }
/// <summary> /// Initializes a new instance of the <see cref="AdShowInfoCollection">AdShowInfoCollection</see> class containing the elements of the specified source collection. /// </summary> /// <param name="value">A <see cref="AdShowInfoCollection">AdShowInfoCollection</see> with which to initialize the collection.</param> public AdShowInfoCollection(AdShowInfoCollection value) { this.AddRange(value); }
/// <summary> /// Initializes a new instance of the <see cref="AdShowInfoCollectionEnumerator">AdShowInfoCollectionEnumerator</see> class referencing the specified <see cref="AdShowInfoCollection">AdShowInfoCollection</see> object. /// </summary> /// <param name="mappings">The <see cref="AdShowInfoCollection">AdShowInfoCollection</see> to enumerate.</param> public AdShowInfoCollectionEnumerator(AdShowInfoCollection mappings) { _temp = ((IEnumerable)(mappings)); _enumerator = _temp.GetEnumerator(); }
/// <summary> /// 获取指定楼层的帖内广告 /// </summary> /// <param name="pagename">页面名称</param> /// <param name="forumid">版块id</param> /// <param name="templatepath">模板路径</param> /// <param name="floor">获取指定楼层的帖内广告</param> public static string GetInPostAdXMLByFloor(string pagename, int forumid, string templatepath, int floor) { string selectstr = GetSelectStr(pagename, forumid, AdType.InPostAd); AdShowInfo[] adshowArray = GetAdsTable(selectstr); StringBuilder sb = new StringBuilder(); if (adshowArray.Length > 0) { Random random = new Random(); //取帖内下方广告 #if NET1 AdShowInfoCollection tmp = new AdShowInfoCollection(); #else List<AdShowInfo> tmp = new List<AdShowInfo>(); #endif foreach (AdShowInfo adshow in adshowArray)//可用的帖内下方广告 { string[] parameter = Utils.SplitString(adshow.Parameters.ToString().Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 0) { string possibleflooridlist = parameter[8]; if (Utils.InArray(floor.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<ad_thread1><![CDATA[{0}]]></ad_thread1>", ad.Code)); } tmp.Clear();//帖内上方 foreach (AdShowInfo adshow in adshowArray) { string[] parameter = Utils.SplitString(adshow.Parameters.ToString().Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 1) { string possibleflooridlist = parameter[8]; if (Utils.InArray(floor.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<ad_thread2><![CDATA[{0}]]></ad_thread2>", ad.Code)); } tmp.Clear();//帖内右侧 foreach (AdShowInfo adshow in adshowArray) { string[] parameter = Utils.SplitString(adshow.Parameters.ToString().Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 2) { string possibleflooridlist = parameter[8]; if (Utils.InArray(floor.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<ad_thread3><![CDATA[{0}]]></ad_thread3>", ad.Code)); } } return sb.ToString(); }
/// <summary> /// 返回贴内广告 /// </summary> /// <param name="pagename">页面名称</param> /// <param name="forumid">版块id</param> /// <param name="templatepath">模板路径</param> /// <param name="count">总数</param> /// <returns>贴内广告内容</returns> public static string GetInPostAd(string pagename, int forumid, string templatepath, int count) { string selectstr = GetSelectStr(pagename, forumid, AdType.InPostAd); AdShowInfo[] adshowArray = GetAdsTable(selectstr); StringBuilder sb = new StringBuilder(); if (adshowArray.Length > 0) { #region 原始代码 sb.Append("<div style=\"display: none;\" id=\"ad_none\">\r\n"); Random random = new Random(); for (int i = 1; i <= count; i++) {//帖内下方的广告 #if NET1 AdShowInfoCollection tmp = new AdShowInfoCollection(); #else List<AdShowInfo> tmp = new List<AdShowInfo>(); #endif string[] parameter; foreach (AdShowInfo adshow in adshowArray) { parameter = Utils.SplitString(adshow.Parameters.Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 0) { string possibleflooridlist = parameter[8]; if (Utils.InArray(i.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<div class=\"ad_textlink1\" id=\"ad_thread1_{0}_none\">{1}</div>\r\n", i, ad.Code)); } } for (int i = 1; i <= count; i++) {//帖内上方的广告 #if NET1 AdShowInfoCollection tmp = new AdShowInfoCollection(); #else List<AdShowInfo> tmp = new List<AdShowInfo>(); #endif string[] parameter; foreach (AdShowInfo adshow in adshowArray) { parameter = Utils.SplitString(adshow.Parameters.Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 1) { string possibleflooridlist = parameter[8]; if (Utils.InArray(i.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<div class=\"ad_textlink2\" id=\"ad_thread2_{0}_none\">{1}</div>\r\n", i, ad.Code)); } } for (int i = 1; i <= count; i++) {//帖内右方的广告 #if NET1 AdShowInfoCollection tmp = new AdShowInfoCollection(); #else List<AdShowInfo> tmp = new List<AdShowInfo>(); #endif foreach (AdShowInfo adshow in adshowArray) { string[] parameter = Utils.SplitString(adshow.Parameters.Trim(), "|", 9); int position = Utils.StrToInt(parameter[7], -1); if (position == 2) { string possibleflooridlist = parameter[8]; if (Utils.InArray(i.ToString(), possibleflooridlist, ",") || possibleflooridlist == "0") { tmp.Add(adshow); } } } if (tmp.Count > 0) { int number = random.Next(0, tmp.Count); AdShowInfo ad = tmp[number]; sb.Append(string.Format("<div class=\"ad_pip\" id=\"ad_thread3_{0}_none\">{1}</div>\r\n", i, ad.Code)); } } sb.Append("</div>"); sb.Append("<script type='text/javascript' src='javascript/template_inforumad.js'></script>\r\n"); } return sb.ToString(); #endregion }