public void Delete_Load(object o, System.EventArgs e)
		{
			if (Mode.Equals(Modes.Delete) && CurrentMisc != null)
			{
				#region Delete file
				BannerSet bs = new BannerSet(
					new Query(
						new And(
							Banner.IsBookedQ,
							new Q(Banner.Columns.LastDay, QueryOperator.GreaterThanOrEqualTo, DateTime.Today),
							new Q(Banner.Columns.MiscK, CurrentMisc.K)
						)
					)
				);
				if (bs.Count == 0)
				{
					int promoterK = CurrentMisc.PromoterK;
					Delete.DeleteAll(CurrentMisc);
					Response.Redirect(UrlInfo.PageUrl("BannerCheck", "Mode", "List"));
				}
				else
				{
					throw new Exception("That's weird! this file is in use by a live banner!!!");
				}
				#endregion
			}
		}
		protected void Page_Load(object sender, EventArgs e)
		{
			ContainerPage.SslPage = true;
            Response.CacheControl = "no-cache";
            Response.AddHeader("Pragma", "no-cache");
            Response.Expires = -1;

			ContainerPage.SetPageTitle("Pending banners");

			if (!Page.IsPostBack)
			{
				Query q = new Query(
							  new And(
								  new Q(Banner.Columns.PromoterK, this.CurrentPromoter.K),
								  new Q(Banner.Columns.StatusBooked, false),
								  new Q(Banner.Columns.LastDay, QueryOperator.GreaterThanOrEqualTo, Common.Time.Now.Date)));
                //q.Columns = new ColumnSet(
                //                Banner.Columns.K, 
                //                Banner.Columns.Name, 
                //                Banner.Columns.TotalRequiredImpressions, 
                //                Banner.Columns.Position,
                //                Banner.Columns.LastDay,
                //                Banner.Columns.FirstDay,
                //                Banner.Columns.EventK,
                //                Banner.Columns.VenueK,
                //                Banner.Columns.PromoterK,
                //                Banner.Columns.BrandK,
                //                Banner.Columns.LinkTarget,
                //                Banner.Columns.LinkUrl,
                //                Banner.Columns.StatusBooked,
                //                Banner.Columns.IsPriceFixed,
                //                Banner.Columns.PriceCreditsStored,
                //                Banner.Columns.DesignType);

				BannerSet bs = new BannerSet(q);
				if (bs.Count == 0)
				{
					NoPendingBannersLabel.Visible = true;
					BookBannersPanel.Visible = false;
				}
				else
				{
					NoPendingBannersLabel.Visible = false;
					BannerGrid.DataSource = bs;
					BannerGrid.DataBind();
					BookBannersPanel.Visible = true;
				}

				PaymentPanel.Visible = false;
				ConfirmedPanel.Visible = false;
			}
		}
Exemple #3
0
		private void Page_Load(object sender, System.EventArgs e)
		{
			ContainerPage.SetPageTitle("My files");

			if (Mode.Equals(Modes.None) || Mode.Equals(Modes.List))
				ChangePanel(PanelList);
			else if (Mode.Equals(Modes.Upload))
				ChangePanel(PanelUpload);
			else if (Mode.Equals(Modes.View))
				ChangePanel(PanelView);
			else if (Mode.Equals(Modes.Delete))
			{
				#region Delete file
				if (Usr.Current.K != CurrentMisc.UsrK && (CurrentMisc.PromoterK == 0 || !Usr.Current.IsPromoterK(CurrentMisc.PromoterK)) && !Usr.Current.IsAdmin)
					throw new Exception("You can't delete this file!");
				else
				{
					BannerSet bs = new BannerSet(
						new Query(
							new And(
								Banner.IsBookedQ,
								new Q(Banner.Columns.LastDay, QueryOperator.GreaterThanOrEqualTo, DateTime.Today),
								new Or(
									new Q(Banner.Columns.MiscK, CurrentMisc.K),
									new Q(Banner.Columns.NewMiscK, CurrentMisc.K)
								)
							)
						)
					);
					if (bs.Count == 0)
					{
						Promoter p = CurrentMisc.Promoter;
						Delete.DeleteAll(CurrentMisc);
						Response.Redirect(p.UrlApp("files"));
					}
					else
					{
						ChangePanel(PanelDelete);
					}
				}
				#endregion
			}
			else
				throw new Exception("Funny mode?");

		}
		public void DateCal_DayRender(object o, DayRenderEventArgs e)
		{
			Query q = new Query();
			q.QueryCondition = new And(
				Banner.IsBookedQ,
				new Q(Banner.Columns.StatusEnabled, true),
				new Q(Banner.Columns.FirstDay, QueryOperator.LessThanOrEqualTo, Time.Now.Date),
				new Q(Banner.Columns.LastDay, QueryOperator.GreaterThanOrEqualTo, Time.Now.Date));
			q.Columns = new ColumnSet();
			q.ExtraSelectElements.Add("sum", "SUM([Banner].[TotalRequiredImpressions] / DateDiff(day, [Banner].[FirstDay], DATEADD(d, 1, [Banner].[LastDay])))");
			BannerSet bs = new BannerSet(q);

			e.Cell.Style["padding"] = "2px";


			if (e.Day.IsOtherMonth)
			{
				e.Day.IsSelectable = false;
				e.Cell.Text = "";
				if (e.Day.Date.Day < 15)
				{
					e.Cell.Visible = false;
				}
			}
			else
			{
				int imps = 0;
				try
				{
					imps = (int)bs[0].ExtraSelectElements["sum"];
				}
				catch { }

				if (e.Day.Date == DateTime.Today)
					e.Cell.Style["background-color"] = "#CBA21E";

				e.Day.IsSelectable = false;
				e.Cell.Text = "<center><small>" + e.Day.DayNumberText + "</small>";
				if (imps > 0)
					e.Cell.Text += "<br><font size=2><b>" + imps.ToString("#,##0") + "</b></font>";

				e.Cell.Text += "</center>";
			}
		}
		private long GetTotalRequiredImpressions(Banner.Positions position, DateTime date)
		{
			return Caching.Instances.Main.Get("RequiredImpressionsForBannerImpressionStats" + date.ToString("yyyymmdd") + position.ToString(), () =>
			{
				long desiredHits = 0;
				using (new Common.General.Context<Clock>(() => Common.Time.Clock, (c) => Common.Time.Clock = c, new FixedClock(date)))
				{
					Query q = new Query();
					q.QueryCondition = new And(Banner.IsLiveQ, new Q(Banner.Columns.Position, position));
					BannerSet bs = new BannerSet(q);

					foreach (Banner b in bs)
					{
						for (Timeslot timeslot = new Timeslot(date); timeslot.StartTime < date.AddDays(1); timeslot = timeslot.GetNextTimeslot())
						{
							BannerTimeslotInfoWithDesiredHits bannerTimeslotInfo = new BannerTimeslotInfoWithDesiredHits(b, timeslot);
							desiredHits += bannerTimeslotInfo.DesiredHits;
						}
					}
				}
				return desiredHits;
				}
			);
		}
