Beispiel #1
0
        public void ProcessLogin(string userPass)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Usercode.Text))
                {
                    MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Usercode.Focus();
                    return;
                }

                var userLoginSuccessful = _loginService.Login(userPass, "user");
                if (userLoginSuccessful == null)
                {
                    MessageBox.Show(@"Wrong PassCode", @"information!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    Usercode.Text = "";
                    Usercode.Focus();
                    return;
                }
                _stateService.SetCurrentlyLoggedInUser(userLoginSuccessful);
                _testEvaluationService.UserInProgress(userLoginSuccessful);

                this.Hide();
                var testPage = Program.CreateServiceProvider().GetRequiredService <TestPage>();
                testPage.Show();
            }
            catch (SqlException exception)
            {
                MessageBox.Show(exception.Message, "information!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Beispiel #2
0
        public void login(string userPass)
        {
            ConnectionString Dbconnect = new ConnectionString();

            if (Usercode.Text == "")
            {
                MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Usercode.Focus();
                return;
            }
            try
            {
                SqlConnection connection = new SqlConnection();
                connection = new SqlConnection(Dbconnect.Connect());
                connection.Open();

                SqlCommand command = new SqlCommand();

                command = new SqlCommand("SELECT * FROM Users WHERE password='******'AND UserType='user'", connection);
                SqlDataReader datareader = command.ExecuteReader();
                int           count      = 0;
                while (datareader.Read())
                {
                    count = count + 1;
                }
                datareader.Close();
                connection.Close();

                if (count == 1)
                {
                    QuestionPage quest    = new QuestionPage();
                    TestPage     testPage = new TestPage();
                    this.Hide();
                    testPage.Show();
                }
                else
                {
                    MessageBox.Show("Wrong Passcode", "information!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    Usercode.Text = "";
                }
            }
            catch (SqlException exception)
            {
                MessageBox.Show(exception.Message, "information!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }