old_flsystem/应用/Weixin.CircleTools/SetTGWForm.cs

261 lines
14 KiB
C#
Raw Permalink Normal View History

2022-09-20 03:10:29 +00:00
using Api.Framework;
using Api.Framework.Cps;
using Api.Framework.Enums;
using Api.Framework.Model;
using Api.Framework.Tools;
using System;
using System.Linq;
using System.Windows.Forms;
using UI.Framework.Controls;
using UI.Framework.Forms;
using Weixin.CircleTools.Entitys;
using Weixin.CircleTools.Properties;
namespace Weixin.CircleTools
{
public partial class SetTGWForm : BaseForm
{
public SetTGWForm()
{
InitializeComponent();
this.Text = Resources.AutoTurnTGWFormTitle;
}
private void SetTGWForm_Load(object sender, EventArgs e)
{
try
{
#region
pageControl1.Bind((page, size) =>
{
var session = ApiClient.GetSession();
var parm = session.NewParamMap();
parm.setPageParamters(page, size);
var result = session.FindPage<tbinfo_temp>($"select ri.id as ID,ri.type as chattype,ri.name as name,ri.nick as nick,flag.adzone_pid as adzone_pid,flag.adzone_name as adzone_name,flag.adzone_pid_cps_name as adzone_pid_cps_name,flag2.adzone_pid as adzone_pid_jd,flag2.adzone_name as adzone_name_jd,flag2.adzone_pid_cps_name as adzone_pid_cps_name_jd ,flag.onoff as onoff from fl_robot_info ri left join (select r.id as ID,r.type as chattype,r.name as name,r.nick as nick,a.adzone_pid as adzone_pid,a.adzone_name as adzone_name,a.onoff as onoff,a.adzone_pid_cps_name as adzone_pid_cps_name from fl_robot_info r left join fl_adzone_info a on r.id = a.robot_id where alliance_id = '{(int)CpsType.阿里妈妈}' and custom_type = '{Resources.SoftwareType}') flag on ri.id = flag.ID left join (select r.id as ID,r.type as chattype,r.name as name,r.nick as nick,a.adzone_pid as adzone_pid,a.adzone_name as adzone_name,a.onoff as onoff,a.adzone_pid_cps_name as adzone_pid_cps_name from fl_robot_info r left join fl_adzone_info a on r.id = a.robot_id where alliance_id = '{(int)CpsType.京东联盟}' and custom_type = '{Resources.SoftwareType}') flag2 on ri.id = flag2.ID", parm);
return new PageControl.SerchResult() { Result = result.DataList, Total = result.Total };
}, gridControl1, 40, true, true);
label1.Visible = gridView2.RowCount == 0;
#endregion
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void gridView2_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
try
{
#region 广
var selectRow = gridView2.GetSelectedRows()[0];
var id = this.gridView2.GetRowCellValue(selectRow, "ID").ToString();//获取列的数据
//点击数大于2弹出窗体进行推广位的选择
if (e.Clicks >= 2)
{
var session = ApiClient.GetSession();
if (e.Column.FieldName == "adzone_name")
{
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.);
if (tgwObj != null)
{
var tgw = tgwObj as Tuiguangwei;
#region 广
var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType. && f.custom_type == Resources.SoftwareType && f.robot_id == long.Parse(id));
if (adzone != null)//数据库中存在的情况
{
if (e.Column.FieldName == "adzone_name")
{
adzone.adzone_pid_cps_name = tgw.Member.username;
adzone.adzone_pid = tgw.Pid;
adzone.adzone_name = tgw.Name;
}
session.SaveOrUpdate(adzone);
}
else
{
//session.BeginTransaction();
try
{
if (e.Column.FieldName == "adzone_name")
adzone = new fl_adzone_info()
{
custom_type = Resources.SoftwareType, //自定义类型
adzone_name = tgw.Name, //推广位名称
adzone_pid = tgw.Pid, //推广位pid
adzone_pid_cps_name = tgw.Member.username, //推广位cps名称
alliance_id = (int)CpsType., //联盟id
robot_id = int.Parse(id), //机器人id
group_id = string.Empty, //群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);
}
}
#endregion
}
}
//if (e.Column.FieldName == "adzone_name_jd")
//{
// var tgw = CpsClient.SelectTuiguangwei(CpsType.京东联盟);
// if (tgw != null)
// {
// #region 京东推广位
// var adzone_jd = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.京东联盟 && f.custom_type == Resources.SoftwareType && f.robot_id == long.Parse(id));
// if (adzone_jd != null)//数据库中存在的情况
// {
// if (e.Column.FieldName == "adzone_name_jd")
// {
// adzone_jd.adzone_pid_cps_name = tgw.Member.username;
// adzone_jd.adzone_pid = tgw.Pid;
// adzone_jd.adzone_name = tgw.Name;
// }
// session.SaveOrUpdate(adzone_jd);
// }
// else
// {
// //session.BeginTransaction();
// try
// {
// if (e.Column.FieldName == "adzone_name_jd")
// adzone_jd = new fl_adzone_info()
// {
// custom_type = Resources.SoftwareType, //自定义类型
// adzone_name = tgw.Name, //推广位名称
// adzone_pid = tgw.Pid, //推广位pid
// adzone_pid_cps_name = tgw.Member.username, //推广位cps名称
// alliance_id = (int)CpsType.京东联盟, //联盟id
// robot_id = int.Parse(id), //机器人id
// group_id = string.Empty, //群id
// member_id = 0, //私人id
// is_download = false, //不下载
// onoff = false //不禁用
// };
// session.SaveOrUpdate(adzone_jd);
// if (0 == adzone_jd.id)
// throw new Exception("对不起,推广位设置异常,请稍后重试!");
// }
// catch (Exception ex)
// {
// ShowError(ex);
// }
// }
// #endregion
// }
//}
pageControl1.GotoPage(1);
session.FindTbInfoTempGroups(true);
label1.Visible = gridView2.RowCount == 0;
session.FindAdzoneInfos(true);
}
#endregion
#region
if (e.Column.FieldName == "onoff")
{
if (e.Clicks == 1)
{
if (!(bool)e.CellValue && MessageBox.Show("该微信推广位确定禁用?", "系统提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
return;
var session = ApiClient.GetSession();
var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType. && f.custom_type == Resources.SoftwareType && f.robot_id == long.Parse(id));
if (adzone != null)//数据库中存在的情况,并且推广位设置了
adzone.onoff = !adzone.onoff;
else
adzone = new fl_adzone_info()
{
custom_type = Resources.SoftwareType, //自定义类型
adzone_name = string.Empty, //推广位名称
adzone_pid = string.Empty, //推广位pid
adzone_pid_cps_name = string.Empty, //推广位cps名称
alliance_id = (int)CpsType., //联盟id
robot_id = int.Parse(id), //机器人id
group_id = string.Empty, //群id
member_id = 0, //私人id
is_download = false, //不下载
onoff = true //不禁用
};
session.SaveOrUpdate(adzone);
pageControl1.GotoPage(1);
label1.Visible = gridView2.RowCount == 0;
session.FindTbInfoTempGroups(true);
session.FindAdzoneInfos(true);
}
}
#endregion
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void gridView2_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
try
{
if ((e.Column.FieldName == "adzone_name" || e.Column.FieldName == "adzone_name_jd") && (e.Value == null || string.IsNullOrEmpty(e.Value.ToString()))) e.DisplayText = "双击设置";
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void 广ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var selectRow = gridView2.GetSelectedRows()[0];
var id = this.gridView2.GetRowCellValue(selectRow, "ID").ToString();//获取列的数据
var session = ApiClient.GetSession();
var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType. && f.custom_type == Resources.SoftwareType && f.robot_id == long.Parse(id));
if (adzone != null)//数据库中存在的情况
{
session.Deleteable(adzone).ExecuteCommand();
pageControl1.GotoPage(1);
session.FindTbInfoTempGroups(true);
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void 广ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var selectRow = gridView2.GetSelectedRows()[0];
var id = this.gridView2.GetRowCellValue(selectRow, "ID").ToString();//获取列的数据
var session = ApiClient.GetSession();
var adzone_jd = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType. && f.custom_type == Resources.SoftwareType && f.robot_id == long.Parse(id));
if (adzone_jd != null)//数据库中存在的情况
{
session.Deleteable(adzone_jd).ExecuteCommand();
pageControl1.GotoPage(1);
session.FindTbInfoTempGroups(true);
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
}
}