Exemple #1
0
        internal FormTalkUser(IMLibrary3.Organization.User User)
        {
            InitializeComponent();
            this.FormClosing += new FormClosingEventHandler(FormTalkUser_FormClosing);
            tsButSendFile.Click += new EventHandler(tsButSendFile_Click);
            tsButAV.Click += new EventHandler(tsButAV_Click);
            video1.Cancel += new OurMsg.Controls.video.CancelEventHandler(video1_Cancel);
            video1.GetIPEndPoint +=new OurMsg.Controls.video.GetIPEndPointEventHandler(video1_GetIPEndPoint);
            flowLayoutPanel1.ControlAdded += new ControlEventHandler(flowLayoutPanel1_ControlAdded);
            flowLayoutPanel1.ControlRemoved += new ControlEventHandler(flowLayoutPanel1_ControlRemoved);
            this.butClose.Click +=new EventHandler(butClose_Click);
            this.butSend.Click +=new EventHandler(butSend_Click);

            this.MessagePanel1.CreateMsgAfter += new OurMsg.Controls.MessagePanel.CreateMsgEventHandler(MessagePanel1_CreateMsgAfter);
            this.MessagePanel1.DragDrop += new DragEventHandler(MessagePanel1_DragDrop);
            this.MessagePanel1.DragEnter += new DragEventHandler(MessagePanel1_DragEnter);
            this.MessagePanel1.SendFile += delegate(object sender, string filename) { sendFile(filename); };
            this.Tag = User.UserID;
            this.User = User; 
        } 
Exemple #2
0
        /// <summary>
        /// 将消息加入 RichTextBox 控件
        /// </summary>
        /// <param name="msg">消息类</param>
        /// <param name="IsSend">标记是发送消息还是收到消息</param>
        public void MsgToRichTextBox(IMLibrary3.Protocol.Message msg, bool IsSend)//将发送的消息加入历史rich
        {
            string title =myUserName  +"(" + myUserID + ")";
            if (!IsSend)
                title = User.UserName + "(" + User.UserID + ")";

            this.MessagePanel1.MsgToRichTextBox(msg, IsSend, title);
        }
Exemple #3
0
 //联接事件
 private void frameTransmit_TransmitConnected(object sender, IMLibrary3.ConnectedType connectedType)
 {
     OnTransmitConnected(connectedType);//触发联系事件
 }
Exemple #4
0
        /// <summary>
        /// 将用户对话消息加入 RichTextBox 控件
        /// </summary>
        /// <param name="msg">消息类</param>
        /// <param name="IsSend">标记是发送消息还是收到消息</param>
        private void MsgToRichTextBox(IMLibrary3.Protocol.Message msg, bool IsSend)//将发送的消息加入历史rich
        {
            string title = myUserName + "(" +myUserID + ")";
      

            MsgToRichTextBox(msg, IsSend, title);
        }
Exemple #5
0
 /// <summary>
 /// 发送数据
 /// </summary>
 /// <param name="e">IMLibrary3.Protocol.Element</param>
 public void Write(IMLibrary3.Protocol.Element e)
 {
     this.Write(IMLibrary3.Protocol.Factory.CreateXMLMsg(e));
 }
