private void PopulateCandidates() { Ballot ballot = Ballot.FromIdentity((int)ViewState[this.ClientID + "SelectedBallot"]); string candidateText = string.Empty; People candidates = ballot.Candidates; int listPosition = 1; foreach (Person candidate in candidates) { string cityName = string.Empty; // Get city name Cities cities = Cities.FromPostalCode(candidate.PostalCode, candidate.CountryId); if (cities.Count == 0) { try { cityName = City.FromName(candidate.CityName, candidate.CountryId).Name; } catch (ArgumentException) { // ignore } } else { cityName = cities[0].Name; // This may be adjusted manually, but will work in 99.9% of cases } if (cityName.Length < 2) { cityName = candidate.CityName; } if (cityName.Contains("(")) { cityName = cityName.Split('(')[0].Trim(); } int age = 2010 - candidate.Birthdate.Year; if (new DateTime(2010, 9, 19) < new DateTime(2010, candidate.Birthdate.Month, candidate.Birthdate.Day)) { age--; } candidateText += string.Format("{0,2}. {1}, {2}, {3} \xE5r\r\n", listPosition++, candidate.Canonical, cityName, age); } this.TextCandidates.Text = candidateText; }
protected void ButtonLookup_Click(object sender, EventArgs e) { string identityString = DropBallots.SelectedValue; Ballot ballot = Ballot.FromIdentity(Int32.Parse(identityString)); ViewState[this.ClientID + "SelectedBallot"] = ballot.Identity; this.TextBallotCount.Text = ballot.Count.ToString(); this.TextDeliveryAddress.Text = ballot.DeliveryAddress; this.LabelBallotName.Text = ballot.Name; this.LabelGeography.Text = ballot.Geography.Name; PopulateCandidates(); }
protected void ButtonSave_Click(object sender, EventArgs e) { Organization org = Organization.PPSE; Election election = Election.September2010; Ballot ballot = Ballot.FromIdentity((int)ViewState[this.ClientID + "SelectedBallot"]); ballot.ClearCandidates(); ballot.DeliveryAddress = this.TextDeliveryAddress.Text; ballot.Count = Int32.Parse(this.TextBallotCount.Text); string[] candidateNames = this.TextCandidates.Text.Split('\r', '\n'); foreach (string candidateNameSource in candidateNames) { if (candidateNameSource.Trim().Length < 3) { continue; } 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) { personId = 1; } ballot.AddCandidate(Person.FromIdentity(personId)); } PopulateCandidates(); Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('Valsedel #" + ballot.Identity + " sparades.');", true); }
protected void ButtonCandidateLookup_Click(object sender, EventArgs e) { Person candidate = this.ComboCandidate.SelectedPerson; ViewState[this.ClientID + "SelectedCandidate"] = candidate.Identity; Dictionary <int, int> ballotLookup = Ballots.GetBallotsForPerson(candidate); this.LabelBallots.Text = string.Empty; foreach (int ballotId in ballotLookup.Keys) { Ballot ballot = Ballot.FromIdentity(ballotId); this.LabelBallots.Text += String.Format("{0} (position {1})\r\n", ballot.Name, ballotLookup[ballotId]); } this.TextPersonalNumber.Text = candidate.PersonalNumber; this.TextPhone.Text = candidate.Phone; this.LabelCandidateName.Text = candidate.Canonical; }