Exemplo n.º 1
0
        /// <summary>
        /// 获取贴内广告
        /// </summary>
        /// <param name="target">目标</param>
        /// <param name="postion">位置</param>
        /// <param name="postIndex">楼层</param>
        /// <returns></returns>
        public string GetInPostAD(string target, ADPosition postion, int Floor, bool isLastFloor)
        {
            //int showBginId;
            //int showTime;
            //string key = "pad_" + target + postion;
            //string keyshowTimes = "pad_st_" + target + postion;

            AdvertCollection ads = SearchAdverts(ADCategory.InPostAd.ID, target, postion, Floor, isLastFloor);
            Random           rnd = new Random();

            if (ads.Count > 0)
            {
                //if ( !PageCacheUtil.TryGetValue<int>(key, out showBginId))
                //{
                //    showBginId = rnd.Next(0, 100000) % ads.Count;
                //    PageCacheUtil.Set(key, showBginId);
                //}

                //if (!PageCacheUtil.TryGetValue<int>(keyshowTimes, out showTime))
                //{
                //    showTime = 0;
                //}
                ads.Sort();
                Advert ad = ads[0];
                ad.showTimes++;
                return(ad.Code);
            }
            return("");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 调用广告
        /// </summary>
        /// <param name="categoryID"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public string ShowAdvert(int categoryID, string target, ADPosition position)
        {
            AdvertCollection ads = SearchAdverts(categoryID, target, position, null, null);

            Random rnd = new Random();

            if (ads.Count > 0)
            {
                ADCategory category = GetCategory(categoryID);
                switch (category.ShowType)
                {
                case ADShowType.Random:
                //int i = 0 ;
                //if (ads.Length > 1)
                //{
                //    i = new Random().Next(ads.Length);
                //}
                case ADShowType.Order:
                    return(ads[rnd.Next(0, 100000) % ads.Count].Code);

                case ADShowType.List:
                    return(BuildAdvertList(ads));
                }
            }
            return("");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 生成列表形式的广告列表
        /// </summary>
        /// <param name="adList"></param>
        /// <returns></returns>
        private string BuildAdvertList(AdvertCollection adList)
        {
            StringBuilder builder = new StringBuilder("");

            foreach (Advert ad in adList)
            {
                builder.AppendFormat(@"<div style=""padding:5px"">{0}</div>", ad.Code);
            }

            return(builder.ToString());
        }
Exemplo n.º 4
0
        public string[] GetAdList(int categoryID, string target, int count)
        {
            AdvertCollection ads = SearchAdverts(categoryID, target, ADPosition.None, null, null);

            if (ads.Count == 0)
            {
                return(new string[0]);
            }

            string[] adArray = new string[ads.Count > count ? count :ads.Count];
            for (int i = 0; i < adArray.Length; i++)
            {
                adArray[i] = ads[i].Code;
            }
            return(adArray);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据类型编号、目标,返回 符合条件的广告列表
        /// </summary>
        /// <param name="categoryID"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private AdvertCollection SearchAdverts(int categoryID, string target, ADPosition position, int?Floor, bool?isLastFloor)
        {
            if (AllSettings.Current.AdvertSettings.EnableAdverts == false)
            {
                return(new AdvertCollection());
            }

            if (!ADCategory.SystemADCategoryes.ContainsKey(categoryID))
            {
                return(new AdvertCollection());
            }

            AdvertCollection ads = ADCategory.SystemADCategoryes.GetValue(categoryID).AdvertList.Limited;

            AdvertCollection adResults;

            string cacheKey = string.Concat(categoryID, ",", target, position, Floor, isLastFloor);

            if (PageCacheUtil.TryGetValue <AdvertCollection>(cacheKey, out adResults) == false)
            {
                adResults = new AdvertCollection();
                foreach (Advert ad in ads)
                {
                    if (ad.Targets.Contains(",all,") || ad.Targets.IndexOf(string.Concat(",", target, ","), StringComparison.OrdinalIgnoreCase) > -1) //投放目标选择
                    {
                        if (position == ADPosition.None || ad.Position == position)                                                                   //投放位置选中(左边还是右边还是上边)
                        {
                            if (Floor == null ||                                                                                                      //忽略
                                ad.Floor.IndexOf(",-1,") > -1 || //全部楼层
                                ad.Floor.IndexOf("," + Floor + ",") > -1 || //匹配特定楼层
                                (ad.Floor.IndexOf(",-2,") > -1 && (isLastFloor != null && isLastFloor.Value))    //最后一楼
                                )
                            {
                                adResults.Add(ad);
                            }
                        }
                    }
                }
                PageCacheUtil.Set(cacheKey, adResults);
            }

            return(adResults);
        }
Exemplo n.º 6
0
        public override AdvertCollection GetAdverts(int categoryID, ADPosition adPosition, int pageSize, int pageNumber, out int totalCount)
        {
            totalCount = 0;

            using (SqlQuery query = new SqlQuery())
            {
                query.Pager.TableName    = "bx_Adverts";
                query.Pager.SortField    = "ADID";
                query.Pager.PageNumber   = pageNumber;
                query.Pager.PageSize     = pageSize;
                query.Pager.PageSize     = Consts.DefaultPageSize;
                query.Pager.SelectCount  = true;
                query.Pager.ResultFields = "*";

                if (categoryID != 0)
                {
                    query.Pager.Condition = "CategoryID = @CategoryID";
                    query.CreateParameter <int>("@CategoryID", categoryID, SqlDbType.Int);
                }

                if (adPosition != ADPosition.None)
                {
                    query.Pager.Condition += " AND [Position] = @Position";
                    query.CreateParameter <byte>("@Position", (byte)adPosition, SqlDbType.TinyInt);
                }

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    AdvertCollection ads = new AdvertCollection(reader);
                    if (reader.NextResult())
                    {
                        while (reader.Read())
                        {
                            totalCount = reader.Get <int>(0);
                        }
                    }
                    return(ads);
                }
            }
        }
Exemplo n.º 7
0
        public override AdvertCollection GetAdverts(int categoryID, ADPosition adPosition, int pageSize, int pageNumber, out int totalCount)
        {
            totalCount = 0;

            using (SqlQuery query = new SqlQuery())
            {

                query.Pager.TableName = "bx_Adverts";
                query.Pager.SortField = "ADID";
                query.Pager.PageNumber = pageNumber;
                query.Pager.PageSize = pageSize;
                query.Pager.PageSize = Consts.DefaultPageSize;
                query.Pager.SelectCount = true;
                query.Pager.ResultFields = "*";

                if (categoryID != 0)
                {
                    query.Pager.Condition = "CategoryID = @CategoryID";
                    query.CreateParameter<int>("@CategoryID", categoryID, SqlDbType.Int);
                }

                if (adPosition != ADPosition.None)
                {
                    query.Pager.Condition += " AND [Position] = @Position";
                    query.CreateParameter<byte>("@Position", (byte)adPosition, SqlDbType.TinyInt);
                }

                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    AdvertCollection ads = new AdvertCollection(reader);
                    if (reader.NextResult())
                    {
                        while (reader.Read())
                            totalCount = reader.Get<int>(0);
                    }
                    return ads;
                }
            }
        }