/// <summary> /// 添加/移除监控 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvWeChatList_CellClick(object sender, DataGridViewCellEventArgs e) { if (ListenWeChatData == null) { ListenWeChatData = new List <WXUser>(); } CurrentSelectedWeChat = string.Empty; DataGridViewCellCollection cells = this.dgvWeChatList.CurrentRow.Cells; if (cells != null && cells["editListen"].ColumnIndex == e.ColumnIndex) { string userName = cells["UserName"].Value.ToString(); if (!IsListenView) { if (!ListenWeChatData.Exists(item => { return(item.UserName == userName); })) { //将群添加到监控列表 ListenWeChatData.Add(new WXUser() { UserName = userName, NickName = cells["ShowName"].Value.ToString() }); NotListenWeChatData.RemoveAll(item => { return(item.UserName == userName); }); } } else { //从监控列表中移除 if (ListenWeChatData.Exists(item => { return(item.UserName == userName); })) { ListenWeChatData.RemoveAll(item => { return(item.UserName == userName); }); //将群添加到监控列表 NotListenWeChatData.Add(new WXUser() { UserName = userName, NickName = cells["ShowName"].Value.ToString() }); } } dgvWeChatList.Rows.RemoveAt(cells["editListen"].RowIndex); } else { if (IsListenView) { string showname = cells["ShowName"].Value.ToString(); CurrentSelectedWeChat = cells["UserName"].Value.ToString(); var data = wxMessageData.FindAll(item => { return(item.MsgUserName == CurrentSelectedWeChat); }); SetDataContentView(data); lbMsgTitle.Text = "群 " + showname + " 消息列表"; } } }
/// <summary> /// 加载微信通讯录 /// </summary> /// <param name="user">The user.</param> private void SetContactsView(WXUser user) { if (NotListenWeChatData == null) { NotListenWeChatData = new List <WXUser>(); } if (dgvWeChatList.InvokeRequired) { this.dgvWeChatList.Invoke(new Action <WXUser>(SetContactsView), new object[] { user }); } else { bool result = false; foreach (DataGridViewRow item in dgvWeChatList.Rows) { if (item.Cells["UserName"].Value.ToString().Equals(user.UserName)) { result = true; item.Cells["ShowName"].Value = user.ShowName; item.Cells["UserName"].Value = user.UserName; break; } } if (!IsListenView && !result) { int i = dgvWeChatList.Rows.Count; dgvWeChatList.Rows.Add(); ++i; dgvWeChatList.Rows[i - 1].Cells["ID"].Value = i; dgvWeChatList.Rows[i - 1].Cells["ShowName"].Value = user.ShowName; dgvWeChatList.Rows[i - 1].Cells["UserName"].Value = user.UserName; dgvWeChatList.Rows[i - 1].Height = 50; dgvWeChatList.Rows[i - 1].DefaultCellStyle.SelectionBackColor = Color.FromArgb(236, 232, 231); } if (NotListenWeChatData.Exists(item => { return(item.UserName == user.UserName); })) { NotListenWeChatData.RemoveAll(u => { return(u.UserName == user.UserName); }); } NotListenWeChatData.Add(user); } }