示例#1
0
 public void addmember(string name)
 {
     if (hasmember(name))
     {
         MessageBox.Show(name + "集合成员已添加过", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
         return;
     }
     else
     {
         TcpClient client = new TcpClient();
         try
         {
             client.Connect(Info.SIp, Info.SPort);
         }
         catch
         {
             MessageBox.Show("连接失败", "连接信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
             client.Close();
         }
         if (client.Connected)
         {
             NetworkStream ClientToServer = client.GetStream();
             string        QueryInfo      = "q" + name;
             MainChat.TcpSend(ClientToServer, QueryInfo);
             string response = MainChat.TcpReceive(ClientToServer);
             if (response.Length > 0)
             {
                 if (response.StartsWith("I") || response.StartsWith("P"))
                 {
                     MessageBox.Show("未找到用户", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                     return;
                 }
                 else if (response == "n")
                 {
                     MessageBox.Show("用户不在线", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                     return;
                 }
                 else
                 {
                     ListViewItem list_data = new ListViewItem();
                     list_data.Text = name;
                     MemberlistView.Items.Add(list_data);
                 }
             }
             ClientToServer.Close();
         }
         client.Close();
     }
 }
示例#2
0
文件: Program.cs 项目: ChenDRAG/QQchy
        static void Main(string[] args)
        {
            Login login = new Login();

            login.ShowDialog();
            if (login.DialogResult == DialogResult.OK)
            {
                login.Close();
                MainChat MC = new MainChat();
                MC.ShowDialog();

                if (Login.Logout() == true)
                {
                    MessageBox.Show("成功下线", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                }
            }

            System.Environment.Exit(0);
        }
示例#3
0
        public void update()
        {
            TcpClient client = new TcpClient();

            try
            {
                client.Connect(Info.SIp, Info.SPort);
            }
            catch
            {
                MessageBox.Show("找不到中央服务器", "连接信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                client.Close();
                return;
            }
            if (client.Connected)
            {
                NetworkStream ClientToServer = client.GetStream();
                string        QueryInfo      = "q" + Name;
                MainChat.TcpSend(ClientToServer, QueryInfo);
                string response = MainChat.TcpReceive(ClientToServer);
                if (response.Length > 0)
                {
                    if (response.StartsWith("I") || response.StartsWith("P"))
                    {
                        Online = false;
                        tag.updateonline(Online);
                    }
                    else if (response == "n")
                    {
                        Online = false;
                        tag.updateonline(Online);
                    }
                    else
                    {
                        Online = true;
                        tag.updateonline(Online);
                    }
                }
                ClientToServer.Close();
            }
            client.Close();
        }
示例#4
0
        public void addthisfriend(string name, bool silentmode = false)
        {
            Friend f = new Friend(name);

            if (name == Info.UserName)
            {
                if (!silentmode)
                {
                    MessageBox.Show("您在线上", "查询结果", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                }
                return;
            }
            for (int i = 0; i < Friends.Count; i++)
            {
                if (f.Name == Friends[i].Name)
                {
                    if (!silentmode)
                    {
                        MessageBox.Show("好友已存在", "查询结果", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    }
                    return;
                }
            }
            TcpClient client = new TcpClient();

            try
            {
                client.Connect(Info.SIp, Info.SPort);
            }
            catch
            {
                if (!silentmode)
                {
                    MessageBox.Show("连接失败", "连接信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                }
                client.Close();
            }
            if (client.Connected)
            {
                NetworkStream ClientToServer = client.GetStream();
                string        QueryInfo      = "q" + f.Name;
                MainChat.TcpSend(ClientToServer, QueryInfo);
                string response = MainChat.TcpReceive(ClientToServer);
                if (response.Length > 0)
                {
                    if (response.StartsWith("I") || response.StartsWith("P"))
                    {
                        if (!silentmode)
                        {
                            MessageBox.Show("未找到用户", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                        }
                        return;
                    }
                    else if (response == "n")
                    {
                        if (!silentmode)
                        {
                            MessageBox.Show("用户不在线", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                        }
                        return;
                    }
                    else
                    {
                        f.IP         = response;
                        f.Online     = true;
                        f.setabove  += new SetAbove(Chatlist_close);
                        f.setabove5 += new SetAbove5(addmember);
                        Friends.Add(f);
                    }
                }
                ClientToServer.Close();
            }
            client.Close();
            if (!silentmode)
            {
                AddShow(Friends.Count - 1);
            }
            return;
        }