/// <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)); } } }
/// <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> 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); } }
/// <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 VoterBoxManager(VoterFilter filter) { this.Filter = filter; }
private IEnumerator <IGrouping <String, VoterDO> > groupsEnumerator; // Enumerator over all groups in the current grouping. /// <summary> /// Initializes a new instance of the <see cref="VoterCardGenerator"/> class. /// </summary> /// <param name="filter">The filter describing the selected subset of voters.</param> public VoterCardGenerator(VoterFilter filter) { this.filter = filter; }
private BackgroundWorker worker; // Worker to avoid main thread being blocked during generation.. #endregion Fields #region Constructors /// <summary> /// Initializes a new instance of the <see cref="VoterCardGenerator"/> class. /// </summary> /// <param name="filter">The filter describing the selected subset of voters.</param> public VoterCardGenerator(VoterFilter filter) { this.filter = filter; }
/// <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. }
public VoterBoxManager(VoterFilter filter) { this.Filter = filter; }