private void BindDataToDDL() { var where = TableHelper.MakeDictionary("IsVisibleByMembers", true); if (AppSettings.PtcAdverts.PTCCreditsEnabled) { where["EndMode"] = (int)End.Mode.Clicks; } var listPacks = TableHelper.SelectRows <PtcAdvertPack>(where); listPacks.Sort(PtcAdvertManager.PackComparision); var list = new Dictionary <string, string>(); foreach (PtcAdvertPack pack in listPacks) { string ends = L1.NEVER; if (pack.Ends.EndMode == End.Mode.Days) { ends = pack.Ends.Value.ToString() + " " + L1.DAYS; } else if (pack.Ends.EndMode == End.Mode.Clicks) { ends = pack.Ends.Value.ToString() + " " + L1.VIEWS; } Money price; PtcAdvert ad = null; try { ad = new PtcAdvert(Convert.ToInt32(ViewState["editid"])); } catch { } if (ad != null && ad.Pack.Id == pack.Id) { price = ad.PackPrice; } else { price = PtcAdvertManager.GetDiscountedPTCPackPrice(pack); } string value = ends + " (" + pack.DisplayTime.TotalSeconds.ToString() + "s) - " + price.ToString(); if (AppSettings.PtcAdverts.AdvertPTCPackCashbackEnabled && pack.PTCPackCashBackPercent != 0) { value += String.Format(" - {0}% cashback", pack.PTCPackCashBackPercent); } list.Add(pack.Id.ToString(), value); } ddlOptions.DataSource = list; ddlOptions.DataTextField = "Value"; ddlOptions.DataValueField = "Key"; ddlOptions.DataBind(); }
protected void GetAdWithPrice(ref PtcAdvert Ad, ref Money AdCost, ref PtcAdvertPack Pack, bool throwExceptions = true) { try { ErrorMessagePanel.Visible = false; int packId = int.Parse(ddlOptions.SelectedValue); //Use Ad Credits only if (packId == -1) { Pack = null; if (!UseExtraViewsCheckBox.Checked && throwExceptions) { throw new MsgException(U5006.SELECTUSEXTRAVIEWS); } } else { Pack = new PtcAdvertPack(packId); } AdCost = Money.Zero; if (Pack != null && Ad.Pack.Id != Pack.Id) { AdCost = PtcAdvertManager.GetDiscountedPTCPackPrice(Pack); Ad.PackPrice = AdCost; } //Set basics if (AppSettings.PtcAdverts.CashLinkViewEnabled == AppSettings.PTCViewMode.CashLink) { Ad.Title = "Cash Link"; //Fixed title for cash links } else { Ad.Title = InputChecker.HtmlEncode(Title.Text, Title.MaxLength, L1.TITLE); } Ad.TargetUrl = URL.Text; int categoryId = -1; if (AppSettings.PtcAdverts.PTCCategoryPolicy == AppSettings.PTCCategoryPolicy.Custom) { int.TryParse(CategoriesDDL.SelectedValue, out categoryId); } Ad.CategoryId = categoryId; if (chbDescription.Checked) { if (Ad.Description == null || Ad.Description == string.Empty) { AdCost += AppSettings.PtcAdverts.DescriptionCost; } Ad.Description = InputChecker.HtmlEncode(Description.Text, Description.MaxLength, L1.DESCRIPTION); } else { Ad.Description = string.Empty; } if (chbBold.Checked) { if (!Ad.HasBoldTitle) { AdCost += AppSettings.PtcAdverts.FontBoldCost; } Ad.HasBoldTitle = true; } if (chbGeolocation.Checked) { if ((Ad.GeolocatedCC == null || Ad.GeolocatedCC == string.Empty) && Ad.GeolocatedAgeMin == 0 && Ad.GeolocatedAgeMax == 0 && Ad.GeolocatedGender == Gender.Null) { AdCost += AppSettings.PtcAdverts.GeolocationCost; } //Now get it from client-state var CTable = GeoCountries.Items; var geoUList = GeolocationUtils.GeoCountData.Keys; StringBuilder sb = new StringBuilder(); foreach (ListItem item in CTable) { if (geoUList.Contains <string>(item.Value)) { var countryCode = CountryManager.GetCountryCode(item.Value); if (!string.IsNullOrWhiteSpace(countryCode)) { sb.Append(CountryManager.GetCountryCode(item.Value)); sb.Append(","); } } } Ad.GeolocatedCC = sb.ToString().Trim(','); Ad.GeolocatedAgeMin = Convert.ToInt32(GeoAgeMin.Text); Ad.GeolocatedAgeMax = Convert.ToInt32(GeoAgeMax.Text); Ad.GeolocatedGender = (Gender)Convert.ToInt32(GeoGenderList.SelectedValue); } else { Ad.GeolocatedCC = string.Empty; Ad.GeolocatedAgeMin = Ad.GeolocatedAgeMax = 0; Ad.GeolocatedGender = Gender.Null; } if (BackgroundColorCheckBox.Checked) { BgColorsDDL.Visible = true; var bgColor = new PtcAdvertBgColor(Convert.ToInt32(BgColorsDDL.SelectedValue)); BgColorsDDL.Attributes.Add("style", string.Format("background-color:{0};color:white;", new PtcAdvertBgColor(Convert.ToInt32(BgColorsDDL.SelectedValue)).BgColor)); if (Ad.BackgroundColor != bgColor.BgColor) { AdCost += bgColor.Price; Ad.BackgroundColor = bgColor.BgColor; } } if (AppSettings.PtcAdverts.FeedbackCaptchaEnabled) { Ad.CaptchaQuestion = InputChecker.HtmlEncode(CaptchaQuestionTexbox.Text, CaptchaQuestionTexbox.MaxLength, U6013.YESNOCAPTCHAQUESTION); } if (AppSettings.PtcAdverts.StarredAdsEnabled && StarredAdCheckBox.Checked) { if (!Ad.IsStarredAd) { AdCost += AppSettings.PtcAdverts.StarredAdsPrice; } Ad.IsStarredAd = true; } if (AppSettings.PtcAdverts.PTCImagesEnabled) { Ad.ImagePath = PTCImage_Image.DescriptionUrl; } else { Ad.ImagePath = null; } } catch (MsgException ex) { ErrorMessagePanel.Visible = true; ErrorMessage.Text = ex.Message; } }