/// <summary> /// Fetch data from the db based on the current filter. /// </summary> public void FetchData() { pDAO = new PollingStationDAO(DigitalVoterList.GetDefaultInstance()); mDAO = new MunicipalityDAO(DigitalVoterList.GetDefaultInstance()); vDAO = new VoterDAO(DigitalVoterList.GetDefaultInstance()); VoterFilter f = this.Filter; if (f.CPRNO != 0) { this.Voters = vDAO.Read(v => v.PrimaryKey == f.CPRNO); VoterDO voter = this.Voters.First(); this.PollingStations = pDAO.Read(ps => ps.PrimaryKey == voter.PollingStationId); PollingStationDO pollingStation = this.PollingStations.First(); this.Municipalities = mDAO.Read(m => m.PrimaryKey == pollingStation.MunicipalityId); } else if (f.PollingStation != null) { this.PollingStations = pDAO.Read(ps => ps.PrimaryKey == f.PollingStation.PrimaryKey); this.Voters = vDAO.Read(v => v.PollingStationId == f.PollingStation.PrimaryKey); this.Municipalities = mDAO.Read(m => m.PrimaryKey == f.PollingStation.MunicipalityId); } else if (f.Municipality != null) { this.Municipalities = mDAO.Read(m => m.PrimaryKey == f.Municipality.PrimaryKey); this.PollingStations = pDAO.Read(p => p.MunicipalityId == f.Municipality.PrimaryKey); this.Voters = Enumerable.Empty<VoterDO>(); foreach (var ps in this.PollingStations) { PollingStationDO ps1 = ps; this.Voters = this.Voters.Concat(vDAO.Read(v => v.PollingStationId == ps1.PrimaryKey)); } } }
public void SetUp() { if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } // Create a municipality var mDAO = new MunicipalityDAO(); mDAO.Create(new MunicipalityDO(9998, "Teststreet 42", "4242 Testcity", "Municipality of Test")); IEnumerator <MunicipalityDO> muns = mDAO.Read(m => m.Name.StartsWith("Municipality of Test")).GetEnumerator(); muns.MoveNext(); this.mun = muns.Current; // Create 3 polling stations. var pDAO = new PollingStationDAO(); pDAO.Create(new PollingStationDO(this.mun.PrimaryKey, 10000, "Test Polling Station 1", "Teststreet 44")); pDAO.Create(new PollingStationDO(this.mun.PrimaryKey, 10001, "Test Polling Station 2", "Teststreet 45")); pDAO.Create(new PollingStationDO(this.mun.PrimaryKey, 10002, "Test Polling Station 3", "Teststreet 46")); IEnumerator <PollingStationDO> pss = pDAO.Read(po => po.Name.StartsWith("Test Polling Station")).GetEnumerator(); int pi = 0; while (pss.MoveNext()) { this.ps[pi++] = pss.Current; } // Create 10 voters. var vDAO = new VoterDAO(); vDAO.Create(new VoterDO(this.ps[0].PrimaryKey, 101264242, "Test Testson 1", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[1].PrimaryKey, 101264243, "Test Testson 2", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[2].PrimaryKey, 101264244, "Test Testson 3", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[0].PrimaryKey, 101264245, "Test Testson 4", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[0].PrimaryKey, 101264246, "Test Testson 5", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[1].PrimaryKey, 101264247, "Test Testson 6", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[1].PrimaryKey, 101264248, "Test Testson 7", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[2].PrimaryKey, 101264249, "Test Testson 8", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[2].PrimaryKey, 101264250, "Test Testson 9", "Teststreet 47", "4242 Testcity", false, false)); vDAO.Create(new VoterDO(this.ps[2].PrimaryKey, 101264251, "Test Testson 10", "Teststreet 47", "4242 Testcity", false, false)); IEnumerator <VoterDO> voters = vDAO.Read(vo => vo.Name.StartsWith("Test Testson")).GetEnumerator(); int vi = 0; while (voters.MoveNext()) { this.v[vi++] = voters.Current; } // Setup Voter Card Generator sub-system. this.filter = new VoterFilter(mun); this.vcg = new VoterCardGenerator(filter); this.vcgView = new VoterCardGeneratorWindow(this.vcg); this.vcgController = new VoterCardGeneratorController(this.vcg, this.vcgView); }
/// <summary> Replace the current voter filter with this voter filter. </summary> public void ReplaceFilter(VoterFilter filter) { this.currentFilter = filter; IEnumerable <VoterDO> voters = null; if (filter.CPRNO != 0) { voters = vDAO.Read(v => v.PrimaryKey == filter.CPRNO); if (voters.Count() > 0) { SelectedMunicipality = voters.Single().PollingStation.Municipality; SelectedPollingStation = voters.Single().PollingStation; } } else if (filter.PollingStation != null) { if (filter.PollingStation.Name.Equals("All Polling Stations")) { voters = vDAO.Read(v => v.PollingStation.MunicipalityId == selectedMunicipality.Id); } else { voters = vDAO.Read(v => v.PollingStation == filter.PollingStation); SelectedMunicipality = filter.PollingStation.Municipality; PollingStations = pDAO.Read(p => p.MunicipalityId == filter.PollingStation.MunicipalityId); SelectedPollingStation = filter.PollingStation; } } else if (filter.Municipality != null) { if (filter.Municipality.Name.Equals("All Municipalities")) { voters = vDAO.Read(v => true); PollingStations = pDAO.Read(o => true); } else { voters = vDAO.Read(v => v.PollingStation.Municipality == filter.Municipality); PollingStations = pDAO.Read(o => o.Municipality == filter.Municipality); } } VoterCount = voters.Count(); // The invariant for Filter stipulates, that at least one field will be initialized, and therefore this will never be null. }
/// <summary> /// Do the polling stations on the VoterBox match the current selection? /// </summary> /// <returns>Answer to query (yes = true | no = false)</returns> public bool ValidatePollingStations() { var serverPS = pDAO.Read(v => true).ToList(); foreach (var ps in this.PollingStations) { if (!serverPS.Contains(ps)) return false; } return true; }
/// <summary> Initializes a new instance of the <see cref="VoterSelection"/> class with proper values for the default selection. </summary> public VoterSelection() { pDAO = new PollingStationDAO(DigitalVoterList.GetDefaultInstance()); mDAO = new MunicipalityDAO(DigitalVoterList.GetDefaultInstance()); vDAO = new VoterDAO(DigitalVoterList.GetDefaultInstance()); // Call database to get initial values (no selection, ie. entire DB) try { Municipalities = mDAO.Read(o => true); PollingStations = pDAO.Read(o => true); voterCount = vDAO.Read(o => true).Count(); currentFilter = null; } catch (Exception e) { System.Windows.Forms.MessageBox.Show( string.Format("The system was not able to connect to the server. The system said: {0}", e.Message)); Environment.Exit(-1); } }
public void ReadOperation3() { // Arrange var pdao = new PollingStationDAO(); PollingStationDO pollingStation = pdao.Read(p => true).First(); // Pick a random polling station. var dao = new VoterDAO(); // Act Expression <Func <VoterDO, bool> > f = v => v.PollingStationId == pollingStation.PrimaryKey; Func <VoterDO, bool> func = f.Compile(); var result = dao.Read(f); Debug.Assert(result.Count() > 0, "No voters matched the arranged query, please generate some new data!"); // The above is very unlikely to fail since we are generating 5000 voters, and the generator only has 50 names to choose from, but we still have to check it. // Assert foreach (VoterDO voter in result) { Debug.Assert(func.Invoke(voter)); } }
public void ReadOperation3() { // Arrange var pdao = new PollingStationDAO(); PollingStationDO pollingStation = pdao.Read(p => true).First(); // Pick a random polling station. var dao = new VoterDAO(); // Act Expression<Func<VoterDO, bool>> f = v => v.PollingStationId == pollingStation.PrimaryKey; Func<VoterDO, bool> func = f.Compile(); var result = dao.Read(f); Debug.Assert(result.Count() > 0, "No voters matched the arranged query, please generate some new data!"); // The above is very unlikely to fail since we are generating 5000 voters, and the generator only has 50 names to choose from, but we still have to check it. // Assert foreach (VoterDO voter in result) { Debug.Assert(func.Invoke(voter)); } }