コード例 #1
0
ファイル: MainForm.cs プロジェクト: oneflyingfish/MessageBird
        /// <summary>
        /// 登录事件
        /// </summary>
        /// <param name="o"></param>
        private void SignInForm_FinishSignIn(object o, string account)
        {
            //初始界面为消息界面
            this.DownForm.MessageGroupBox.PerformClick();
            //初始化主界面
            this.UpForm.EmailLabel.Text = account;
            UserInformation.Account     = account;

            //初始化昵称???云请求
            FunctionWords functionWordsForUserName = this.SendNewsAndReceiveAnswer(FunctionKind.SeekForUserName, account, "", null);

            if (functionWordsForUserName != null && functionWordsForUserName.stringList.Count > 0)
            {
                this.UpForm.UserNameLabel.Text = functionWordsForUserName.stringList[0];
                UserInformation.UserName       = functionWordsForUserName.stringList[0];
            }

            //初始化图像???云请求
            FunctionWords functionWordsForImage = this.SendNewsAndReceiveAnswer(FunctionKind.SeekForImage, account, "", null);

            if (functionWordsForImage != null && functionWordsForImage.bitmapList.Count > 0)
            {
                this.UpForm.UserImagePictureBox.BackgroundImage = functionWordsForImage.bitmapList[0];
                UserInformation.Image = functionWordsForImage.bitmapList[0];
            }

            //初始化主窗体
            init();

            CommonEvent.AddNewFriendEvent           += CommonEvent_AddNewFriendEvent;
            CommonEvent.AddNewGroupEvent            += CommonEvent_AddNewGroupEvent;
            CommonEvent.AddNewMessageEvent          += CommonEvent_AddNewMessageEvent;
            CommonEvent.OnlineChangeEvent           += CommonEvent_OnlineChangeEvent;
            CommonEvent.AnswerApplyToAddFriendEvent += CommonEvent_AnswerApplyToAddFriendEvent;
            CommonEvent.AnswerApplyToAddGroupEvent  += CommonEvent_AnswerApplyToAddGroupEvent;

            //向服务器声明自己
            CallServer.AddSendNews(MessageProtocol.GetStartBytes(FunctionKind.DeclareConnect), MessageBirdCommon.UserInformation.Account.ToTxtBytes(), MessageProtocol.GetEndBytes());

            //模拟好友/群聊消息接收
            RunVirtualMessage();
        }
