Exemple #1
0
        // 用户登陆尝试,调用CS模块
        void Login(object currWindow)
        {
            String reply = CSClient.getInstance().SendAMsg($"{userName}_{passWord}");

            if (reply != "lol")
            {
                return;
            }


            App.mainWindow = new MainWindow();
            App.mainWindow.Show();
            isLogging = false;
        }
        // 好友添加,向服务器确认ID是否合法,合法后添加好友
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            var    btn   = (Button)sender;
            string recv  = CSClient.getInstance().SendAMsg($"q{(string)btn.Tag}");
            string Alias = (string)btn.ToolTip;

            if (Alias == null || Alias.Length == 0)
            {
                Alias = (string)btn.Tag;
            }
            switch (recv)
            {
            case "error":
                MessageBox.Show("添加失败");
                break;

            case "Please send the correct message.":
                MessageBox.Show("不存在此用户");
                break;

            default:
                foreach (var item in viewModel.addressBook.items)
                {
                    if (item.UserName == (string)btn.Tag)
                    {
                        MessageBox.Show("此用户已经是您的好友");
                        return;
                    }
                }
                Model.AddressBook.Item newItem = new AddressBook.Item()
                {
                    Alias     = Alias,
                    UserName  = (string)btn.Tag,
                    isOnline  = (recv != "n"),
                    IPAddress = recv != "n" ? recv : ""
                };
                viewModel.addressBook.items.Add(newItem);
                MessageBox.Show("添加成功");

                // 更新界面
                contactList.ItemsSource = null;
                contactList.ItemsSource = viewModel.addressBook.items;
                break;
            }
        }
        // 在线状态查询按钮
        private void QueryBtn_Click(object sender, RoutedEventArgs e)
        {
            var    btn  = (Button)sender;
            string recv = CSClient.getInstance().SendAMsg($"q{(string)btn.Tag}");

            switch (recv)
            {
            case "error":
                MessageBox.Show("添加失败");
                break;

            case "Please send the correct message.":
                MessageBox.Show("不存在此用户");
                break;

            case "n":
                MessageBox.Show("用户已注册但不在线");
                break;

            default:
                MessageBox.Show($"用户主机位于{recv}");
                break;
            }
        }