Esempio n. 1
0
        private void registerButton_Click(object sender, EventArgs e)
        {
            String username  = registerUsernameTextBox.Text;
            String password  = registerPasswordTextBox.Text;
            String state     = registerStateComboBox.Text;
            String birthdate = registerBirthdateDatePicker.Value.ToString("yyyy-MM-dd");
            String gender    = registerGenderComboBox.Text;
            String race      = registerRaceComboBox.Text;

            if (username == "" || password == "" || state == "" || birthdate == "" || gender == "" || race == "")
            {
                MessageBox.Show("One or more of the fields were left empty");
                return;
            }

            if (database.doesUserExist(username))   // If user already exists, don't allow another to be created
            {
                MessageBox.Show("User with given username already exists");
                return;
            }

            User user = new User(username, password, state, birthdate, gender, race); // Create new user object with given fields

            database.createNewUser(user);                                             // Insert object into database

            SelectBallot selectBallot = new SelectBallot(user);                       // Display the select ballot UI with the new user

            selectBallot.Show();
        }
Esempio n. 2
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            List <Vote> votes = new List <Vote>();

            DateTime now = DateTime.UtcNow;
            int      age = now.Year - Convert.ToDateTime(user.DateOfBirth).Year;

            if (Convert.ToDateTime(user.DateOfBirth) > now.AddYears(-age))
            {
                age--;
            }

            for (int question = 0; question < this.ballot.Questions.Count; question++)
            {
                Question q = this.ballot.Questions[question];

                Panel p = (Panel)optionsPanel.Controls[question];

                RadioButton checkedButton = p.Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked);

                if (checkedButton == null)
                {
                    continue;
                }

                for (int option = 0; option < q.Options.Count; option++)
                {
                    Option o = q.Options[option];

                    if (o.OptionText == checkedButton.Text)
                    {
                        votes.Add(new Vote(o.OptionId, q.QuestionId, user.State, age, user.Gender, user.Race));
                    }
                }
            }

            foreach (Vote vote in votes)
            {
                database.storeVote(vote);
            }

            database.storeUserBallot(user, ballot, DateTime.UtcNow);

            MessageBox.Show("Vote successfully submitted");

            SelectBallot selectBallot = new SelectBallot(this.user);

            selectBallot.Show();

            this.Close();
        }
Esempio n. 3
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            String username = loginUsernameTextBox.Text;
            String password = loginPasswordTextBox.Text;

            User user = database.authenticateUser(username, password);  // Have the database authenticate that the user exists

            if (user != null)
            {
                SelectBallot selectBallot = new SelectBallot(user); // Show the select ballot screen
                selectBallot.Show();
            }
            else
            {
                MessageBox.Show("Either user does not exist or password is incorrect"); // Is null, so something didn't go right with authentication
            }
        }