public static Money GetDiscountedPTCPackPrice(PtcAdvertPack pack) { Money price = pack.Price; int pricePercentage = 100; //Cutom pack price dependable on number of members if (TitanFeatures.isSatvetErturkmen && AppSettings.PtcAdverts.DynamicPTCPriceEnabled) { Money PricePer1000views = AppSettings.PtcAdverts.BasePricePer1000ViewsPtc + new Money((Decimal)AppSettings.TotalMembers / (Decimal)AppSettings.PtcAdverts.DecimalPricePer1000ViewsPtc); price = new Money((Convert.ToDecimal(pack.Ends.Value) / (Decimal)1000)) * PricePer1000views; } if (AppSettings.PtcAdverts.RegistrationDiscountEnabled && Member.IsLogged) { var discountStarts = AppSettings.PtcAdverts.RegistrationDiscountStartDate; var discountEnds = AppSettings.PtcAdverts.RegistrationDiscountStartDate.AddDays(AppSettings.PtcAdverts.RegistrationDiscountDays); var now = AppSettings.ServerTime; var userRegistered = Member.CurrentInCache.Registered; if (now >= discountStarts && now <= discountEnds && userRegistered >= discountStarts && userRegistered <= discountEnds) { pricePercentage = 100 - (AppSettings.PtcAdverts.RegistrationDiscountValue < 100 ? AppSettings.PtcAdverts.RegistrationDiscountValue : 0); } } return(Money.MultiplyPercent(price, pricePercentage)); }
public static int PackComparision(PtcAdvertPack x, PtcAdvertPack y) { if ((int)x.Ends.EndMode < (int)y.Ends.EndMode) { return(1); } else if ((int)x.Ends.EndMode == (int)y.Ends.EndMode) { if (x.Price > y.Price) { return(1); } if (x.Price == y.Price) { return(0); } return(-1); } return(-1); }
protected void PTCCreditsTextBox_TextChanged(object sender, EventArgs e) { decimal pTCCreditsPerDayOrClick; if (TitanFeatures.isSatvetErturkmen) { pTCCreditsPerDayOrClick = (decimal)TableHelper.SelectScalar("SELECT TOP 1 PTCCreditsPerDayOrClick FROM PtcAdvertPacks"); } else { pTCCreditsPerDayOrClick = new PtcAdvertPack(Convert.ToInt32(ddlOptions.SelectedValue)).PTCCreditsPerDayOrClick; } try { int inputViews = Convert.ToInt32(PTCCreditsTextBox.Text); decimal PTCCreditsPrice = Convert.ToInt32(PTCCreditsTextBox.Text) * pTCCreditsPerDayOrClick; var availablePTCCredits = Member.Current.PTCCredits; var availablePTCCreditsString = string.Empty; if (availablePTCCredits >= PTCCreditsPrice) { availablePTCCreditsString = string.Format("<span style={0}>{1}</span>", "'color: #87a131; font-weight: bold;'", availablePTCCredits); } else { availablePTCCreditsString = string.Format("<span style={0}>{1}</span>", "'color: red; font-weight: bold;'", availablePTCCredits); } string extraViews = string.Format(@"<b>{0}</b> {1} = <b>{2}</b> {3} ({4} {5})", inputViews, inputViews == 1 ? U5006.VIEW.ToLower() : L1.VIEWS.ToLower(), PTCCreditsPrice, U5006.ADCREDITS, availablePTCCreditsString, U4200.AVAILABLE); AvailablePTCCreditsLiteral.Text = extraViews; } catch (Exception ex) { AvailablePTCCreditsLiteral.Text = string.Format("<span style='color: red;'>{0}</span>", U5006.INVALIDINTEGER); } }
protected void CreateAdButton_Click(object sender, EventArgs e) { ErrorMessagePanel.Visible = false; if (Page.IsValid) { try { AppSettings.DemoCheck(); if (Ad.Status == AdvertStatus.Finished) { Member User = Member.Logged(Context); PtcAdvertPack Pack = new PtcAdvertPack(Int32.Parse(ddlOptions.SelectedValue)); if (Pack.Price > User.PurchaseBalance) { throw new MsgException(L1.NOTENOUGHFUNDS); } //Take money and save the user string note = "PTC views"; User.SubtractFromPurchaseBalance(Pack.Price, note); User.SaveBalances(); PtcCrediter.TryToCreditReferrerAfterPurchase(User, Pack.Price, note); //Modify Ad.Prolong(Pack); Ad.Status = AdvertStatus.Paused; Ad.SaveStatus(); Ad.Save(); //Add history entry string entryText = ""; if (Pack.Ends.EndMode == End.Mode.Clicks) { entryText = (Convert.ToInt32(Pack.Ends.Value)).ToString() + " ad clicks"; } else if (Pack.Ends.EndMode == End.Mode.Days) { entryText = (Convert.ToInt32(Pack.Ends.Value)).ToString() + " ad days"; } History.AddPurchase(User.Name, Pack.Price, entryText); Response.Redirect("ads.aspx"); } } catch (MsgException ex) { ErrorMessagePanel.Visible = true; ErrorMessage.Text = ex.Message; } catch (Exception ex) { ErrorLogger.Log(ex); throw ex; } } }
protected void CreateAdButton_Click(object sender, EventArgs e) { ErrorMessagePanel.Visible = false; SuccMessagePanel.Visible = false; if (Page.IsValid) { try { AppSettings.DemoCheck(); Member User = null; int oldPackId = 0; if (Member.IsLogged) { User = Member.Logged(Context); } if (URL.Enabled) { throw new MsgException(U4200.CHECKURL); } PtcAdvert Ad; if (PageRequest == RequestType.Edit) { int adId = Convert.ToInt32(ViewState["editid"]); Ad = new PtcAdvert(adId); oldPackId = Ad.Pack.Id; } else { Ad = new PtcAdvert(); } Money AdCost = Money.Zero; PtcAdvertPack Pack = new PtcAdvertPack(); GetAdWithPrice(ref Ad, ref AdCost, ref Pack); //Add the ad to the db (for approval) Ad.Price = AdCost; if (Pack != null) { Ad.Pack = Pack; } if (Member.IsLogged) { //Take money and save the user int adViews = 0; if (AppSettings.PtcAdverts.PTCCreditsEnabled && UseExtraViewsCheckBox.Checked) { adViews = Convert.ToInt32(PTCCreditsTextBox.Text); if (adViews < 0) { throw new MsgException("Input cannot be negative."); } decimal adCreditsSpent = 0; var creditsPerDayOrClick = 0m; if (Pack == null) { if (TitanFeatures.isSatvetErturkmen) { PtcAdvertPack advertPack = TableHelper.GetListFromRawQuery <PtcAdvertPack>("SELECT TOP 1 * FROM PtcAdvertPacks")[0]; Ad.Pack = advertPack; Ad.Ends = End.FromClicks(adViews); creditsPerDayOrClick = advertPack.PTCCreditsPerDayOrClick; } } else { Ad.Ends = Ad.Ends.AddValue(adViews); creditsPerDayOrClick = Pack.PTCCreditsPerDayOrClick; } if (PageRequest == RequestType.Edit && Ad.ExtraViews != -1) { adCreditsSpent = (adViews - Ad.ExtraViews) * creditsPerDayOrClick; if (adCreditsSpent < 0) { adCreditsSpent = 0; } } else { adCreditsSpent = adViews * creditsPerDayOrClick; } Ad.ExtraViews = adViews; if (adCreditsSpent > Member.Current.PTCCredits) { throw new MsgException(U5006.NOTENOUGHADCREDITS); } else { User.SubstractFromPTCCredits(adCreditsSpent, "PTC advert"); } } else { Ad.ExtraViews = -1; } if (PageRequest == RequestType.Edit) { Ad.IsEdited = true; } Ad.TargetBalance = TargetBalanceRadioButtonList.TargetBalance; PurchaseOption.ChargeBalance(User, AdCost, TargetBalanceRadioButtonList.Feature, Ad.TargetBalance, PageRequest == RequestType.Edit ? "PTC update" : "PTC advert"); Ad.Advertiser = Advertiser.AsMember(User.Name); Ad.AdvertiserUserId = User.Id; Ad.Status = AdvertStatusExtensions.GetStartingStatus(); if (AppSettings.PtcAdverts.AdvertPTCPackCashbackEnabled && Pack.PTCPackCashBackPercent != 0) { Money CashBack = new Money(Double.Parse(AdCost.ToClearString()) * ((Double)Pack.PTCPackCashBackPercent / 100.0)); User.AddToTrafficBalance(CashBack, U6010.PTCCASHBACK); User.Save(); } } else { Ad.Advertiser = Advertiser.AsStranger(OutEmail.Text); Ad.TargetBalance = PurchaseBalances.PaymentProcessor; Ad.Status = AdvertStatus.Null; } if (oldPackId != 0 && oldPackId != Ad.Pack.Id) { Ad.ResetClicks(); } Ad.Save(); if (Member.IsLogged) { //Achievements trial int UserCurrentCampaigns = TableHelper.CountOf <PtcAdvert>(TableHelper.MakeDictionary("CreatorUsername", User.Name)); bool ShouldBeSaved = User.TryToAddAchievements( Prem.PTC.Achievements.Achievement.GetProperAchievements( Prem.PTC.Achievements.AchievementType.AfterAdvertisingPtcCampaigns, UserCurrentCampaigns)); if (ShouldBeSaved) { User.Save(); } if (PageRequest == RequestType.Edit) { History.AddEdit(User.Name, AdCost, "Advert campaign"); } else { History.AddPurchase(User.Name, AdCost, "Advert campaign"); MatrixBase.TryAddMemberAndCredit(User, AdCost, AdvertType.PTC); } if (Ad.Status != AdvertStatus.WaitingForAcceptance) { PtcCrediter.TryToCreditReferrerAfterPurchase(User, AdCost, PageRequest == RequestType.Edit ? "PTC update" : "PTC advert"); } Title.Text = ""; URL.Text = ""; chbDescription.Checked = false; chbGeolocation.Checked = false; chbBold.Checked = false; BackgroundColorCheckBox.Checked = false; StarredAdCheckBox.Checked = false; SuccMessagePanel.Visible = true; if (PageRequest == RequestType.Edit) { SuccMessage.Text = Ad.Status == AdvertStatus.WaitingForAcceptance ? U6012.EDITEDADAWAITSAPPROVAL : U6012.ADUPDATED; } else { SuccMessage.Text = Ad.Status == AdvertStatus.WaitingForAcceptance ? U4200.ADAWAITSAPPROVAL : U3501.ADCREATED; } } else { //Show buttons PaymentButtons.Visible = true; CreateAdButton.Visible = false; PaymentButtons.Text = GenerateHTMLButtons.GetPaymentButtons(new BuyAdvertButtonGenerator <IPtcAdvertPack>(Ad)); } ViewState["editid"] = null; } catch (MsgException ex) { ErrorMessagePanel.Visible = true; ErrorMessage.Text = ex.Message; } catch (Exception ex) { ErrorLogger.Log(ex); } } }
protected void RefreshAdvertAndPrice(object sender, EventArgs e) { PtcAdvert Ad; if (PageRequest == RequestType.Edit) { int adId = Convert.ToInt32(ViewState["editid"]); Ad = new PtcAdvert(adId); } else { Ad = new PtcAdvert(); } Money AdCost = Money.Zero; PtcAdvertPack Pack = new PtcAdvertPack(); GetAdWithPrice(ref Ad, ref AdCost, ref Pack, false); if (AppSettings.PtcAdverts.CashLinkViewEnabled == AppSettings.PTCViewMode.CashLink) { //CashLink titleTr.Visible = false; descriptionTr.Visible = false; boldTr.Visible = false; BuyWithPTCCreditsPlaceHolder.Visible = false; Abox1.Visible = true; } Abox1.IsActive = true; Abox1.Object = Ad; Abox1.DataBind(); Money totalCost = AdCost;// - Ad.Price; lblPrice.Text = (totalCost < Money.Zero ? Money.Zero : totalCost).ToString(); if (AppSettings.PtcAdverts.AdvertPTCPackCashbackEnabled) { if (Pack.PTCPackCashBackPercent != 0) { Double CashBack = Double.Parse(totalCost.ToClearString()) * ((Double)Pack.PTCPackCashBackPercent / 100.0); CashBackLabel.Text = new Money(CashBack).ToString(); } else { CashBackLabel.Text = U6010.NOCASHBACK; } } if (Pack != null && Pack.Ends.EndMode == End.Mode.Days) { TotalViewsPlaceHolder.Visible = false; } else { TotalViewsPlaceHolder.Visible = true; var totalViews = string.Empty; var totalViewsInt = 0; if (Pack != null && Pack.Ends.EndMode == End.Mode.Clicks) { totalViews += Pack.Ends.Value; totalViewsInt += (int)Pack.Ends.Value; } if (AppSettings.PtcAdverts.PTCCreditsEnabled && UseExtraViewsCheckBox.Checked) { int ptcCreditViews = 0; if (int.TryParse(PTCCreditsTextBox.Text, out ptcCreditViews)) { totalViews += " + " + PTCCreditsTextBox.Text; totalViewsInt += ptcCreditViews; } } lblViews.Text = totalViews; totalViewsInt = totalViewsInt - Ad.Clicks; if (totalViewsInt < 0) { totalViewsInt = 0; } lblTotalViews.Text = string.Format("{0} = {1}", U5008.TOTALVIEWSDESC.ToLower(), totalViewsInt); } }
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; } }
protected void DirectRefsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //The ad id [1] PtcAdvert Ad = new PtcAdvert(Convert.ToInt32(e.Row.Cells[1].Text)); //Description [23] if (string.IsNullOrEmpty(e.Row.Cells[23].Text)) { e.Row.Cells[23].Text = HtmlCreator.GetCheckboxUncheckedImage(); } else { e.Row.Cells[23].Text = HtmlCreator.GetCheckboxCheckedImage(); } //End mode [17] End.Mode Mode = (End.Mode)Convert.ToInt32(e.Row.Cells[17].Text); //Status [25] AdvertStatus Status = (AdvertStatus)Convert.ToInt32(e.Row.Cells[25].Text); e.Row.Cells[25].Text = HtmlCreator.GetColoredStatus(Status); //Pack [3] AdvertPack Pack = new PtcAdvertPack(Convert.ToInt32(e.Row.Cells[3].Text)); //Displaytime [18] e.Row.Cells[18].Text += "s"; //Shorten url [4] if (e.Row.Cells[4].Text.Length > 18) { e.Row.Cells[4].Text = e.Row.Cells[4].Text.Substring(0, 15) + "..."; } //TItle [5] e.Row.Cells[5].Text = e.Row.Cells[5].Text.Replace("<", "<"); e.Row.Cells[5].Text = e.Row.Cells[5].Text.Replace(">", ">"); e.Row.Cells[5].Text = Ad.TargetUrl; string starredAd = Ad.IsStarredAd ? "<img src='Images/Misc/star.png' style='width:16px;height:16px;'> " : ""; string targetUrl = Ad.TargetUrl.Length > 12 ? Ad.TargetUrl.Substring(0, 12) + "..." : Ad.TargetUrl; e.Row.Cells[5].Text = starredAd + Ad.Title + "<br/><i>" + targetUrl + "</i>"; //Progress [11] e.Row.Cells[11].Text = HtmlCreator.GenerateAdProgressHTML(Ad).Replace("clicks", L1.CLICKSSMALL).Replace("days", L1.DAYS); //PointsEarnedFromViews [12] if (AppSettings.PtcAdverts.PTCCreditsEnabled) { e.Row.Cells[12].Text = string.Format("{0}/~{1}", Ad.PointsEarnedFromViews, Member.CurrentInCache.Membership.PointsYourPTCAdBeingViewed * Ad.Ends.Value); } else { e.Row.Cells[12].CssClass = "displaynone"; } //Add % progress [13] e.Row.Cells[13].Text = Ad.ProgressInPercent.ToString() + "%"; //Add total views [14] e.Row.Cells[14].Text = e.Row.Cells[15].Text; //Geolocation check [24] var check = (CheckBox)e.Row.Cells[24].Controls[0]; if (check.Checked) { e.Row.Cells[24].Text = HtmlCreator.GetCheckboxCheckedImage(); } else { e.Row.Cells[24].Text = HtmlCreator.GetCheckboxUncheckedImage(); } // Start[31] Pause[32] Add [33] Remove [34] if (Status != AdvertStatus.Paused) { e.Row.Cells[31].Text = " "; } if (Status != AdvertStatus.Active) { e.Row.Cells[32].Text = " "; } if (Status != AdvertStatus.Finished) { e.Row.Cells[33].Text = " "; } if (!Status.CanBeRemoved()) { e.Row.Cells[34].Text = " "; } //Edit button [35] ((LinkButton)e.Row.Cells[35].FindControl("ImageButton4")).ToolTip = U5007.EDIT; if (Ad.Status == AdvertStatus.Rejected) { e.Row.Cells[35].Controls.Clear(); } } else if (e.Row.RowType == DataControlRowType.Header) { //PointsEarnedFromViews [12] DirectRefsGridView.Columns[12].HeaderText = string.Format(U5007.EARNED, AppSettings.PointsName); } if (!AppSettings.PtcAdverts.FeedbackCaptchaEnabled) { DirectRefsGridView.Columns[28].HeaderStyle.CssClass = "displaynone"; DirectRefsGridView.Columns[29].HeaderStyle.CssClass = "displaynone"; DirectRefsGridView.Columns[30].HeaderStyle.CssClass = "displaynone"; DirectRefsGridView.Columns[28].ItemStyle.CssClass = "displaynone"; DirectRefsGridView.Columns[29].ItemStyle.CssClass = "displaynone"; DirectRefsGridView.Columns[30].ItemStyle.CssClass = "displaynone"; } if (!AppSettings.PtcAdverts.PTCCreditsEnabled) { DirectRefsGridView.Columns[12].HeaderStyle.CssClass = "displaynone"; } }