コード例 #1
0
        private HashSet<Quiz> GenerateSecurityQuestions(RawPerson rawPerson)
        {
            Contract.Ensures(Contract.Result<HashSet<Quiz>>() != null);

            var quizzes = new HashSet<Quiz>();

            if (!String.IsNullOrEmpty(rawPerson.Birthplace)) quizzes.Add(new Quiz("Where were you born?", rawPerson.Birthplace));
            if (!String.IsNullOrEmpty(rawPerson.Education)) quizzes.Add(new Quiz("What is your education?", rawPerson.Education));
            if (!String.IsNullOrEmpty(rawPerson.Address) && !String.IsNullOrEmpty(rawPerson.AddressPrevious)) quizzes.Add(new Quiz("Where did you live before you moved to " + rawPerson.Address + " ?", rawPerson.AddressPrevious));
            if (!String.IsNullOrEmpty(rawPerson.TelephoneNumber)) quizzes.Add(new Quiz("What is your telephone number?", rawPerson.TelephoneNumber));
            if (!String.IsNullOrEmpty(rawPerson.Workplace)) quizzes.Add(new Quiz("Where do you work?", rawPerson.Workplace));
            if (!String.IsNullOrEmpty(rawPerson.City)) quizzes.Add(new Quiz("In what city do you live?", rawPerson.City));
            if (!String.IsNullOrEmpty(rawPerson.DriverID)) quizzes.Add(new Quiz("What is your driver ID number", rawPerson.DriverID));
            if (!String.IsNullOrEmpty(rawPerson.PassportNumber)) quizzes.Add(new Quiz("What is your passport number", rawPerson.PassportNumber));

            //We will not ask questions about a persons parents if they are dead.
            if (!rawPerson.FatherDead)
            {
                if (rawPerson.FatherAge != null && rawPerson.FatherAge == 0) quizzes.Add(new Quiz("What is your fathers age?", rawPerson.FatherAge.ToString()));
                if (!String.IsNullOrEmpty(rawPerson.FatherBirthday)) quizzes.Add(new Quiz("When were your father born?", rawPerson.FatherBirthday));
                if (!String.IsNullOrEmpty(rawPerson.FatherEducation)) quizzes.Add(new Quiz("What is your fathers education", rawPerson.FatherEducation));
                if (!String.IsNullOrEmpty(rawPerson.FatherName)) quizzes.Add(new Quiz("What is your fathers name?", rawPerson.FatherName));
            }

            if (!rawPerson.MotherDead)
            {
                if (rawPerson.MotherAge != null && rawPerson.MotherAge == 0) quizzes.Add(new Quiz("What is your mothers age?", rawPerson.MotherAge.ToString()));
                if (!String.IsNullOrEmpty(rawPerson.MotherBirthday)) quizzes.Add(new Quiz("When were your mother born?", rawPerson.MotherBirthday));
                if (!String.IsNullOrEmpty(rawPerson.MotherEducation)) quizzes.Add(new Quiz("What is your mothers education", rawPerson.MotherEducation));
                if (!String.IsNullOrEmpty(rawPerson.MotherName)) quizzes.Add(new Quiz("What is your mothers name?", rawPerson.MotherName));
            }

            return quizzes;
        }