Exemple #6
0
		public DeleteReturnStatus DeleteAllUsr(Usr u)
		{
			if (!u.IsSuper && u.K!=this.OwnerUsrK)
				return DeleteReturnStatus.FailNoPermission;

			if (this.PromoterK>0 && this.PromoterStatus.Equals(Venue.PromoterStatusEnum.Confirmed))
				return DeleteReturnStatus.FailPromoter;

			if (this.TotalComments>10)
			{
				Mailer smComments = new Mailer();
				smComments.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") attempted to delete venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				smComments.Body+="<p>This operation failed because "+this.Name+" has "+this.TotalComments+" comments.</p>";
				smComments.Subject="Delete venue operation failed because too many comments in venue";
				smComments.TemplateType=Mailer.TemplateTypes.AdminNote;
				smComments.To = "*****@*****.**";
				smComments.Send();
				return DeleteReturnStatus.FailComments;
			}

			if (this.Events.Count>3)
			{
				Mailer smEvents = new Mailer();
				smEvents.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") attempted to delete venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				smEvents.Body+="<p>This operation failed because "+this.Name+" has "+this.Events.Count+" events.</p>";
				smEvents.Subject="Delete venue operation failed because too many events";
				smEvents.TemplateType=Mailer.TemplateTypes.AdminNote;
				smEvents.To = "*****@*****.**";
				smEvents.Send();
				return DeleteReturnStatus.FailEvents;
			}

			int totalPhotos = 0;
			foreach (Event ev in this.Events)
			{
				totalPhotos += ev.TotalPhotos;
			}
			if (totalPhotos>5)
			{
				Mailer smPhotos = new Mailer();
				smPhotos.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") attempted to delete venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				smPhotos.Body+="<p>This operation failed because events at "+this.Name+" have "+totalPhotos+" photos.</p>";
				smPhotos.Subject="Delete venue operation failed because too many photos in events";
				smPhotos.TemplateType=Mailer.TemplateTypes.AdminNote;
				smPhotos.To = "*****@*****.**";
				smPhotos.Send();
				return DeleteReturnStatus.FailPhotos;
			}


			//banners?
			Query qBanners = new Query();
			qBanners.TableElement=new Join(Banner.Columns.EventK, Event.Columns.K);
			qBanners.QueryCondition=new Q(Event.Columns.VenueK,this.K);
			qBanners.ReturnCountOnly=true;
			BannerSet bs = new BannerSet(qBanners);
			if (bs.Count>0)
			{
				Mailer smBanner = new Mailer();
				smBanner.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") attempted to delete venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				smBanner.Body+="<p>This operation failed because "+this.Name+" has "+bs.Count+" banner"+(bs.Count==1?"":"s")+".</p>";
				smBanner.Subject="Delete venue operation failed because venue has a banner";
				smBanner.TemplateType=Mailer.TemplateTypes.AdminNote;
				smBanner.To = "*****@*****.**";
				smBanner.Send();
				return DeleteReturnStatus.FailPromoter;
			}
			//guestlists?
			Query qGuestlists = new Query();
			qGuestlists.QueryCondition=new And(new Q(Event.Columns.HasGuestlist,true),new Q(Event.Columns.VenueK,this.K));
			qGuestlists.ReturnCountOnly=true;
			EventSet es = new EventSet(qGuestlists);
			if (es.Count>0)
			{
				Mailer smGuestlist = new Mailer();
				smGuestlist.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") attempted to delete venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				smGuestlist.Body+="<p>This operation failed because "+this.Name+" has "+es.Count+" guestlist"+(es.Count==1?"":"s")+".</p>";
				smGuestlist.Subject="Delete venue operation failed because venue has a guestlist";
				smGuestlist.TemplateType=Mailer.TemplateTypes.AdminNote;
				smGuestlist.To = "*****@*****.**";
				smGuestlist.Send();
				return DeleteReturnStatus.FailPromoter;
			}
			//competitions?
			Query qComp = new Query();
			qComp.TableElement=new Join(Comp.Columns.EventK, Event.Columns.K);
			qComp.QueryCondition=new Q(Event.Columns.VenueK,this.K);
			qComp.ReturnCountOnly=true;
			CompSet cs = new CompSet(qComp);
			if (cs.Count>0)
			{
				Mailer smComp = new Mailer();
				smComp.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") attempted to delete venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				smComp.Body+="<p>This operation failed because "+this.Name+" has "+cs.Count+" competition"+(cs.Count==1?"":"s")+".</p>";
				smComp.Subject="Delete venue operation failed because venue has a competition";
				smComp.TemplateType=Mailer.TemplateTypes.AdminNote;
				smComp.To = "*****@*****.**";
				smComp.Send();
				return DeleteReturnStatus.FailPromoter;
			}
			//dontations?
			Query qDonated = new Query();
			qDonated.QueryCondition=new And(new Q(Event.Columns.VenueK,this.K),new Q(Event.Columns.Donated,true));
			qDonated.ReturnCountOnly=true;
			EventSet esDon = new EventSet(qDonated);
			if (esDon.Count>0)
			{
				Mailer smDonate = new Mailer();
				smDonate.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") attempted to delete venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				smDonate.Body+="<p>This operation failed because "+this.Name+" has "+esDon.Count+" events with donations.</p>";
				smDonate.Subject="Delete venue operation failed because venue has an event donation";
				smDonate.TemplateType=Mailer.TemplateTypes.AdminNote;
				smDonate.To = "*****@*****.**";
				smDonate.Send();
				return DeleteReturnStatus.FailPromoter;
			}
            //ticket runs?
            Query qTicketRuns = new Query();
            qTicketRuns.QueryCondition = new Q(Event.Columns.VenueK, this.K);
            qTicketRuns.TableElement = new Join(Event.Columns.VenueK, Venue.Columns.K);
            qTicketRuns.ReturnCountOnly = true;
            EventSet esTix = new EventSet(qTicketRuns);
            if (esTix.Count > 0)
            {
                Mailer smDonate = new Mailer();
                smDonate.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete venue " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
                smDonate.Body += "<p>This operation failed because " + this.Name + " has " + esTix.Count + " events with ticket runs.</p>";
                smDonate.Subject = "Delete venue operation failed because venue has at least one event with a ticket run";
                smDonate.TemplateType = Mailer.TemplateTypes.AdminNote;
                smDonate.To = "*****@*****.**";
                smDonate.Send();
                return DeleteReturnStatus.FailPromoter;
            }

			try
			{
				Bobs.Delete.DeleteAll(this);

				//Mailer smDone = new Mailer();
				//smDone.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") deleted venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				//smDone.Subject="Venue "+this.K.ToString()+" deleted";
				//smDone.TemplateType=Mailer.TemplateTypes.AdminNote;
				//smDone.To = "*****@*****.**";
				//smDone.Send();

				return DeleteReturnStatus.Success;
			}
			catch(Exception ex)
			{
			
				Mailer smException = new Mailer();
				smException.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") attempted to delete venue "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				smException.Body+="<p>This operation failed because of an unhandled exception:</p><p>"+ex.ToString()+"</p>";
				smException.Subject="Delete venue operation failed because of exception";
				smException.TemplateType=Mailer.TemplateTypes.AdminNote;
				smException.To="*****@*****.**";
				smException.Send();
				return DeleteReturnStatus.FailException;
			}
		}
		public void Save(bool pass)
		{
			if (!(ViewFlashLinkTagYes.Checked || ViewFlashLinkTagNo.Checked))
				throw new DsiUserFriendlyException("Form not completed!");

			CurrentMisc.BannerLinkTag = ViewFlashLinkTagYes.Checked;

			CurrentMisc.BannerBroken = !pass;

			if (!pass)
				CurrentMisc.BannerBrokenReason = FailTextBox.Text;
		
			CurrentMisc.NeedsAuth = false;
			CurrentMisc.Update();

			Query q = new Query();
			q.NoLock = true;
			q.QueryCondition = new Q(Banner.Columns.NewMiscK, CurrentMisc.K);
			BannerSet bs = new BannerSet(q);
			foreach (Banner b in bs)
			{
				Bobs.Misc.CanUseAsBannerReturn ret = CurrentMisc.CanUseAsBanner(b.Position);
				if (ret.CanUseNow)
				{
					b.MiscK = CurrentMisc.K;
					b.DisplayType = CurrentMisc.DisplayType;
					b.NewMiscK = 0;
					if (!b.StatusArtwork && b.FirstDay < DateTime.Today) 
						b.FirstDay = DateTime.Today;
					b.StatusArtwork = true;
					b.Update();
					foreach (Usr u in b.Promoter.AdminUsrs)
					{
						Mailer sm = new Mailer();
						sm.Subject = "Banner file passed admin check for banner-" + b.K;
						sm.Body += "<p>Banner file passed admin check for banner-" + b.K + "</p>";
						if (ret.LinkTagWarning)
						{
							sm.Body += "<p><center><img src=\"[WEB-ROOT]gfx/icon-warning.png\" width=\"26\" height=\"21\"></center></p>";
							sm.Body += "<p>Your banner doesn't support link tags - this means some features may not work. See the <a href=\"[WEB-ROOT]misc/banners.pdf\">banner instructions</a> for how to fix this. If you need to send the instructions to your designer, use this link: <b>www.dontstayin.com/misc/banners.pdf</b></p>";
						}
						sm.Body += "<p><a href=\"[LOGIN(" + b.Url() + ")]\">Banner options page</a></p>";
						sm.Body += "<p><a href=\"[LOGIN(" + CurrentMisc.ViewUrl() + ")]\">View file details</a></p>";
						sm.To = u.Email;
						sm.UsrRecipient = u;
						sm.TemplateType = Mailer.TemplateTypes.AnotherSiteUser;
						sm.RedirectUrl = b.Url();
						sm.Send();
					}
				}
				else
				{
					b.NewMiscK = 0;
					b.Update();
					foreach (Usr u in b.Promoter.AdminUsrs)
					{
						Mailer sm = new Mailer();
						sm.Subject = "Banner file FAILED admin check for banner-" + b.K;
						sm.Body += "<p>Banner file FAILED admin check for banner-" + b.K + "</p>";
						sm.Body += "<p>Because:<br>";
						foreach (string s in ret.Errors)
							sm.Body += s + "<br>";
						sm.Body += "</p>";
						if (ret.BrokenError.Length>0)
						{
							sm.Body += "<p>One of our admins added this information, which might be useful:</p><p><i>" + ret.BrokenError + "</i></p>";
						}
						sm.Body += "<h2>How to fix the problems</h2>";
						sm.Body += "<p>See the <a href=\"[WEB-ROOT]misc/banners.pdf\">banner instructions</a> for how to get your banners working. If you need to send the instructions to your designer, use this link: <b>www.dontstayin.com/misc/banners.pdf</b></p>";
						sm.Body += "<p><a href=\"[LOGIN(" + b.Url() + ")]\">Banner options page</a></p>";
						sm.Body += "<p><a href=\"[LOGIN(" + CurrentMisc.ViewUrl() + ")]\">View file details</a></p>";
						sm.To = u.Email;
						sm.UsrRecipient = u;
						sm.TemplateType = Mailer.TemplateTypes.AnotherSiteUser;
						sm.RedirectUrl = CurrentMisc.ViewUrl();
						sm.Send();
					}
				}
			}
			if (bs.Count == 0)
			{
				if (CurrentMisc.Promoter != null)
				{
					foreach (Usr u in CurrentMisc.Promoter.AdminUsrs)
					{
						Mailer sm = new Mailer();
						sm.Subject = "Banner file checked by admin";
						sm.Body += "<p>See the file details page for banner usage restrictions.</p>";
						sm.Body += "<p><a href=\"[LOGIN(" + CurrentMisc.ViewUrl() + ")]\">View file details</a></p>";
						sm.To = u.Email;
						sm.UsrRecipient = u;
						sm.TemplateType = Mailer.TemplateTypes.AnotherSiteUser;
						sm.RedirectUrl = CurrentMisc.ViewUrl();
						sm.Send();
					}
				}
				else
				{
					Mailer sm = new Mailer();
					sm.Subject = "Banner file checked by admin";
					sm.Body += "<p>See the file details page for banner usage restrictions.</p>";
					sm.Body += "<p><a href=\"[LOGIN(" + CurrentMisc.ViewUrl() + ")]\">View file details</a></p>";
					sm.To = CurrentMisc.Usr.Email;
					sm.UsrRecipient = CurrentMisc.Usr;
					sm.TemplateType = Mailer.TemplateTypes.AnotherSiteUser;
					sm.RedirectUrl = CurrentMisc.ViewUrl();
					sm.Send();
				}
			}
			Response.Redirect(UrlInfo.PageUrl("BannerCheck", "Mode", "List"));


		}
		private void SetupUnprocessedBanners()
		{
			this.AddBannerInvoiceItemRow.Visible = false;

			this.AddBannerInvoiceItemDropDownList.Items.Clear();

			if (CurrentPromoter != null && CurrentPromoter.K > 0)
			{
				Query unprocessedBannerQuery = new Query(new And(new Q(Banner.Columns.PromoterK, CurrentPromoter.K),
																 new Q(Banner.Columns.LastDay, QueryOperator.GreaterThanOrEqualTo, DateTime.Today),
																 new Q(Banner.Columns.StatusBooked, false)));

				foreach (InvoiceItemDataHolder iidh in this.InvoiceItemDataHolderList)
				{
					if (iidh.BuyableObjectK > 0 && iidh.BuyableObjectType == Model.Entities.ObjectType.Banner)
						unprocessedBannerQuery.QueryCondition = new And(unprocessedBannerQuery.QueryCondition,
																		new Q(Banner.Columns.K, QueryOperator.NotEqualTo, iidh.BuyableObjectK));
				}

				unprocessedBannerQuery.Columns = new ColumnSet(Banner.Columns.K, Banner.Columns.Name, Banner.Columns.Position);

				BannerSet unprocessedBanners = new BannerSet(unprocessedBannerQuery);

				if (unprocessedBanners.Count > 0)
				{
					this.AddBannerInvoiceItemRow.Visible = true;

					foreach (Banner banner in unprocessedBanners)
					{
						this.AddBannerInvoiceItemDropDownList.Items.Add(
							new ListItem("K=" + banner.K.ToString() + " | " + Utilities.CamelCaseToString(banner.Position.ToString()) + " | " + banner.Name, banner.K.ToString()));
					}
				}
			}
		}
		void BannerListBind()
		{
			if (EnsureSecure)
			{
				Query q = new Query();
				q.QueryCondition = new And(new Q(Banner.Columns.PromoterK, CurrentPromoter.K), new Q(Banner.Columns.EventK, CurrentEvent.K));
				q.OrderBy = new OrderBy(Banner.Columns.LastDay, OrderBy.OrderDirection.Descending);
				BannerSet bs = new BannerSet(q);
				BannersPanel.Visible = bs.Count > 0;
				NoBannersPanel.Visible = bs.Count == 0;
				if (bs.Count > 0)
				{
					BannerDataGrid.AllowPaging = bs.Count > BannerDataGrid.PageSize;
					BannerDataGrid.DataSource = bs;
					BannerDataGrid.DataBind();
				}
			}
		}