コード例 #2
0
        /// <summary>
        /// 执行注册操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RunButton_Click(object sender, EventArgs e)
        {
            //初步判断邮箱符合规则
            if (!this.EmailAccount.Text.Contains("@"))
            {
                MessageBox.Show("请输入合法的邮箱", "账户不符合规则");
                return;
            }

            //确认昵称符合规则
            if (this.NameTextBox.Text == "" || this.NameTextBox.Text.Contains(" ") || this.NameTextBox.Text.Contains("|") || this.NameTextBox.Text.Contains(@"\"))
            {
                MessageBox.Show(@"昵称不能为空,且不能含有空格、|、\", "信息不符合规则");
                return;
            }

            //确认密码符合规则
            if (this.Password1.Text != this.Password2.Text)
            {
                MessageBox.Show("您两次输入的密码不一致,请重试", "密码不符合规则");
                return;
            }

            if (!File.Exists(ImagePathTextBox.Text) || (!ImagePathTextBox.Text.EndsWith(".jpg") && !ImagePathTextBox.Text.EndsWith(".png")))
            {
                MessageBox.Show("请选择可用的图像,建议为正方形", "图像不符合规则");
                return;
            }
            //确认验证码
            if (this.ConfigString == "" || this.ConfigString != this.ConfigTextBox.Text)
            {
                MessageBox.Show("验证码错误,请重新填写验证码", "系统消息");
                return;
            }
            //与服务器通信,修改参数
            //账户:EmailAccount.Text
            //昵称:NameTextBox.Text
            //密码:Password1.Text
            CallServer.AddSendNews(MessageProtocol.GetStartBytes(FunctionKind.RequestToRegeditAccount), EmailAccount.Text.ToTxtBytes(), NameTextBox.Text.ToTxtBytes(), Password1.Text.ToTxtBytes(), MessageProtocol.GetEndBytes());
            MessageBox.Show("修改成功", "系统消息");
        }
コード例 #3
0
        /// <summary>
        /// 发送请求
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sendbutton_Click(object sender, EventArgs e)
        {
            if (this.sendbutton.Text == "发送请求")
            {
                switch (currentFunction)
                {
                case FunctionChoice.AddFriend:
                    if (!this.accountTextbox.Text.EndsWith(".com") || this.accountTextbox.Text == "")
                    {
                        MessageBox.Show("请输入正确的好友邮箱");
                        return;
                    }

                    //云验证账户,并请求昵称???
                    FunctionWords functionWordsForFriendUserName = this.SendNewsAndReceiveAnswer(FunctionKind.SeekForUserName, this.accountTextbox.Text, "", null);
                    if (functionWordsForFriendUserName != null && functionWordsForFriendUserName.stringList.Count > 0)
                    {
                        this.userNameTextBox.Text = functionWordsForFriendUserName.stringList[0];
                        this.showBusyLabel.Text   = "已返回昵称,请确认";
                        break;
                    }
                    this.showBusyLabel.Text = "账户不存在";
                    return;

                case FunctionChoice.AddToGroup:
                    if (this.accountTextbox.Text.EndsWith(".com") || this.accountTextbox.Text == "")
                    {
                        MessageBox.Show("请输入正确的群号");
                        return;
                    }

                    //云验证账户,并请求昵称???
                    FunctionWords functionWordsForGroupUserName = this.SendNewsAndReceiveAnswer(FunctionKind.SeekForUserName, this.accountTextbox.Text, "", null);
                    if (functionWordsForGroupUserName != null && functionWordsForGroupUserName.stringList.Count > 0)
                    {
                        this.userNameTextBox.Text = functionWordsForGroupUserName.stringList[0];
                        this.showBusyLabel.Text   = "已返回昵称,请确认";
                        break;
                    }
                    this.showBusyLabel.Text = "账户不存在";
                    return;

                case FunctionChoice.CreateGroup:
                    if (this.userNameTextBox.Text == "")
                    {
                        MessageBox.Show("请输入正确的昵称");
                        return;
                    }

                    //云请求群号,返回群号???
                    FunctionWords functionWordsForCreateGroup = this.SendNewsAndReceiveAnswer(FunctionKind.SeekForNewGroupAccount, "", "", null);
                    if (functionWordsForCreateGroup != null && functionWordsForCreateGroup.stringList.Count > 0)
                    {
                        this.accountTextbox.Text = functionWordsForCreateGroup.stringList[0];
                        this.showBusyLabel.Text  = "已返回群号,请确认";
                        break;
                    }
                    this.showBusyLabel.Text = "服务器异常,请稍后重试";
                    return;

                default:
                    return;
                }
                this.sendbutton.Text = "确认";
            }
            else if (this.sendbutton.Text == "确认")
            {
                if (this.userNameTextBox.Text == "" || this.accountTextbox.Text == "")
                {
                    MessageBox.Show("错误: 似乎存在信息不完整,请重试");
                    this.sendbutton.Text = "发送请求";
                    return;
                }

                switch (currentFunction)
                {
                case FunctionChoice.AddFriend:
                    //发送请求???
                    CallServer.AddSendNews(MessageProtocol.GetStartBytes(FunctionKind.ApplyToAddFriend), MessageBirdCommon.UserInformation.Account.ToTxtBytes(), MessageBirdCommon.UserInformation.UserName.ToTxtBytes(), this.accountTextbox.Text.ToTxtBytes(), MessageProtocol.GetEndBytes());
                    break;

                case FunctionChoice.AddToGroup:
                    //发送请求???
                    CallServer.AddSendNews(MessageProtocol.GetStartBytes(FunctionKind.ApplyToAddGroup), MessageBirdCommon.UserInformation.Account.ToTxtBytes(), MessageBirdCommon.UserInformation.UserName.ToTxtBytes(), this.accountTextbox.Text.ToTxtBytes(), MessageProtocol.GetEndBytes());
                    break;

                case FunctionChoice.CreateGroup:
                    //发送请求???
                    MessageBox.Show("请选择小于30KB的png图片");
                    OpenFileDialog fileDialog = new OpenFileDialog();
                    DialogResult   result     = fileDialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        FileInfo fileInfo = new FileInfo(fileDialog.FileName);
                        double   length   = Convert.ToDouble(fileInfo.Length);
                        if (!fileInfo.FullName.ToLower().EndsWith(".png") || (fileInfo.Length > 31457280))
                        {
                            MessageBox.Show("目前仅支持小于30KB的png图像");
                            return;
                        }
                        Bitmap image = new Bitmap(Image.FromFile(fileDialog.FileName));
                        CallServer.AddSendNews(MessageProtocol.GetStartBytes(FunctionKind.RequestToRegeditGroup), MessageBirdCommon.UserInformation.Account.ToTxtBytes(), MessageBirdCommon.UserInformation.UserName.ToTxtBytes(), this.accountTextbox.Text.ToTxtBytes(), image.ToImageBytes(), MessageProtocol.GetEndBytes());
                    }
                    else
                    {
                        return;
                    }
                    break;

                default:
                    return;
                }
                MessageBox.Show("申请信息已发出");
                this.sendbutton.Text = "发送请求";
            }
        }