Beispiel #1
0
 public DownloadFile(ChatFromMsg parent, FTPClient ftpClient)
 {
     this.parent = parent;
     this.ftpClient = ftpClient;
 }
Beispiel #2
0
 public UploadFile(ChatFromMsg parent)
 {
     this.parent = parent;
 }
Beispiel #3
0
        /// <summary>
        /// 聊天窗口打开事件
        /// </summary>
        /// <param name="sender"></param>
        public void listView_fd_OpenChatEvent(Friend sender)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new QQListViewEx.delegate_openChat(listView_fd_OpenChatEvent), new object[] { sender });
                return;
            }

            System.GC.Collect();

            //for (int i = 0; i < 50; i++)
            //{
            //    ChatFromMsg chat = new ChatFromMsg(sender.Ritem.Jid, XmppCon);
            //    chat.Show();
            //}

            if (!Util.ChatForms.ContainsKey(sender.Ritem.Jid.Bare))
            {
                try
                {
                    string nickName = listView_fd.GetFriendNickName(sender.Ritem.Jid.Bare);
                    ChatFromMsg chat = new ChatFromMsg(sender.Ritem.Jid, XmppCon, nickName);
                    chat.UpdateFriendOnline(sender.IsOnline);//设置好友在线状态
                    ChatMessageBox.GetInstance(this).RemoveFriend(sender.Ritem.Jid);
                    if (msgBox.ContainsKey(sender.Ritem.Jid.ToString()))
                    {
                        chat.FristMessage(msgBox[sender.Ritem.Jid.ToString()]);
                        msgBox.Remove(sender.Ritem.Jid.ToString());
                    }
                    chat.Show();
                    if (ChatMessageBox.GetInstance(this).FrienMessageCount() > 0)
                        Debug.WriteLine("?");
                    else
                    {
                        notifyIcon_MessageQueue.Icon = CSS.IM.UI.Properties.Resources.Iico;
                        timer_MessageAlert.Enabled = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }
            else
            {
                try
                {
                    ChatFromMsg chatform = Util.ChatForms[sender.Ritem.Jid.Bare] as ChatFromMsg;
                    chatform.WindowState = FormWindowState.Normal;
                    chatform.Activate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            System.GC.Collect();
        }
Beispiel #4
0
        public void XmppCon_OnIq(object sender, IQ iq)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new IqHandler(XmppCon_OnIq), new object[] { sender, iq });
                return;
            }

            if (iq != null)
            {
                if (iq.HasTag(typeof(CSS.IM.XMPP.protocol.extensions.si.SI)))
                {
                    if (iq.Type == IqType.set)
                    {
                        CSS.IM.XMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(CSS.IM.XMPP.protocol.extensions.si.SI)) as CSS.IM.XMPP.protocol.extensions.si.SI;

                        CSS.IM.XMPP.protocol.extensions.filetransfer.File file = si.File;
                        if (file != null)
                        {
                            if (!Util.ChatForms.ContainsKey(iq.From.Bare))//查看聊天窗口是否已经打开了
                            {
                                try
                                {
                                    Friend flfriend = listView_fd.Rosters[iq.From.Bare];
                                    string nickName = listView_fd.GetFriendNickName(iq.From.Bare);
                                    ChatFromMsg chatForm = new ChatFromMsg(iq.From, XmppCon, nickName);
                                    chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                    chatForm.Show();
                                    //chatForm.FileTransfer(iq);
                                    chatForm.Activate();
                                }
                                catch (Exception)
                                {

                                }
                            }
                            else
                            {

                            }

                        }
                    }
                }
                else
                {

                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// 通过消息盒子打开消息窗体
        /// </summary>
        /// <param name="friend"></param>
        /// <param name="sender"></param>
        /// <param name="CName"></param>
        void QQMainForm_OpenChatEvent(Friend friend, Jid sender, string CName)
        {
            RosterItem ritem = new RosterItem(sender);
            friend.Ritem = ritem;
            //throw new NotImplementedException();
            //friendListView_OpenChatEvent(friend);
            if (!Util.ChatForms.ContainsKey(friend.Ritem.Jid.Bare))
            {
                listView_fd.UpdateFriendFlicker(friend.Ritem.Jid.Bare);

                string nickName = listView_fd.GetFriendNickName(friend.Ritem.Jid.Bare);
                ChatFromMsg chat = new ChatFromMsg(friend.Ritem.Jid, XmppCon, nickName);

                Friend flfriend = listView_fd.Rosters[friend.Ritem.Jid.Bare];
                if (flfriend != null)
                {
                    chat.UpdateFriendOnline(flfriend.IsOnline);
                }

                if (msgBox.ContainsKey(friend.Ritem.Jid.Bare.ToString()))
                {
                    chat.FristMessage(msgBox[friend.Ritem.Jid.Bare.ToString()]);
                    msgBox.Remove(friend.Ritem.Jid.Bare.ToString());
                }
                chat.Show();
            }
            else
            {
                try
                {
                    ChatFromMsg chatform = Util.ChatForms[friend.Ritem.Jid.Bare] as ChatFromMsg;
                    chatform.WindowState = FormWindowState.Normal;
                    chatform.Activate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            if (ChatMessageBox.GetInstance(this).FrienMessageCount() > 0)
                Debug.WriteLine("?");
            else
            {
                notifyIcon_MessageQueue.Icon = CSS.IM.UI.Properties.Resources.Iico;
                timer_MessageAlert.Enabled = false;
            }
        }
Beispiel #6
0
        private void tsmi发送消息_Click(object sender, EventArgs e)
        {
            if (treeView_nt.SelectedNode == null)
                return;
            if (treeView_nt.SelectedNode.Tag == null)
                return;
            Jid j = new Jid(treeView_nt.SelectedNode.Tag.ToString(), XmppCon.Server, null);
            if (!Util.ChatForms.ContainsKey(j.Bare))
            {
                listView_fd.UpdateFriendFlicker(j.Bare);

                string nickName = listView_fd.GetFriendNickName(j.Bare);
                ChatFromMsg chat = new ChatFromMsg(j, XmppCon, nickName);

                Friend friend;
                if (listView_fd.Rosters.ContainsKey(j.Bare))
                {
                    friend = listView_fd.Rosters[j.Bare];
                }
                else
                {
                    friend = null;
                }

                if (friend != null)
                {
                    chat.UpdateFriendOnline(listView_fd.Rosters[j.Bare].IsOnline);
                }

                if (msgBox.ContainsKey(j.Bare.ToString()))
                {
                    chat.FristMessage(msgBox[j.Bare.ToString()]);
                    msgBox.Remove(j.Bare.ToString());
                }
                try
                {
                    chat.Show();
                }
                catch (Exception)
                {

                }

            }
        }
Beispiel #7
0
        /// <summary>
        /// 查看联系人详细信息事件、删除、备注
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="item"></param>
        public void listView_fd_friend_qcm_MouseClickEvent(object sender, Friend item, String type)
        {
            CSS.IM.XMPP.protocol.iq.roster.RosterItem ritem = null;

            if (listView_fd.SelectFriend!=null)
            {
                ritem = listView_fd.SelectFriend.Ritem;
            }

            Document doc_setting = new Document();
            Settings.Settings config = new Settings.Settings();
            Settings.Paths path = null;

            switch (type)
            {
                case "vcar":
                    if (vcardForm == null || vcardForm.IsDisposed)
                    {
                        vcardForm = new VcardInfoForm(ritem.Jid, XmppCon);
                    }
                    vcardForm.Show();
                    vcardForm.Activate();

                    break;
                case "chat":
                    if (!Util.ChatForms.ContainsKey(item.Ritem.Jid.Bare))
                    {
                        try
                        {
                            string nickName = listView_fd.GetFriendNickName(item.Ritem.Jid.Bare);
                            ChatFromMsg chat = new ChatFromMsg(item.Ritem.Jid, XmppCon, nickName);
                            chat.UpdateFriendOnline(item.IsOnline);//设置好友在线状态
                            chat.Show();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }

                    }
                    else
                    {
                        try
                        {
                            ChatFromMsg chatform = Util.ChatForms[item.Ritem.Jid.Bare] as ChatFromMsg;
                            chatform.WindowState = FormWindowState.Normal;
                            chatform.Activate();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    break;
                case "dele":
                    Jid jid = item.Ritem.Jid;
                    Friend friend = new Friend();
                    friend.NikeName = item.Ritem.Jid.User;
                    friend.Description = "";//心情
                    friend.HeadIMG = "big1";
                    friend.IsSysHead = true;
                    friend.State = 1;

                    if (item.Ritem.GetGroups().Count > 0)
                    {
                        CSS.IM.XMPP.protocol.Base.Group g = (CSS.IM.XMPP.protocol.Base.Group)item.Ritem.GetGroups().Item(0);
                        int groupID = 0;

                        foreach (var groups in listView_fd.Groups)
                        {
                            if (groups.Value.Title == g.Name)
                            {
                                groupID = groups.Value.Id;
                            }
                        }
                        //if (groupID == 0)
                        //{
                        //    friendListView.AddGroup(g.Name);
                        //    groupID = friendListView.Groups[g.Name].Id;
                        //    friendListView.UpdateLayout(3, groupID);

                        //}
                        friend.GroupID = groupID;
                        friend.GroupName = g.Name;
                    }
                    else
                    {
                        //离线联系人
                        Group group = listView_fd.Groups["我的联系人"];
                        friend.GroupID = group.Id;
                        friend.GroupName = group.Title;
                    }
                    friend.Ritem = item.Ritem;
                    friend.IsOnline = false;

                    DialogResult msgResult = MsgBox.Show(this, "CSS&IM", "确认要删除联系人么?", MessageBoxButtons.YesNo);

                    if (msgResult == DialogResult.Yes)
                    {
                        listView_fd.RemoveFriend(friend);

                        try
                        {
                            RosterIq riq = new RosterIq();
                            riq.Type = IqType.set;
                            XmppCon.RosterManager.RemoveRosterItem(jid);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    break;
                case "move":

                    if (moveFriendGroup == null || moveFriendGroup.IsDisposed)
                    {
                        moveFriendGroup = new MoveFriendGroup();
                    }
                    Dictionary<string, Group> group_args = listView_fd.Groups;
                    string[] strvalue = new string[group_args.Count];
                    int index = 0;
                    foreach (String keystr in group_args.Keys)
                    {
                        Group groupargs = group_args[keystr];
                        strvalue[index] = groupargs.Title;
                        index++;

                    }

                    moveFriendGroup.basicComboBox1.Items = strvalue;
                    moveFriendGroup.basicComboBox1.SelectIndex = 0;
                    DialogResult reslut = moveFriendGroup.ShowDialog();

                    String groupupdate = moveFriendGroup.basicComboBox1.SelectItem.ToString();

                    String Bare_move = listView_fd.SelectFriend.Ritem.Jid.Bare;
                    if (reslut == DialogResult.Yes)
                    {

                        foreach (String user_key in listView_fd.Rosters.Keys)
                        {
                            if (listView_fd.Rosters[user_key].Ritem.Jid.Bare == Bare_move)
                            {

                                Friend friend_old = listView_fd.Rosters[user_key];
                                listView_fd.RemoveFriend(listView_fd.Rosters[user_key].Ritem.Jid.Bare);

                                Group fgroup = listView_fd.Groups[groupupdate];
                                friend_old.GroupID = fgroup.Id;
                                friend_old.GroupName = fgroup.Title;

                                listView_fd.AddFriend(friend_old);
                                listView_fd.RefreshGroup();
                                break;

                            }
                        }

                        CSS.IM.XMPP.protocol.Base.Group group_move = new CSS.IM.XMPP.protocol.Base.Group(groupupdate);
                        CSS.IM.XMPP.protocol.Base.Item item_move = new CSS.IM.XMPP.protocol.Base.Item();
                        item_move.Namespace = null;
                        item_move.AddChild(group_move);
                        item_move.SetAttribute("jid", listView_fd.SelectFriend.Ritem.Jid);
                        item_move.SetAttribute("subscripton", "from");

                        CSS.IM.XMPP.protocol.Base.Query query_move = new CSS.IM.XMPP.protocol.Base.Query();
                        query_move.Namespace = CSS.IM.XMPP.Uri.IQ_ROSTER;
                        query_move.AddChild(item_move);

                        IQ iq = new IQ(IqType.set);
                        iq.GenerateId();
                        iq.Namespace = null;
                        iq.AddChild(query_move);

                        XmppCon.IqGrabber.SendIq(iq);

                    }
                    break;
                case "g_dele":

                    break;
                case "remark":

                    //RemarkFriendGroup _RemarkFriendGroup = new RemarkFriendGroup();
                    //Dictionary<string, Group> group_args = friendListView.Groups;
                    //string[] strvalue = new string[group_args.Count];
                    //int index = 0;
                    //foreach (String keystr in group_args.Keys)
                    //{
                    //    Group groupargs = group_args[keystr];
                    //    strvalue[index] = groupargs.Title;
                    //    index++;

                    //}

                    //_MoveFriendGroup.basicComboBox1.Items = strvalue;
                    //_MoveFriendGroup.basicComboBox1.SelectIndex = 0;
                    //DialogResult reslut = _MoveFriendGroup.ShowDialog();

                    //String groupupdate = _MoveFriendGroup.basicComboBox1.SelectItem.ToString();

                    //String name_move = friendListView.SelectedFriend.Ritem.Jid.User;
                    //if (reslut == DialogResult.Yes)
                    //{

                    //    foreach (String user_key in friendListView.Rosters.Keys)
                    //    {
                    //        if (friendListView.Rosters[user_key].Ritem.Jid.User == name_move)
                    //        {

                    //            Friend friend_old = friendListView.Rosters[user_key];
                    //            friendListView.RemoveFriend(friendListView.Rosters[user_key].Ritem.Jid.User);

                    //            Group fgroup = friendListView.Groups[groupupdate];
                    //            friend_old.GroupID = fgroup.Id;
                    //            friend_old.GroupName = fgroup.Title;

                    //            friendListView.AddFriend(friend_old);

                    //            friendListView.UpdateLayout(3, 0);
                    //            break;

                    //        }
                    //    }

                    //    CSS.IM.XMPP.protocol.Base.Group group_move = new CSS.IM.XMPP.protocol.Base.Group(groupupdate);
                    //    CSS.IM.XMPP.protocol.Base.Item item_move = new CSS.IM.XMPP.protocol.Base.Item();
                    //    item_move.Namespace = null;
                    //    item_move.AddChild(group_move);
                    //    item_move.SetAttribute("jid", friendListView.SelectedFriend.Ritem.Jid);
                    //    item_move.SetAttribute("subscripton", "from");

                    //    CSS.IM.XMPP.protocol.Base.Query query_move = new CSS.IM.XMPP.protocol.Base.Query();
                    //    query_move.Namespace = CSS.IM.XMPP.Uri.IQ_ROSTER;
                    //    query_move.AddChild(item_move);

                    //    IQ iq = new IQ(IqType.set);
                    //    iq.GenerateId();
                    //    iq.Namespace = null;
                    //    iq.AddChild(query_move);

                    //    XmppCon.IqGrabber.SendIq(iq);
                    break;
                case "HeadSmall":
                    //listView_fd.FCType = FriendContainerType.Small;
                    CSS.IM.UI.Util.Path.FriendContainerType = false;
                    doc_setting.LoadFile(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
                    path = doc_setting.RootElement.SelectSingleElement(typeof(Settings.Paths),false) as Settings.Paths;
                    path.FriendContainerType = CSS.IM.UI.Util.Path.FriendContainerType;
                    config.Paths = path;
                    config.Font = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SFont), false) as Settings.SFont;
                    config.Color = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SColor), false) as Settings.SColor;

                    doc_setting.Clear();
                    doc_setting.ChildNodes.Add(config);

                    try
                    {
                        doc_setting.Save(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
                    }
                    catch (Exception)
                    {

                    }

                    listView_fd.FCType = CSS.IM.UI.Util.Path.FriendContainerType == true ? FriendContainerType.Big : FriendContainerType.Small;
                    chatHistory_lt.FCType = listView_fd.FCType;
                    listView_gp.FCType = listView_fd.FCType;
                    break;
                case "HeadBig":
                    //listView_fd.FCType = FriendContainerType.Small;
                    CSS.IM.UI.Util.Path.FriendContainerType = true;
                    doc_setting.LoadFile(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
                    path = doc_setting.RootElement.SelectSingleElement(typeof(Settings.Paths),false) as Settings.Paths;
                    path.FriendContainerType = CSS.IM.UI.Util.Path.FriendContainerType;
                    config.Paths = path;
                    config.Font = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SFont), false) as Settings.SFont;
                    config.Color = doc_setting.RootElement.SelectSingleElement(typeof(Settings.SColor), false) as Settings.SColor;

                    doc_setting.Clear();
                    doc_setting.ChildNodes.Add(config);
                    try
                    {
                        doc_setting.Save(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, Program.UserName));
                    }
                    catch (Exception)
                    {

                    }
                    listView_fd.FCType = CSS.IM.UI.Util.Path.FriendContainerType == true ? FriendContainerType.Big : FriendContainerType.Small;
                    chatHistory_lt.FCType = listView_fd.FCType;
                    listView_gp.FCType = listView_fd.FCType;
                    break;
                default:
                    break;
            }
        }
Beispiel #8
0
        protected override void DefWndProc(ref System.Windows.Forms.Message m)
        {
            switch (m.Msg)
            {
                case WM_COPYDATA:
                    COPYDATASTRUCT mystr = new COPYDATASTRUCT();
                    Type mytype = mystr.GetType();
                    mystr = (COPYDATASTRUCT)m.GetLParam(mytype);

                    //MessageBox.Show(mystr.lpData);
                    Jid openJid = new Jid(mystr.lpData, XmppCon.Server,null);
                    //MessageBox.Show(openJid.ToString());

                    Friend item=null;
                    if (listView_fd.Rosters.ContainsKey(openJid.Bare))
                    {
                        item = listView_fd.Rosters[openJid.Bare];
                        if (!Util.ChatForms.ContainsKey(item.Ritem.Jid.Bare))
                        {
                            try
                            {
                                string nickName = listView_fd.GetFriendNickName(openJid.Bare);
                                ChatFromMsg chat = new ChatFromMsg(openJid, XmppCon, nickName);
                                chat.UpdateFriendOnline(item.IsOnline);//设置好友在线状态
                                chat.Show();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                        else
                        {
                            try
                            {
                                ChatFromMsg chatform = Util.ChatForms[item.Ritem.Jid.Bare] as ChatFromMsg;
                                chatform.WindowState = FormWindowState.Normal;
                                chatform.Activate();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                    }
                    else
                    {
                        if (!Util.ChatForms.ContainsKey(openJid.Bare))
                        {
                            listView_fd.UpdateFriendFlicker(openJid.Bare);
                            string nickName = listView_fd.GetFriendNickName(openJid.Bare);
                            ChatFromMsg chat = new ChatFromMsg(openJid, XmppCon, nickName);

                            Friend friend;
                            if (listView_fd.Rosters.ContainsKey(openJid.Bare))
                            {
                                friend = listView_fd.Rosters[openJid.Bare];
                            }
                            else
                            {
                                friend = null;
                            }

                            if (friend != null)
                            {
                                chat.UpdateFriendOnline(listView_fd.Rosters[openJid.Bare].IsOnline);
                            }

                            if (msgBox.ContainsKey(openJid.Bare.ToString()))
                            {
                                chat.FristMessage(msgBox[openJid.Bare.ToString()]);
                                msgBox.Remove(openJid.Bare.ToString());
                            }
                            try
                            {
                                chat.Show();
                            }
                            catch (Exception)
                            {

                            }

                        }
                        else
                        {
                            try
                            {
                                ChatFromMsg chatform = Util.ChatForms[openJid.Bare.ToString()] as ChatFromMsg;
                                chatform.WindowState = FormWindowState.Normal;
                                chatform.Activate();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("打开窗体错误:"+ex.Message);
                            }
                        }
                    }

                    break;
                default:
                    base.DefWndProc(ref m);
                    break;
            }
        }
Beispiel #9
0
        public void XmppCon_OnMessage(object sender, CSS.IM.XMPP.protocol.client.Message msg)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                Invoke(new OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // Dont handle GroupChat Messages here, they have their own callbacks in the
            // GroupChat Form
            if (msg.Type == MessageType.groupchat)
            {
                //Debug.WriteLine("创建聊天室发送了消息:"+msg.Body);
                return;
            }
            if (msg.Type == MessageType.error)
            {
                //Handle errors here
                // we dont handle them in this example
                return;
            }
            //if (msg.Type == MessageType.normal)
            //{
            //    filename = msg.Body;
            //    Debug.WriteLine(msg.ToString());
            //    return;
            //}

            // check for xData Message

            if (msg.HasTag(typeof(Data)))//如果是文件
            {
                Element e = msg.SelectSingleElement(typeof(Data));
                Data xdata = e as Data;
                if (xdata.Type == XDataFormType.form)
                {
                    //frmXData fXData = new frmXData(xdata);
                    //fXData.Text = "xData Form from " + msg.From.ToString();
                    //fXData.Show();
                }
            }
            else if (msg.HasTag(typeof(CSS.IM.XMPP.protocol.extensions.ibb.Data)))
            {
                // ignore IBB messages
                return;
            }
            else
            {
                //if (msg.Body != null)
                //{
                    if (msg.GetTag("subject") == "notify")//xu
                    {
                        filename = msg.Body;
                        return;
                    }
                    else if(msg.GetTag("subject") == "homepage")
                    {
                        Msg.MqMessage mqmsg = MessageBoxForm.MarkMessage_Mq(msg);
                        CSS.IM.UI.Util.Path.DefaultURL = mqmsg.Herf + "?url=" + mqmsg.Url + "&token=" + mqmsg.Token + "&loginname=" +XmppCon.Username +"&pwd=" + Base64.EncodeBase64(XmppCon.Password);

                       return;
                    }
                    else if (msg.GetTag("subject") == "window")
                    {
                        if (CSS.IM.UI.Util.Path.ReveiveSystemNotification)//是否接收服务器消息
                        {
                            if (CSS.IM.UI.Util.Path.SystemSwitch)
                                SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.SystemPath);

                            MessageBoxForm sBox = new MessageBoxForm("系统通知", msg,XmppCon.Username, XmppCon.Password);

                            try
                            {
                                sBox.TopMost = true;
                                sBox.Show();
                            }
                            catch (Exception)
                            {

                            }
                            string sqlstr = "insert into MessageLog (Belong,MessageType,MessageLog,[DateNow]) values ({0},{1},{2},{3})";
                            sqlstr = String.Format(sqlstr,
                                "'" + XmppCon.MyJID.Bare.ToString() + "'",
                                "'0'",
                                "'" + msg.ToString() + "'",
                                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);
                        }
                        return;
                    }
                    if (msg.From.ToString() == msg.From.Server)
                    {
                        if (CSS.IM.UI.Util.Path.ReveiveSystemNotification)//是否接收服务器消息
                        {
                            if (CSS.IM.UI.Util.Path.SystemSwitch)
                                SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.SystemPath);

                            MessageBoxForm sBox = new MessageBoxForm("系统通知", msg, XmppCon.Username,XmppCon.Password);

                            try
                            {
                                sBox.TopMost = true;
                                sBox.Show();
                            }
                            catch (Exception)
                            {

                            }

                            string sqlstr = "insert into MessageLog (Belong,MessageType,MessageLog,[DateNow]) values ({0},{1},{2},{3})";
                            sqlstr = String.Format(sqlstr,
                                "'" + XmppCon.MyJID.Bare.ToString() + "'",
                                "'0'",
                                "'" + msg.ToString() + "'",
                                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);
                        }
                    }
                    else
                    {

                        if (!Util.ChatForms.ContainsKey(msg.From.Bare))//查看聊天窗口是否已经打开了
                        {

                            //RosterNode rn = rosterControl.GetRosterItem(msg.From);
                            //string nick = msg.From.Bare;
                            //if (rn != null)
                            //    nick = rn.Text;
                            try
                            {
                                //string sqlstr = "insert into ChatMessageLog (Jid,[MessageLog],[DateNow])values ({0},{1},{2})";
                                //sqlstr = String.Format(sqlstr,
                                //    "'" + msg.From.Bare.ToString() + "'",
                                //    "'" + msg.ToString() + "'",
                                //     "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                                //CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);
                                /**
                                 * 0、普通消息
                                 * 8、ftp离线文件
                                 * 9、对方拒绝接收主线文件
                                 * 11、接收到red的视频请求
                                 * */
                                if (msg.GetTagInt("m_type") == 0 || msg.GetTagInt("m_type") == 8 || msg.GetTagInt("m_type") == 9 || msg.GetTagInt("m_type") == 11)//如果为0就是正常消息,就播放声音
                                {
                                    if (CSS.IM.UI.Util.Path.MsgSwitch)
                                        SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.MsgPath);
                                }
                                else//代码进入到这里,说明,聊天的窗口已经关闭,接收到属于聊天窗口里面的业务不做处理
                                {
                                    //6发图片
                                    //1接收视频

                                    if (!(msg.GetTagInt("m_type") == 6 || msg.GetTagInt("m_type") == 1))
                                    {
                                        return;
                                    }
                                }

                                //MessageBox.Show("1");
                                Friend flfriend=null;
                                if (listView_fd.Rosters.Count > 0)
                                {
                                    try
                                    {
                                        flfriend = listView_fd.Rosters[msg.From.Bare];
                                    }
                                    catch (Exception)
                                    {
                                        flfriend = null;
                                    }

                                }
                                //MessageBox.Show("2");
                                if (CSS.IM.UI.Util.Path.ChatOpen)
                                {
                                    //friendListView.flickerFriend(new Jid(msg.From.Bare));
                                    //ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                    //timer_notifyIco.Enabled = true;

                                    //MessageBox.Show("3");
                                    string nickName = "";
                                    if (flfriend == null)
                                        nickName = msg.From.User;
                                    else
                                        nickName = listView_fd.GetFriendNickName(msg.From.Bare);

                                    //MessageBox.Show(nickName);

                                    ChatFromMsg chatForm = new ChatFromMsg(msg.From, XmppCon, nickName);
                                    try
                                    {
                                        chatForm.UpdateFriendOnline(flfriend==null?false:flfriend.IsOnline);//设置好友在线状态
                                        chatForm.Show();
                                        chatForm.Activate();
                                        chatForm.IncomingMessage(msg);
                                    }
                                    catch (Exception)
                                    {

                                    }

                                }
                                else
                                {
                                    if (msgBox.ContainsKey(msg.From.Bare.ToString()))
                                    {
                                        List<CSS.IM.XMPP.protocol.client.Message> msgs = msgBox[msg.From.Bare.ToString()];
                                        msgs.Add(msg);
                                        msgBox.Remove(msg.From.Bare.ToString());
                                        msgBox.Add(msg.From.Bare.ToString(), msgs);
                                        listView_fd.flickerFriend(new Jid(msg.From.Bare));

                                    }
                                    else
                                    {
                                        if (listView_fd.Rosters.ContainsKey(msg.From.Bare))
                                        {
                                            List<CSS.IM.XMPP.protocol.client.Message> msgs = new List<XMPP.protocol.client.Message>();
                                            msgs.Add(msg);
                                            msgBox.Add(msg.From.Bare.ToString(), msgs);
                                            listView_fd.flickerFriend(new Jid(msg.From.Bare));
                                            ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                            timer_MessageAlert.Enabled = true;
                                        }
                                        else
                                        {
                                            string nickName = listView_fd.GetFriendNickName(msg.From.Bare);
                                            ChatFromMsg chatForm = new ChatFromMsg(msg.From, XmppCon, nickName);
                                            try
                                            {
                                                chatForm.UpdateFriendOnline(flfriend.IsOnline==null?false:flfriend.IsOnline);//设置好友在线状态
                                                chatForm.Show();
                                                chatForm.Activate();
                                                chatForm.IncomingMessage(msg);
                                            }
                                            catch (Exception)
                                            {

                                            }

                                        }

                                        //Friend item=friendListView.Rosters[msg.From.Bare.ToString()];
                                    }
                                }
                                //ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                //chatForm.Show();
                                //chatForm.IncomingMessage(msg);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("系统错误,打开消息窗体失败,原因:"+ex.Message+"请联系软件开发商。");
                            }

                        }
                    }
                //}
            }
        }
        void friend_list_OpenChatEvent(UI.Entity.Friend friend)
        {
            if (!Util.ChatForms.ContainsKey(friend.Ritem.Jid.Bare.ToString()))
            {
                ChatFromMsg chat = new ChatFromMsg(friend.Ritem.Jid, _connection);
                try
                {
                    chat.Show();
                }
                catch (Exception)
                {

                }

            }
        }
        /// <summary>
        /// 通过分组聊天列表,打开点对点聊天
        /// </summary>
        /// <param name="friend"></param>
        private void friend_list_OpenChatEvent(UI.Entity.Friend friend, string nickName)
        {
            if (!Util.ChatForms.ContainsKey(friend.Ritem.Jid.Bare))
            {
                ChatFromMsg chat = new ChatFromMsg(friend.Ritem.Jid, XmppConn, nickName);
                chat.UpdateFriendOnline(true);
                try
                {
                    chat.Show();
                }
                catch (Exception)
                {

                }
            }
            else
            {
                try
                {
                    ChatFromMsg chatform = Util.ChatForms[friend.Ritem.Jid.Bare] as ChatFromMsg;
                    chatform.WindowState = FormWindowState.Normal;
                    chatform.Activate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }