Exemplo n.º 1
0
        private void btnSendMessage_Click(object sender, RoutedEventArgs e) //发送消息
        {
            if (sendmsg.Text == string.Empty)
            {
                MessageBox.Show("消息不能为空");
                return;
            }
            GroupMessage message = new GroupMessage();

            message.Content  = sendmsg.Text;
            message.Userid   = msgsender.Id;
            message.Groupid  = group.Id;
            message.Sendtype = 4;
            message.Sendtime = DateTime.Now;
            message.Sendfile = null;
            GroupMessageBLL bLL = new GroupMessageBLL();

            if (!bLL.SendMessage(message))
            {
                MessageBox.Show("服务器异常");
            }
            else
            {
                string msg = "\n" + msgsender.Name + "    " + message.Sendtime.ToString() + "\n" + message.Content + "\n";
                ShowMessage.AppendText(msg);
                sendmsg.Text = "";
                ShowMessage.ScrollToEnd();
                msgscroll.ScrollToEnd();
            }
        }
Exemplo n.º 2
0
        private void btnSendFile_Click(object sender, RoutedEventArgs e) //发送群文件
        {
            OpenFileDialog  op     = new OpenFileDialog();
            Nullable <bool> result = op.ShowDialog();

            if (result == true)
            {
                string filename = op.FileName;
                sendmsg.Text = filename;
                FileStream fs       = new FileStream(@filename, FileMode.Open, FileAccess.Read);
                long       FileSize = fs.Length;
                byte[]     rawData  = new byte[FileSize];
                fs.Read(rawData, 0, (int)FileSize);
                fs.Close();
                GroupMessage message = new GroupMessage();
                message.Content  = sendmsg.Text;
                message.Userid   = msgsender.Id;
                message.Groupid  = group.Id;
                message.Sendtype = 6;
                message.Sendtime = DateTime.Now;
                message.Sendfile = rawData;
                GroupMessageBLL bLL = new GroupMessageBLL();
                if (!bLL.SendMessage(message))
                {
                    MessageBox.Show("服务器异常");
                }
                else
                {
                    string strArr = message.Content.Substring(message.Content.LastIndexOf('\\') + 1);
                    string fname  = ".\\groupfile\\" + strArr;
                    string msg    = "\n" + msgsender.Name + "    " + message.Sendtime.ToString() + "\n" + "文件: " + fname + "\n";
                    ShowMessage.AppendText(msg);
                    sendmsg.Text = "";
                    ShowMessage.ScrollToEnd();
                    msgscroll.ScrollToEnd();
                }
            }
        }