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(); } }
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); }