Exemple #10
0
		public string PromoterHtmlEmailBanner(Promoter p)
		{
			Query q = new Query();
			q.QueryCondition = new And(new Q(Banner.Columns.PromoterK, p.K), new Q(Banner.Columns.EventK, this.K), Banner.IsBookedQ, new Q(Banner.Columns.Position, Banner.Positions.EmailBanner));
			q.ReturnCountOnly = true;
			BannerSet bs = new BannerSet(q);
			return TickCrossHtml(bs.Count > 0);
		}
Exemple #11
0
		public DeleteReturnStatus DeleteAllUsr(Usr u)
		{
			if (!u.IsSuper && u.K != this.OwnerUsrK)
				return DeleteReturnStatus.FailNoPermission;

			if (this.TotalComments > 10)
			{
				Mailer smComments = new Mailer();
				smComments.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smComments.Body += "<p>This operation failed because " + this.Name + " has " + this.TotalComments + " comments.</p>";
				smComments.Subject = "Delete event operation failed because too many comments in event";
				smComments.TemplateType = Mailer.TemplateTypes.AdminNote;
				smComments.To = "*****@*****.**";
				smComments.Send();
				return DeleteReturnStatus.FailComments;
			}

			if (this.TotalPhotos > 5)
			{
				Mailer smPhotos = new Mailer();
				smPhotos.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smPhotos.Body += "<p>This operation failed because " + this.Name + " has " + this.TotalPhotos + " photos.</p>";
				smPhotos.Subject = "Delete event operation failed because too many photos in event";
				smPhotos.TemplateType = Mailer.TemplateTypes.AdminNote;
				smPhotos.To = "*****@*****.**";
				smPhotos.Send();
				return DeleteReturnStatus.FailPhotos;
			}

			//banners?
			Query qBanners = new Query();
			qBanners.QueryCondition = new Q(Banner.Columns.EventK, this.K);
			qBanners.ReturnCountOnly = true;
			BannerSet bs = new BannerSet(qBanners);
			if (bs.Count > 0)
			{
				Mailer smBanner = new Mailer();
				smBanner.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smBanner.Body += "<p>This operation failed because " + this.Name + " has " + bs.Count + " banner" + (bs.Count == 1 ? "" : "s") + ".</p>";
				smBanner.Subject = "Delete event operation failed because event has a banner";
				smBanner.TemplateType = Mailer.TemplateTypes.AdminNote;
				smBanner.To = "*****@*****.**";
				smBanner.Send();
				return DeleteReturnStatus.FailPromoter;
			}
			//guestlists?
			if (this.HasGuestlist)
			{
				Mailer smGuestlists = new Mailer();
				smGuestlists.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smGuestlists.Body += "<p>This operation failed because " + this.Name + " has a guestlist.</p>";
				smGuestlists.Subject = "Delete event operation failed because event has a guestlist";
				smGuestlists.TemplateType = Mailer.TemplateTypes.AdminNote;
				smGuestlists.To = "*****@*****.**";
				smGuestlists.Send();
				return DeleteReturnStatus.FailPromoter;
			}
			//competitions?
			Query qComp = new Query();
			qComp.QueryCondition = new Q(Comp.Columns.EventK, this.K);
			qComp.ReturnCountOnly = true;
			CompSet cs = new CompSet(qComp);
			if (cs.Count > 0)
			{
				Mailer smComp = new Mailer();
				smComp.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smComp.Body += "<p>This operation failed because " + this.Name + " has " + cs.Count + " competition" + (cs.Count == 1 ? "" : "s") + ".</p>";
				smComp.Subject = "Delete event operation failed because event has a competition";
				smComp.TemplateType = Mailer.TemplateTypes.AdminNote;
				smComp.To = "*****@*****.**";
				smComp.Send();
				return DeleteReturnStatus.FailPromoter;
			}
			//ticket runs?
			if (this.TicketRuns.Count > 0)
			{
				string ticketRuns = (this.TicketRuns.Count > 1 ? "ticket runs" : "a ticket run");
				Mailer smTicketRuns = new Mailer();
				smTicketRuns.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smTicketRuns.Body += "<p>This operation failed because " + this.Name + " has " + ticketRuns + ".</p>";
				smTicketRuns.Subject = "Delete event operation failed because event has " + ticketRuns;
				smTicketRuns.TemplateType = Mailer.TemplateTypes.AdminNote;
				smTicketRuns.To = "*****@*****.**";
				smTicketRuns.Send();
				return DeleteReturnStatus.FailPromoter;
			}
			if (this.Donated)
			{
				Mailer smDonated = new Mailer();
				smDonated.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smDonated.Body += "<p>This operation failed because the event has donated.</p>";
				smDonated.Subject = "Delete event operation failed because event has a donation";
				smDonated.TemplateType = Mailer.TemplateTypes.AdminNote;
				smDonated.To = "*****@*****.**";
				smDonated.Send();
				return DeleteReturnStatus.FailPromoter;
			}

			if (this.TotalPhotos > 5)
			{
				Mailer smPhotos = new Mailer();
				smPhotos.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smPhotos.Body += "<p>This operation failed because " + this.Name + " has " + this.TotalPhotos + " photos.</p>";
				smPhotos.Subject = "Delete event operation failed because too many photos in event";
				smPhotos.TemplateType = Mailer.TemplateTypes.AdminNote;
				smPhotos.To = "*****@*****.**";
				smPhotos.Send();
				return DeleteReturnStatus.FailPhotos;
			}

			try
			{
				Bobs.Delete.DeleteAll(this);
				//Mailer smDone = new Mailer();
				//smDone.Body+="<p><a href=\"http://"+Vars.DomainName+u.Url()+"\">"+u.NickNameSafe+"</a> ("+u.Email+") deleted event "+this.K+" (<a href=\"http://"+Vars.DomainName+this.Url()+"\">"+this.FriendlyName+"</a>).</p>";
				//smDone.Subject="Event "+this.K.ToString()+" deleted";
				//smDone.TemplateType=Mailer.TemplateTypes.AdminNote;
				//smDone.To="*****@*****.**";
				//smDone.Send();

				return DeleteReturnStatus.Success;
			}
			catch (Exception ex)
			{
				Mailer smException = new Mailer();
				smException.Body += "<p><a href=\"http://" + Vars.DomainName + u.Url() + "\">" + u.NickNameSafe + "</a> (" + u.Email + ") attempted to delete event " + this.K + " (<a href=\"http://" + Vars.DomainName + this.Url() + "\">" + this.FriendlyName + "</a>).</p>";
				smException.Body += "<p>This operation failed because of an unhandled exception:</p><p>" + ex.ToString() + "</p>";
				smException.Subject = "Delete event operation failed because of exception";
				smException.TemplateType = Mailer.TemplateTypes.AdminNote;
				smException.To = "*****@*****.**";
				smException.Send();
				return DeleteReturnStatus.FailException;
			}
		}
