Example #1
0
        //获取加群请求
        private void getGroupRequest(WebServiceMessage.Messages msg)
        {
            object       obj    = msg.Details;
            DialogResult result = MessageBox.Show(string.Format("用户{0}请求加入{1}群,是否同意?", msg.Sender, msg.Details), "请求", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            WsMessage.HandleGroupRequst(currentUsername, result == DialogResult.Yes, msg.Sender, msg.Details);;
        }
Example #2
0
        //获取文件
        private void GetFile(WebServiceMessage.Messages msg)
        {
            DialogResult dr = MessageBox.Show("好友" + msg.Sender + "给你发来一个文件(" + msg.FileFullName +
                                              ",Size:" + msg.Details.Length + "Byte.)。\r\n是否接受该文件?",
                                              "接收文件", MessageBoxButtons.YesNo);

            //如果用户不接受该文件,放弃本次文件传递
            if (dr != DialogResult.Yes)
            {
                return;
            }

            //设置文件名称
            string filename = this.GetNewFilename(msg.FileFullName);

            byte[] fileContent = ConvertStringAndBytes.ConvertStringToBytes(msg.Details);
            //创建一个文件流对象,并初始化
            FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);

            //向文件流中写入内容
            fs.Write(fileContent, 0, fileContent.Length);

            //关闭流
            fs.Close();
        }
Example #3
0
        //点击发送按钮的Click事件
        private void btnSend_Click(object sender, EventArgs e)
        {
            string content           = this.txtMessage.Text.Trim();
            object targetUsersOnline = this.lstOnline.SelectedItem;

            if (content == string.Empty)
            {
                return;
            }
            //与好友聊天

            if (targetUsersOnline == null)
            {
                MessageBox.Show("请选择好友!");
                return;
            }

            WebServiceMessage.Messages msg = new WebServiceMessage.Messages();
            msg.Classify = 1;
            msg.Details  = content;
            msg.Receiver = targetUsersOnline.ToString();

            WsMessage.SendMessage(msg);

            //将发送的消息加入列表
            string message = "我对" + msg.Receiver + "说:\r\n" + msg.Details;

            this.AddMessageToList(message);

            //清空文本框
            this.txtMessage.Text = string.Empty;
        }
Example #4
0
        //获取好友请求
        private void GetFriendRequest(WebServiceMessage.Messages msg)
        {
            DialogResult result = MessageBox.Show("用户" + msg.Sender +
                                                  "请求添加你为好友,是否同意?", "好友请求",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            WsMessage.HandleFriendRequst(result == DialogResult.Yes, msg.Sender);
        }
Example #5
0
        //获取群请求回应
        private void getGroupResponse(WebServiceMessage.Messages msg)
        {
            if (msg.Classify == 7)
            {
                MessageBox.Show("用户" + msg.Sender + " 同意了你的添加群{0}请求。", msg.Details);
            }
            else
            {
                MessageBox.Show("用户" + msg.Sender + " 拒绝了你的添加群{0}请求。", msg.Details);
            }

            //刷新好友列表
            this.RefreshAllListBox();
        }
Example #6
0
        //获取好友请求响应
        private void GetFriendResponse(WebServiceMessage.Messages msg)
        {
            if (msg.Classify == 4)
            {
                MessageBox.Show("用户" + msg.Sender + " 同意了你的添加请求。");
            }
            else
            {
                MessageBox.Show("用户" + msg.Sender + " 拒绝了你的添加请求。");
            }

            //刷新好友列表
            this.RefreshFriendList();
        }
Example #7
0
        //将消息加入列表
        private void btnFayan_Click(object sender, EventArgs e)
        {
            string content = this.txtfayan.Text.Trim();


            object targetGroup        = this.list1.SelectedItem; //获取选正的群
            object targetGroupMembers = this.listBox1.Items;     //获取群中所有成员



            if (content == string.Empty)
            {
                return;
            }

            {
                string groupName = targetGroup.ToString();

                if (groupName == null)
                {
                    MessageBox.Show("聊天请先请选择好友或群");
                }
                WebServiceMessage.Messages msg = new WebServiceMessage.Messages();
                msg.Classify = 0;
                msg.Details  = string.Format(content + "[{0}群消息]", groupName);

                foreach (string drv in this.listBox1.Items)
                {
                    msg.Receiver = drv.ToString();
                    WsMessage.SendMessageQun(msg);
                }

                ////将发送的消息加入列表
                //string message = "我说:\r\n" + msg.Details;
            }

            //清空文本框
            this.txtfayan.Text = string.Empty;
        }
Example #8
0
        private void SendFile(string filename, string target)
        {
            //创建一个文件流对象
            FileStream fs = new FileStream(filename, FileMode.Open);

            //创建一个二进制组
            byte[] bs = new byte[fs.Length];

            //从文件流中读出内容
            fs.Read(bs, 0, bs.Length);

            //关闭流
            fs.Close();

            //初始化Messages对象
            WebServiceMessage.Messages msg = new WebServiceMessage.Messages();
            msg.Classify     = 2;
            msg.Details      = ConvertStringAndBytes.ConvertBytesToString(bs);
            msg.Receiver     = target;
            msg.FileFullName = filename.Substring(filename.LastIndexOf("\\"));

            //执行发送操作
            WsMessage.SendFile(msg);
        }
Example #9
0
        private void GetMessagequn(WebServiceMessage.Messages msg)
        {
            string m = msg.Sender + "说:\r\n" + msg.Details;

            this.AddMessageToListQun(m);
        }