public void CheckUserIDExists()
        {
            FunctionsForAllProgram funcs = new FunctionsForAllProgram();

            // existing user
            bool IDExists = funcs.ifUserIDinDatabase(3233);

            Assert.IsTrue(IDExists);

            // not existing user
            IDExists = funcs.ifUserIDinDatabase(99999);
            Assert.IsFalse(IDExists);
        }
Exemplo n.º 2
0
        private void addStudentToDatabase_Click(object sender, EventArgs e)
        {
            User newAssociate;
            FunctionsForAllProgram funcs = new FunctionsForAllProgram();
            String username = this.username_box.Text;
            String id       = this.id_box.Text;
            int    id_int   = -1;


            if (checkFields() == false)
            {
                return;
            }

            try
            {
                id_int = Convert.ToInt32(id);
            }
            catch
            {
                MessageBox.Show("ID field contains non-digit symbols this field is empty!");
                return;
            }

            bool userExists = funcs.ifUserInDatabase(username) || funcs.ifUserIDinDatabase(id_int);

            if (userExists == false)
            {
                string email       = this.email_Box.Text;
                bool   emailExists = funcs.ifEmailInDatabase(email);
                if (emailExists)
                {
                    MessageBox.Show("User with email " + email + " already exists");
                    return;
                }
                String Name = this.firstname_box.Text, surename = this.secondName_box.Text, password = this.password_box.Text;

                newAssociate = new User(id, username, Name, surename, password, email);
                DBconnect db = new DBconnect();
                try
                {
                    db.addUserToDB(newAssociate);
                    MessageBox.Show("New Associate member been added to database!");
                }
                catch
                {
                    MessageBox.Show("Something went wrong, user not been added! \ncheck your database connection and fields correctness and try again!");
                }
            }
        }