Exemple #12
0
		private static long getPredictedRequiredImpressions(DateTime date, Banner.Positions position)
		{
			BannerSet bs;
			Query q = new Query();
			q.Columns = new ColumnSet(Banner.Columns.K, Banner.Columns.FirstDay, Banner.Columns.LastDay, Banner.Columns.TotalRequiredImpressions);
			q.QueryCondition = new And(Banner.IsLiveOnDateQ(date), new Q(Banner.Columns.Position, position), new Q(Banner.Columns.TotalRequiredImpressions, QueryOperator.GreaterThan, 0));
			bs = new BannerSet(q);

			// if we're inspecting the past, predict as if today is the date in the past.
			// otherwise future predictions need to use current data.
			DateTime fixedDate;
			if (date < Time.Today)
			{
				fixedDate = date;
			}
			else
			{
				fixedDate = Time.Today;
			}

			Bobs.BannerServer.Traffic.DataDrivenTrafficShape ts = new Bobs.BannerServer.Traffic.DataDrivenTrafficShape();
			Log.Items logItem = Banner.GetLogItemTypeFromPositionType(position);

			long requiredImpressions = 0;

			foreach (Banner b in bs)
			{
				double thisDayCount = ts.GetPredictedCountOfLogItemBetweenDates(logItem, date, date.AddDays(1), fixedDate);
				double totalWeekCount = thisDayCount;

				for (DateTime d = date.AddDays(1); d <= date.AddDays(6); d = d.AddDays(1))
				{
					totalWeekCount += ts.GetPredictedCountOfLogItemBetweenDates(logItem, d, d.AddDays(1), fixedDate);
				}

				requiredImpressions += (int)Math.Round(b.TotalRequiredImpressions * (thisDayCount / totalWeekCount) * (7.0 / ((b.LastDay - b.FirstDay).TotalDays + 1)));
			}

			return requiredImpressions;
		}
