/// <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> /// Opens the normal voter window where the user can register the voter as registered. /// </summary> /// <param name="voter">The voter to be shown</param> public void OpenNormalWindow(VoterDO voter) { this.normalVoterWindow = new NormVW(voter); this.normalVoterWindow.RegButton.Click += (o, eA) => this.VoterShown(); this.normalVoterWindow.RegButton.Click += (o, eA) => this.normalVoterWindow.Close(); this.normalVoterWindow.ShowDialog(); }
public bool Equals01([PexAssumeUnderTest] VoterDO target, object obj) { bool result = target.Equals(obj); return(result); // TODO: add assertions to method VoterDOTest.Equals01(VoterDO, Object) }
public VoterDO Constructor01() { VoterDO target = new VoterDO(); return(target); // TODO: add assertions to method VoterDOTest.Constructor01() }
public int GetHashCode01([PexAssumeUnderTest] VoterDO target) { int result = target.GetHashCode(); return(result); // TODO: add assertions to method VoterDOTest.GetHashCode01(VoterDO) }
public bool FullyInitialized([PexAssumeUnderTest] VoterDO target) { bool result = target.FullyInitialized(); return(result); // TODO: add assertions to method VoterDOTest.FullyInitialized(VoterDO) }
public PollingStationDO PollingStationGet([PexAssumeUnderTest] VoterDO target) { PollingStationDO result = target.PollingStation; return(result); // TODO: add assertions to method VoterDOTest.PollingStationGet(VoterDO) }
public string CprStringGet([PexAssumeUnderTest] VoterDO target) { string result = target.CprString; return(result); // TODO: add assertions to method VoterDOTest.CprStringGet(VoterDO) }
public uint?PrimaryKeyGet([PexAssumeUnderTest] VoterDO target) { uint?result = target.PrimaryKey; return(result); // TODO: add assertions to method VoterDOTest.PrimaryKeyGet(VoterDO) }
/// <summary> /// (To be called when a group has finished being generated) /// Prepares for and starts the generation of the next group, if any remain. /// If no groups remain; the voters are updated in the database. /// </summary> /// <param name="sender">BackgroundWorker that just completed a generation process.</param> /// <param name="e">Worker event completion parameters (currently not used).</param> private void GroupGenerated(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { return; } var worker = sender as BackgroundWorker; this.GroupDoneCount++; // Prepare and start generation of next group, if any remain. if (this.groupsEnumerator.MoveNext()) { this.currentGroup = this.groupsEnumerator.Current; this.CurrentGroupName = this.currentGroup.Key; this.voterCount = this.currentGroup.Count(); this.voterDoneCount = 0; this.VoterDonePerc = 0; worker.RunWorkerAsync(); } // ..Otherwise update voters in db and declare completed. else { this.CurrentGroupName = "Updating Database.."; var voterDAO = new VoterDAO(); var template = new VoterDO(null, null, null, null, null, true, null); var predicate = filter != null?filter.ToPredicate() : v => true; voterDAO.Update(predicate, template); GenerationEnded("Completed"); } }
/// <summary> /// Opens the warning window where the user is warned that the voter has already vote. /// </summary> /// <param name="voter">The voter to be shown</param> public void OpenWarningWindow(VoterDO voter) { { warningWindow = new WarningVW(voter); this.warningWindow.UnlockButton.Click += (o, eA) => this.Unlock(); this.warningWindow.UnlockButton.Click += (o, eA) => this.warningWindow.Close(); this.warningWindow.ShowDialog(); } }
/// <summary> /// Window where the user can register the voter and where the voter's information is shown /// </summary> /// <param name="voter">The voter to be shown.</param> public NormVW(VoterDO voter) { InitializeComponent(); voterNameLabel.Text = voter.Name; voterAddressLabel.Text = voter.Address; voterCityLabel.Text = voter.City; this.MaximumSize = new System.Drawing.Size(368, 218); this.MinimumSize = new System.Drawing.Size(368, 218); }
public WarningVW(VoterDO voter) { InitializeComponent(); voterNameLabel.Text = voter.Name; voterAddressLabel.Text = voter.Address; voterCityLabel.Text = voter.City; Size size = new Size(384, 277); this.MaximumSize = size; this.MinimumSize = size; }
public VoterDO Constructor( uint? pollingStationId, uint? cpr, string name, string address, string city, bool? cardPrinted, bool? voted ) { VoterDO target = new VoterDO(pollingStationId, cpr, name, address, city, cardPrinted, voted); return target; // TODO: add assertions to method VoterDOTest.Constructor(Nullable`1<UInt32>, Nullable`1<UInt32>, String, String, String, Nullable`1<Boolean>, Nullable`1<Boolean>) }
public UnRegVW(VoterDO voter) { InitializeComponent(); voterNameLabel.Text = voter.Name; voterAddressLabel.Text = voter.Address; voterCityLabel.Text = voter.City; //Window is not resizable var size = new System.Drawing.Size(377, 345); this.MinimumSize = size; this.MaximumSize = size; }
public VoterDO Constructor( uint?pollingStationId, uint?cpr, string name, string address, string city, bool?cardPrinted, bool?voted ) { VoterDO target = new VoterDO(pollingStationId, cpr, name, address, city, cardPrinted, voted); return(target); // TODO: add assertions to method VoterDOTest.Constructor(Nullable`1<UInt32>, Nullable`1<UInt32>, String, String, String, Nullable`1<Boolean>, Nullable`1<Boolean>) }
public void GenerateVoters(int voters, int pollingstations) { var v = new HashSet<VoterDO>(); for (uint i = 0; i < voters; i++) { uint cpr = data.GetCPR(); var voter = new VoterDO((uint)this.r.Next(pollingstations), cpr, data.GetFirstName(cpr) + " " + data.GetLastname(), data.GetRoadname() + " " + r.Next(1000), data.GetCityname(), false, false); v.Add(voter); } var dao = new VoterDAO(dvl); dao.Create(v); }
/// <summary> /// Fetches the voter matching the cprno. /// </summary> /// <param name="cprno">The cprno of the voter to be fetched in the voter box.</param> /// <returns>The voter matching </returns> public VoterDO FetchVoter(uint cprno) { Contract.Requires(cprno != null); VoterDO voter; try { voter = staticPvdao.Read(cprno); } catch (Exception) { voter = new VoterDO(); ConnectionError(); } return(voter); }
public void GenerateVoters(int voters, int pollingstations) { var v = new HashSet <VoterDO>(); for (uint i = 0; i < voters; i++) { uint cpr = data.GetCPR(); var voter = new VoterDO((uint)this.r.Next(pollingstations), cpr, data.GetFirstName(cpr) + " " + data.GetLastname(), data.GetRoadname() + " " + r.Next(1000), data.GetCityname(), false, false); v.Add(voter); } var dao = new VoterDAO(dvl); dao.Create(v); }
public VoterDO Read(uint id) { Contract.Requires(this.TransactionStarted()); Contract.Ensures(Contract.Result <VoterDO>() != null ? Contract.Result <VoterDO>().PrimaryKey == id : true); // Command building MySqlCommand command = this.connection.CreateCommand(); command.Connection = this.connection; command.Transaction = this.transaction; command.CommandTimeout = this.timeout; // Query building command.CommandText = "call voter_read( @id_param );"; MySqlParameter p = new MySqlParameter("@id_param", MySqlDbType.UInt32) { Value = id }; command.Parameters.Add(p); // Query execution MySqlDataReader reader = command.ExecuteReader(); VoterDO voter = null; while (reader.Read()) { uint pollingStationId = uint.Parse(reader["pollingStationId"].ToString()); uint cpr = uint.Parse(reader["cpr"].ToString()); string name = reader["name"].ToString(); string address = reader["address"].ToString(); string city = reader["city"].ToString(); bool crdPrinted = bool.Parse(reader["cardPrinted"].ToString()); bool voted = bool.Parse(reader["voted"].ToString()); voter = new VoterDO(pollingStationId, cpr, name, address, city, crdPrinted, voted); } reader.Close(); return(voter); }
public void FetchVoterTest() { VoterDAO vdao = new VoterDAO(DigitalVoterList.GetInstance(user, password, server)); vdao.Create(voter); Model model = new Model(); SetupInfo si = new SetupInfo(server, 0); model.SetupInfo = si; model.AdminPass = password; model.initializeStaticDAO(); VoterDO v = model.FetchVoter((uint)this.voter.PrimaryKey); Assert.AreEqual(voter.PrimaryKey, v.PrimaryKey); Model.cleanUpDAO(); vdao.Delete(x => x.PrimaryKey == voter.PrimaryKey); }
/// <summary> /// Updates the current voter with the voter matching the cprno. /// /// </summary> /// <param name="cprno">The cpr number of the voter to be found</param> public void FindVoter(uint cprno) { Contract.Requires(cprno != null); Contract.Ensures(cprno == currentVoter.PrimaryKey); try { currentVoter = staticPvdao.Read(cprno); //Update the current voter with the found voter CurrentVoterChanged(currentVoter); //Update log with read entry this.UpdateLog(ActivityEnum.R); } catch (Exception e) { Console.WriteLine(e); ConnectionError(); // notify that the connection has been lost. return; } }
/// <summary> /// Updates /// </summary> /// <param name="voter"></param> public void ShowSpecificVoter(VoterDO voter) { //If the voter is null, it doesn't exists in the database if (voter == null) { return; } //Open an ordinary voter window if the voter has not voted yet. if (voter.Voted == false) { this.OpenNormalWindow(voter); } //Open a voter window with warning message indicating that the voter has alredy voted. if (voter.Voted == true) { this.OpenWarningWindow(voter); } }
/// <summary> /// Unregisters the current voter. /// </summary> public void UnregisterCurrentVoter() { Contract.Requires(currentVoter.Voted == true); Contract.Requires(currentVoter != null); Contract.Ensures(currentVoter.Voted == false); try { staticPvdao.Update((uint)currentVoter.PrimaryKey, false); //refresh the current voter to reflect the new voted status currentVoter = FetchVoter((uint)currentVoter.PrimaryKey); staticPvdao.EndTransaction(); this.UpdateLog(ActivityEnum.U); //Update log with unregister entry } catch (Exception) { ConnectionError(); return; } }
public void showSpecificVoter(VoterDO voter) { ///Ordinary voter window //VoterWindow vw1 = new VoterWindow(voter); //vw1.Height = 220; //vw1.panel1.Controls.Add(new RegAndCancelUC()); //vw1.Show(); ///Voter window with error message VoterWindow vw = new VoterWindow(voter); vw.Height = 280; vw.panel1.Controls.Add(new WarningUC()); vw.Show(); ///Voter window with unreg functionality //VoterWindow vw = new VoterWindow(voter); //vw.Height = 340; //vw.panel1.Controls.Add(new UnregUC()); //vw.Show(); }
/// <summary> /// Populate a voter card with the information of a given voter. /// </summary> /// <param name="page">The page containing the card.</param> /// <param name="pdf">The pdf containing the page.</param> /// <param name="xO">The horizontal offset of the card in points.</param> /// <param name="yO">The vertical offset of the card in points.</param> /// <param name="voter">The voter whose information to be populated onto the card.</param> private static void PopulateCard(Page page, PDF pdf, double xO, double yO, VoterDO voter) { // ----- POPULATE: POLLING STATION ----- PollingStationDO ps = voter.PollingStation; var font = new Font(pdf, CoreFont.HELVETICA); font.SetSize(9); var t = new TextLine(font, ps.Name); t.SetPosition(xO + 9 * U, yO + 27.5 * U); t.DrawOn(page); t = new TextLine(font, ps.Address); t.SetPosition(xO + 9 * U, yO + 32 * U); t.DrawOn(page); t = new TextLine(font, "valgfrit"); t.SetPosition(xO + 29 * U, yO + 48.8 * U); t.DrawOn(page); t = new TextLine(font, "02-04861"); t.SetPosition(xO + 29 * U, yO + 58.7 * U); t.DrawOn(page); t = new TextLine(font, "09:00 - 20:00"); t.SetPosition(xO + 29 * U, yO + 68.2 * U); t.DrawOn(page); // ----- POPULATE: VOTER ----- MunicipalityDO mun = voter.PollingStation.Municipality; font = new Font(pdf, CoreFont.COURIER); font.SetSize(10); // Add top voter number 'Vælgernr.' t = new TextLine(font, "02-04861"); t.SetPosition(xO + 102 * U, yO + 12 * U); t.DrawOn(page); // Add sender 'Afsender' t = new TextLine(font, mun.Name); t.SetPosition(xO + 102 * U, yO + 32.5 * U); t.DrawOn(page); t = new TextLine(font, mun.Address); t.SetPosition(xO + 102 * U, yO + 36.5 * U); t.DrawOn(page); t = new TextLine(font, mun.City); t.SetPosition(xO + 102 * U, yO + 40.5 * U); t.DrawOn(page); // Add reciever 'Modtager' t = new TextLine(font, voter.Name); t.SetPosition(xO + 102 * U, yO + 62.5 * U); t.DrawOn(page); t = new TextLine(font, voter.Address); t.SetPosition(xO + 102 * U, yO + 66.5 * U); t.DrawOn(page); t = new TextLine(font, voter.City); t.SetPosition(xO + 102 * U, yO + 70.5 * U); t.DrawOn(page); // Add CPR barcode string barcode = BarCodeHashing.Hash(voter.PrimaryKey.Value).ToString(); var b = new BarCode(BarCode.CODE128, barcode); b.SetPosition(xO + 160 * U, yO + 60 * U); b.DrawOn(page); t = new TextLine(font, barcode); t.SetPosition(xO + 160 * U, yO + 72 * U); t.DrawOn(page); }
public void TearDown() { voter = null; }
public void Setup() { voter = new VoterDO(1, 3112999900, "Test Person", "TestRoad 31", "Testville", true, false); }
public void UpdateValues([PexAssumeUnderTest] VoterDO target, IDataObject dummy) { target.UpdateValues(dummy); // TODO: add assertions to method VoterDOTest.UpdateValues(VoterDO, IDataObject) }
public VoterDO Constructor01() { VoterDO target = new VoterDO(); return target; // TODO: add assertions to method VoterDOTest.Constructor01() }
public void ResetAssociations([PexAssumeUnderTest] VoterDO target) { target.ResetAssociations(); // TODO: add assertions to method VoterDOTest.ResetAssociations(VoterDO) }
public VoterDO Read(uint id) { Contract.Requires(this.TransactionStarted()); Contract.Ensures(Contract.Result<VoterDO>() != null ? Contract.Result<VoterDO>().PrimaryKey == id : true); // Command building MySqlCommand command = this.connection.CreateCommand(); command.Connection = this.connection; command.Transaction = this.transaction; command.CommandTimeout = this.timeout; // Query building command.CommandText = "call voter_read( @id_param );"; MySqlParameter p = new MySqlParameter("@id_param", MySqlDbType.UInt32) { Value = id }; command.Parameters.Add(p); // Query execution MySqlDataReader reader = command.ExecuteReader(); VoterDO voter = null; while (reader.Read()) { uint pollingStationId = uint.Parse(reader["pollingStationId"].ToString()); uint cpr = uint.Parse(reader["cpr"].ToString()); string name = reader["name"].ToString(); string address = reader["address"].ToString(); string city = reader["city"].ToString(); bool crdPrinted = bool.Parse(reader["cardPrinted"].ToString()); bool voted = bool.Parse(reader["voted"].ToString()); voter = new VoterDO(pollingStationId, cpr, name, address, city, crdPrinted, voted); } reader.Close(); return voter; }