Exemple #6
0
        /// <summary>
        /// 联系人更改状态
        /// </summary>
        /// <param name="pres"></param>
        public void onPresence(IMLibrary3.Protocol.Presence pres)
        {
            //查找联系人列表中是否存在此联系人,如果存在,则更新状态信息
            exUser user = findUser(pres.from );
            if (user != null)
            {
                user.Status = pres.Status;
                user.ShowType = pres.ShowType;

                if (user.UserID == MyAuth.UserID)
                {
                    MyAuth.ShowType = user.ShowType;
                    MyAuth.UserName = user.UserName;
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// 开始登录 
        /// </summary>
        /// <param name="auth">登录用户参数</param>
        /// <param name="IsOutTime">是否超时时钟重复的登录</param>
        public void Login(IMLibrary3.Protocol.Auth auth, bool IsOutTime)
        {
            if (myPassword!="")//如果已经登录成功过
                auth.Password = myPassword;//将正确的密码设置为登录密码

            MyAuth = auth;//暂存自己的登录信息于内存

            if (tcpClient == null || tcpClient.IsDisposed)
            {
                tcpClient = new TCPClient();
                tcpClient.PacketReceived += new TCP_Client.PacketReceivedEventHandler(tcpClient_PacketReceived);
                tcpClient.Disonnected += new EventHandler(tcpClient_Disonnected);
            }
            if (!tcpClient.IsConnected)
                tcpClient.Connect(Global.ServerDomain,Global.ServerMsgPort);

            if (!this.timerLogin1.Enabled)
                this.timerLogin1.Enabled = true;

            SendMessageToServer(auth);//向服务器登录
        }
Exemple #8
0
 /// <summary>
 /// 收到用户对话消息
 /// </summary>
 private void OnUserMessage(IMLibrary3.Protocol.Message msg,exUser user)
 {
     FormTalkUser fs = GetUserMsgForm(user);
     fs.MsgToRichTextBox(msg, false);
     fs.Show();
     fs.Activate();
 }
Exemple #9
0
 private void ShowType1_ShowTypeChanged(object sender, IMLibrary3.Controls.ShowType.ShowTypeEventArgs e)
 {
     this.controlPanel1.setMyPresence(e.ShowType);
 }
Exemple #10
0
        /// <summary>
        /// 将用户对话消息加入 RichTextBox 控件
        /// </summary>
        /// <param name="msg">消息类</param>
        /// <param name="IsSend">标记是发送消息还是收到消息</param>
        /// <param name="title">标题(用户名+用户ID)</param>
        public void MsgToRichTextBox(IMLibrary3.Protocol.Message msg, bool IsSend, string title)//将发送的消息加入历史rich
        {
            int iniPos = txtRecord.TextLength;//获得当前记录richBox中最后的位置
            title += System.DateTime.Now.ToString();
            Color titleColor = Color.Red;

            if (!IsSend)//如果是收到消息
                titleColor = Color.Blue;
          

            txtRecord.AppendText(title);
            txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
            txtRecord.SelectionFont = new Font("宋体", 10);
            txtRecord.SelectionColor = titleColor;

            txtRecord.AppendText("\n  ");

            iniPos = txtRecord.TextLength;//获得当前记录richBox中最后的位置

            #region //如果消息中有图片,则添加图片
            if (msg.ImageInfo != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = msg.ImageInfo.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称 
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    txtRecord.AppendText(msg.Content.Substring(textPos, currPos - addPos));
                    txtRecord.SelectionStart = txtRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image = null;
                    if (IsSend)//如果图片是自己发送给自己的
                    {
                        image = txtSend.GetPicture(imageContent[1]).Image;
                    }
                    else//如果图片是对方发送过来的
                    {
                        if (txtRecord.GetPicture(imageContent[1]) != null)
                            image = txtRecord.GetPicture(imageContent[1]).Image;
                        else
                        {
                            string fileName = myUserID + "\\ArrivalImage\\" + imageContent[1] + ".gif";
                            if (System.IO.File.Exists(fileName)) //如果本地已经有此文件已经存在 
                                image = System.Drawing.Image.FromFile(fileName);
                        }

                        if (imageContent[1].Length < 32 && image == null)
                            image = System.Drawing.Image.FromFile(Application.StartupPath + @"\face\" + imageContent[1] + ".gif");
                    }
                    if (image == null)
                    {
                        image = OurMsg.Properties.Resources.Wait ;
                        IMLibrary3.MyPicture pic = txtRecord.addGifControl(imageContent[1], image);
                        needRecPictures.Add(pic);
                    }
                    else
                    {
                        txtRecord.addGifControl(imageContent[1], image);
                    }

                    addPos++;
                }
                this.txtRecord.AppendText(msg.Content.Substring(textPos, msg.Content.Length - textPos) + "  \n");
            }
            #endregion

            #region  //如果消息中没有图片,则直接添加消息文本
            else//如果消息中没有图片,则直接添加消息文本
            {
                txtRecord.AppendText(msg.Content + "\n");
            }
            #endregion

            txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
            txtRecord.SelectionFont = msg.Font;
            txtRecord.SelectionColor = msg.Color;

            txtRecord.Select(txtRecord.TextLength, 0);
            txtRecord.ScrollToCaret();
        }
Exemple #11
0
 /// <summary>
 /// 设置对方视频位图信息,以便构造解码器
 /// </summary>
 /// <param name="msg"></param>
 public void SetVideoBitmapinfo(IMLibrary3.Protocol.AVMsg msg)
 {
     IMLibrary.AV.BITMAPINFO bitmapinfo = new IMLibrary.AV.BITMAPINFO();
     bitmapinfo.bmiHeader.biBitCount = msg.biBitCount;
     bitmapinfo.bmiHeader.biClrImportant = msg.biClrImportant;
     bitmapinfo.bmiHeader.biClrUsed = msg.biClrUsed;
     bitmapinfo.bmiHeader.biCompression = msg.biCompression;
     bitmapinfo.bmiHeader.biHeight = msg.biHeight;
     bitmapinfo.bmiHeader.biPlanes = msg.biPlanes;
     bitmapinfo.bmiHeader.biSize = msg.biSize;
     bitmapinfo.bmiHeader.biSizeImage = msg.biSizeImage;
     bitmapinfo.bmiHeader.biWidth = msg.biWidth;
     bitmapinfo.bmiHeader.biXPelsPerMeter = msg.biXPelsPerMeter;
     bitmapinfo.bmiHeader.biYPelsPerMeter = msg.biYPelsPerMeter;
     video1.SetVideoBitmapinfo(bitmapinfo);
 }
Exemple #12
0
 /// <summary>
 /// 设置视频对话远程主机信息
 /// </summary>
 public void setAVRometEP(IMLibrary3.Protocol.AVMsg msg)
 {
     video1.SetRometEP(new IPEndPoint(msg.LocalIP, msg.LocalPort), new IPEndPoint(msg.remoteIP, msg.remotePort));
 }
Exemple #13
0
 /// <summary>
 /// 设置文件传输远程主机信息
 /// </summary>
 public void setFileRometEP(IMLibrary3.Protocol.P2PFileMsg  pfile)
 {
     foreach (Control c in flowLayoutPanel1.Controls)
     {
         OurMsg.Controls.FileTransmit ft = c as OurMsg.Controls.FileTransmit;
         if (ft != null && ft.P2PFileTransmit.TFileInfo.MD5 == pfile.MD5)
         {
             ft.P2PFileTransmit.Start(true);//发送方参数须设置为真
             ft.P2PFileTransmit.setRemoteIP(new IPEndPoint(pfile.LocalIP ,pfile.LocalPort ),
                                            new IPEndPoint(pfile.remoteIP ,pfile.remotePort));//设置文件传输远程主机信息
              
         } 
     }
 }
Exemple #14
0
        /// <summary>
        /// 取消文件传输
        /// </summary>
        /// <param name="pfile"></param>
        public void CancelFile(IMLibrary3.Protocol.P2PFileMsg  pfile)
        {
            if (pfile.MD5 == "")
            {
                flowLayoutPanel1.Controls.Clear();
                MessagePanel1.addRemarkTextToRecord(" 对方取消了所有文件的传输!");
                return;
            }

            foreach (Control c in flowLayoutPanel1.Controls)
            {
                OurMsg.Controls.FileTransmit ft = c as OurMsg.Controls.FileTransmit;
                if (ft != null && (ft.P2PFileTransmit.TFileInfo.MD5 == pfile.MD5))
                {
                    ft.CancelTransmit();
                    MessagePanel1.addRemarkTextToRecord(" 对方取消了文件“" + ft.P2PFileTransmit.TFileInfo.Name + "”的传输!");
                    flowLayoutPanel1.Controls.Remove(ft);
                    ft.Dispose();
                    ft = null;
                }
            }
        }
Exemple #15
0
        /// <summary>
        /// 准备接收文件传输
        /// </summary>
        /// <param name="pfile"></param>
        public void ReceiveFile(IMLibrary3.Protocol.P2PFileMsg  pfile)
        {
            TFileInfo tFileInfo = new TFileInfo();
            tFileInfo.Name = pfile.Name;
            tFileInfo.Length = pfile.Length;
            tFileInfo.Extension = pfile.Extension;
            tFileInfo.MD5 = pfile.MD5;

            OurMsg.Controls.FileTransmit ft = new Controls.FileTransmit();
            ft.P2PFileTransmit = new p2pFileClient(Global.FileTransmitServerEP, tFileInfo);
            ft.fileTransmitCancel += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitCancel);
            ft.P2PFileTransmit.GetIPEndPoint += new FileTransmitBase.GetIPEndPointEventHandler(P2PFileTransmit_GetIPEndPoint);
            ft.fileTransmitted += new OurMsg.Controls.FileTransmit.fileTransmitEventHandler(ft_fileTransmitted);
            flowLayoutPanel1.Controls.Add(ft);
        }
Exemple #16
0
        /// <summary>
        /// 处理用户发送的对话消息 
        /// </summary>
        /// <param name="msg"></param>
        private void onMessage(IMLibrary3.Protocol.Message msg)
        {
            exUser user = findUser(msg.from);
            if (user == null) return;
            if (user.UserID == MyAuth.UserID) return;//如果是自己发送给自己的消息,则不处理

            OpeRecordDB.AddMsg(msg);//将消息添加到数据库

            if (msg.MessageType == IMLibrary3.Enmu.MessageType.User)//如果消息发送给用户
            {
                    OnUserMessage(msg,user);
            }
            else if (msg.MessageType == IMLibrary3.Enmu.MessageType.Group)//如果消息发送给群
            {
                OnGroupTalk(msg,user);
            }
            else if (msg.MessageType == IMLibrary3.Enmu.MessageType.Notice)//如果发送通知消息给多个用户
            {
                OnNoticeMsg(msg, user);
            }
            else if (msg.MessageType == IMLibrary3.Enmu.MessageType.broadcasting)//如果发送通知消息给所有用户
            {

            }
        }
Exemple #17
0
        /// <summary>
        /// 收到通知消息
        /// </summary>
        private void OnNoticeMsg(IMLibrary3.Protocol.Message msg,exUser user)
        {
            FormNotice fs = new FormNotice();
            fs.MsgToRichTextBox(msg, user);
            fs.Show();
          

        }
Exemple #18
0
 private void ShowType1_ShowTypeExitApp(object sender, IMLibrary3.Controls .ShowType.ShowTypeEventArgs e)
 {
     this.ExitApp();
 }
Exemple #19
0
        /// <summary>
        /// 收到群组对话消息
        /// </summary>
        private void OnGroupTalk(IMLibrary3.Protocol.Message Msg, exUser user)
        { 
            exRoom room = findRoom(Msg.to);//获得消息接收群
            if (room == null) return;

            FormTalkRoom fs = GetRoomMsgForm(room);
            fs.MsgToRichTextBox(Msg, false, user.UserName + "(" + user.UserID + ")");
            fs.Show();
        }
Exemple #20
0
        private void controlPanel1_UserLoginSuccessful(object sender, IMLibrary3.Protocol.Auth auth)
        {
            this.showNotifyIconMessage("上次登录IP:" + (auth.LastIP == null ? "" : auth.LastIP) + " \n上次登录时间:" + (auth.LastDateTime == null ? "" : auth.LastDateTime), "OurMsg 登录成功", 5000);
            this.notifyIcon1.Text ="OurMsg:"+ auth.UserName + "(" + auth.UserID + ")";
            this.labUserName.Text = auth.UserName + "(" + auth.UserID + ")";
            ShowType1.State = auth.ShowType;

            #region 删除登录进度效果显示面板
            this.Controls.Remove(this.userLoginPanel1);
            this.userLoginPanel1.Dispose();
            #endregion

            IsLogined = true;//标识当前用户已经登录过系统
        }
Exemple #21
0
        /// <summary>
        /// 设置登录用户在线状态
        /// </summary>
        /// <param name="showType"></param>
        public void setMyPresence(IMLibrary3.Enmu.ShowType showType)
        {
            if (showType == MyAuth.ShowType)//如果状态未做改变,则无需发送到服务器
                return;

            if (showType == IMLibrary3.Enmu.ShowType.Offline
                && (tcpClient != null && !tcpClient.IsDisposed && tcpClient.IsConnected)) //如果要下线
            {
                this.tcpClient.Disconnect();
                this.tcpClient.Dispose();
                this.tcpClient = null;
                return;
            }

            if (showType != IMLibrary3.Enmu.ShowType.Offline 
                && (tcpClient == null || tcpClient.IsDisposed || !tcpClient.IsConnected))//如果已经下线,则上线
            { 
                MyAuth.ShowType = showType;
                Login(MyAuth, true);//登录。。。 
                return;
            }

            Presence pre = new Presence();
            pre.from = MyAuth.UserID;
            pre.ShowType = showType;
            pre.type = type.set;//必须设置 set,以表示是设置,如果为get,则是获取所有联系人的状态
            SendMessageToServer(pre );
        }
Exemple #22
0
 /// <summary>
 /// 设置登录参数
 /// </summary>
 public void SetLoginParameter(IMLibrary3.Protocol.Auth auth)
 {
     this.auth = auth;
     cmbBoxUserID.Text = auth.UserID;
     txtPassword.Text = auth.Password;
     ShowType1.State = auth.ShowType;
     checkBoxSavePassword.Checked = auth.IsSavePassword;
     checkBoxAutoLogin.Checked = auth.IsAutoLogin;
 }
Exemple #23
0
 public ShowTypeEventArgs(IMLibrary3.Enmu.ShowType  ShowType,string ShowTypeString )
 {
     this.ShowType = ShowType;
     this.ShowTypeString = ShowTypeString;
 }
Exemple #24
0
        /// <summary>
        /// 获得消息集合
        /// </summary>
        /// <param name="MsgInfoClass">消息类型</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static List<IMLibrary3.Protocol.Message> GetMsg(IMLibrary3.Enmu.MessageType MessageType, int pageIndex, int pageSize)
        {
            List<IMLibrary3.Protocol.Message> Msgs = null;

            System.Data.SQLite.SQLiteParameter messageType = new System.Data.SQLite.SQLiteParameter("MessageType", MessageType);

            string sql = "select * from MsgRecord where MessageType=@MessageType "
                 + " order by ID limit " + pageSize.ToString() + " offset " + ((pageIndex - 1) * pageSize).ToString();

            System.Data.SQLite.SQLiteDataReader dr = SQLiteDBHelper.ExecuteReader(sql, messageType);

            if (dr != null)
            {
                Msgs = new List<IMLibrary3.Protocol.Message>();
                while (dr.Read())
                    Msgs.Add(GetDrMsg(dr));
            }
            dr.Close(); dr.Dispose();

            return Msgs;
        }
Exemple #25
0
        private void MessagePanel1_CreateMsgAfter(object sender, IMLibrary3.Protocol.Message Message)
        {
            Message.MessageType = IMLibrary3.Enmu.MessageType.Group;//消息类型为组对话
            Message.from = myUserID;
            Message.to   = Room.RoomID;//将群组编号存入Tag
            if (SendMsgToGroup != null)
                SendMsgToGroup(Message, Room);
            this.MsgToRichTextBox(Message, true);

            #region 发送截图
            List<IMLibrary3.MyPicture> pictures = MessagePanel1.GetSendPicture();
            if (pictures != null)//如果文件是截图
                foreach (IMLibrary3.MyPicture pic in pictures)
                    if (pic.MD5.Length == 32)
                    {
                        string fileName =myUserID  + "\\sendImage\\" + pic.MD5 + ".gif";
                        ImageFileClient tcpFile = new ImageFileClient(Global.ImageServerEP, fileName);//发送图片文件到服务器
                        tcpFile.fileTransmitted += delegate(object sender1, fileTransmitEvnetArgs e)
                        {
                            if (SendMsgToGroup != null)
                            {
                                IMLibrary3.Protocol.ImageFileMsg fileMsg = new IMLibrary3.Protocol.ImageFileMsg();
                                fileMsg.from = myUserID;
                                fileMsg.to = Room.RoomID;
                                fileMsg.MessageType = IMLibrary3.Enmu.MessageType.Group;
                                fileMsg.Name = "";
                                fileMsg.MD5 = e.fileInfo.MD5;
                                fileMsg.Extension = e.fileInfo.Extension;
                                fileMsg.Length = e.fileInfo.Length;
                                SendMsgToGroup(fileMsg, Room);
                            }
                            (sender1 as ImageFileClient).Dispose();
                            sender1 = null;
                        };
                    }
            #endregion

            this.MessagePanel1.ClearMsgTextBox();
        }
Exemple #26
0
       /// <summary>
       /// 添加消息
       /// </summary>
       public static void AddMsg(IMLibrary3.Protocol.Message Msg)
       {
           string sql = "insert into MsgRecord(froms,tos,MessageType,DateTime,Vcard)" +
                          "values(@froms,@tos,@MessageType,@DateTime,@Vcard)";
 
           System.Data.SQLite.SQLiteParameter[] parameters = new System.Data.SQLite.SQLiteParameter[]{   
                    new System.Data.SQLite.SQLiteParameter("@froms",Msg.from ),   
                    new System.Data.SQLite.SQLiteParameter("@tos",Msg.to ),   
                    new System.Data.SQLite.SQLiteParameter("@MessageType",Convert.ToByte( Msg.MessageType )),   
                    new System.Data.SQLite.SQLiteParameter("@DateTime",  Msg.DateTime==null?DateTime.Now.ToString():Msg.DateTime ),   
                    new System.Data.SQLite.SQLiteParameter("@Vcard",IMLibrary3.Protocol.Factory.CreateXMLMsg(Msg))  
                                      };
           try
           {
               SQLiteDBHelper.ExecuteNonQuery(sql, parameters);
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Source + ex.Message);
           }
       }
Exemple #27
0
 /// <summary>
 /// 将用户对话消息加入 RichTextBox 控件
 /// </summary>
 /// <param name="msg">消息类</param>
 /// <param name="IsSend">标记是发送消息还是收到消息</param>
 /// <param name="title">标题(用户名+用户ID)</param>
 public void MsgToRichTextBox(IMLibrary3.Protocol.Message msg, bool IsSend, string title)//将发送的消息加入历史rich
 {
     this.MessagePanel1.MsgToRichTextBox(msg, IsSend, title);
 }
Exemple #28
0
      /// <summary>
      /// 更新本地数据库组织机构版本信息
      /// </summary>
        public static void UpdateOrgVersion(IMLibrary3.Protocol.OrgVersion orgVersion)
        {
            try
            {
                if (orgVersion.RoomsVersion == null)
                    orgVersion.RoomsVersion = "";
                if (orgVersion.GroupsVersion == null)
                    orgVersion.GroupsVersion = "";
                if (orgVersion.UsersVersion== null)
                    orgVersion.UsersVersion = "";

                string sql = "update OrgVersion set Password='',GroupsVersion=@GroupsVersion,UsersVersion=@UsersVersion,RoomsVersion=@RoomsVersion";

                System.Data.SQLite.SQLiteParameter[] parameters = new System.Data.SQLite.SQLiteParameter[]{   
                     new System.Data.SQLite.SQLiteParameter("@GroupsVersion",orgVersion.GroupsVersion  ),   
                     new System.Data.SQLite.SQLiteParameter("@UsersVersion",orgVersion.UsersVersion ),   
                     new System.Data.SQLite.SQLiteParameter("@RoomsVersion",orgVersion.RoomsVersion ),   
                                       };
                SQLiteDBHelper.ExecuteNonQuery(sql, parameters);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Source + ex.Message);
            }
        }
