コード例 #1
0
        private void OkButton_OnClick(object sender, RoutedEventArgs e)
        {
            // Close if no changes detected
            if (!_isExpanded)
            {
                MessageBox.Show("No changes to be done");
                Close();
            }

            #region Username validation for regular employees

            if (_employee.AccessMode == AccessMode.None)
            {
                if (UserNameTextBox.Text == "")
                {
                    MessageBox.Show("One or more fields are empty");
                }
                if (_isUserNameUnique == null)
                {
                    CheckIfUserNameAvailable();
                }
                if (_isUserNameUnique == false)
                {
                    MessageBox.Show("This username is already taken. Please choose another");
                }
            }

            #endregion

            var accessMode = (AccessMode)UserTypeComboBox.SelectedIndex;
            if (_employee.AccessMode != AccessMode.None)
            {
                // should update existing employee if there are any changes
                _uaHandler.UpdateUserAccess(_user, accessMode);
                MessageBox.Show("User access updated successfully");
            }
            else
            {
                // should add new user to database
                _uaHandler.AddUserAccess(_employee, accessMode, UserNameTextBox.Text);
                MessageBox.Show("User AccessMode provided Successfully");
            }
            DialogResult = true;
            Close();
        }