Esempio n. 1
0
 public ChatForm(GetFriendsResponseModel friendModel)
 {
     InitializeComponent();
     this.friendModel = friendModel;
     // 设置窗体标题
     this.Text = string.Format("与{0}聊天中", friendModel.nickName);
     // 设置窗体顶部显示的好友信息
     picFace.Image  = ilFaces.Images[friendModel.faceimg];
     lblFriend.Text = string.Format("{0}", friendModel.nickName);
     txtSendMess.Focus();
 }
Esempio n. 2
0
 public void OnLineFriend(int friendId)
 {
     this.Invoke(new Action(() => {
         if (dicFriends.ContainsKey(friendId))
         {
             GetFriendsResponseModel respondeModel = dicFriends[friendId];
             MyItem sbItem = dicItems[respondeModel];
             sbItem.Text   = respondeModel.nickName + "(在线)";
             sbFriends.Invalidate();
         }
     }));
     Application.DoEvents();
 }
Esempio n. 3
0
        public void GetOffLineChatMessHandler(GetOffLineChatMessResponseModel responseModel)
        {
            this.Invoke(new Action(() => {
                SbItemTimer.Start();
                ChatForm chatForm = null;
                lock (this)
                {
                    if (dicChats.ContainsKey(responseModel.fromid))
                    {
                        chatForm = dicChats[responseModel.fromid];
                    }
                    else if (dicFriends.ContainsKey(responseModel.fromid))
                    {
                        GetFriendsResponseModel friendModel = dicFriends[responseModel.fromid];
                        chatForm = new ChatForm(friendModel);
                        dicChats.Add(friendModel.friendid, chatForm);
                    }
                }
                if (chatForm != null)
                {
                    chatForm.ShowMessage(responseModel.createtime, responseModel.nickName, responseModel.content);
                }
                else
                {
                    lock (this)
                    {
                        GetFriendsResponseModel friendModel = new GetFriendsResponseModel();
                        friendModel.faceimg  = responseModel.faceimg;
                        friendModel.friendid = responseModel.fromid;
                        friendModel.nickName = responseModel.nickName;
                        chatForm             = new ChatForm(friendModel);
                        chatForm.ShowMessage(responseModel.createtime, responseModel.nickName, responseModel.content);
                    }
                }

                lock (this) {
                    if (!chatForm.Visible)
                    {
                        if (dicFriends.ContainsKey(responseModel.fromid))
                        {
                            if (dicItems.ContainsKey(dicFriends[responseModel.fromid]))
                            {
                                MyItem sbItem     = dicItems[dicFriends[responseModel.fromid]];
                                sbItem.isShandong = true;
                            }
                        }
                    }
                }
            }));
            Application.DoEvents();
        }
Esempio n. 4
0
        // 双击一项,弹出聊天窗体
        private void sbFriends_ItemDoubleClick(SbItemEventArgs e)
        {
            GetFriendsResponseModel friendModel = (GetFriendsResponseModel)e.Item.Tag;
            ChatForm chatForm = null;

            lock (this) {
                if (dicChats.ContainsKey(friendModel.friendid))
                {
                    chatForm = dicChats[friendModel.friendid];
                    chatForm.Show();
                }
                else
                {
                    // 显示聊天窗体
                    chatForm = new ChatForm(friendModel);
                    dicChats.Add(friendModel.friendid, chatForm);
                    chatForm.Show();
                }
                ((MyItem)e.Item).isShandong = false;
            }
        }
