/// <summary> /// Parses the xml file into a list of polling venues /// </summary> /// <param name="xDocument">The xml file</param> /// <param name="notifier">Event subscriber if validation of the xml file fails</param> /// <returns>A list of polling venues</returns> private List <PollingVenue> LoadVenues(XDocument xDocument, ValidationEventHandler notifier) { if (!this.ValidateXmlFile(xDocument, notifier)) { var pollingVenuesElements = from n in xDocument.Descendants("PollingVenue") select n; List <PollingVenue> pollingVenues = new List <PollingVenue>(); foreach (var xElement in pollingVenuesElements) { Address pollingVenueAddress = new Address { Name = xElement.Element("Name").Value, Street = xElement.Element("Street").Value, City = xElement.Element("City").Value }; Address municipalityAddress = new Address { Name = xElement.Parent.Parent.Element("Name").Value, Street = xElement.Parent.Parent.Element("Street").Value, City = xElement.Parent.Parent.Element("City").Value }; PollingVenue pollingVenue = new PollingVenue { Persons = this.LoadPersons(xElement), PollingVenueAddress = pollingVenueAddress, MunicipalityAddress = municipalityAddress }; pollingVenues.Add(pollingVenue); } return(pollingVenues); } return(null); }
/// <summary> /// Can you save the polling cards for this polling venue on the harddrive? /// </summary> /// <param name="pollingVenue">The polling venue</param> /// <param name="electionName">The name of the election</param> /// <param name="electionDate">The date of the election</param> public void SavePollingCards(PollingVenue pollingVenue, string electionName, string electionDate) { Contract.Requires(pollingVenue != null); Contract.Ensures(File.Exists(this.path + "\\PollingCards.pdf")); var pollingCards = new PollingCards(electionName, electionDate, "09.00 - 20.00"); foreach (var person in pollingVenue.Persons) { pollingCards.CreatePollingCard(person, pollingVenue.MunicipalityAddress, pollingVenue.PollingVenueAddress); } pollingCards.SaveToDisk(this.path + "\\PollingCards.pdf"); }
/// <summary> /// Can you save these voters to a csv file seperated with a ;? /// </summary> /// <param name="pollingVenue">The polling venue</param> public void SaveVoters(PollingVenue pollingVenue) { Contract.Requires(pollingVenue != null); Contract.Ensures(File.Exists(this.path + "\\Voters.csv")); var sw = new StreamWriter(this.path + "\\Voters.csv", false); sw.WriteLine("FirstName;LastName;Cpr;VoterId;PollingTable;PollingVenueName"); //Header in the csv file foreach (var person in pollingVenue.Persons) { sw.WriteLine(person.FirstName + ";" + person.LastName + ";" + person.Cpr + ";" + person.VoterId + ";" + person.PollingTable + ";" + pollingVenue.PollingVenueAddress.Name); } sw.Close(); }