示例#1
0
        private bool search_account(string search_account, out string outStr)
        {
            string sendString = (int)CMD.CMD_FIND_ACCOUNTS + ";" + login_account + ";" + search_account;
            int    cmd        = (int)CMD.CMD_FIND_ACCOUNTS;

            lock (parent.getCmdLock(cmd))
            {
                byte[] bs = Encoding.UTF8.GetBytes(sendString); //把字符串编码为字节
                mySocket.Send(bs, bs.Length, 0);                //lock and then send buffer
                bool noTimeOut = Monitor.Wait(parent.getCmdLock(cmd), 5000);
                if (noTimeOut)
                {
                    if (parent.getReplyMessage(cmd).getReply() == (int)REPLY.REPLY_OK)
                    {
                        outStr = parent.getReplyMessage(cmd).getMsg();
                        return(true);
                    }
                    else
                    {
                        label_state.Text      = "搜索发生错误";
                        label_state.ForeColor = Color.Red;
                        outStr = "";
                    }
                }
                else
                {
                    label_state.Text      = "搜索超时";
                    label_state.ForeColor = Color.Red;
                    outStr = "";
                }
            }

            return(false);
        }
示例#2
0
        private void button_login_Click(object sender, EventArgs e)
        {
            string account  = textbox_account.Text.Trim();
            string password = textbox_password.Text.Trim();

            if (mySocket.Connected)
            {
                if (account.Length == 0)
                {
                    MessageBoxEx.Show("账号不能为空");
                    return;
                }
                if (password.Length == 0)
                {
                    MessageBoxEx.Show("密码不能为空");
                    return;
                }

                string sendString = (int)CMD.CMD_ACCOUNT_LOGIN + ";" + account + ";" + password;
                int    cmd        = (int)CMD.CMD_ACCOUNT_LOGIN;

                //send buffer to server
                lock (myParent.getCmdLock(cmd))
                {
                    byte[] bs = Encoding.UTF8.GetBytes(sendString); //把字符串编码为字节
                    mySocket.Send(bs, bs.Length, 0);                //lock and then send buffer
                    bool noTimeOut = Monitor.Wait(myParent.getCmdLock(cmd), 5000);
                    if (noTimeOut)
                    {
                        if (myParent.getReplyMessage(cmd).getReply() == (int)REPLY.REPLY_OK)
                        {
                            login_account     = account;
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                        }
                        else if (myParent.getReplyMessage(cmd).getReply() == (int)REPLY.REPLY_ERROR_ACCOUNT)
                        {
                            MessageBoxEx.Show("未注册的账号");
                        }
                        else if (myParent.getReplyMessage(cmd).getReply() == (int)REPLY.REPLY_ERROR_PASSWORD)
                        {
                            MessageBoxEx.Show("密码错误");
                        }
                        else
                        {
                            MessageBoxEx.Show("发生未知错误");
                        }
                    }
                    else
                    {
                        MessageBoxEx.Show("登录超时");
                    }
                }
            }
            else
            {
                MessageBoxEx.Show("无法连接服务器");
            }
        }
示例#3
0
        private void button_checkAccount_Click(object sender, EventArgs e)
        {
            bool valid = checkStringValid(textBox_account.Text, label_account);

            if (!valid)
            {
                return;
            }

            //check account
            string sendString = (int)CMD.CMD_CHECK_ACCOUNT + ";" + textBox_account.Text;
            int    cmd        = (int)CMD.CMD_CHECK_ACCOUNT;

            //send buffer to server
            lock (myParent.getCmdLock(cmd))
            {
                byte[] bs = Encoding.UTF8.GetBytes(sendString); //把字符串编码为字节
                mySocket.Send(bs, bs.Length, 0);                //lock and then send buffer
                bool noTimeOut = Monitor.Wait(myParent.getCmdLock(cmd), 5000);
                if (noTimeOut)
                {
                    if (myParent.getReplyMessage(cmd).getReply() == (int)REPLY.REPLY_OK)
                    {
                        label_account.Text      = "账号可用";
                        label_account.ForeColor = Color.Green;
                    }
                    else if (myParent.getReplyMessage(cmd).getReply() == (int)REPLY.REPLY_ERROR_ACCOUNT)
                    {
                        label_account.Text      = "账号已被注册,请更换";
                        label_account.ForeColor = Color.Red;
                    }
                    else
                    {
                        label_account.Text      = "未知错误";
                        label_account.ForeColor = Color.Red;
                    }
                }
                else
                {
                    label_account.Text      = "查询超时,服务器异常";
                    label_account.ForeColor = Color.Red;
                }
            }
        }