Пример #1
0
        /// <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));
                }
            }
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        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);
        }
Пример #4
0
 /// <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();
     }
 }
Пример #5
0
        /// <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();
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        /// <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);
            }
        }
Пример #9
0
        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);
        }
Пример #10
0
 /// <summary>
 /// Create a new DAO that connects to the specified server.
 /// </summary>
 /// <param name="c">The connection.</param>
 public MunicipalityDAO(DigitalVoterList c)
     : base(c)
 {
 }
Пример #11
0
 public PessimisticVoterDAO(string server, string password)
 {
     this.connection = DigitalVoterList.GetConnectionInstance("groupCJN", password, server);
 }
Пример #12
0
 public Generator(DigitalVoterList dvl)
 {
     this.dvl = dvl;
 }
Пример #13
0
 /// <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;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractDataAccessObject{T}"/> class,
 /// connects to the default instance.
 /// </summary>
 protected AbstractDataAccessObject()
 {
     this.db = DigitalVoterList.GetDefaultInstance();
 }
Пример #15
0
 public Generator(DigitalVoterList dvl)
 {
     this.dvl = dvl;
 }
Пример #16
0
 /// <summary>
 /// Create a new DAO that connects to the specified server.
 /// </summary>
 /// <param name="c">The connection.</param>
 public VoterDAO(DigitalVoterList c)
     : base(c)
 {
 }
Пример #17
0
 /// <summary>
 /// Create a new DAO that connects to the specified server.
 /// </summary>
 /// <param name="c">The connection.</param>
 public PollingStationDAO(DigitalVoterList c)
     : base(c)
 {
 }
Пример #18
0
 /// <summary>
 /// Create a new DAO that connects to the specified server.
 /// </summary>
 /// <param name="c">The connection.</param>
 public LogDAO(DigitalVoterList c)
     : base(c)
 {
 }