Exemplo n.º 1
0
        private void friendsListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (friendsListView.SelectedItems.Count > 0)
            {
                int index = 0;
                foreach (ListViewItem lvi in friendsListView.SelectedItems)  //选中项遍历
                {
                    index = lvi.Index;
                }

                User selectedUser = (User)searchList[index];
                //判断好友关系
                bool isFriend = friendBll.isFriend(currUser.UId, selectedUser.UId);
                if (isFriend)
                {
                    MessageBox.Show("对方已是您好友,重复添加无效!");
                    return;
                }
                string text  = "添加好友?";
                string title = "添加好友信息";
                if (MessageBox.Show(text, title, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Friend friend = new Friend();
                    //选择群
                    IList <Model.Group> groupList = groupBll.getGroupList(currUser.UId);
                    //弹出下拉表单进行选择分组
                    ChooseGroup chooseGroup = new ChooseGroup(currUser, selectedUser, groupList);
                    chooseGroup.Visible = true;
                }
            }
            else
            {
                return;
            }
        }
Exemplo n.º 2
0
        private void FriendListForm_Load(object sender, EventArgs e)
        {
            friendListBox.IconSizeMode = ChatListItemIcon.Large;
            Random        rnd       = new Random();
            IList <Group> groupList = groupBll.getGroupList(user.UId);

            Console.WriteLine("user.UId----------------------->>>>>>>>" + user.UId + "count----->" + groupList.Count);

            foreach (Group group in groupList)
            {
                Console.WriteLine("group" + group.Name + "groupid" + group.GId);



                ChatListItem   groupItem  = new ChatListItem(group.Name);
                IList <Friend> friendList = friendBll.getFriendByGroup(user.UId, group.GId);
                Console.WriteLine("user.UId" + user.UId + "group.GId" + group.GId);
                Console.WriteLine("friendList" + friendList.Count);
                foreach (Friend friend in friendList)
                {
                    Console.WriteLine("friendList" + friend.NickName);
                    User            fModel     = userBll.getUser(friend.FriendId);
                    ChatListSubItem friendItem = new ChatListSubItem();
                    friendItem.DisplayName = friend.FriendName;
                    friendItem.ID          = friend.FriendId;
                    //设置好友头像
                    if (friend.Photo == null)
                    {
                        Image errorIm = Image.FromFile("Head/error.jpg");
                        Size  size    = new Size(60, 60);
                        friendItem.HeadImage = new Bitmap(errorIm, size);
                    }
                    else
                    {
                        MemoryStream stream = new MemoryStream(friend.Photo);
                        friendItem.HeadImage = new Bitmap(stream);
                    }

                    friendItem.NicName     = friend.NickName;
                    friendItem.PersonalMsg = fModel.Sign;
                    friendItem.IpAddress   = fModel.LastLoginIp;
                    groupItem.SubItems.Add(friendItem);
                }

                try
                {
                    openWith.Add(group.GId, groupItem);
                }
                catch
                {
                    Console.WriteLine("An element with Key = \"txt\" already exists.");
                }
                friendListBox.Items.Add(groupItem);
            }
        }