Ejemplo n.º 1
0
        //BUtton on form
        private void btnLogInUser_Click(object sender, EventArgs e)
        {
            string user = txtBoxUserName.Text;
            string pass = txtBoxPassword.Text;

            //check if user is eligible to be logged in

            if (login.IsLoggedIn(user, pass))
            {
                StudentInterface studentEntry = new StudentInterface();
                studentEntry.Show();
                Close();
            }

            else
            {
                MessageBox.Show("Try again!");
                foreach (var c in Controls)
                {
                    if (c is TextBox)
                    {
                        ((TextBox)c).Text = String.Empty;
                    }
                }
            }
        }
        //Submit Button - Submits student to DB & performs verification checks on click
        private void submitBtn_Click(object sender, EventArgs e)
        {
            //Validates collection of textboxes on form to ensure they are not empty
            var textBoxCollection = new[] { textBoxStudentId, textBoxfName, textBoxSName, textBoxEmail, textBoxPhone,
                                            textBoxAddressL1, textBoxAddressL2, textBoxCity, textBoxLevel, textBoxCourse };

            bool atleastOneTextboxEmpty = textBoxCollection
                                          .Any(t => String.IsNullOrWhiteSpace(t.Text));

            //If one is empty, form will not submit
            if (atleastOneTextboxEmpty)
            {
                MessageBox.Show("No fields can be left empty.");
                DialogResult = DialogResult.None;
            }
            //Email validation
            else if (!IsValidEmail(textBoxEmail.Text))
            {
                MessageBox.Show("Email address must be valid format");
                DialogResult = DialogResult.None;
            }
            else
            {
                Student.addStudent(int.Parse(textBoxStudentId.Text),
                                   textBoxfName.Text, textBoxSName.Text,
                                   textBoxEmail.Text, textBoxPhone.Text,
                                   textBoxAddressL1.Text, textBoxAddressL2.Text,
                                   textBoxCity.Text, cBoxCounty.Text,
                                   textBoxLevel.Text, textBoxCourse.Text);


                StudentInterface studentInterface = new StudentInterface();
                studentInterface.Show();
                Close();
            }
        }