/// <summary> /// Copies the elements of the specified <see cref="AdShowInfo">AdShowInfo</see> array to the end of the collection. /// </summary> /// <param name="value">An array of type <see cref="AdShowInfo">AdShowInfo</see> containing the Components to add to the collection.</param> public void AddRange(AdShowInfo[] value) { for (int i = 0; (i < value.Length); i = (i + 1)) { this.Add(value[i]); } }
/// <summary> /// 按查询字符串得到广告列表 /// </summary> /// <param name="selectstr">查询字符串</param> /// <returns>广告列表</returns> private static AdShowInfo[] GetAdsTable(string selectstr) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable dt = cache.RetrieveObject("/Forum/Advertisements") as DataTable; if (dt == null) { dt = Discuz.Data.Advertisenments.GetAdsTable(); cache.AddObject("/Forum/Advertisements", dt); } DataRow[] drs = dt.Select(selectstr); AdShowInfo[] adarray = new AdShowInfo[drs.Length]; for (int i = 0; i < drs.Length; i++) { adarray[i] = new AdShowInfo(); adarray[i].Advid = Utils.StrToInt(drs[i]["advid"].ToString(), 0); adarray[i].Displayorder = Utils.StrToInt(drs[i]["displayorder"].ToString(), 0); adarray[i].Code = drs[i]["code"].ToString().Trim(); adarray[i].Parameters = drs[i]["parameters"].ToString().Trim(); } return adarray; }
public int Add(AdShowInfo value) { return this.List.Add(value); }
/// <summary> /// Initializes a new instance of the <see cref="AdShowInfoCollection">AdShowInfoCollection</see> class containing the specified array of <see cref="AdShowInfo">AdShowInfo</see> Components. /// </summary> /// <param name="value">An array of <see cref="AdShowInfo">AdShowInfo</see> Components with which to initialize the collection. </param> public AdShowInfoCollection(AdShowInfo[] value) { this.AddRange(value); }
public void Remove(AdShowInfo value) { List.Remove(value); }
public void Insert(int index, AdShowInfo value) { List.Insert(index, value); }
/// <summary> /// Gets the index in the collection of the specified <see cref="AdShowInfoCollection">AdShowInfoCollection</see>, if it exists in the collection. /// </summary> /// <param name="value">The <see cref="AdShowInfoCollection">AdShowInfoCollection</see> to locate in the collection.</param> /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns> public int IndexOf(AdShowInfo value) { return this.List.IndexOf(value); }
public int Add(AdShowInfo value) { return(this.List.Add(value)); }
/// <summary> /// Gets the index in the collection of the specified <see cref="AdShowInfoCollection">AdShowInfoCollection</see>, if it exists in the collection. /// </summary> /// <param name="value">The <see cref="AdShowInfoCollection">AdShowInfoCollection</see> to locate in the collection.</param> /// <returns>The index in the collection of the specified object, if found; otherwise, -1.</returns> public int IndexOf(AdShowInfo value) { return(this.List.IndexOf(value)); }
/// <summary> /// 获取显示广告信息 /// </summary> /// <param name="adshowArray">显示的广告数据</param> /// <param name="floor">获取指定楼层的帖内广告</param> /// <param name="inPostAdType">帖内广告类型 0:帖内下方的广告 1:帖内上方的广告 2:帖内右方的广告</param> /// <returns>广告信息</returns> public static string GetAdShowInfoXMLByFloor(AdShowInfo[] adshowArray, int floor, int inPostAdType) { string adsMsg = ""; Random random = new Random(); //取帖内下方广告 List<AdShowInfo> tmp = new List<AdShowInfo>(); foreach (AdShowInfo adshow in adshowArray)//可用的帖内下方广告 { string[] parameter = Utils.SplitString(adshow.Parameters.ToString().Trim(), "|", 9); if (Utils.StrToInt(parameter[7], -1) == inPostAdType) { //parameter[8]:possibleflooridlist if (Utils.InArray(floor.ToString(), parameter[8], ",") || parameter[8] == "0") tmp.Add(adshow); } } if (tmp.Count > 0) { AdShowInfo ad = tmp[random.Next(0, tmp.Count)]; adsMsg = string.Format("<ad_thread{0}><![CDATA[{1}]]></ad_thread{0}>", inPostAdType, ad.Code); } return adsMsg; }
/// <summary> /// 获取广告信息 /// </summary> /// <param name="adshowArray">广告信息数组</param> /// <param name="parameter">要返回的广告参数</param> /// <returns>广告信息</returns> private static string GetAdsMsg(AdShowInfo[] adshowArray, ref string[] parameter) { if (adshowArray.Length == 0) //当没有浮动广告时直接返回空串 return ""; string result = ""; int number = 0; if (adshowArray.Length > 1) //如果浮动广告的条数大于一条,则随机显示一条 number = new Random().Next(0, adshowArray.Length); if (Utils.StrIsNullOrEmpty(adshowArray[number].Parameters)) return ""; //初始化参数 parameter = adshowArray[number].Parameters.Split('|'); if (parameter[0].ToLower() == "flash") result = string.Format("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"{0}\" height=\"{1}\"><param name=\"movie\" value=\"{2}\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"opaque\">{3}<embed src=\"{2}\" wmode=\"opaque\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"{0}\" height=\"{1}\"></embed></object>", parameter[2], parameter[3], parameter[1], adshowArray[number].Code); else result = adshowArray[number].Code; return result; }
/// <summary> /// 获取显示广告信息 /// </summary> /// <param name="adshowArray">显示的广告数据</param> /// <param name="count">总数</param> /// <param name="inPostAdType">帖内广告类型 0:帖内下方的广告 1:帖内上方的广告 2:帖内右方的广告</param> /// <returns>广告信息</returns> public static string GetAdShowInfo(AdShowInfo[] adshowArray, int count, int inPostAdType) { string adsMsg = ""; Random random = new Random(); for (int i = 1; i <= count; i++) { List<AdShowInfo> tmp = new List<AdShowInfo>(); string[] parameter; foreach (AdShowInfo adshow in adshowArray) { parameter = Utils.SplitString(adshow.Parameters.Trim(), "|", 9); if (Utils.StrToInt(parameter[7], -1) == inPostAdType) { //parameter[8]: possibleflooridlist if (Utils.InArray(i.ToString(), parameter[8], ",") || parameter[8] == "0") tmp.Add(adshow); } } if (tmp.Count > 0) { switch (inPostAdType) { case 0: //帖内下方的广告 adsMsg += string.Format("<div class=\"ad_textlink1\" id=\"ad_thread1_{0}_none\">{1}</div>\r\n", i, tmp[random.Next(0, tmp.Count)].Code); break; case 1: //帖内上方的广告 adsMsg += string.Format("<div class=\"ad_textlink2\" id=\"ad_thread2_{0}_none\">{1}</div>\r\n", i, tmp[random.Next(0, tmp.Count)].Code); break; default: //帖内右方的广告 adsMsg += string.Format("<div class=\"ad_pip\" id=\"ad_thread3_{0}_none\">{1}</div>\r\n", i, tmp[random.Next(0, tmp.Count)].Code); break; } } } return adsMsg; }
/// <summary> /// Gets a value indicating whether the collection contains the specified <see cref="AdShowInfoCollection">AdShowInfoCollection</see>. /// </summary> /// <param name="value">The <see cref="AdShowInfoCollection">AdShowInfoCollection</see> to search for in the collection.</param> /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns> public bool Contains(AdShowInfo value) { return this.List.Contains(value); }
/// <summary> /// Gets a value indicating whether the collection contains the specified <see cref="AdShowInfoCollection">AdShowInfoCollection</see>. /// </summary> /// <param name="value">The <see cref="AdShowInfoCollection">AdShowInfoCollection</see> to search for in the collection.</param> /// <returns><b>true</b> if the collection contains the specified object; otherwise, <b>false</b>.</returns> public bool Contains(AdShowInfo value) { return(this.List.Contains(value)); }
/// <summary> /// Copies the collection Components to a one-dimensional <see cref="T:System.Array">Array</see> instance beginning at the specified index. /// </summary> /// <param name="array">The one-dimensional <see cref="T:System.Array">Array</see> that is the destination of the values copied from the collection.</param> /// <param name="index">The index of the array at which to begin inserting.</param> public void CopyTo(AdShowInfo[] array, int index) { this.List.CopyTo(array, index); }
/// <summary> /// 按查询字符串得到广告列表 /// </summary> /// <param name="selectstr">查询字符串</param> /// <returns>广告列表</returns> private static AdShowInfo[] GetAdsTable(string selectstr) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable dt = cache.RetrieveObject("/Advertisements") as DataTable; if (dt == null) { dt = DatabaseProvider.GetInstance().GetAdsTable(); cache.AddObject("/Advertisements", dt); } DataRow[] drs = dt.Select(selectstr); int adlength = drs.Length; AdShowInfo[] adarray = new AdShowInfo[adlength]; for (int i = 0; i < adlength; i++) { adarray[i] = new AdShowInfo(); adarray[i].Advid = Convert.ToInt32(drs[i]["advid"].ToString()); adarray[i].Displayorder = Convert.ToInt32(drs[i]["displayorder"].ToString()); adarray[i].Code = drs[i]["code"].ToString().Trim(); adarray[i].Parameters = drs[i]["parameters"].ToString().Trim(); } return adarray; }