Exemple #13
0
		public static void RefundFinishedBanners()
		{
			Query q = new Query();
			q.Columns = new ColumnSet(
							Banner.Columns.K, 
							Banner.Columns.Name, 
							Banner.Columns.PromoterK, 
							Banner.Columns.Position, 
							Banner.Columns.Refunded, 
							Banner.Columns.RefundCampaignCreditK, 
							Banner.Columns.RefundedCredits, 
							Banner.Columns.TotalRequiredImpressions,
							Banner.Columns.PriceCreditsStored);

			q.TableElement = new JoinLeft(Banner.Columns.K, BannerStat.Columns.BannerK);
			string totalHitsExtraSelectElementName = "TotalHits";
			q.ExtraSelectElements.Add(totalHitsExtraSelectElementName, "ISNULL(SUM([Hits]),0)");

			q.QueryCondition = new And(
				new Q(Banner.Columns.LastDay, QueryOperator.GreaterThanOrEqualTo, new DateTime(2007, 9, 10)), // date new BannerServer went live
				new Q(Banner.Columns.LastDay, QueryOperator.LessThan, Time.Today),
				new Bobs.Or(new Q(Banner.Columns.Refunded, QueryOperator.IsNull, null), new Q(Banner.Columns.Refunded, false)),
				new Q(Banner.Columns.StatusBooked, true));

			q.GroupBy = new GroupBy(
							new GroupBy(Banner.Columns.K),
							new GroupBy(Banner.Columns.Name),
							new GroupBy(Banner.Columns.PromoterK),
							new GroupBy(Banner.Columns.Refunded),
							new GroupBy(Banner.Columns.RefundCampaignCreditK),
							new GroupBy(Banner.Columns.RefundedCredits),
							new GroupBy(Banner.Columns.TotalRequiredImpressions),
							new GroupBy(Banner.Columns.LastDay),
							new GroupBy(Banner.Columns.Position),
							new GroupBy(Banner.Columns.Refunded),
							new GroupBy(Banner.Columns.PriceCreditsStored));

			q.Having = new Q("ISNULL(SUM([Hits]),0) < {0}", Banner.Columns.TotalRequiredImpressions, null);
			q.OrderBy = new OrderBy(Banner.Columns.PromoterK);

			BannerSet bs = new BannerSet(q);

			List<string> exceptions = new List<string>();
			int promoterK = 0;
			int displayOrder = 0;
			foreach (Banner b in bs)
			{
				try
				{
					// Fix to ensure different displayOrder for CampaignCredits with the same promoter, which is needed for proper calculation of CampaignCredit.BalanceToDate
					if (promoterK == b.PromoterK)
						displayOrder++;
					else
						displayOrder = 0;
					b.Refund(b.TotalRequiredImpressions - (int)b.ExtraSelectElements[totalHitsExtraSelectElementName], 0, displayOrder);
					promoterK = b.PromoterK;
				}
				catch (Exception ex)
				{
					exceptions.Add("BannerK: " + b.K + " Exception: " + ex.ToString());
				}
			}

			if (exceptions.Count > 0)
			{
				throw new Exception(string.Join("<br><br>", exceptions.ToArray()));
			}
		}
		protected void Page_Load(object sender, EventArgs e)
		{
			Query q = Bobs.BannerServer.Server.GetQueryForBannersActiveBetweenTwoTimes(DateTime.Today, DateTime.Now);
			q.OrderBy = new OrderBy(new OrderBy(Banner.Columns.Position), new OrderBy(Banner.Columns.K));
			BannerSet bannerSet = new BannerSet(q);
			List<Banner> banners = bannerSet.ToList();

			Timeslot timeslotMinus0 = Timeslots.GetCurrentTimeslot();
			Timeslot timeslotMinus1 = timeslotMinus0.GetPreviousTimeslot();

			if (!IsPostBack){
				this.TimeslotStart.Items.Add(timeslotMinus0.StartTime.ToString());
				this.TimeslotEnd.Items.Add(timeslotMinus0.StartTime.ToString());
				DateTime date = timeslotMinus0.StartTime.Date.AddDays(-7);
				while (date < timeslotMinus0.StartTime)
				{
					this.TimeslotStart.Items.Insert(1, date.ToString());
					this.TimeslotEnd.Items.Insert(1, date.ToString());
					date = date.AddHours(8);
				}
				this.TimeslotStart.SelectedIndex = (int) global::Caching.Instances.MainCounterStore.GetCounter("BannerHitViewer.TimeslotStart.SelectedValue for Usr " + Usr.Current.K, () => 0u);
				this.TimeslotEnd.SelectedIndex = (int)global::Caching.Instances.MainCounterStore.GetCounter("BannerHitViewer.TimeslotEnd.SelectedValue for Usr " + Usr.Current.K, () => 1u);
			}

			global::Caching.Instances.MainCounterStore.SetCounter("BannerHitViewer.TimeslotStart.SelectedValue for Usr " + Usr.Current.K, (uint) this.TimeslotStart.SelectedIndex);
			global::Caching.Instances.MainCounterStore.SetCounter("BannerHitViewer.TimeslotEnd.SelectedValue for Usr " + Usr.Current.K, (uint) this.TimeslotEnd.SelectedIndex);


			List<BannerInfo> bannerData = new List<BannerInfo>();
			List<BannerTotalStat> bannerTotalStat = BannerStat.GetBannerStatTotals(banners.ConvertAll(b=>b.K).ToArray());
			

			for (int i=0;i<banners.Count;i++)
			{
				Banner banner = banners[i];
				BannerTimeslotInfoWithDesiredHits bannerTimeslotInfo = new BannerTimeslotInfoWithDesiredHits(banner, timeslotMinus0);
				BannerTimeslotInfoWithDesiredHits previousBannerTimeslotInfo = new BannerTimeslotInfoWithDesiredHits(banner, timeslotMinus1);
				long actualHitsPreviousTimeslot = previousBannerTimeslotInfo.ActualHits.Value;
				long hitsRequiredPreviousTimeslot = previousBannerTimeslotInfo.RequiredHits;
				long hitsDesiredPreviousTimeslot = previousBannerTimeslotInfo.DesiredHits;
				long actualHitsCurrentTimeslot = bannerTimeslotInfo.ActualHits.Value;
				long hitsRequiredCurrentTimeslot = bannerTimeslotInfo.RequiredHits;
				long hitsDesiredCurrentTimeslot = bannerTimeslotInfo.DesiredHits;

				float elapsedLifespan = (float) (Time.Now - banner.FirstDay).TotalDays;
				float lifespan = (float) (banner.LastDay - banner.FirstDay).TotalDays + 1;

				BannerInfo bannerInfo = new BannerInfo()
					{
						K = banner.K,
						Name = banner.Name,
						Position = banner.Position,
						Url = banner.Url(),
						IsMusicTargetted = banner.IsMusicTargetted,
						IsPlaceTargetted = banner.IsPlaceTargetted,
						HitsRequired = banner.TotalRequiredImpressions,
						HitsSoFar = banner.TotalHits,
						UniqueHitsSoFar = bannerTotalStat[i].UniqueVisitors,
						HitsSoFarDb = bannerTotalStat[i].Hits,
						ClicksSoFar = (int)banner.TotalClicks,
						ClicksSoFarDb = bannerTotalStat[i].Clicks,
						ElapsedLifespan = elapsedLifespan,
						Lifespan = lifespan,
						IsTotalHitRateBad = elapsedLifespan / lifespan > 0.5 && ((float)banner.TotalHits / (float)banner.TotalRequiredImpressions) < (0.9 * elapsedLifespan / lifespan),
						ActualHitsCurrentTimeslot = actualHitsCurrentTimeslot,
						HitsRequiredCurrentTimeslot = hitsRequiredCurrentTimeslot,
						HitsDesiredCurrentTimeslot = hitsDesiredCurrentTimeslot,
						ActualHitsPreviousTimeslot = actualHitsPreviousTimeslot,
						HitsRequiredPreviousTimeslot = hitsRequiredPreviousTimeslot,
						HitsDesiredPreviousTimeslot = hitsDesiredPreviousTimeslot,
						IsPreviousTimeslotBad = actualHitsPreviousTimeslot < 0.9 * hitsDesiredPreviousTimeslot,
						IsCurrentTimeslotBad = actualHitsCurrentTimeslot < 0.9 * (Timeslot.ElapsedTimeSinceStartOfCurrentTimeInterval(Time.Now, Timeslot.Duration).TotalMinutes / Timeslot.Duration.TotalMinutes) * hitsDesiredCurrentTimeslot,
						TimesConsidered = bannerTimeslotInfo.Considerations.Value,
						TimesConsideredPrev = previousBannerTimeslotInfo.Considerations.Value,
						Rate = bannerTimeslotInfo.ProportionToBeServed,
						RatePrev = previousBannerTimeslotInfo.ProportionToBeServed,
						RemainingSecondsWhenPreviousBannerCompleted = bannerTimeslotInfo.NumberOfSecondsLeftWhenAllHitsWereServed.Value,
						CreditsPerClick =  ((double)banner.PriceCredits * ((double)banner.TotalHits / (double)banner.TotalRequiredImpressions)) / (double)banner.TotalClicks
					};
				bannerData.Add(bannerInfo);
			}

			this.BannerInfoRepeater.DataSource = bannerData;
			this.BannerInfoRepeater.DataBind();

			

			List<TimeslotInfo> timeslotInfos = new List<TimeslotInfo>();
			Timeslot first;
			try
			{
				first = new Timeslot(DateTime.Parse(TimeslotStart.SelectedValue));
			}
			catch
			{
				first = timeslotMinus0;
			}
			Timeslot last;
			try
			{
				last = new Timeslot(DateTime.Parse(TimeslotStart.SelectedValue));
			}
			catch
			{
				last = timeslotMinus1;
			}
			
			if (first.StartTime < last.StartTime)
			{
				Timeslot temp = first;
				first = last;
				last = temp;
			}

			List<Timeslot> timeslots = new List<Timeslot>();
			while(first.StartTime >= last.StartTime)
			{
				timeslots.Add(first);
				first = first.GetPreviousTimeslot();
			}
			foreach (Timeslot ts in timeslots)
			{
				long actualHits = 0;
				long requiredHits = 0;

				if (ts.StartTime != timeslotMinus0.StartTime)
				{
					actualHits = global::Caching.Instances.Main.Get(ts.GetCacheKey() + "actualHitsForBannerHitViewer", () =>
						{
							long hits = 0;
							banners.ForEach(b =>
							{
								BannerTimeslotInfo info = new BannerTimeslotInfo(b.K, ts);
								hits += info.ActualHits.Value; 
							});
							return hits;
						}
					);
					requiredHits = global::Caching.Instances.Main.Get(ts.GetCacheKey() + "requiredHitsForBannerHitViewer", () =>
						{
							long hits = 0;
							banners.ForEach(b => {
								BannerTimeslotInfoWithDesiredHits info = new BannerTimeslotInfoWithDesiredHits(b, ts);
								hits += info.DesiredHits; 
							});
							return hits;
						}
					);
				}
				else
				{

					banners.ForEach(b => {
						BannerTimeslotInfo info = new BannerTimeslotInfo(b.K, ts); 
						actualHits += info.ActualHits.Value; 
					});
					banners.ForEach(b => {
						BannerTimeslotInfoWithDesiredHits info = new BannerTimeslotInfoWithDesiredHits(b, ts); 
						requiredHits += info.DesiredHits;
					});
				}
				

				
				
				TimeslotInfo ti = new TimeslotInfo()
								  {
									  TimeslotStart = ts.StartTime,
									  NotShown = ts.TotalNotShown().Value,
									  Actual = actualHits,
									  Required = requiredHits,
									  Timeouts = ts.BannerTimeouts().Value,
									  CallsToBannerServer = ts.CallsToBannerServer().Value

								  };

				
				timeslotInfos.Add(ti);
			}


			this.TimeslotInfoRepeater.DataSource = timeslotInfos;
			this.TimeslotInfoRepeater.DataBind();
			
			
		}
		void ShowBanner(Banner banner)
		{

			if (banner != null)
			{
				if (Vars.UrlScheme.Equals("https") && banner.DisplayType.Equals(Banner.DisplayTypes.CustomHtml))
				{
					EmitDefaultText();
				}
				else
				{
					AddPromoterBanner(banner, true);
				}

			}
			else if (ThreadSafeRandom.NextDouble() < (double.Parse(Common.Settings.HouseBannersAsPercentageOfNullBanners.Replace("%", "")) / 100.0))
			{
				try
				{
					Query q = new Query();
					q.CacheDuration = TimeSpan.FromHours(1);
					q.QueryCondition = new And(
						new Q(Banner.Columns.PromoterK, 1622),
						new Q(Banner.Columns.BannerFolderK, 5879),
						new Q(Banner.Columns.Position, this.Position),
						new Q(Banner.Columns.StatusArtwork, true)
						);
					BannerSet bs = new BannerSet(q);
					if (bs.Count > 0)
					{
						AddPromoterBanner(bs[ThreadSafeRandom.Next(bs.Count)], true);
					}
					else
					{
						EmitDefaultText();
					}
				}
				catch 
				{
					EmitDefaultText();
				}
				Timeslots.GetCurrentTimeslot().TotalNotShown().Increment();

			}
			else if( Common.Settings.UseGoogleAds && !(Vars.UrlScheme.Equals("https") ))
			{
				EmitGoogleTag();
			}
			else
			{
				EmitDefaultText();
				Timeslots.GetCurrentTimeslot().TotalNotShown().Increment();
			}

			
		}
		private void BookBanners(List<CampaignCredit> campaignCredits)
		{
            List<int> bookedBannerKs = new List<int>();
			foreach (CampaignCredit cc in campaignCredits)
			{
                if (cc.BuyableObjectType == Model.Entities.ObjectType.Banner)
                    bookedBannerKs.Add(cc.BuyableObjectK);
			}

            BannerSet bookedBanners = new BannerSet(new Query(new Q(Banner.Columns.K, bookedBannerKs.ToArray())));
            this.BookedBannersGridView.DataSource = bookedBanners;
            this.BookedBannersGridView.DataBind();

            H1Title.InnerHtml = "Booked Banners";
		}
