private void btn_Login_Click(object sender, EventArgs e) { label_Info.Visible = false; bool bAdministrator = false; string username = textBox_UserName.Text.Trim(); string password = textBox_Password.Text.Trim(); //string username = "******"; //string password = "******"; if (String.IsNullOrEmpty(username)) { label_Info.Visible = true; label_Info.Text = "用户名不能为空!"; return; } if (String.IsNullOrEmpty(password)) { label_Info.Visible = true; label_Info.Text = "密码不能为空!"; return; } if (username == "admin" && password == "admin") { bAdministrator = true; CCurrentLoginUser.Instance.Login(username, password, bAdministrator); //登陆成功,通知主界面进入管理员或者普通用户模式 if (UserModeChanged != null) { CSystemInfoMgr.Instance.AddInfo(string.Format("用户{0}登录,权限:{1}", username, bAdministrator ? "管理员" : "普通用户")); UserModeChanged.Invoke(this, new CEventSingleArgs <bool>(bAdministrator)); } this.Close(); return; } try { if (CDBDataMgr.Instance.GetUserProxy().UserLogin(username, password, ref bAdministrator)) { CCurrentLoginUser.Instance.Login(username, password, bAdministrator); //登陆成功,通知主界面进入管理员或者普通用户模式 if (UserModeChanged != null) { CSystemInfoMgr.Instance.AddInfo(string.Format("用户{0}登录,权限:{1}", username, bAdministrator ? "管理员" : "普通用户")); UserModeChanged.Invoke(this, new CEventSingleArgs <bool>(bAdministrator)); } this.Close(); return; } } #pragma warning disable CS0168 // 声明了变量“exp”,但从未使用过 catch (Exception exp) { } #pragma warning restore CS0168 // 声明了变量“exp”,但从未使用过 // 登陆失败,显示提示信息 label_Info.Visible = true; label_Info.Text = "用户名或密码错误!"; }
private void Listener_OnUserModeChange(object sender, UserModeChangeEventArgs e) { UserModeChanged?.Invoke(this, e); foreach (KeyValuePair <string, Channel> item in _channels) { Connection.Sender.Names(item.Key); } }