Esempio n. 5
0
 public void GetFriendsRespondeHandler(GetFriendsResponseModel responseModel)
 {
     this.Invoke(new Action(() => {
         lock (this)
         {
             MyItem item = null;
             if (!dicFriends.ContainsKey(responseModel.friendid))
             {
                 dicFriends.Add(responseModel.friendid, responseModel);
                 item = new MyItem();
                 sbFriends.Groups[0].Items.Add(item);
                 dicItems.Add(responseModel, item);
             }
             else
             {
                 GetFriendsResponseModel temRes = dicFriends[responseModel.friendid];
                 item = dicItems[temRes];
                 dicFriends[responseModel.friendid] = responseModel;
                 dicItems.Remove(temRes);
                 dicItems.Add(responseModel, item);
             }
             string nickName = responseModel.nickName;
             if (responseModel.state == 1)
             {
                 nickName += "(在线)";
             }
             else
             {
                 nickName += "(离线)";
             }
             item.Text       = nickName;
             item.ImageIndex = responseModel.faceimg;
             item.FaceImg    = item.ImageIndex;
             item.Tag        = responseModel;
             sbFriends.Invalidate();
         }
     }));
     Application.DoEvents();
 }
Esempio n. 6
0
 private static void Ws_OnMessage(object sender, MessageEventArgs e)
 {
     try {
         string     json         = e.Data;
         CommonMess responseMess = JsonHelper.DeserializeObject <CommonMess>(json);
         int        messType     = -responseMess.messType;
         if (messType == MessType.AddFriend)
         {
             searchFormFriend.AddFriendOK();
         }
         else if (messType == MessType.AgreeAddFriend)
         {
         }
         else if (messType == MessType.GetFriends)
         {
             GetFriendsResponseModel responseModel = JsonHelper.DeserializeObject <GetFriendsResponseModel>(responseMess.content);
             mainForm.GetFriendsRespondeHandler(responseModel);
         }
         else if (messType == MessType.GetOffLineChatMess)
         {
             GetOffLineChatMessResponseModel responseModel = JsonHelper.DeserializeObject <GetOffLineChatMessResponseModel>(responseMess.content);
             mainForm.GetOffLineChatMessHandler(responseModel);
         }
         else if (messType == MessType.GetSysMess)
         {
             GetSysMessResponseModel responseModel = JsonHelper.DeserializeObject <GetSysMessResponseModel>(responseMess.content);
             SysMessHandler(responseModel);
         }
         else if (messType == MessType.Login)
         {
             LoginResponseModel responseModel = JsonHelper.DeserializeObject <LoginResponseModel>(responseMess.content);
             SystemHelper.currentUser = responseModel;
             loginForm.LoginOK(responseModel);
         }
         else if (messType == MessType.LoginOut)
         {
         }
         else if (messType == MessType.Register)
         {
             RegisetResponseModel responseModel = JsonHelper.DeserializeObject <RegisetResponseModel>(responseMess.content);
             registerForm.RegisterOK(responseModel);
         }
         else if (messType == MessType.SearchFriend)
         {
             SearchFriendResponseModel responseModel = JsonHelper.DeserializeObject <SearchFriendResponseModel>(responseMess.content);
             searchFormFriend.SerarchFriendsResult(responseModel);
         }
         else if (messType == MessType.SendChatMess)
         {
         }
         else if (messType == MessType.EditInfo)
         {
             EditInfoResponseModel respondeModel = JsonHelper.DeserializeObject <EditInfoResponseModel>(responseMess.content);
             if (respondeModel.state == 1)
             {
                 SystemHelper.currentUser.age      = respondeModel.age;
                 SystemHelper.currentUser.blood    = respondeModel.blood;
                 SystemHelper.currentUser.conste   = respondeModel.conste;
                 SystemHelper.currentUser.faceimg  = respondeModel.faceimg;
                 SystemHelper.currentUser.gender   = respondeModel.gender;
                 SystemHelper.currentUser.nickname = respondeModel.nickname;
                 if (mainForm != null && mainForm.IsHandleCreated)
                 {
                     mainForm.Invoke(new Action(() => {
                         mainForm.ShowSelfInfo();
                     }));
                     Application.DoEvents();
                 }
             }
             else
             {
                 MessageBox.Show("用户信息修改失败!");
             }
         }
     }
     catch (Exception err) {
         MessageBox.Show(err.ToString(), "OnMessageError");
     }
 }