Example #1
0
        //属于命令UserSearchCommand
        private void SearchUser(object obj)
        {
            string sender   = dataService.UserName;
            string userName = search;
            string nickName = search;
            string gender   = GenderSelected;
            int    age      = AgeSelected;
            string ageString;

            if (age == -1)
            {
                ageString = "Unlimited";
            }
            else
            {
                ageString = age.ToString();
            }
            string  content = userName + "|" + nickName + "|" + gender + "|" + ageString;
            Message msg     = new Message(MessageType.FRIENDSEARCH, sender, content);
            var     found   = dataService.SendFriendSearchMessage(msg);

            FriendsFound.Clear();
            //注意为空情况
            if (found.Count == 0)
            {
                MessageBox.Show("没有找到用户");
            }
            else if (found.Count == 1 && found.First().UserName == dataService.UserName)
            {
                MessageBox.Show("没有找到用户");
            }
            else
            {
                foreach (var user in found)
                {
                    if (user.UserName != dataService.UserName)
                    {
                        FriendsFound.Add(user);
                    }
                }
            }
        }