using Api.Framework; using Api.Framework.Cps; using Api.Framework.Enums; using Api.Framework.Model; using Api.Framework.Tools; using CouponsSend.Entitys; using CouponsSend.Properties; 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 CouponsSend { public partial class EditGroupInfoForm : BaseForm { string id = string.Empty; public EditGroupInfoForm(string id = "") { InitializeComponent(); this.id = id; } private void EditGroupInfoForm_Load(object sender, EventArgs e) { var robotname = string.Empty; if (!string.IsNullOrWhiteSpace(id)) { var session = ApiClient.GetSession(); var adzone = session.FindSingle("select * from fl_adzone_info where id = @id", new { id = id }); if (adzone != null)//数据库中存在的情况 { textBox2.Text = adzone.extend; textBox1.Text = adzone.group_id; hyperlinkLabelControl1.Text = string.IsNullOrWhiteSpace(adzone.adzone_name) ? "双击设置" : adzone.adzone_name; Tuiguangwei tgw = null; if (!string.IsNullOrWhiteSpace(adzone.adzone_pid)) tgw = new Tuiguangwei() { Pid = adzone.adzone_pid, Name = adzone.adzone_name, Member = new fl_cps_member() { username = adzone.adzone_pid_cps_name } }; hyperlinkLabelControl1.Tag = tgw; var robot = session.FindRobots().FirstOrDefault(f => f.id == adzone.robot_id); if (robot == null) return; robotname = robot.name; } } var realIndex = -1; var comList = new List(); this.comboBoxEdit1.Properties.Items.Add("请选择群所对应机器人"); var wxs = Chat.Framework.ChatClient.WXClient.Values.ToList(); foreach (var item in wxs) { comList.Add(new ComboxData() { Text = $"{item.User.Nick}({item.WeixinHao})", Value = item.WeixinHao, Type = (item.WeixinType == Chat.Framework.WXSdk.Implement.WeixinType.QYHook微信 ? Api.Framework.SDK.ChatType.企业微信 : Api.Framework.SDK.ChatType.微信) }); if (item.WeixinHao == robotname) realIndex = comList.Count; } var qqs = Chat.Framework.ChatClient.QQClients.Values; foreach (var item in qqs) { comList.Add(new ComboxData() { Text = $"{item.Nickname}({item.QQ})", Value = item.QQ.ToString(), Type = Api.Framework.SDK.ChatType.QQ }); if (item.QQ.ToString() == robotname) realIndex = comList.Count; } this.comboBoxEdit1.Properties.Items.AddRange(comList); this.comboBoxEdit1.SelectedIndex = realIndex == -1 ? 0 : realIndex; } private void simpleButton2_Click(object sender, EventArgs e) { this.Close(); } private void simpleButton1_Click(object sender, EventArgs e) { try { if (this.comboBoxEdit1.SelectedIndex == 0) throw new Exception("请选择群所对应机器人"); if (string.IsNullOrWhiteSpace(textBox2.Text)) throw new Exception("请填写群昵称!"); if (string.IsNullOrWhiteSpace(textBox1.Text)) throw new Exception("请填写群账号!"); var session = ApiClient.GetSession(); var value = (comboBoxEdit1.SelectedItem as ComboxData); var robot = session.FindRobots().FirstOrDefault(f => f.type == value.Type && f.name == value.Value); fl_adzone_info adzone = null; if (string.IsNullOrWhiteSpace(id)) { adzone = session.FindSingle("select * from fl_adzone_info where alliance_id = @alliance_id and custom_type = @custom_type and robot_id = @robot_id and group_id = @group_id", new { alliance_id = CpsType.阿里妈妈, custom_type = Resources.SoftwareType, robot_id = robot.id, group_id = textBox1.Text.Trim() }); } else adzone = session.FindSingle("select * from fl_adzone_info where id=@id", new { id = id }); Tuiguangwei tgw = null; if (hyperlinkLabelControl1.Tag != null) tgw = hyperlinkLabelControl1.Tag as Tuiguangwei; if (adzone != null)//数据库中存在的情况 { if (tgw != null) { adzone.adzone_name = tgw.Name; //推广位名称 adzone.adzone_pid = tgw.Pid; //推广位pid adzone.adzone_pid_cps_name = tgw.Member.username; //推广位cps名称 } adzone.extend = textBox2.Text.Trim(); adzone.group_id = textBox1.Text.Trim(); adzone.robot_id = robot.id; session.SaveOrUpdate(adzone); } else { try { adzone = new fl_adzone_info() { extend = textBox2.Text.Trim(), custom_type = Resources.SoftwareType, //自定义类型 adzone_name = tgw == null ? string.Empty : tgw.Name, //推广位名称 adzone_pid = tgw == null ? string.Empty : tgw.Pid, //推广位pid adzone_pid_cps_name = tgw == null ? string.Empty : tgw.Member.username, //推广位cps名称 alliance_id = (int)CpsType.阿里妈妈, //联盟id robot_id = robot.id, //机器人id group_id = textBox1.Text.Trim(), //群id member_id = 0, //私人id is_download = false, //不下载 onoff = false //不禁用 }; session.SaveOrUpdate(adzone); if (0 == adzone.id) throw new Exception("对不起,推广位设置异常,请稍后重试!"); } catch (Exception ex) { ShowError(ex); } } session.FindAdzoneInfos(true); } catch (Exception ex) { ShowError(ex); } } private void hyperlinkLabelControl1_Click(object sender, EventArgs e) { try { var session = ApiClient.GetSession(); var tgwObj = CpsClient.SelectTuiguangwei(CpsType.阿里妈妈); if (tgwObj != null) { hyperlinkLabelControl1.Tag = tgwObj; var tgw = tgwObj as Tuiguangwei; hyperlinkLabelControl1.Text = tgw.Name; } } catch (Exception ex) { ShowError(ex); } } } }