public void CurrentComp_PreRender(object o, System.EventArgs e) { if (DateTime.Now > CurrentComp.DateTimeStart) { HtmlRenderer r = new HtmlRenderer(); r.LoadHtml(CurrentComp.SponsorDetails); PromoterDetailsPh.Controls.Clear(); PromoterDetailsPh.Controls.Add(new LiteralControl(r.Render(PromoterDetailsPh))); QuestionLabel.Text = CurrentComp.Question; if (Usr.Current != null && Usr.Current.HasEntered(CompK)) { CompEntry entry = Usr.Current.CompEntry(CompK); SelectedAnswerLabel.Text = entry.AnswerText; DateTimeCloseLabel.Text = Cambro.Misc.Utility.FriendlyDate(CurrentComp.DateTimeClose, false); EnteredPanel.Visible = true; } else EnteredPanel.Visible = false; if ((Usr.Current == null || !Usr.Current.HasEntered(CompK)) && CurrentComp.Running) { EnterLinkButton1.Text = CurrentComp.Answer1; EnterLinkButton2.Text = CurrentComp.Answer2; EnterLinkButton3.Text = CurrentComp.Answer3; DateTimeCloseLabel1.Text = Cambro.Misc.Utility.FriendlyDate(CurrentComp.DateTimeClose, false); EntryPanel.Visible = true; } else EntryPanel.Visible = false; if (!CurrentComp.Running) { CorrentAnswerLabel.Text = CurrentComp.CorrectAnswerText; FinishedPanel.Visible = true; WinnersPanel.Visible = CurrentComp.WinnersPicked; NoWinnersPanel.Visible = !CurrentComp.WinnersPicked; if (CurrentComp.WinnersPicked) { WinnersPh.Controls.Clear(); UsrSet winners = CurrentComp.UsrWinners; bool currentUsrWinner = false; for (int prize = 1; prize <= 3; prize++) { CompEntrySet ces = new CompEntrySet( new Query( new And( new Q(CompEntry.Columns.CompK, CurrentComp.K), new Q(CompEntry.Columns.Winner, true), new Q(CompEntry.Columns.Prize, prize) ) ) ); if (ces.Count > 0) { bool first = true; string prizeString = "1st prize - " + CurrentComp.Prize; if (prize == 2) prizeString = "2nd prize - " + CurrentComp.Prize2; else if (prize == 3) prizeString = "Runners up prize - " + CurrentComp.Prize3; WinnersPh.Controls.Add(new LiteralControl("<p>" + prizeString + ":</p><p>")); foreach (CompEntry ce in ces) { if (Usr.Current != null && ce.Usr.K == Usr.Current.K) currentUsrWinner = true; if (!first && (Usr.Current == null || Usr.Current.K != CurrentComp.Owner.K)) WinnersPh.Controls.Add(new LiteralControl(", ")); HtmlAnchor a = new HtmlAnchor(); a.InnerText = ce.Usr.NickName; if (Usr.Current != null && Usr.Current.K == CurrentComp.Owner.K) { if (ce.WinnerThreadK > 0) a.HRef = ce.WinnerThread.Url(); else { ce.Usr.MakeRollover(a); a.HRef = ce.Usr.Url(); } } else { ce.Usr.MakeRollover(a); a.HRef = ce.Usr.Url(); } WinnersPh.Controls.Add(a); if (Usr.Current != null && Usr.Current.K == CurrentComp.Owner.K) { WinnersPh.Controls.Add(new LiteralControl(" (" + ce.Usr.FirstName + " " + ce.Usr.LastName + ")<br>")); } first = false; } WinnersPh.Controls.Add(new LiteralControl("</p>")); } } if (currentUsrWinner) { CurrentComp.Owner.MakeRollover(OwnerAnchor); OwnerAnchor.InnerText = CurrentComp.Owner.NickName; OwnerAnchor.HRef = CurrentComp.Owner.Url(); YouAreAWinnerPanel.Visible = true; } else { YouAreAWinnerPanel.Visible = false; } } } else FinishedPanel.Visible = false; } }
public void PickWinners() { if (!this.Running && !this.WinnersPicked) { Query q = new Query(); q.QueryCondition=new And( new Q(CompEntry.Columns.CompK,this.K), new Q(CompEntry.Columns.Answer,this.CorrectAnswer), new Q(CompEntry.Columns.Winner,false), new Q(Usr.Columns.IsAdmin,false), new Q(Usr.Columns.K,QueryOperator.NotEqualTo,this.OwnerUsrK) ); q.TableElement=new Join(CompEntry.Columns.UsrK,Usr.Columns.K); q.OrderBy=new OrderBy(OrderBy.OrderDirection.Random); q.TopRecords=this.Winners+this.Winners2+this.Winners3; CompEntrySet cs = new CompEntrySet(q); int winnerCount = 0; foreach (CompEntry ce in cs) { ce.Winner=true; if (winnerCount<this.Winners) ce.Prize=1; else if (winnerCount<(this.Winners+this.Winners2)) ce.Prize=2; else ce.Prize=3; ce.Update(); winnerCount++; } this.WinnersPicked=true; this.Update(); CompEntrySet csEmails = new CompEntrySet(new Query(new Q(CompEntry.Columns.CompK,this.K))); Usr DSI = new Usr(8); foreach (CompEntry ce in csEmails) { Mailer sm = new Mailer(); int threadK = 0; if (ce.Winner) { string prize = this.Prize; if (ce.Prize==2) prize = this.Prize2; if (ce.Prize==3) prize = this.Prize3; #region Add a PM string body = @"<i>This private message has been sent automatically by the DontStayIn competition system.</i> Congratulations! "+ce.Usr.NickName+@" has won <b>"+prize+@"</b> in the competition. "+this.Owner.NickName+@" is dealing with sorting the prizes out. The full name of "+ce.Usr.NickName+@" is <i>"+ce.Usr.FirstName+@" "+ce.Usr.LastName+@"</i>. If any more details are needed, e.g. postal address, please post them here. <a href="""+this.Url()+@""">Click here to go to the competition page</a>"; Thread.Maker m = new Thread.Maker(); m.Subject="Congratulations! "+ce.Usr.NickName+@" has won a prize!"; m.Body=body; m.ParentType=Model.Entities.ObjectType.None; m.DuplicateGuid=Guid.NewGuid(); m.Private=true; m.PostingUsr=DSI; m.InviteKs.Add(ce.Usr.K); m.InviteKs.Add(this.Owner.K); Thread.MakerReturn r = m.Post(); threadK = r.Thread.K; ce.WinnerThreadK=threadK; ce.Update(); #endregion sm.Subject="YOU'VE WON the DontStayIn competition!"; sm.Body="<p>You have won <b>"+prize+"</b> in our competition. For details of how to claim your prize, click the login link below.</p>"; } else { sm.Subject="Sorry, you didn't win the DontStayIn competition."; sm.Body="<p>Sorry, you didn't win <b>"+this.Prize+"</b> in our competition. To see the winners, click the login link below.</p>"; } if (ce.Winner) { Thread t = new Thread(threadK); sm.RedirectUrl=t.Url(); } else sm.RedirectUrl=this.Url(); sm.TemplateType=Mailer.TemplateTypes.AnotherSiteUser; sm.UsrRecipient=ce.Usr; sm.Send(); } Mailer smOwner = new Mailer(); smOwner.Subject="We have drawn the winners in your competition"; smOwner.Body="<p>We've automatically picked this winner(s) in the <b>"+this.Name+"</b> competition. We've automatically invited you to a private message with each of the winners. Please arrange delivery of their prizes ASAP. To see a list of the winners, please click the login link below.</p>"; smOwner.RedirectUrl=this.Url(); smOwner.TemplateType=Mailer.TemplateTypes.AnotherSiteUser; smOwner.To=this.Owner.Email; smOwner.UsrRecipient=this.Owner; smOwner.Send(); } }