/// <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> /// Insert the data that was fected onto the remote server. /// </summary> /// <param name="server">The address of the server.</param> /// <param name="port">The port of the server.</param> /// <param name="user">The username.</param> /// <param name="password">The password.</param> public void InsertData(string server, string port, string user, string password) { foreach (var municipality in this.Municipalities) { municipality.ResetAssociations(); } foreach (var pollingStation in this.PollingStations) { pollingStation.ResetAssociations(); } foreach (var voter in this.Voters) { voter.ResetAssociations(); } var context = DigitalVoterList.GetInstance(user, password, server, port); mDAO = new MunicipalityDAO(context); pDAO = new PollingStationDAO(context); vDAO = new VoterDAO(context); mDAO.Create(this.Municipalities); pDAO.Create(this.PollingStations); vDAO.Create(this.Voters); }
public void Setup() { var connection = new MySqlConnection( "server=localhost;" + "port=3306;" + "uid=groupCJN;" + "password=abc123;" + "Sql Server Mode=true;" + "database=groupcjn;"); var creator = new DBCreator(connection); var generator = new Generator(DigitalVoterList.GetDefaultInstance()); generator.Generate(10, 100, 5000); }
/// <summary> /// Updates the log with activity registered for the current voter /// </summary> /// <param name="ae">The activity to be logged</param> private void UpdateLog(ActivityEnum ae) { try { //Create the log DAO with setup information, activity and current voter. var ldo = new LogDO(setupInfo.TableNo, currentVoter.PrimaryKey, ae); var ldao = new LogDAO(DigitalVoterList.GetInstanceFromServer(setupInfo.Ip)); ldao.Create(ldo); } catch (Exception) { ConnectionError(); } }
/// <summary> /// Create a new model that fetches data from the specified server. /// </summary> /// <param name="password">The password to the server</param> /// <param name="server">The address of the server.</param> public LogModel(string password, string server) { this.password = password; this.server = server; var conn = DigitalVoterList.GetInstance("groupCJN", this.password, this.server); this.logs = new BindingList <LogDO>(); this.lDAO = new LogDAO(conn); this.vDAO = new VoterDAO(conn); this.Update(); this.filter = new LogFilter(); }
public void Setup() { this.daos = new List <PessimisticVoterDAO>(); var connection = new MySqlConnection( "server=localhost;" + "port=3306;" + "uid=groupCJN;" + "password=abc123;" + "Sql Server Mode=true;" + "database=groupcjn;"); var creator = new DBCreator(connection); var generator = new Generator(DigitalVoterList.GetDefaultInstance()); generator.Generate(1, 1, 3); VoterDAO voterDAO = new VoterDAO(); this.voters = voterDAO.Read(v => true); }
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> 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 FindVoterTest() { 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(); //string msg; //model.ConnectionError += (x => msg = x); model.ConnectionError += this.DummyMethod; model.FindVoter((uint)voter.PrimaryKey); Assert.AreEqual(model.currentVoter, voter); Model.cleanUpDAO(); vdao.Delete(x => x.PrimaryKey == voter.PrimaryKey); }
/// <summary> /// Create a new DAO that connects to the specified server. /// </summary> /// <param name="c">The connection.</param> public MunicipalityDAO(DigitalVoterList c) : base(c) { }
public PessimisticVoterDAO(string server, string password) { this.connection = DigitalVoterList.GetConnectionInstance("groupCJN", password, server); }
public Generator(DigitalVoterList dvl) { this.dvl = dvl; }
/// <summary> /// Initializes a new instance of the <see cref="AbstractDataAccessObject{T}"/> class, /// that connects to the specified DataContext. /// </summary> /// <param name="dc"> /// The datacontext /// </param> protected AbstractDataAccessObject(DigitalVoterList dc) { this.db = dc; }
/// <summary> /// Initializes a new instance of the <see cref="AbstractDataAccessObject{T}"/> class, /// connects to the default instance. /// </summary> protected AbstractDataAccessObject() { this.db = DigitalVoterList.GetDefaultInstance(); }
/// <summary> /// Create a new DAO that connects to the specified server. /// </summary> /// <param name="c">The connection.</param> public VoterDAO(DigitalVoterList c) : base(c) { }
/// <summary> /// Create a new DAO that connects to the specified server. /// </summary> /// <param name="c">The connection.</param> public PollingStationDAO(DigitalVoterList c) : base(c) { }
/// <summary> /// Create a new DAO that connects to the specified server. /// </summary> /// <param name="c">The connection.</param> public LogDAO(DigitalVoterList c) : base(c) { }