コード例 #2
0
        /// <summary>
        /// What votingVenue should be used for this citizen
        /// </summary>
        /// <returns></returns>
        public override bool CitizenEligibleToVote(RawPerson rawPerson)
        {
            /*
             * This method should calculate whether a citizen is eligible to vote or not. An example of such calculation is given here:
             */

            //Voter is disempowered to vote
            if (rawPerson.Disempowered)
            {
                return(false);
            }

            //Person is too young
            if (rawPerson.Age < 18)
            {
                return(false);
            }

            //Person is not danish
            if (rawPerson.Nationality != "DNK")
            {
                return(false);
            }

            //Person is dead
            if (rawPerson.Dead == true)
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// What votingVenue should be used for this citizen
        /// </summary>
        /// <returns></returns>
        public override VotingVenue VotingVenueForCitizen(RawPerson rawPerson)
        {
            /*
             *  This method should calculate there a citizen should vote from his data. This might be calculated from a list of zipcodes in the database,
             *  by looking at GPS coordinates or other stuff. In this example, every citizen votes at the same voting venue.
             */

            return(new VotingVenue(1, "Dyssegårdskolens aula", "Dyssegårdsvej 34"));
        }
コード例 #4
0
        /// <summary>
        /// What votingVenue should be used for this citizen
        /// </summary>
        /// <returns></returns>
        public override VotingVenue VotingVenueForCitizen(RawPerson rawPerson)
        {
            /*
                This method should calculate there a citizen should vote from his data. This might be calculated from a list of zipcodes in the database,
             *  by looking at GPS coordinates or other stuff. In this example, every citizen votes at the same voting venue.
            */

            return new VotingVenue(1, "Dyssegårdskolens aula", "Dyssegårdsvej 34");
        }
コード例 #5
0
 /// <summary>
 /// What citizen would I get if I gave him/her this rawPersons information?
 /// </summary>
 /// <param name="person"></param>
 /// <param name="rawPerson"></param>
 /// <returns></returns>
 private Citizen UpdateCitizen(Citizen citizen, RawPerson rawPerson)
 {
     citizen.Name = rawPerson.Name;
     citizen.Cpr = rawPerson.CPR;
     citizen.Address = rawPerson.Address;
     citizen.PassportNumber = rawPerson.PassportNumber;
     citizen.PlaceOfBirth = rawPerson.Birthplace;
     citizen.EligibleToVote = Settings.Election.CitizenEligibleToVote(rawPerson);
     citizen.SecurityQuestions = this.GenerateSecurityQuestions(rawPerson);
     citizen.VotingPlace = Settings.Election.VotingVenueForCitizen(rawPerson);
     return citizen;
 }
コード例 #6
0
 /// <summary>
 /// What citizen would I get if I gave him/her this rawPersons information?
 /// </summary>
 /// <param name="person"></param>
 /// <param name="rawPerson"></param>
 /// <returns></returns>
 private Citizen UpdateCitizen(Citizen citizen, RawPerson rawPerson)
 {
     citizen.Name              = rawPerson.Name;
     citizen.Cpr               = rawPerson.CPR;
     citizen.Address           = rawPerson.Address;
     citizen.PassportNumber    = rawPerson.PassportNumber;
     citizen.PlaceOfBirth      = rawPerson.Birthplace;
     citizen.EligibleToVote    = Settings.Election.CitizenEligibleToVote(rawPerson);
     citizen.SecurityQuestions = this.GenerateSecurityQuestions(rawPerson);
     citizen.VotingPlace       = Settings.Election.VotingVenueForCitizen(rawPerson);
     return(citizen);
 }
コード例 #7
0
        /// <summary>
        /// What votingVenue should be used for this citizen
        /// </summary>
        /// <returns></returns>
        public override bool CitizenEligibleToVote(RawPerson rawPerson)
        {
            /*
             * This method should calculate whether a citizen is eligible to vote or not. An example of such calculation is given here:
             */

            //Voter is disempowered to vote
            if (rawPerson.Disempowered) return false;

            //Person is too young
            if (rawPerson.Age < 18) return false;

            //Person is not danish
            if (rawPerson.Nationality != "DNK") return false;

            //Person is dead
            if (rawPerson.Dead == true) return false;

            return true;
        }
コード例 #8
0
        private HashSet <Quiz> GenerateSecurityQuestions(RawPerson rawPerson)
        {
            Contract.Ensures(Contract.Result <HashSet <Quiz> >() != null);

            var quizzes = new HashSet <Quiz>();

            if (!String.IsNullOrEmpty(rawPerson.Birthplace))
            {
                quizzes.Add(new Quiz("Where were you born?", rawPerson.Birthplace));
            }
            if (!String.IsNullOrEmpty(rawPerson.Education))
            {
                quizzes.Add(new Quiz("What is your education?", rawPerson.Education));
            }
            if (!String.IsNullOrEmpty(rawPerson.Address) && !String.IsNullOrEmpty(rawPerson.AddressPrevious))
            {
                quizzes.Add(new Quiz("Where did you live before you moved to " + rawPerson.Address + " ?", rawPerson.AddressPrevious));
            }
            if (!String.IsNullOrEmpty(rawPerson.TelephoneNumber))
            {
                quizzes.Add(new Quiz("What is your telephone number?", rawPerson.TelephoneNumber));
            }
            if (!String.IsNullOrEmpty(rawPerson.Workplace))
            {
                quizzes.Add(new Quiz("Where do you work?", rawPerson.Workplace));
            }
            if (!String.IsNullOrEmpty(rawPerson.City))
            {
                quizzes.Add(new Quiz("In what city do you live?", rawPerson.City));
            }
            if (!String.IsNullOrEmpty(rawPerson.DriverID))
            {
                quizzes.Add(new Quiz("What is your driver ID number", rawPerson.DriverID));
            }
            if (!String.IsNullOrEmpty(rawPerson.PassportNumber))
            {
                quizzes.Add(new Quiz("What is your passport number", rawPerson.PassportNumber));
            }

            //We will not ask questions about a persons parents if they are dead.
            if (!rawPerson.FatherDead)
            {
                if (rawPerson.FatherAge != null && rawPerson.FatherAge == 0)
                {
                    quizzes.Add(new Quiz("What is your fathers age?", rawPerson.FatherAge.ToString()));
                }
                if (!String.IsNullOrEmpty(rawPerson.FatherBirthday))
                {
                    quizzes.Add(new Quiz("When were your father born?", rawPerson.FatherBirthday));
                }
                if (!String.IsNullOrEmpty(rawPerson.FatherEducation))
                {
                    quizzes.Add(new Quiz("What is your fathers education", rawPerson.FatherEducation));
                }
                if (!String.IsNullOrEmpty(rawPerson.FatherName))
                {
                    quizzes.Add(new Quiz("What is your fathers name?", rawPerson.FatherName));
                }
            }

            if (!rawPerson.MotherDead)
            {
                if (rawPerson.MotherAge != null && rawPerson.MotherAge == 0)
                {
                    quizzes.Add(new Quiz("What is your mothers age?", rawPerson.MotherAge.ToString()));
                }
                if (!String.IsNullOrEmpty(rawPerson.MotherBirthday))
                {
                    quizzes.Add(new Quiz("When were your mother born?", rawPerson.MotherBirthday));
                }
                if (!String.IsNullOrEmpty(rawPerson.MotherEducation))
                {
                    quizzes.Add(new Quiz("What is your mothers education", rawPerson.MotherEducation));
                }
                if (!String.IsNullOrEmpty(rawPerson.MotherName))
                {
                    quizzes.Add(new Quiz("What is your mothers name?", rawPerson.MotherName));
                }
            }

            return(quizzes);
        }
コード例 #9
0
 public abstract bool CitizenEligibleToVote(RawPerson rawPerson);
コード例 #10
0
 public abstract VotingVenue VotingVenueForCitizen(RawPerson rawPerson);
コード例 #11
0
 public abstract bool CitizenEligibleToVote(RawPerson rawPerson);
コード例 #12
0
 public abstract VotingVenue VotingVenueForCitizen(RawPerson rawPerson);
コード例 #13
0
ファイル: DAOMySql.cs プロジェクト: hyllekilde/PX3-BDSA-E2011
        /// <summary>
        /// Update all persons in the dataset with this update
        /// </summary>
        /// <param name="updateFunc"></param>
        public void UpdatePeople(Func<Citizen, RawPerson, Citizen> updateFunc)
        {
            var connection = new MySqlConnection(this._connectionString);
            connection.Open();
            const string Query =
                "SELECT " + "p.*, " + "f.name AS fathers_name, " + "f.birthday AS fathers_birthday, "
                + "f.age AS fathers_age, " + "f.education AS fathers_education, " + "f.dead AS father_dead, "
                + "m.name AS mothers_name, " + "m.birthday AS mothers_birthday, " + "m.age AS mothers_age, "
                + "m.education AS mothers_education, " + "m.dead AS mother_dead " + "FROM raw_person_data p "
                + "LEFT JOIN raw_person_data f ON p.father_cpr = f.cpr "
                + "LEFT JOIN raw_person_data m ON p.mother_cpr = m.cpr;";
            var loadRowPeople = new MySqlCommand(Query, connection);
            MySqlDataReader rdr = null;

            try
            {
                rdr = loadRowPeople.ExecuteReader();

                while (rdr.Read())
                {
                    RawPerson rawPerson = new RawPerson();
                    DoIfNotDbNull(rdr, "address", lbl => rawPerson.Address = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "address_previous", lbl => rawPerson.AddressPrevious = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "age", lbl => rawPerson.Age = rdr.GetInt32(lbl));
                    DoIfNotDbNull(rdr, "birthday", lbl => rawPerson.Birthday = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "birthplace", lbl => rawPerson.Birthplace = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "CPR", lbl => rawPerson.CPR = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "city", lbl => rawPerson.City = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "deathdate", lbl => rawPerson.Deathdate = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "dead", lbl => rawPerson.Dead = rdr.GetBoolean(lbl));
                    DoIfNotDbNull(rdr, "disempowered", lbl => rawPerson.Disempowered = rdr.GetBoolean(lbl));
                    DoIfNotDbNull(rdr, "driver_id", lbl => rawPerson.DriverID = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "education", lbl => rawPerson.Education = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "military_served", lbl => rawPerson.MilitaryServed = rdr.GetBoolean(lbl));
                    DoIfNotDbNull(rdr, "name", lbl => rawPerson.Name = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "nationality", lbl => rawPerson.Nationality = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "passport_number", lbl => rawPerson.PassportNumber = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "telephone", lbl => rawPerson.TelephoneNumber = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "workplace", lbl => rawPerson.Workplace = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "zipcode", lbl => rawPerson.Zipcode = rdr.GetInt32(lbl));

                    DoIfNotDbNull(rdr, "fathers_name", lbl => rawPerson.FatherName = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "fathers_age", lbl => rawPerson.FatherAge = rdr.GetInt32(lbl));
                    DoIfNotDbNull(rdr, "fathers_birthday", lbl => rawPerson.FatherBirthday = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "fathers_education", lbl => rawPerson.FatherEducation = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "father_dead", lbl => rawPerson.FatherDead = rdr.GetBoolean(lbl));

                    DoIfNotDbNull(rdr, "mothers_name", lbl => rawPerson.MotherName = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "mothers_age", lbl => rawPerson.MotherAge = rdr.GetInt32(lbl));
                    DoIfNotDbNull(rdr, "mothers_birthday", lbl => rawPerson.MotherBirthday = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "mothers_education", lbl => rawPerson.MotherEducation = rdr.GetString(lbl));
                    DoIfNotDbNull(rdr, "mother_dead", lbl => rawPerson.MotherDead = rdr.GetBoolean(lbl));

                    if (rawPerson.CPR != null)
                    {

                        List<Citizen> listOfCitizens =
                            FindCitizens(
                                new Dictionary<CitizenSearchParam, object>() { { CitizenSearchParam.Cpr, rawPerson.CPR } }, SearchMatching.Exact);

                        if ((listOfCitizens.Count > 0))
                        {
                            Citizen c = updateFunc(listOfCitizens[0], rawPerson);
                            DoTransaction(() => PriSave(c));
                        }
                        else
                        {
                            Citizen c = updateFunc(new Citizen(0, rawPerson.CPR), rawPerson);
                            DoTransaction(() => PriSaveNew(c));
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (rdr != null) rdr.Close();
                connection.Close();
            }

            //Update people that are not in the raw data
            DoTransaction(() => this.MarkPeopleNotInRawDataUneligibleToVote());
        }