Exemple #29
0
        /// <summary>
        /// 将用户对话消息加入 RichTextBox 控件
        /// </summary>
        /// <param name="msg">消息类</param>
        /// <param name="IsSend">标记是发送消息还是收到消息</param>
        public void MsgToRichTextBox(IMLibrary3.Protocol.Message  msg,  exUser user)//将发送的消息加入历史rich
        {
            int iniPos = txtRecord.TextLength;//获得当前记录richBox中最后的位置

            if (msg.Title!= "")
            {
                #region 添加标题
                txtRecord.AppendText(msg.Title);
                txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
                txtRecord.SelectionFont = new Font("宋体", 18);
                txtRecord.SelectionColor = msg.Color;
                txtRecord.SelectionAlignment = HorizontalAlignment.Center;
                txtRecord.AppendText("\n\n");
                #endregion
            }

            #region 添加内容
            iniPos = txtRecord.TextLength;//获得当前记录richBox中最后的位置

            #region //如果消息中有图片,则添加图片
            if (msg.ImageInfo != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = msg.ImageInfo.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称 
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    this.txtRecord.AppendText(msg.Content.Substring(textPos, currPos - addPos));
                    this.txtRecord.SelectionStart = this.txtRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image;

                    if (this.txtRecord.GetPicture (imageContent[1]) == null)
                        image = System.Drawing.Image.FromFile(Application.StartupPath + @"\face\" + imageContent[1] + ".gif");
                    else
                        image = this.txtRecord.GetPicture(imageContent[1]).Image;

                    this.txtRecord.addGifControl(imageContent[1], image);
                    addPos++;
                }
                this.txtRecord.AppendText(msg.Content.Substring(textPos, msg.Content.Length - textPos) + "  \n");
            }
            #endregion
            #region  //如果消息中没有图片,则直接添加消息文本
            else//如果消息中没有图片,则直接添加消息文本
            {
                txtRecord.AppendText(msg.Content + "\n");
            }
            #endregion
            txtRecord.Select(iniPos, this.txtRecord.TextLength - iniPos);
            txtRecord.SelectionFont = msg.Font;
            txtRecord.SelectionColor = msg.Color;
            txtRecord.SelectionAlignment = HorizontalAlignment.Left ;
            #endregion

            if (msg.remark != "")
            {
                #region 添加落款
                iniPos = txtRecord.TextLength;//获得当前记录richBox中最后的位置
                txtRecord.AppendText("\n" + msg.remark);
                txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
                txtRecord.SelectionFont = new Font("宋体", 13);
                txtRecord.SelectionColor = msg.Color;
                txtRecord.SelectionAlignment = HorizontalAlignment.Right;
                txtRecord.AppendText("\n  ");
                #endregion
            }


            iniPos = txtRecord.TextLength;//获得当前记录richBox中最后的位置
            txtRecord.AppendText("\n发送用户:"+ user.UserName +"("+user.UserID +")\n");
            txtRecord.AppendText("发送时间:" + System.DateTime.Now.ToString()+ "\n");
            txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
            txtRecord.SelectionFont = txtRecord.Font ;
            txtRecord.SelectionAlignment = HorizontalAlignment.Left ;

            txtRecord.Select(this.txtRecord.TextLength, 0);
        }
Exemple #30
0
        /// <summary>
        /// 更新群Card,无数据则添加
        /// </summary>
        /// <param name="RoomID"></param>
        /// <param name="e"></param>
        public static void UpdateRoomVcard(string RoomID, IMLibrary3.Protocol.Element e)
        {
            //string sql = "delete from RoomsVcard  ";

            string sql = "update RoomsVcard set Vcard=@Vcard where RoomID=@RoomID";
            System.Data.SQLite.SQLiteParameter[] parameters = new System.Data.SQLite.SQLiteParameter[]{   
                     new System.Data.SQLite.SQLiteParameter("@RoomID",RoomID ),   
                     new System.Data.SQLite.SQLiteParameter("@Vcard",IMLibrary3.Protocol.Factory.CreateXMLMsg(e))};
            if (SQLiteDBHelper.ExecuteNonQuery(sql, parameters) ==0)
            {
                sql = "insert into RoomsVcard(RoomID,Vcard) values(@RoomID,@Vcard)";
                SQLiteDBHelper.ExecuteNonQuery(sql, parameters);
            }
        }