Ejemplo n.º 1
0
        private void ShowMsg(Packet pct)
        {
            var friend = onLineUserList.Where(s => s.userAccount == pct.comeNo).FirstOrDefault();

            if (friend == null)
            {
                friend = offLineUserList.Where(s => s.userAccount == pct.comeNo).FirstOrDefault();
            }
            if (friend != null)
            {
                pct.comeName = friend.userName;
                FrmClientTcp frmtcp = null;
                if (dicChatFrm.Keys.Contains(pct.comeNo))
                {
                    frmtcp = dicChatFrm[pct.comeNo];
                    frmtcp.Invoke(new Action(() =>
                    {
                        if (pct.type == MessageType.Message)
                        {
                            frmtcp.DisplayMessage(pct.comeName, pct.msg);
                            frmtcp.Show();
                        }
                        if (pct.type == MessageType.Shake)
                        {
                            frmtcp.FrmShake();
                            //pct.msg = "发来振动";
                        }
                        if (pct.type == MessageType.Img)
                        {
                            frmtcp.DisplayImg(pct);
                        }
                        //frmtcp.DisplayMessage(pct.comeName, pct.msg);
                        //frmtcp.Show();
                        //if (pct.type == MessageType.Shake)
                        //{
                        //    this.thDataFromServer.sl
                        //    if (frmtcp.WindowState == FormWindowState.Minimized)
                        //    {
                        //        frmtcp.WindowState = FormWindowState.Normal;
                        //    }

                        //}
                    }));
                }
                else
                {
                    this.Invoke(new Action(() =>
                    {
                        Chat ct = new Chat()
                        {
                            userNo   = this.account,
                            userName = this.uname,
                            chatName = pct.comeName,
                            chatNo   = pct.comeNo,
                        };
                        frmtcp         = new FrmClientTcp(ct, clientSocket);
                        frmtcp.Closed += (s, args) => this.RemoveFrm(pct.comeNo);
                        dicChatFrm.Add(pct.comeNo, frmtcp);
                        if (pct.type == MessageType.Message)
                        {
                            frmtcp.DisplayMessage(pct.comeName, pct.msg);
                            frmtcp.Show();
                        }
                        if (pct.type == MessageType.Shake)
                        {
                            frmtcp.FrmShake();
                        }
                        if (pct.type == MessageType.Img)
                        {
                            frmtcp.DisplayImg(pct);
                        }
                    }));
                }
            }
        }