// 登录事件 private void OnLoginIn(object sender, RoutedEventArgs e) { //{ // SelectWindow select = new SelectWindow(); // select.Show(); // this.Close(); //} if (redisIPTextBox.Text == null) { MessageBox.Show("请输入数据库地址!", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } string ip = redisIPTextBox.Text; int port = int.Parse(redisPortTextBox.Text); if (!IsConnected(ip, port)) { MessageBox.Show("连接失败!", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } myRedisIP = ip; myRedisPort = port; string name = usernameTextBox.Text; string pwd = passwordPasswordBox.Password; int authority = VerifyHelper.VerifyUser(name, pwd); if (authority == (int)UserAuthority.None) { MessageBox.Show("用户名或密码错误", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (authority == (int)UserAuthority.Alrealy) { MessageBox.Show("不允许多个用户使用同一账号!", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } myUsername = name; myPassword = pwd; myAuthority = authority; // 普通用户和管理员进入不同的界面 if (authority == (int)UserAuthority.Normal) { CompileToolWindow tool = new CompileToolWindow(); tool.Show(); } else { SelectWindow select = new SelectWindow(); select.Show(); } this.Close(); }
// 确认更改用户信息按钮 private void OnEditUser(object sender, RoutedEventArgs e) { string name = usernameTextBox.Text; string pwd = passwordTextBox.Text; if (name == null || pwd == null || name == "" || pwd == "") { MessageBox.Show("用户名和密码不可为空", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (name.Contains(" ") || pwd.Contains(" ")) { MessageBox.Show("用户名或密码不可包含空格", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (oldUser != null && oldUser.UserName != name && VerifyHelper.IsExist(name)) { MessageBox.Show("用户名已存在", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (oldUser == null && VerifyHelper.IsExist(name)) { MessageBox.Show("用户名已存在", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } for (int i = 0; i < allCommand.Count && i < allCheckBox.Count; i++) { if (((CheckBox)allCheckBox[i]).IsChecked == true) { redis.Set <int>(RedisKeyName.userAuthorityPrefix + name + ":" + Encoding.UTF8.GetString((byte[])allCommand[i]), 1); } else { redis.Set <int>(RedisKeyName.userAuthorityPrefix + name + ":" + Encoding.UTF8.GetString((byte[])allCommand[i]), 0); } } if (oldUser != null && oldUser.UserName == name && oldUser.Password == pwd) { this.Close(); return; } newUser.UserName = name; newUser.Password = pwd; if (oldUser != null) { newUser.Authority = oldUser.Authority; } else { newUser.Authority = 1; } ManageWindow manage = (ManageWindow)this.Owner; if (oldUser != null) { manage.EditUser(oldUser, newUser); } else { manage.AddNewUser(newUser); } this.Close(); }