/// <summary> /// 刷新在线用户 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void picRefresh_Click(object sender, EventArgs e) { this.cmbOnlieClient.Items.Clear(); foreach (var item in fastPrintNetClient.GetOnlineClientsInfo()) { this.cmbOnlieClient.Items.Add(item.UserID); } if (this.cmbOnlieClient.Items.Count > 0) { this.cmbOnlieClient.SelectedIndex = 0; } }
private void btnLogin_Click(object sender, EventArgs e) { string msg = string.Empty; Thread tdLogining = new Thread(() => { try { this.BeginInvoke(new MethodInvoker(() => { this.btnLogin.Enabled = false; })); string _LoginID = string.Empty; string _Password = string.Empty; //验证登录框信息 if (VerifyInputTextBoxAreEmpty(out msg)) { WriteToolStripMsg(msg, Color.Red); return; } //获取控件上输入的登录用户和密码 _LoginID = this.txtUserName.Text.Trim(); _Password = this.txtPwd.Text.Trim(); WriteToolStripMsg("登录中,请等待..."); string message = string.Empty; //获取服务端的所有在线客户端 var onlineClients = fastPrintNetClient.GetOnlineClientsInfo(); //若登录用户存在,表示已登录 if (onlineClients.ConvertToEntityList <OnlineClient>().Exists(s => s.UserID.ToLower() == _LoginID.ToLower())) { message = string.Format("账号[{0}]已经登录,不能重复登录!", _LoginID); WriteToolStripMsg(message, Color.Red); } else { if (_LoginID == _Password)//这里是模拟的登录方式 { GlobalStatic.UserId = _LoginID; this.DialogResult = DialogResult.OK; } else { message = "账号或密码不正确"; WriteToolStripMsg(message, Color.Red); } } } finally { if (this.IsHandleCreated)//指示控件是否有与他关联的句柄,如果已经为控件分配了句柄,则为 true;否则为 false。 { this.BeginInvoke(new MethodInvoker(() => { this.btnLogin.Enabled = true; })); } } }); tdLogining.IsBackground = true; tdLogining.Start(); }