protected void ButtonSubmit_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } Person candidate = this.PersonCandidate.SelectedPerson; int pollId = Int32.Parse(Request.QueryString["PollId"]); MeetingElection poll = MeetingElection.FromIdentity(pollId); if (_currentUser.Identity != 1 && _currentUser.Identity != poll.CreatedByPersonId) { throw new UnauthorizedAccessException("Access Denied"); } candidate.PortraitPhotographer = this.TextPhotographer.Text; candidate.PersonalNumber = this.TextPersonalNumber.Text; candidate.BlogName = this.TextBlogName.Text; candidate.BlogUrl = this.TextBlogUrl.Text; poll.AddCandidate(candidate, this.TextCandidacy.Text); this.PersonCandidate.SelectedPerson = null; this.TextPhotographer.Text = string.Empty; this.TextPersonalNumber.Text = string.Empty; this.TextCandidacy.Text = string.Empty; this.TextBlogName.Text = string.Empty; this.TextBlogUrl.Text = string.Empty; this.ImageCandidatePhoto.ImageUrl = string.Empty; Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", "alert ('The candidate \"" + candidate.Canonical.Replace("'", "''") + "\" was added to the poll \"" + poll.Name.Replace("'", "''") + "\".\\r\\nCurrent candidate count: " + poll.Candidates.Count.ToString() + ".');", true); }
private static void MailRawElectionResults(MeetingElection poll, SchulzeProcessor processor, bool stillOpen) { MeetingElectionCandidates candidates = processor.FinalOrder; Dictionary <int, bool> dropoutLookup = new Dictionary <int, bool>(); // TODO SOMETIME: implement and populate dropouts here string body = "These are " + (stillOpen ? "intermediate" : "THE FINAL") + " results for the poll \"" + poll.Name + "\". Note that the Dist field is purely informative and not part of the Schulze ranking.\r\n\r\n"; body += "Rank Dist Candidate\r\n"; for (int candidateIndex = 0; candidateIndex < candidates.Count; candidateIndex++) { int distance = processor.GetCandidateDistance(candidateIndex); body += String.Format("{0:D3}. {1} {2}{3}\r\n", candidateIndex + 1, (distance > 0 ? distance.ToString("D4") : "----"), candidates[candidateIndex].Person.Canonical, dropoutLookup.ContainsKey(candidates[candidateIndex].PersonId) ? " [hoppat av]" : string.Empty); } int[] recipients = new int[] { 1, poll.CreatedByPersonId }; // Send to Rick too while stabilizing functionality -- remove as soon as Rick is running in any poll string subject = (stillOpen ? "Intermediate" : "FINAL") + " results for poll - " + poll.Name; foreach (int personId in recipients) { Person.FromIdentity(personId).SendNotice( subject, body, Organization.PPSEid); } }
protected void ButtonChangeVote_Click(object sender, EventArgs e) { MeetingElection poll = MeetingElection.FromIdentity(Int32.Parse(Request.QueryString["PollId"])); InternalPollVoterStatus voterStatus = poll.GetVoterStatus(_currentUser); if (voterStatus == InternalPollVoterStatus.HasAlreadyVoted) { string verificationCode = this.TextVerificationCode.Text; try { MeetingElectionVote vote = MeetingElectionVote.FromVerificationCode(verificationCode); if (vote.InternalPollId == poll.Identity) { Response.Redirect(Request.RawUrl + "&VerificationCode=" + verificationCode); } } catch (Exception) { ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope", "alert ('There is no such verification code associated with this poll.');", true); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string pollIdParameter = Request.QueryString["PollId"]; if (string.IsNullOrEmpty(pollIdParameter)) { PopulatePollGrid(); this.PanelPollList.Visible = true; this.PanelVoting.Visible = false; this.PanelPollIntro.Visible = false; } else { MeetingElection poll = MeetingElection.FromIdentity(Int32.Parse(pollIdParameter)); this.LabelPollName1.Text = poll.Name; InternalPollVoterStatus voterStatus = poll.GetVoterStatus(_currentUser); if (!poll.VotingOpen) { this.PanelVoting.Visible = false; this.PanelVotingClosed.Visible = true; } else if (voterStatus == InternalPollVoterStatus.NotEligibleForPoll) { this.PanelVoting.Visible = false; this.PanelNoVote.Visible = true; } else if (voterStatus == InternalPollVoterStatus.HasAlreadyVoted) { string verificationCode = Request.QueryString["VerificationCode"]; if (string.IsNullOrEmpty(verificationCode)) { this.PanelVoting.Visible = false; this.PanelComplete.Visible = true; this.PanelEnterCode.Visible = true; } else { // The voter wishes to redo his/her vote PopulateLists(poll, verificationCode); this.ListVote.DataBind(); this.ListCandidates.DataBind(); this.ButtonVote.Enabled = true; } } else // open; the voter has not yet voted { PopulateLists(poll, string.Empty); this.ListCandidates.DataBind(); } } } }
protected void Page_Load(Object sender, EventArgs e) { // Set the title. this.Chart.Title = "Valdeltagande per valkrets"; string pollIdString = Request.QueryString["PollId"]; if (pollIdString == null || pollIdString.Length == 0) { pollIdString = "2"; } Chart.Title += " - " + MeetingElection.FromIdentity(Int32.Parse(pollIdString)).Name; // Set the chart Type Chart.Type = ChartType.ComboHorizontal; // Turn 3D off. Chart.Use3D = false; // Change the shading mode Chart.ShadingEffectMode = ShadingEffectMode.Three; // Set a default transparency Chart.DefaultSeries.DefaultElement.Transparency = 20; // Set the x axis scale Chart.ChartArea.XAxis.Scale = Scale.Stacked; // Set the x axis label Chart.ChartArea.XAxis.Label.Text = "Valdeltagande i promille"; // Set the y axis label Chart.ChartArea.YAxis.Label.Text = ""; // Set the directory where the images will be stored. Chart.TempDirectory = "temp"; // Set the chart size. Chart.Width = 600; Chart.Height = 550; if (Request.QueryString["Height"] != null) { Chart.Height = Int32.Parse(Request.QueryString["Height"]); } // Add the random data. Chart.SeriesCollection.Add(GetRankingData()); Chart.LegendBox.Position = LegendBoxPosition.None; Chart.LegendBox.Template = "%Icon%Name"; Chart.Debug = false; Chart.Mentor = false; }
static private void ReportPollResults(MeetingElection poll, bool stillOpen) { SchulzeProcessor processor = new SchulzeProcessor(); processor.Candidates = poll.Candidates; processor.Votes = MeetingElectionVotes.ForInternalPoll(poll); processor.Process(); MailRawElectionResults(poll, processor, stillOpen); }
protected void Page_Load(object sender, EventArgs e) { MeetingElectionCandidates candidates = MeetingElectionCandidates.ForPoll(MeetingElection.Primaries2010); string pollIdString = Request.QueryString["PollId"]; if (!string.IsNullOrEmpty(pollIdString)) { int pollId = Int32.Parse(pollIdString); candidates = MeetingElectionCandidates.ForPoll(MeetingElection.FromIdentity(pollId)); } this.RepeaterCandidates.DataSource = candidates; this.RepeaterCandidates.DataBind(); }
protected void ButtonCreate_Click(object sender, EventArgs e) { // TODO: Add Validation Organization org = Organization.PPSE; // HACK -- can't make OrganizationDropDownTree and GeographyDropDownTree cooperate Geography geo = this.DropGeographies.SelectedGeography; DateTime dateOpen = (DateTime)this.DateFirst.SelectedDate; DateTime dateClose = ((DateTime)this.DateLast.SelectedDate).AddDays(1).AddMinutes(-1); string pollName = this.TextPollName.Text; MeetingElection poll = MeetingElection.Create(_currentUser, org, geo, pollName, InternalPollResultsType.Schulze, 0, new DateTime(2006, 1, 1), new DateTime(2006, 1, 8), dateOpen, dateClose); ScriptManager.RegisterStartupScript(this, Page.GetType(), "alldone", "alert ('Internal poll #" + poll.Identity + " has been created.');", true); Reset(); }
protected void Page_Load(object sender, EventArgs e) { Dictionary <int, bool> personLookup = new Dictionary <int, bool>(); for (int pollId = 9; pollId <= 36; pollId++) { MeetingElectionCandidates candidates = MeetingElectionCandidates.ForPoll(MeetingElection.FromIdentity(pollId)); foreach (MeetingElectionCandidate candidate in candidates) { personLookup[candidate.PersonId] = true; } } foreach (int personId in personLookup.Keys) { this.LiteralMailAddresses.Text += Person.FromIdentity(personId).Email + "<br/>"; } }
protected void GridPolls_ItemCreated(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { MeetingElection poll = (MeetingElection)e.Item.DataItem; if (poll == null) { return; } HyperLink editLink = (HyperLink)e.Item.FindControl("LinkVote"); if (editLink != null) { editLink.Attributes["href"] = "PlaceInternalVote.aspx?PollId=" + poll.Identity.ToString(); } Label labelOpen = (Label)e.Item.FindControl("LabelVotingOpen"); labelOpen.Text = poll.VotingOpen? "Ja!" : "Nej"; } }
public void PopulateLists(MeetingElection poll, string verificationCode) { MeetingElectionCandidates candidates = poll.Candidates; Dictionary<int, bool> lookup = new Dictionary<int, bool>(); if (!string.IsNullOrEmpty(verificationCode)) { MeetingElectionVote vote = MeetingElectionVote.FromVerificationCode(verificationCode); if (poll.Identity != vote.InternalPollId) { throw new ArgumentException("Verification Code does not exist or does not match Poll Identity"); } int[] candidateIds = vote.SelectedCandidateIdsInOrder; foreach (int candidateId in candidateIds) { lookup[candidateId] = true; MeetingElectionCandidate candidate = MeetingElectionCandidate.FromIdentity(candidateId); this.ListVote.Items.Add(new RadListBoxItem(candidate.Person.Canonical, candidate.Identity.ToString())); } } foreach (MeetingElectionCandidate candidate in candidates) { if (!lookup.ContainsKey(candidate.Identity)) { this.ListCandidates.Items.Add(new RadListBoxItem(candidate.Person.Canonical, candidate.Identity.ToString())); } } this.ListCandidates.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { this.TextCandidacy.Style[HtmlTextWriterStyle.Width] = "400px"; this.PersonCandidate.Authority = _authority; if (!Page.IsPostBack) { int pollId = Int32.Parse(Request.QueryString["PollId"]); MeetingElection poll = MeetingElection.FromIdentity(pollId); if (_currentUser.Identity != 1 && _currentUser.Identity != poll.CreatedByPersonId) { throw new UnauthorizedAccessException("Access Denied"); } this.LabelPollName1.Text = poll.Name; this.LabelPollName2.Text = poll.Name; this.LabelPollName3.Text = poll.Name; } }
protected void Page_Load(object sender, EventArgs e) { string parameterString = Request["PollId"]; if (!String.IsNullOrEmpty(parameterString)) { int pollId = Int32.Parse(parameterString); MeetingElection poll = MeetingElection.FromIdentity(pollId); Page.Title = "Vote Verification - Internal Poll - " + poll.Name; if (poll.VotingCloses > DateTime.Now) { throw new UnauthorizedAccessException("Voting for this poll is not yet closed."); } MeetingElectionVotes votes = MeetingElectionVotes.ForInternalPoll(poll); personIdLookup = poll.GetCandidatePersonMap(); this.RepeaterVotes.DataSource = votes; this.RepeaterVotes.DataBind(); this.LabelVoteCount.Text = votes.Count.ToString(); } }
public void PopulateLists(MeetingElection poll, string verificationCode) { MeetingElectionCandidates candidates = poll.Candidates; Dictionary <int, bool> lookup = new Dictionary <int, bool>(); if (!string.IsNullOrEmpty(verificationCode)) { MeetingElectionVote vote = MeetingElectionVote.FromVerificationCode(verificationCode); if (poll.Identity != vote.InternalPollId) { throw new ArgumentException("Verification Code does not exist or does not match Poll Identity"); } int[] candidateIds = vote.SelectedCandidateIdsInOrder; foreach (int candidateId in candidateIds) { lookup[candidateId] = true; MeetingElectionCandidate candidate = MeetingElectionCandidate.FromIdentity(candidateId); this.ListVote.Items.Add(new RadListBoxItem(candidate.Person.Canonical, candidate.Identity.ToString())); } } foreach (MeetingElectionCandidate candidate in candidates) { if (!lookup.ContainsKey(candidate.Identity)) { this.ListCandidates.Items.Add(new RadListBoxItem(candidate.Person.Canonical, candidate.Identity.ToString())); } } this.ListCandidates.DataBind(); }
protected void PersonCandidate_SelectedPersonChanged(object sender, EventArgs e) { Person candidate = this.PersonCandidate.SelectedPerson; int pollId = Int32.Parse(Request.QueryString["PollId"]); MeetingElection poll = MeetingElection.FromIdentity(pollId); this.ImageCandidatePhoto.ImageUrl = "http://data.piratpartiet.se/Handlers/DisplayPortrait.aspx?YSize=300&PersonId=" + candidate.Identity.ToString(); this.LabelCandidateName1.Text = this.LabelCandidateName2.Text = this.LabelCandidateName3.Text = candidate.Canonical; // Already running? MeetingElectionCandidates candidates = poll.Candidates; bool alreadyCandidate = false; foreach (MeetingElectionCandidate testCandidate in candidates) { if (candidate.PersonId == testCandidate.PersonId) { alreadyCandidate = true; break; } } this.PanelCandidacy.Visible = !alreadyCandidate; this.PanelAlreadyCandidate.Visible = alreadyCandidate; if (!alreadyCandidate) { this.TextBlogUrl.Text = candidate.BlogUrl; this.TextBlogName.Text = candidate.BlogName; this.TextPhotographer.Text = candidate.PortraitPhotographer; this.TextPersonalNumber.Text = candidate.PersonalNumber; } }
protected void Page_Load(object sender, EventArgs e) { string parameterString = Request["PollId"]; if (!String.IsNullOrEmpty(parameterString)) { int pollId = Int32.Parse(parameterString); MeetingElection poll = MeetingElection.FromIdentity(pollId); Page.Title = "Voter Verification - Internal Poll - " + poll.Name; this.LabelPollName.Text = poll.Name; if (poll.VotingCloses > DateTime.Now) { throw new UnauthorizedAccessException("Voting for this poll is not yet closed."); } MeetingElectionVoters voters = poll.GetClosedVoters(); List <string> voterList = new List <string>(); foreach (MeetingElectionVoter voter in voters) { // Must not disclose member identities -- we use initials and person Id, not full name! voterList.Add(voter.Person.Initials + " (#" + voter.PersonId.ToString() + ")"); } CultureInfo previousCulture = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(poll.Organization.DefaultCountry.Culture); voterList.Sort(); System.Threading.Thread.CurrentThread.CurrentCulture = previousCulture; this.RepeaterVoters.DataSource = voterList.ToArray(); this.RepeaterVoters.DataBind(); this.LabelVoterCount.Text = voters.Count.ToString(); } }
protected void ButtonAdd_Click(object sender, EventArgs e) { Organization org = Organization.PPSE; Geography geo = this.DropGeographies.SelectedGeography; Election election = Election.September2010; string ballotName = this.TextName.Text; MeetingElectionCandidates candidates = MeetingElection.FromIdentity(Int32.Parse(this.DropPolls.SelectedValue)).Candidates; Ballot ballot = Ballot.Create(election, org, geo, ballotName, 0, string.Empty); Dictionary <string, int> nameLookup = new Dictionary <string, int>(); foreach (MeetingElectionCandidate candidate in candidates) { nameLookup[candidate.Person.Name.ToLowerInvariant()] = candidate.PersonId; } string[] candidateNames = this.TextCandidates.Text.Split('\r', '\n'); foreach (string candidateNameSource in candidateNames) { int personId = 0; int idStartIndex = candidateNameSource.LastIndexOf("(#"); if (idStartIndex > 0) { string identityString = candidateNameSource.Substring(idStartIndex + 2); int idEndIndex = identityString.IndexOf(")"); identityString = identityString.Substring(0, idEndIndex); personId = Int32.Parse(identityString); } if (personId == 0) { // Derive from name string candidateName = candidateNameSource; int parenIndex = candidateName.IndexOfAny(new char[] { '(', ',' }); if (parenIndex >= 0) { candidateName = candidateName.Substring(0, parenIndex); } candidateName = candidateName.ToLowerInvariant().Trim(); if (candidateName.Length < 1) { continue; } personId = nameLookup[candidateName]; } ballot.AddCandidate(Person.FromIdentity(personId)); } Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('Valsedel #" + ballot.Identity + " registrerades.');", true); }
protected void Page_Load(object sender, EventArgs e) { this.TextCandidacy.Style[HtmlTextWriterStyle.Width] = "400px"; this.TextEditCandidacy.Style[HtmlTextWriterStyle.Width] = "400px"; if (!Page.IsPostBack) { MeetingElection poll = MeetingElection.Primaries2010; MeetingElectionCandidates candidates = MeetingElection.Primaries2010.Candidates; bool thisUserIsCandidate = false; MeetingElectionCandidate thisCandidate = null; foreach (MeetingElectionCandidate candidate in candidates) { if (candidate.PersonId == _currentUser.Identity) { thisUserIsCandidate = true; thisCandidate = candidate; break; } } if (!poll.RunningOpen) { this.PanelCallForCandidatesIntro.Visible = false; this.PanelCallForCandidatesClosed.Visible = true; } if (!_currentUser.MemberOf(Organization.PPSE)) { this.PanelNotEligible.Visible = true; this.PanelCandidacy.Visible = false; this.PanelCandidate.Visible = false; } else if (thisUserIsCandidate) { this.PanelCandidate.Visible = true; this.PanelCandidacy.Visible = false; this.PanelEditCandidacy.Visible = true; this.TextEditCandidacy.Text = thisCandidate.CandidacyStatement; } this.TextPersonalNumber.Text = _currentUser.PersonalNumber; this.TextPhotographer.Text = _currentUser.PortraitPhotographer; this.TextBlogName.Text = _currentUser.BlogName; if (String.IsNullOrEmpty(_currentUser.BlogUrl)) { this.TextBlogUrl.Text = "http://"; } else { this.TextBlogUrl.Text = _currentUser.BlogUrl; } string tShirtSize = _currentUser.TShirtSize; if (!String.IsNullOrEmpty(tShirtSize)) { this.DropTShirtSizes.SelectedValue = tShirtSize; } } }
static public object FromBasic(IHasIdentity basic) { string argumentType = basic.GetType().ToString(); switch (argumentType) { // ----- Is there any way to make self-writing code here through replication or similar, so // ----- that every case doesn't need to be listed? // ------------ COMMUNICATION CLASSES ------------ case "Swarmops.Basic.Types.BasicCommunicationTurnaround": return(CommunicationTurnaround.FromBasic((BasicCommunicationTurnaround)basic)); case "Swarmops.Basic.Types.Communications.BasicOutboundComm": return(OutboundComm.FromBasic((BasicOutboundComm)basic)); case "Swarmops.Basic.Types.Communications.BasicOutboundCommRecipient": return(OutboundCommRecipient.FromBasic((BasicOutboundCommRecipient)basic)); // ----------- FINANCIAL CLASSES ---------- case "Swarmops.Basic.Types.BasicExpenseClaim": return(ExpenseClaim.FromBasic((BasicExpenseClaim)basic)); case "Swarmops.Basic.Types.Financial.BasicCashAdvance": return(CashAdvance.FromBasic((BasicCashAdvance)basic)); case "Swarmops.Basic.Types.BasicInboundInvoice": return(InboundInvoice.FromBasic((BasicInboundInvoice)basic)); case "Swarmops.Basic.Types.Financial.BasicFinancialAccount": return(FinancialAccount.FromBasic((BasicFinancialAccount)basic)); case "Swarmops.Basic.Types.Financial.BasicFinancialTransaction": return(FinancialTransaction.FromBasic((BasicFinancialTransaction)basic)); case "Swarmops.Basic.Types.BasicFinancialValidation": return(FinancialValidation.FromBasic((BasicFinancialValidation)basic)); case "Swarmops.Basic.Types.BasicOutboundInvoice": return(OutboundInvoice.FromBasic((BasicOutboundInvoice)basic)); case "Swarmops.Basic.Types.BasicOutboundInvoiceItem": return(OutboundInvoiceItem.FromBasic((BasicOutboundInvoiceItem)basic)); case "Swarmops.Basic.Types.BasicPayment": return(Payment.FromBasic((BasicPayment)basic)); case "Swarmops.Basic.Types.BasicPaymentGroup": return(PaymentGroup.FromBasic((BasicPaymentGroup)basic)); case "Swarmops.Basic.Types.BasicPayout": return(Payout.FromBasic((BasicPayout)basic)); case "Swarmops.Basic.Types.BasicPayrollAdjustment": return(PayrollAdjustment.FromBasic((BasicPayrollAdjustment)basic)); case "Swarmops.Basic.Types.BasicPayrollItem": return(PayrollItem.FromBasic((BasicPayrollItem)basic)); case "Swarmops.Basic.Types.BasicSalary": return(Salary.FromBasic((BasicSalary)basic)); case "Swarmops.Basic.Types.Financial.BasicFinancialTransactionTagSet": return(FinancialTransactionTagSet.FromBasic((BasicFinancialTransactionTagSet)basic)); case "Swarmops.Basic.Types.Financial.BasicFinancialTransactionTagType": return(FinancialTransactionTagType.FromBasic((BasicFinancialTransactionTagType)basic)); // ------------ GOVERNANCE CLASSES ------------ case "Swarmops.Basic.Types.BasicBallot": return(Ballot.FromBasic((BasicBallot)basic)); case "Swarmops.Basic.Types.BasicMeetingElectionCandidate": return(MeetingElectionCandidate.FromBasic((BasicInternalPollCandidate)basic)); case "Swarmops.Basic.Types.BasicMeetingElection": return(MeetingElection.FromBasic((BasicInternalPoll)basic)); case "Swarmops.Basic.Types.BasicMeetingElectionVote": return(MeetingElectionVote.FromBasic((BasicInternalPollVote)basic)); case "Swarmops.Basic.Types.Governance.BasicMotion": return(Motion.FromBasic((BasicMotion)basic)); case "Swarmops.Basic.Types.Governance.BasicMotionAmendment": return(MotionAmendment.FromBasic((BasicMotionAmendment)basic)); // ------------ PARLEY/ACTIVISM CLASSES ------------ case "Swarmops.Basic.Types.BasicExternalActivity": return(ExternalActivity.FromBasic((BasicExternalActivity)basic)); case "Swarmops.Basic.Types.BasicParley": return(Parley.FromBasic((BasicParley)basic)); case "Swarmops.Basic.Types.BasicParleyAttendee": return(ParleyAttendee.FromBasic((BasicParleyAttendee)basic)); case "Swarmops.Basic.Types.BasicParleyOption": return(ParleyOption.FromBasic((BasicParleyOption)basic)); case "Swarmops.Basic.Types.BasicPerson": return(Person.FromBasic((BasicPerson)basic)); // ------------------ FAIL ---------------- default: throw new NotImplementedException("Unimplemented argument type: " + argumentType); } }
Series GetRankingData() { string pollIdString = Request.QueryString["PollId"]; if (String.IsNullOrEmpty(pollIdString)) { pollIdString = "2"; } int pollId = Int32.Parse(pollIdString); SeriesCollection collection = new SeriesCollection(); // Gather the data Dictionary <int, int> totalVoteCount = new Dictionary <int, int>(); Dictionary <int, int> geographyIdCircuit = new Dictionary <int, int>(); Dictionary <int, int> peopleGeographies = People.GetPeopleGeographies(); Dictionary <int, int> closedVoteCount = Optimizations.GetInternalPollVoteCountsPerGeography(pollId); MeetingElectionVoters voters = MeetingElectionVoters.ForPoll(MeetingElection.FromIdentity(pollId), true); foreach (MeetingElectionVoter voter in voters) { if (!peopleGeographies.ContainsKey(voter.PersonId)) { throw new InvalidOperationException("Person not in geography dictionary"); } int geographyId = peopleGeographies[voter.PersonId]; if (!geographyIdCircuit.ContainsKey(geographyId)) { Geography geo = Geography.FromIdentity(geographyId); while (geo.ParentGeographyId != 0 && !geo.AtLevel(GeographyLevel.ElectoralCircuit)) { geo = geo.Parent; } if (geo.ParentGeographyId == 0) { geographyIdCircuit[geographyId] = 0; } else { geographyIdCircuit[geographyId] = geo.Identity; } } int circuitId = geographyIdCircuit[geographyId]; if (circuitId == 0) { continue; } if (!totalVoteCount.ContainsKey(circuitId)) { totalVoteCount[circuitId] = 0; } totalVoteCount[circuitId]++; } List <GeographyBar> barList = new List <GeographyBar>(); foreach (int geographyId in totalVoteCount.Keys) { GeographyBar bar = new GeographyBar(); bar.Geography = Geography.FromIdentity(geographyId); int thisClosedVoteCount = 0; if (closedVoteCount.ContainsKey(geographyId)) { thisClosedVoteCount = closedVoteCount[geographyId]; } bar.Value = thisClosedVoteCount * 1000.0 / totalVoteCount[geographyId]; barList.Add(bar); } GeographyBar[] bars = barList.ToArray(); Array.Sort(bars); // Populate the data Series series = new Series(); series.Name = "No particular name"; int count = 0; foreach (GeographyBar bar in bars) { Element element = new Element(); element.YValue = bar.Value; element.Name = bar.Geography.Name; element.SmartLabel = new SmartLabel(); element.SmartLabel.Text = bar.Value.ToString("N2"); series.Elements.Add(element); count++; } // Removing the overflow entries afterwards is a bit backwards, but it's due to the sorting series.DefaultElement.Color = System.Drawing.Color.DarkViolet; series.DefaultElement.ShowValue = true; return(series); }
protected void ButtonVote_Click(object sender, EventArgs e) { MeetingElection poll = MeetingElection.FromIdentity(Int32.Parse(Request.QueryString["PollId"])); if (!poll.VotingOpen) { ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope", "alert ('This poll has closed. You can not cast the vote.');", true); return; } if (this.ListVote.Items.Count == 0) { ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope", "alert ('You need to pick one or more candidates in order to cast a vote.');", true); return; } if (this.ListVote.Items.Count > poll.MaxVoteLength) { ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope", "alert ('You have chosen too many candidates. The maximum number is " + poll.MaxVoteLength.ToString() + ". Please remove at least " + (this.ListVote.Items.Count - poll.MaxVoteLength).ToString() + ".');", true); return; } string verificationCode = Request.QueryString["VerificationCode"]; InternalPollVoterStatus voterStatus = poll.GetVoterStatus(_currentUser); if (voterStatus == InternalPollVoterStatus.CanVote || (!string.IsNullOrEmpty(verificationCode) && voterStatus == InternalPollVoterStatus.HasAlreadyVoted)) { this.PanelPollIntro.Visible = false; this.PanelVoting.Visible = false; this.PanelComplete.Visible = true; this.PanelCode.Visible = true; MeetingElectionVote vote = null; if (string.IsNullOrEmpty(verificationCode) && voterStatus == InternalPollVoterStatus.CanVote) { vote = poll.CreateVote(_currentUser, Request.UserHostAddress.ToString()); } else { vote = MeetingElectionVote.FromVerificationCode(verificationCode); vote.Clear(); } this.LabelReference.Text = vote.VerificationCode; for (int index = 0; index < this.ListVote.Items.Count; index++) { MeetingElectionCandidate candidate = MeetingElectionCandidate.FromIdentity(Int32.Parse(this.ListVote.Items[index].Value)); vote.AddDetail(index + 1, candidate); } } }