Exemple #17
0
		public void DeleteAll(Transaction transaction)
		{
			if (!this.Bob.DbRecordExists)
				return;

			BannerSet bs = new BannerSet(
				new Query(
					new Or(
						new Q(Banner.Columns.MiscGuid, this.Guid),
						new Q(Banner.Columns.MiscK, this.K),
						new Q(Banner.Columns.NewMiscK, this.K),
						new Q(Banner.Columns.FailedMiscK, this.K)
					)
				)
			);
			foreach (Banner b in bs)
			{
				if (b.MiscGuid.Equals(this.Guid))
					b.MiscGuid = Guid.Empty;
				if (b.MiscK == this.K)
					b.MiscK = 0;
				if (b.NewMiscK == this.K)
					b.NewMiscK = 0;
				if (b.FailedMiscK == this.K)
					b.FailedMiscK = 0;
				b.Update(transaction);
			}

			this.Delete(transaction);

			Storage.RemoveFromStore(Storage.Stores.Pix, this.Guid, this.Extention);
		}
		public void BookBannersButton_Click(object o, EventArgs e)
		{
			if (!Page.IsValid)
			{
				return;
			}

			Payment.Reset();

            List<int> bannerKs = new List<int>();
			foreach (GridViewRow row in this.BannerGrid.Rows)
			{
                try
                {
				    if (((CheckBox)row.FindControl("CheckBox")).Checked)
				    {
					    bannerKs.Add(Convert.ToInt32((((Label)row.FindControl("BannerK")).Text)));
                    }
                }
                catch
                {}
            }

            if(bannerKs.Count > 0)
            {
                Query bannerQuery = new Query(new Q(Banner.Columns.K, bannerKs.ToArray()));
                //bannerQuery.Columns = new ColumnSet(Banner.Columns.K, Banner.Columns.TotalRequiredImpressions, Banner.Columns.Position, Banner.Columns.Name, Banner.Columns.PriceStored, Banner.Columns.PromoterK,
                //                                    Banner.Columns.FirstDay, Banner.Columns.LastDay, Banner.Columns.StatusBooked, Banner.Columns.IsPriceFixed, Banner.Columns.PriceCreditsStored);
                BannerSet banners = new BannerSet(bannerQuery);

                foreach (Banner banner in banners)
                {
					Payment.CampaignCredits.AddRange(banner.ToCampaignCredits(Usr.Current, CurrentPromoter.K, true));
                }
			}
            

			Payment.PromoterK = CurrentPromoter.K;
			Payment.Initialize();
			Payment.LoadBuyerDetailsToScreen();

			ShowPaymentOptions();
		}
		private void Page_Load(object sender, System.EventArgs e)
		{
			
			//Query qBrands = new Query();
			//qBrands.NoLock = true;
			//qBrands.TableElement = new Join(Brand.Columns.PromoterK, Promoter.Columns.K);
			//qBrands.QueryCondition = new And(
			//    Promoter.EnabledQ,
			//    new Q(Brand.Columns.PromoterStatus, Brand.PromoterStatusEnum.Unconfirmed)
			//);
			//BrandSet bsUnconfirmed = new BrandSet(qBrands);
			//if (bsUnconfirmed.Count > 0)
			//{
			//    PanelUnconfirmedBrands.Visible = true;
			//    BrandRepeater.DataSource = bsUnconfirmed;
			//    BrandRepeater.DataBind();
			//}
			//else
			//    PanelUnconfirmedBrands.Visible = false;

			//Query qVenues = new Query();
			//qVenues.TableElement = new Join(Venue.Columns.PromoterK, Promoter.Columns.K);
			//qVenues.QueryCondition = new And(
			//    Promoter.EnabledQ,
			//    new Q(Venue.Columns.PromoterStatus, Venue.PromoterStatusEnum.Unconfirmed)
			//);
			//VenueSet vsUnconfirmed = new VenueSet(qVenues);
			//if (vsUnconfirmed.Count > 0)
			//{
			//    PanelUnconfirmedVenues.Visible = true;
			//    VenueRepeater.DataSource = vsUnconfirmed;
			//    VenueRepeater.DataBind();
			//}
			//else
			//    PanelUnconfirmedVenues.Visible = false;
			

			//Query qGuestlists = new Query();
			//qGuestlists.NoLock = true;
			//qGuestlists.QueryCondition = new And(
			//    new Q(Event.Columns.DateTime, QueryOperator.GreaterThan, DateTime.Today.AddDays(-7)),
			//    new Q(Event.Columns.HasGuestlist, true)
			//    );
			//qGuestlists.OrderBy = Event.FutureEventOrder;
			//EventSet guestlists = new EventSet(qGuestlists);
			//GuestlistDataGrid.DataSource = guestlists;
			//GuestlistDataGrid.DataBind();




			Query qBannedUsr = new Query();
			qBannedUsr.QueryCondition = new Q(Usr.Columns.Banned, true);
			qBannedUsr.NoLock = true;
			qBannedUsr.TopRecords = 10;
			qBannedUsr.OrderBy = new OrderBy(Usr.Columns.BannedDateTime, OrderBy.OrderDirection.Descending);
			UsrSet usBanned = new UsrSet(qBannedUsr);
			BannedUsrDataGrid.DataSource = usBanned;
			BannedUsrDataGrid.DataBind();


			Query qNotBookedBanners = new Query();
			qNotBookedBanners.QueryCondition = new And(
				new NotQ(Banner.IsBookedQ),
				new Q(Banner.Columns.LastDay, QueryOperator.GreaterThanOrEqualTo, DateTime.Today),
				new Q(Banner.Columns.PromoterK, QueryOperator.GreaterThan, 1)
				);
			qNotBookedBanners.NoLock = true;
			qNotBookedBanners.OrderBy = new OrderBy(Banner.Columns.FirstDay, OrderBy.OrderDirection.Descending);
			BannerSet notBookedBanners = new BannerSet(qNotBookedBanners);
			NotPaidForBanners.Banners = notBookedBanners;

			Query qBookedBanners = new Query();
			qBookedBanners.QueryCondition = new And(
				Banner.IsBookedQ,
				new NotQ(Banner.IsLiveQ),
				new Q(Banner.Columns.LastDay, QueryOperator.GreaterThanOrEqualTo, DateTime.Today)
			);
			qBookedBanners.NoLock = true;
			qBookedBanners.OrderBy = new OrderBy(Banner.Columns.FirstDay, OrderBy.OrderDirection.Descending);
			BannerSet bookedBanners = new BannerSet(qBookedBanners);
			PaidForBanners.Banners = bookedBanners;

			Query qLeaderboards = new Query();
			qLeaderboards.QueryCondition = new And(
				Banner.IsLiveQ,
				new Q(Banner.Columns.Position, Banner.Positions.Leaderboard)
				);
			qLeaderboards.NoLock = true;
			qLeaderboards.OrderBy = new OrderBy(Banner.Columns.FirstDay, OrderBy.OrderDirection.Descending);
			BannerSet leaderboards = new BannerSet(qLeaderboards);
			LiveLeaderboards.Banners = leaderboards;

			Query qHotBoxes = new Query();
			qHotBoxes.QueryCondition = new And(
				Banner.IsLiveQ,
				new Q(Banner.Columns.Position, Banner.Positions.Hotbox)
				);
			qHotBoxes.NoLock = true;
			qHotBoxes.OrderBy = new OrderBy(Banner.Columns.FirstDay, OrderBy.OrderDirection.Descending);
			BannerSet hotBoxes = new BannerSet(qHotBoxes);
			LiveHotBoxes.Banners = hotBoxes;

			Query qSkyscrapers = new Query();
			qSkyscrapers.QueryCondition = new And(
				Banner.IsLiveQ,
				new Q(Banner.Columns.Position, Banner.Positions.Skyscraper)
				);
			qSkyscrapers.NoLock = true;
			qSkyscrapers.OrderBy = new OrderBy(Banner.Columns.FirstDay, OrderBy.OrderDirection.Descending);
			BannerSet skyscrapers = new BannerSet(qSkyscrapers);
			LiveSkyscrapers.Banners = skyscrapers;

			Query qPhotoBanners = new Query();
			qPhotoBanners.QueryCondition = new And(
				Banner.IsLiveQ,
				new Q(Banner.Columns.Position, Banner.Positions.PhotoBanner)
				);
			qPhotoBanners.NoLock = true;
			qPhotoBanners.OrderBy = new OrderBy(Banner.Columns.FirstDay, OrderBy.OrderDirection.Descending);
			BannerSet photoBanners = new BannerSet(qPhotoBanners);
			LivePhotoBanners.Banners = photoBanners;


			Query qEmailBanners = new Query();
			qEmailBanners.QueryCondition = new And(
				Banner.IsLiveQ,
				new Q(Banner.Columns.Position, Banner.Positions.EmailBanner)
				);
			qEmailBanners.NoLock = true;
			qEmailBanners.OrderBy = new OrderBy(Banner.Columns.FirstDay, OrderBy.OrderDirection.Descending);
			BannerSet emailBanners = new BannerSet(qEmailBanners);
			LiveEmailBanners.Banners = emailBanners;

			//	LinkP.Visible=(us.Count>0);
			//	LinkP1.Visible=(usReq.Count>0);

			//Query vq = new Query();
			//vq.NoLock = false;
			//vq.QueryCondition = new Or(new Q(Venue.Columns.IsNew, true), new Q(Venue.Columns.IsEdited, true));
			//vq.ReturnCountOnly = true;
			//VenueSet vs = new VenueSet(vq);

			//Query eq = new Query();
			//eq.NoLock = false;
			//eq.QueryCondition = new Or(new Q(Event.Columns.IsNew, true), new Q(Event.Columns.IsEdited, true));
			//eq.ReturnCountOnly = true;
			//EventSet es = new EventSet(eq);

			//if (vs.Count == 0 && es.Count == 0)
			//    NewEvents.Text = "No new events / venues.";
			//else
			//    NewEvents.Text = es.Count.ToString() + " new/edited event(s) and " + vs.Count.ToString() + " new/edited venue(s). <a href=\"/pages/venues/moderate\">Click here to view them</a>.";

			GallerySet gs = new GallerySet(new Query(new Q(Gallery.Columns.TotalPhotos, QueryOperator.NotEqualTo, Gallery.Columns.LivePhotos, true)));
			GalleriesDataGrid.DataSource = gs;
			GalleriesDataGrid.DataBind();

			this.DataBind();

		}
		protected void SaveToDatabase()
		{
			if (Page.IsValid)
			{

				Banner b;
				if (CurrentBanner == null)
				{
					Query q = new Query();
					q.QueryCondition = new Q(Banner.Columns.DuplicateGuid, (Guid)ViewState["BannerDuplicateGuid"]);
					BannerSet bs = new BannerSet(q);
					if (bs.Count == 0)
					{
						b = new Banner();
						b.UsrK = Usr.Current.K;
						b.StatusEnabled = true;
						//b.DateLastHit = DateTime.Today;
						b.PromoterK = CurrentPromoter.K;
						b.DuplicateGuid = (Guid)ViewState["BannerDuplicateGuid"];
					}
					else
					{
						Response.Redirect(bs[0].Url());
						return;
					}
				}
				else
				{
					b = CurrentBanner;
				}

				if (((IBuyableCredits)b).IsLocked)
					throw new DsiUserFriendlyException("It looks we're processing a payment for this banner... If not - wait a minute before trying again.");

				#region Link
				b.LinkTarget = GetSelectedLinkTarget();
				b.EventK = b.LinkTarget.Equals(Banner.LinkTargets.Event) ? CurrentEvent.K : 0;
				b.BrandK = b.LinkTarget.Equals(Banner.LinkTargets.Brand) || b.LinkTarget.Equals(Banner.LinkTargets.TicketsBrand) ? CurrentBrand.K : 0;
				b.VenueK = b.LinkTarget.Equals(Banner.LinkTargets.Venue) || b.LinkTarget.Equals(Banner.LinkTargets.TicketsVenue) ? CurrentVenue.K : 0;
				b.LinkUrl = b.LinkTarget.Equals(Banner.LinkTargets.InternalUrl) || b.LinkTarget.Equals(Banner.LinkTargets.ExternalUrl) ? LinkCustomTextBox.Text : "";
				#endregion
				#region Position
				if (!LockedPosition)
				{
					b.Position = GetSelectedBannerPosition();
				}
				#endregion
				#region Dates
				if (!LockedDates)
				{
					if (CustomDatesSelected)
					{
						b.AutomaticDates = false;
						b.AutomaticDatesWeeks = 0;
					}
					else
					{
						b.AutomaticDates = true;
						b.AutomaticDatesWeeks = GetSelectedAutomaticDatesWeeks();
					}
					b.FirstDay = GetSelectedFirstDay();
					b.LastDay = GetSelectedLastDay();
				}
				#endregion
				#region Exposure
				if (!LockedExposure)
				{
					int impressions;
					int credits;
					if (ExposureCustomRadio.Checked)
					{
						b.AutomaticExposure = false;
						b.AutomaticExposureLevel = Banner.ExposureLevels.None;

						impressions = int.Parse(ImpressionsTextBox.Text.Replace(",", ""));
						//credits = (int)Math.Ceiling((double)impressions / (double)GetImpressionsPerCredit());
					}
					else
					{
						b.AutomaticExposure = true;
						b.AutomaticExposureLevel = GetSelectedExposureLevel();

						credits = GetCreditsPerDay(b.AutomaticExposureLevel) * GetTotalDays();
						impressions = credits * GetImpressionsPerCredit();
					}
					b.TotalRequiredImpressions = impressions;
					//b.PriceStored = credits;
					//Should we be storing credits somewhere?
				}
				#endregion
				#region Targetting
				if (DisplayTargettingAutomaticSpan() && TargettingAutomaticRadio.Checked)
				{
					b.AutomaticTargetting = true;
					//we update the music / place targetting below (we need a banner k to do it)
				}
				else if (TargettingCustomRadio.Checked)
				{
					b.AutomaticTargetting = false;
					//we update the music / place targetting below (we need a banner k to do it)
				}
				else
				{
					b.AutomaticTargetting = false;
					b.IsMusicTargetted = false;
					b.IsPlaceTargetted = false;
				}
				#endregion
				#region Artwork
				if (!LockedArtwork)
				{
					b.DisplayType = GetSelectedDisplayType();
					b.DesignType = GetSelectedDesignType();

					if (DisplayArtworkAutomaticSpan() && ArtworkAutomaticRadio.Checked)
					{
						b.SetAutomaticBannerText(AutomaticEventBannerHidden.Value);
						if (!b.StatusArtwork && b.FirstDay < DateTime.Today) b.FirstDay = DateTime.Today;
						b.StatusArtwork = true;
					}

					if (Edit)
					{
						//Remove any non-relevant assigned files
						if (b.DisplayType.Equals(Banner.DisplayTypes.AutoEventBanner) || b.DisplayType.Equals(Banner.DisplayTypes.CustomAutoEventBanner))
						{
							b.MiscK = 0;
							b.NewMiscK = 0;
						}
						else if (b.Misc != null && !b.Misc.DisplayType.Equals(CurrentBanner.DisplayType))
						{
							b.MiscK = 0;
						}
					}
				}
				#endregion
				#region Name
				b.Name = Cambro.Web.Helpers.Strip(NameTextBox.Text);
				#endregion
				#region Folder
				if (DisplayFolderActionEventSpan() && FolderActionEventRadio.Checked)
				{
					Query q = new Query();
					q.QueryCondition = new And(
						new Q(BannerFolder.Columns.EventK, CurrentEvent.K),
						new Q(BannerFolder.Columns.PromoterK, CurrentPromoter.K));
					BannerFolderSet bfs = new BannerFolderSet(q);
					if (bfs.Count == 0)
					{
						BannerFolder bf = new BannerFolder();
						bf.PromoterK = CurrentPromoter.K;
						bf.EventK = CurrentEvent.K;
						bf.Name = "Event: " + Cambro.Misc.Utility.Snip(CurrentEvent.Name, 30) + " @ " + Cambro.Misc.Utility.Snip(CurrentEvent.Venue.Name, 20) + ", " + CurrentEvent.DateTime.ToString("MMM dd yy");
						bf.DuplicateGuid = (Guid)ViewState["BannerFolderDuplicateGuid"];
						bf.DateTimeCreated = DateTime.Now;
						bf.Update();
						b.BannerFolderK = bf.K;
					}
					else
						b.BannerFolderK = bfs[0].K;
				}
				else if (FolderActionExistingRadio.Checked)
				{
					BannerFolder bf = new BannerFolder(int.Parse(FolderExistingDropDown.SelectedValue));
					if (bf.PromoterK != CurrentPromoter.K)
						throw new DsiUserFriendlyException("Selected banner folder isn't in your promoter account!");
					b.BannerFolderK = bf.K;
				}
				else if (FolderActionNewRadio.Checked)
				{
					Query q = new Query();
					q.QueryCondition = new And(
						new Q(BannerFolder.Columns.DuplicateGuid, (Guid)ViewState["BannerFolderDuplicateGuid"]));
					BannerFolderSet bfs = new BannerFolderSet(q);
					if (bfs.Count == 0)
					{
						BannerFolder bf = new BannerFolder();
						bf.PromoterK = CurrentPromoter.K;
						bf.Name = Cambro.Web.Helpers.Strip(FolderNewTextBox.Text);
						bf.DuplicateGuid = (Guid)ViewState["BannerFolderDuplicateGuid"];
						bf.DateTimeCreated = DateTime.Now;
						bf.Update();
						b.BannerFolderK = bf.K;	
					}
					else
					{
						if (bfs[0].PromoterK != CurrentPromoter.K)
							throw new DsiUserFriendlyException("Selected banner folder isn't in your promoter account!");
						b.BannerFolderK = bfs[0].K;
					}
				}
				#endregion

				#region if Copy - extra Properties to Copy from existing Banner
				if (Copy)
				{
					b.TargettingProperties0 = CopyBanner.TargettingProperties0;
					b.TargettingProperties1 = CopyBanner.TargettingProperties1;

					if (b.DesignType == Banner.DesignTypes.None)
					{
						if (!b.StatusArtwork && CopyBanner.StatusArtwork && b.FirstDay < DateTime.Today) b.FirstDay = DateTime.Today;
						b.StatusArtwork = CopyBanner.StatusArtwork;
						b.MiscK = CopyBanner.MiscK;
					}
				}
				#endregion

				b.Update();

				if (b.AutomaticTargetting)
				{
					b.IsPlaceTargetted = b.SavePlaceTargetting(CurrentEvent);
					b.IsMusicTargetted = b.SaveMusicTargetting(CurrentEvent);
					b.Update();
				}
				else if (TargettingCustomRadio.Checked)
				{
					b.IsPlaceTargetted = b.SavePlaceTargetting(new List<string>(LocationTargettingHidden.Value.Split(',')).ConvertAll(s => int.Parse(s.Trim())));
					b.IsMusicTargetted = b.SaveMusicTargetting(new List<string>(MusicTargettingHidden.Value.Split(',')).ConvertAll(s => int.Parse(s.Trim())));
					b.Update();
				}
				else
				{
					b.IsPlaceTargetted = b.SavePlaceTargetting(new List<int>(0));
					b.IsMusicTargetted = b.SaveMusicTargetting(new List<int>(1) { 1 });
					b.Update();
				}

                CurrentBanner = b;
                //if (Add || Copy)
                //{
                //    if (HasFixedCurrentEvent)
                //        Response.Redirect(CurrentPromoter.UrlEventOptions(CurrentEvent));
                //    else
                //        Response.Redirect(CurrentPromoter.UrlApp("banners"));
                //}
                //else
                //{
                //    if (HasFixedCurrentEvent)
                //        Response.Redirect(CurrentBanner.OptionsUrl("eventk", CurrentEvent.K.ToString()));
                //    else
						Response.Redirect(CurrentBanner.Url());
                //}
			}
		}
Exemple #21
0
		void BannerListBind()
		{
			Q folderQ = FolderK > 0 ? new Q(Banner.Columns.BannerFolderK, FolderK) : new Q(true);

			Query q = new Query();

			q.QueryCondition = new And(
				new Q(Banner.Columns.PromoterK, CurrentPromoter.K),
				folderQ);
			q.OrderBy = new OrderBy(Banner.Columns.LastDay, OrderBy.OrderDirection.Descending);
			q.NoLock = true;
			BannerSet bs = new BannerSet(q);
			BannerListDataGrid.AllowPaging = bs.Count > BannerListDataGrid.PageSize;
			BannerListDataGrid.DataSource = bs;
			BannerListDataGrid.DataBind();
		}