Пример #1
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string        username = txtUserName.Text;
            string        password = txtPassword.Password;
            UserContainer user;

            bool success = wgDB.IsServerConnected();

            if (success)
            {
                success = wgDB.GetUserByUsername(username, out user);

                if (success)
                {
                    if (user != null)
                    {
                        if (user.Password == password)
                        {
                            GlobalVars.Instance.UserID          = user.UserID;
                            GlobalVars.Instance.UserDisplayName = user.Firstname + " " + user.Lastname;
                            GlobalVars.Instance.UserRole        = user.Role;

                            ExperimentParams expParams = ExperimentParams.GetExperimentParams;
                            expParams.user = user;

                            LoginSuccess = true;

                            Close();
                        }
                        else
                        {  // password not correct
                            MessageBoxResult result = MessageBox.Show("Incorrect Password", "Login Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    else
                    {
                        // username not found
                        MessageBoxResult result = MessageBox.Show("Username: '******' not found", "Login Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    // database query issue
                    MessageBoxResult result = MessageBox.Show("Database query failure!", "Database Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                // database connection issue
                string           errMsg = wgDB.GetLastErrorMsg();
                MessageBoxResult result = MessageBox.Show(errMsg, "Database Connection Failure",
                                                          MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }