using Api.Framework; using Api.Framework.Model; using Api.Framework.Tools; using Chat.Framework.WXSdk; using Chat.Framework.WXSdk.Implement; using DevExpress.XtraTab; using SqlSugar; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using UI.Framework.Forms; namespace FissionData { public partial class MainForm : BaseForm { public MainForm() { InitializeComponent(); this.pageControl2.Bind(delegate (int index, int pagesize) { try { var session = ApiClient.GetSession(); var map = session.NewParamMap(); map.setPageParamters(index, pagesize); var sql = "select * from FissionClass where 1 = 1 "; var groupkey = textEdit2.Text.Trim(); var friendkey = textEdit3.Text.Trim(); var flag = false; if (!string.IsNullOrWhiteSpace(friendkey))//判断是否是用户数据id { var uid = 0; if (int.TryParse(friendkey, out uid)) { var member = session.FindMemberInfoById(uid); if (member != null) { flag = true; if (string.IsNullOrWhiteSpace(groupkey)) sql += $"and username = '{member.username}'"; else sql += $"and (groupid like '%{groupkey}%' or groupnick like '%{groupkey}%') and username = '{member.username}'"; } } } if (!flag) { if (string.IsNullOrWhiteSpace(groupkey) && !string.IsNullOrWhiteSpace(friendkey)) sql += $"and (username like '%{friendkey}%' or nickname like '%{friendkey}%')"; else if (!string.IsNullOrWhiteSpace(groupkey) && string.IsNullOrWhiteSpace(friendkey)) sql += $"and (groupid like '%{groupkey}%' or groupnick like '%{groupkey}%')"; else if (!string.IsNullOrWhiteSpace(groupkey) && !string.IsNullOrWhiteSpace(friendkey)) sql += $"and (groupid like '%{groupkey}%' or groupnick like '%{groupkey}%') and (username like '%{friendkey}%' or nickname like '%{friendkey}%')"; } PageResult result = session.FindPage(sql, map); return new UI.Framework.Controls.PageControl.SerchResult() { Result = result.DataList, Total = result.Total }; } catch (Exception ex) { BaseForm.ShowError(ex); } return null; }, this.gridControl2, 100, false, true); } public void CloseForm() { try { if (!this.IsDisposed) { this.Invoke(new Action(delegate { this.Close(); this.Dispose(); })); } } catch (Exception ex) { ShowError(ex); } } private void MainForm_Load(object sender, EventArgs e) { UpdateWxList(); settingControl1.Bind(Class1.Config, 100); } public void UpdateWxList() { try { //comboBoxEdit1.Properties.Items.Clear(); //comboBoxEdit1.Properties.Items.Add("全部机器人"); //var wxs = Chat.Framework.ChatClient.WXClient.Values.Where(f => f.WeixinType == Chat.Framework.WXSdk.Implement.WeixinType.Grpc微信 && f.Status == Chat.Framework.WXSdk.WxStatus.在线); //var groupInfoList = new List() { "全部机器人" }; //foreach (var wx in wxs) //{ // comboBoxEdit1.Properties.Items.Add($"{wx.User.Nick}({wx.WeixinHao})"); // groupInfoList.Add(wx.WeixinHao); //} //comboBoxEdit1.Tag = groupInfoList; //if (comboBoxEdit1.Properties.Items.Count != 0) // comboBoxEdit1.SelectedIndex = 0; } catch (Exception ex) { } } private void xtraTabControl1_Selected(object sender, TabPageEventArgs e) { if (e.PageIndex == 2) pageControl2.Go(sender, e); } private void simpleButton1_Click(object sender, EventArgs e) { try { var session = ApiClient.GetSession(); //var groupList = comboBoxEdit1.Tag as List; //var groupInfos = new List(); //if (comboBoxEdit1.SelectedIndex == 0) //{ //var wxs = Chat.Framework.ChatClient.WXClient.Values.Where(f => f.WeixinType == WeixinType.Grpc微信 && f.Status == WxStatus.在线); //foreach (var wx in wxs) //{ // groupInfos.AddRange(GroupParse(wx)); //} //} // else // { // var wx = Chat.Framework.ChatClient.WXClient.Values.First(f => f.WeixinType == WeixinType.Grpc微信 && f.Status == WxStatus.在线 && f.WeixinHao == groupList[comboBoxEdit1.SelectedIndex]); // if (wx == null) throw new Exception("微信不在线"); // groupInfos.AddRange(GroupParse(wx)); //} var groupInfos = new List(); var key = textEdit1.Text.Trim(); if (string.IsNullOrWhiteSpace(key)) groupInfos = session.Queryable().GroupBy(f => f.groupid).Select(z => new GroupInfo() { groupid = z.groupid, groupnick = z.groupnick }).ToList(); else groupInfos = session.Queryable().Where(f => f.groupid.Contains(key) || f.groupnick.Contains(key)).GroupBy(f => f.groupid).Select(z => new GroupInfo() { groupid = z.groupid, groupnick = z.groupnick }).ToList(); gridControl1.DataSource = groupInfos; } catch (Exception ex) { ShowError(ex); } } //public List GroupParse(WeixinBase wx) //{ // var groupInfos = new List(); // try // { // var ipad = wx as WXClientImpl_IPAD; // if (ipad == null) return null; // ipad.GetContact // if (ipad.Friends.Count == 0) { } // var temps = ipad.Friends.Values.Where(f => f.UserName.Contains("@chatroom")); // foreach (var item in temps) // { // groupInfos.Add(new GroupInfo() { robotname = ipad.WeixinHao, robotnick = ipad.User.Nick, groupid = item.UserName, groupnick = item.NickName }); // } // } // catch (Exception ex) // { } // return groupInfos; //} private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { Util.Save(Class1.Config); } private void 查看用户ToolStripMenuItem_Click(object sender, EventArgs e) { try { var rows = gridView1.GetSelectedRows(); if (rows == null || rows.Length <= 0) throw new Exception("获取数据异常"); //var username = gridView1.GetRowCellValue(rows[0], "robotname").ToString(); //var robotnick = gridView1.GetRowCellValue(rows[0], "robotnick").ToString(); var groupid = gridView1.GetRowCellValue(rows[0], "groupid").ToString(); //var groupnick = gridView1.GetRowCellValue(rows[0], "groupnick").ToString(); xtraTabControl1.SelectedTabPageIndex = 2; textEdit2.Text = groupid; textEdit3.Text = string.Empty; simpleButton2_Click(null, null); } catch (Exception ex) { ShowError(ex); } } private void simpleButton2_Click(object sender, EventArgs e) { pageControl2.Go(sender, e); } private void toolStripMenuItem1_Click(object sender, EventArgs e) { try { var rows = this.gridView2.GetSelectedRows(); if (rows != null && rows.Length > 0) { var row = this.gridView2.GetRow(rows[0]) as FissionClass; var cashForm = new CashForm(row); if (cashForm.ShowDialog() == DialogResult.OK) { pageControl2.Go(sender, e); } } } catch (Exception ex) { ShowError(ex); } } } }