239 lines
8.4 KiB
C#
239 lines
8.4 KiB
C#
using Api.Framework.Model;
|
|
using Chat.Framework.WXSdk;
|
|
using Chat.Framework.WXSdk.Implement;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using UI.Framework.Forms;
|
|
|
|
namespace FLSystem.Forms
|
|
{
|
|
public partial class GroupForm : BaseForm
|
|
{
|
|
public class Groups
|
|
{
|
|
//public WXClientImpl_IPAD Client { get; private set; }
|
|
//public Friend Friend { get; private set; }
|
|
|
|
//public Groups(WXClientImpl_IPAD Client, Friend Friend)
|
|
//{
|
|
// this.Client = Client;
|
|
// this.Friend = Friend;
|
|
//}
|
|
|
|
public WeixinBase Client { get; private set; }
|
|
public Friend Friend { get; private set; }
|
|
|
|
public Groups(WeixinBase Client, Friend Friend)
|
|
{
|
|
this.Client = Client;
|
|
this.Friend = Friend;
|
|
}
|
|
public string groupid { get; set; }
|
|
public string groupname { get; set; }
|
|
}
|
|
|
|
public GroupForm()
|
|
{
|
|
InitializeComponent();
|
|
|
|
#region 增加所有的机器人账号
|
|
this.comboBoxEdit3.Properties.Items.Clear();
|
|
var weixinBases = Chat.Framework.ChatClient.WXClient.Values.ToList();
|
|
var objList = new List<object>() { "全部平台" };
|
|
foreach (var item in weixinBases)
|
|
{
|
|
objList.Add(item.WeixinHao);
|
|
}
|
|
|
|
var qqBases = Chat.Framework.ChatClient.QQClients.Values;
|
|
foreach (var item in qqBases)
|
|
{
|
|
objList.Add(item.QQ.ToString());
|
|
}
|
|
|
|
this.comboBoxEdit3.Properties.Items.AddRange(objList);
|
|
#endregion
|
|
|
|
}
|
|
|
|
private void GroupForm_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (groups != null && groups.Count != 0)
|
|
{
|
|
List<object> objs = new List<object>();
|
|
if (comboBoxEdit3.SelectedIndex != 0)
|
|
groups = groups.Where(f => f.Client.WeixinHao == comboBoxEdit3.Text).ToList();
|
|
foreach (var item in groups)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(textEdit1.Text))
|
|
objs.Add(new { groupid = item.Friend.UserName, groupname = item.Friend.NickName });
|
|
else if (item.Friend.UserName.Contains(textEdit1.Text) || item.Friend.NickName.Contains(textEdit1.Text))
|
|
objs.Add(new { groupid = item.Friend.UserName, groupname = item.Friend.NickName });
|
|
}
|
|
gridControl1.DataSource = objs;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!this.IsDisposed)
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private CancellationTokenSource tokenSource = new CancellationTokenSource();
|
|
|
|
private async void comboBoxEdit3_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
List<KeyValuePair<string, WeixinBase>> clients = null;
|
|
if (comboBoxEdit3.SelectedIndex == 0)
|
|
clients = Chat.Framework.ChatClient.WXClient.Where(f => /*f.Value.WeixinType == WeixinType.Grpc微信 &&*/ f.Value.Status == WxStatus.在线).ToList();
|
|
else
|
|
clients = Chat.Framework.ChatClient.WXClient.Where(f => f.Value.Status == WxStatus.在线 /*&& f.Value.WeixinType == WeixinType.Grpc微信*/ && f.Value.WeixinHao == comboBoxEdit3.Text).ToList();
|
|
|
|
try
|
|
{
|
|
await Task.Run(() => GetGroup(clients), tokenSource.Token);
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
|
|
if (clients != null && clients.Count > 0) GroupForm_Load(null, null);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!this.IsDisposed)
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|
{
|
|
GroupForm_Load(null, null);
|
|
}
|
|
|
|
|
|
static List<Groups> groups = new List<Groups>();//缓存
|
|
|
|
/// <summary>
|
|
/// 获取群集合
|
|
/// </summary>
|
|
/// <param name="clients"></param>
|
|
/// <returns></returns>
|
|
public static void GetGroup(List<KeyValuePair<string, WeixinBase>> clients)
|
|
{
|
|
Task.Delay(30000);
|
|
groups = new List<Groups>();//缓存
|
|
foreach (var client in clients)
|
|
{
|
|
if (client.Value.GetType() == typeof(WXClientImpl_IPAD))
|
|
{
|
|
var ipad = client.Value as WXClientImpl_IPAD;
|
|
if (ipad == null || ipad.Friends == null) continue;
|
|
var friends = ipad.Friends.Values.Where(f => f.UserName.EndsWith("@chatroom")).ToList();
|
|
|
|
foreach (var item in friends)
|
|
{
|
|
groups.Add(new Groups(ipad, item));
|
|
}
|
|
}
|
|
else if (client.Value.GetType() == typeof(WXClientImpl_HOOK))
|
|
{
|
|
var ipad = client.Value as WXClientImpl_HOOK;
|
|
if (ipad == null || ipad.Friends == null) continue;
|
|
var friends = ipad.Friends.Values.Where(f => f.UserName.EndsWith("@chatroom")).ToList();
|
|
|
|
foreach (var item in friends)
|
|
{
|
|
groups.Add(new Groups(ipad, item));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void hyperlinkLabelControl1_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Loding.ShowWaitForm();//开启等待
|
|
|
|
List<KeyValuePair<string, WeixinBase>> clients = null;
|
|
if (comboBoxEdit3.SelectedIndex == 0)//全部机器人
|
|
clients = Chat.Framework.ChatClient.WXClient.Where(f => /*f.Value.WeixinType == WeixinType.Grpc微信 &&*/ f.Value.Status == WxStatus.在线).ToList();
|
|
else
|
|
clients = Chat.Framework.ChatClient.WXClient.Where(f => f.Value.WeixinHao == comboBoxEdit3.Text /*&& f.Value.WeixinType == WeixinType.Grpc微信*/ && f.Value.Status == WxStatus.在线).ToList();
|
|
|
|
if (clients != null && clients.Count != 0)
|
|
{
|
|
foreach (var item in clients)
|
|
{
|
|
var ipad = item.Value as WXClientImpl_IPAD;
|
|
if (ipad.Status == WxStatus.在线 && ipad.Friends.Count == 0 && !ipad.IsRefreshContact)
|
|
{
|
|
ipad.RefreshContact();
|
|
}
|
|
}
|
|
ShowSuccess("刷新通讯录,请等待");
|
|
}
|
|
else
|
|
throw new Exception("没有在线的微信号,或者没有符合的微信号");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!this.IsDisposed)
|
|
ShowError(ex);
|
|
}
|
|
finally
|
|
{
|
|
Loding.CloseWaitForm();
|
|
}
|
|
}
|
|
|
|
public fl_group_person group = null;
|
|
|
|
void change_user()
|
|
{
|
|
try
|
|
{
|
|
var rows = this.gridView1.GetSelectedRows();
|
|
if (rows != null && rows.Length > 0)
|
|
{
|
|
var groupid = this.gridView1.GetRowCellValue(rows[0], "groupid").ToString();//获取列的数据
|
|
var groupname = this.gridView1.GetRowCellValue(rows[0], "groupname").ToString();//获取列的数据
|
|
|
|
group = new fl_group_person() { groupid = groupid, groupname = groupname };
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
|
|
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
|
|
{
|
|
change_user();
|
|
}
|
|
|
|
private void gridView1_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
change_user();
|
|
}
|
|
|
|
private void GroupForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
tokenSource.Cancel();
|
|
}
|
|
}
|
|
}
|