private void YesButton_Click(object sender, RoutedEventArgs e)
        {
            var user     = UserComboBox.Text.Trim();
            var password = PasswordTextBox.Password.Trim();

            ErrorTextBlock.Text = string.Empty;
            if (string.IsNullOrEmpty(user))
            {
                ErrorTextBlock.Text = "用户不能为空";
                UserComboBox.Focus();
                return;
            }

            if (string.IsNullOrEmpty(password))
            {
                ErrorTextBlock.Text = "密码不能为空";
                PasswordTextBox.Focus();
                return;
            }

            if (!PermissionService.Login(user, password))
            {
                ErrorTextBlock.Text = "用户或密码错误";
                UserComboBox.Focus();
                return;
            }

            var loginUsers = Activator.ConfigurationService.Get(Activator.Bundle, "LoginUsers", string.Empty);

            if (string.IsNullOrEmpty(loginUsers)) // 如果为空,则直接存储
            {
                loginUsers = user;
                // 保存
                Activator.ConfigurationService.Set(Activator.Bundle, "LoginUsers", loginUsers);
            }
            else
            {
                // 如果当前用户与登录用户不相同或者当前用户的最后一个用户与登录用户不同
                // 则需要将当前登录用户放在最后
                if (!loginUsers.Equals(user) && !loginUsers.EndsWith(";" + user))
                {
                    if (loginUsers.Contains(user + ";")) // 当前登录用户是否在中间
                    {
                        loginUsers = loginUsers.Replace(user + ";", "");
                    }

                    loginUsers += ";" + user; // 放在最后
                    // 保存登录用户
                    Activator.ConfigurationService.Set(Activator.Bundle, "LoginUsers", loginUsers);
                }
            }

            var mainWindow = new MainWindow();

            Application.Current.MainWindow = mainWindow;
            Application.Current.MainWindow.Show();

            Window.GetWindow(this).Close();
        }
Example #2
0
        private void SetUserComboBoxOptions(string folderPath)
        {
            string currentlySelectedUser = UserComboBox.Text;

            string[] users = GetUsers(folderPath);
            UserComboBox.Items.Clear();
            UserComboBox.Items.AddRange(users);
            UserComboBox.SelectedIndex = UserComboBox.FindStringExact(currentlySelectedUser);
            if (UserComboBox.SelectedIndex == -1)
            {
                UserComboBox.SelectedIndex = 0;
            }
        }
Example #3
0
        // Used when we already have settings but need to update them
        public SettingsForm(string folderPath, string userName, bool hideSettingsInMainForm)
        {
            InitializeComponent();

            // Try to use the folder path provided. If it no longer exists, leave default
            if (Directory.Exists(folderPath))
            {
                SettingsFolderTextBox.Text = folderPath;
                SetUserComboBoxOptions(folderPath);
                UserComboBox.SelectedIndex = UserComboBox.FindStringExact(userName);
                checkBox1.Checked          = hideSettingsInMainForm;
            }
            else
            {
                MessageBox.Show("Error reading configuration! Please configure again.", "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #4
0
        private void UpdateUserComboBox()
        {
            UserComboBox.Items.Clear();

            foreach (Backend.User user in Users)
            {
                UserComboBox.Items.Add(user);
            }

            // if there are no items selected, select the one just added
            if (UserComboBox.SelectedIndex == -1 &&
                Users.Count() > 0)
            {
                UserComboBox.SelectedIndex = 0;
            }

            UserComboBox.Refresh();
        }
Example #5
0
        private void YesBtnClick(object sender, RoutedEventArgs e)
        {
            LogHelper.Info("OnEntry YesButton_Click in");
            var loginName = UserComboBox.Text.Trim();
            var password  = PasswordTextBox.Password.Trim();

            if (string.IsNullOrEmpty(loginName))
            {
                MessageDxUtil.ShowError(MainMessage.MAIN_MSG_005);
                UserComboBox.Focus();
                return;
            }
            if (string.IsNullOrEmpty(password))
            {
                MessageDxUtil.ShowError(MainMessage.MAIN_MSG_006);
                PasswordTextBox.Focus();
                return;
            }

            //登録ユーザーを設定に保存する(次回登録時、cobobox最初行に表示する)
            int userConut = 0;

            if (Settings.Default.LastLoginUser != null)
            {
                userConut = Settings.Default.LastLoginUser.Length;
            }
            List <System.String> userList = new List <System.String>();

            userList.Add(loginName);

            for (int i = 0; i < userConut; i++)
            {
                userList.Add(Properties.Settings.Default.LastLoginUser[i].ToString());
            }

            userList = userList.Distinct().ToList();

            //Settings.Default.LastLoginUser = userList.ToArray();
            Settings.Default.Save();
        }
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     UserComboBox.Focus();
 }