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 DYRebate.Entitys ;
using DYRebate.Properties ;
using SqlSugar ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Linq ;
using System.Windows.Forms ;
using UI.Framework.Controls ;
using UI.Framework.Forms ;
namespace DYRebate
{
public partial class MainForm : BaseForm
{
SqlSugarClient session = null ;
public MainForm ( )
{
InitializeComponent ( ) ;
this . Text = Resources . MainFormTitle ;
session = ApiClient . GetSession ( ) ;
}
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 )
{
try
{
var apis = ApiClient . GetSession ( ) . FindNoticeapiRobots ( ) . ToArray ( ) ;
var rst = new List < string > ( ) ;
rst . Add ( "请选择(钉钉/微信群机器人API名称) " ) ;
foreach ( var item in apis ) rst . Add ( item . name ) ;
comboBox4 . DataSource = rst ;
this . settingControl1 . Bind ( Class1 . Config , 110 ) ;
this . buttonCheck2 . Checked = Class1 . Config . ReceivingTimeCheck_Switch ;
this . numericUpDown1 . Value = Class1 . Config . ReceivingTimeCheck_Hour ;
this . comboBox3 . SelectedIndex = Class1 . Config . ReceivingTimeCheck_OperateType = = OperateType . 拉 入 黑 名 单 ? 0 : Class1 . Config . ReceivingTimeCheck_OperateType = = OperateType . 通 知 钉 钉 群 ? 1 : 2 ;
this . numericUpDown2 . Value = Class1 . Config . ReceivingTimeCheck_FreezeTime ;
this . comboBox4 . SelectedIndex = rst . IndexOf ( Class1 . Config . notice_robotname ) = = - 1 ? 0 : rst . IndexOf ( Class1 . Config . notice_robotname ) ;
this . memoEdit5 . Text = string . Join ( "," , Class1 . Config . ItemIDRestrictList ) ;
#region 加 载 所 有 的 账 号
pageControl1 . Bind ( ( page , size ) = >
{
var session = ApiClient . GetSession ( ) ;
var parm = session . NewParamMap ( ) ;
parm . setPageParamters ( page , size ) ;
var result = session . FindPage < dyinfo_temp > ( $"select ri.id as ID,ri.type as chattype,ri.name as name,ri.nick as nick,flag.* from fl_robot_info ri left join (select ai1_temp.robot_id as id,ai1_temp.onoff as onoff,ai1_temp.adzone_pid_cps_name as pid_chief_cps_name,ai1_temp.adzone_pid as pid_chief,ai1_temp.adzone_name as pid_chief_name,ai2_temp.adzone_pid_cps_name as pid_deputy_cps_name,ai2_temp.adzone_pid as pid_deputy,ai2_temp.adzone_name as pid_deputy_name from (select * from fl_adzone_info ai1 where ai1.alliance_id = '{(int)CpsType.抖音联盟}' and ai1.custom_type = '{Resources.SoftwareType}' and ai1.extend = 'chief') ai1_temp INNER JOIN (select * from fl_adzone_info ai2 where ai2.alliance_id = '{(int)CpsType.抖音联盟}' and ai2.custom_type = '{Resources.SoftwareType}' and ai2.extend='deputy') ai2_temp on ai1_temp.robot_id = ai2_temp.robot_id) flag on ri.id = flag.id" , parm ) ;
return new PageControl . SerchResult ( ) { Result = result . DataList , Total = result . Total } ;
} , gridControl1 , 40 , true , true ) ;
label1 . Visible = gridView1 . RowCount = = 0 ;
#endregion
2023-04-06 01:07:55 +00:00
#region 加 载 所 有 抖 客 的 账 号
pageControl2 . Bind ( ( page , size ) = >
{
var session = ApiClient . GetSession ( ) ;
var parm = session . NewParamMap ( ) ;
parm . setPageParamters ( page , size ) ;
var result = session . FindPage < dyinfo_temp > ( $"select ri.id as ID,ri.type as chattype,ri.name as name,ri.nick as nick,flag.* from fl_robot_info ri left join (select ai1_temp.robot_id as id,ai1_temp.onoff as onoff,ai1_temp.adzone_pid_cps_name as pid_chief_cps_name,ai1_temp.adzone_pid as pid_chief,ai1_temp.adzone_name as pid_chief_name,ai2_temp.adzone_pid_cps_name as pid_deputy_cps_name,ai2_temp.adzone_pid as pid_deputy,ai2_temp.adzone_name as pid_deputy_name from (select * from fl_adzone_info ai1 where ai1.alliance_id = '{(int)CpsType.抖客联盟}' and ai1.custom_type = '{Resources.SoftwareTypeDouKe}' and ai1.extend = 'chief') ai1_temp INNER JOIN (select * from fl_adzone_info ai2 where ai2.alliance_id = '{(int)CpsType.抖客联盟}' and ai2.custom_type = '{Resources.SoftwareTypeDouKe}' and ai2.extend='deputy') ai2_temp on ai1_temp.robot_id = ai2_temp.robot_id) flag on ri.id = flag.id" , parm ) ;
return new PageControl . SerchResult ( ) { Result = result . DataList , Total = result . Total } ;
} , gridControl2 , 40 , true , true ) ;
label2 . Visible = gridView2 . RowCount = = 0 ;
#endregion
2022-09-20 03:10:29 +00:00
}
catch ( Exception ex )
{
ShowError ( ex ) ;
}
}
/// <summary>
/// 行单元格单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridView1_RowCellClick ( object sender , DevExpress . XtraGrid . Views . Grid . RowCellClickEventArgs e )
{
try
{
#region 双 击 单 元 格 设 置 推 广 位
var selectRow = gridView1 . GetSelectedRows ( ) [ 0 ] ;
var id = this . gridView1 . GetRowCellValue ( selectRow , "ID" ) . ToString ( ) ; //获取列的数据
//点击数大于2弹出窗体进行推广位的选择
if ( e . Clicks > = 2 )
{
if ( e . Column . FieldName = = "pid_chief_name" | | e . Column . FieldName = = "pid_deputy_name" )
{
var tgwObj = CpsClient . SelectTuiguangwei ( CpsType . 抖 音 联 盟 ) ;
if ( tgwObj ! = null )
{
var tgw = tgwObj as Tuiguangwei ;
var session = ApiClient . GetSession ( ) ;
var adzones = session . FindAdzoneInfos ( true ) . Where ( f = > f . alliance_id = = ( int ) CpsType . 抖 音 联 盟 & & f . custom_type = = Resources . SoftwareType & & f . robot_id = = long . Parse ( id ) ) . ToList ( ) ;
var pidName = e . Column . FieldName = = "pid_chief_name" ? "chief" : "deputy" ;
var adzone = adzones . FirstOrDefault ( f = > f . extend = = pidName ) ;
#region 这 里 判 断 存 在 两 个 推 广 位 ( 主 / 副 ) , 不 存 在 的 ( 主 副 数 据 将 创 建 对 象 )
if ( adzones ! = null & & adzones . Count < 2 )
{
var pidNames = new string [ ] { "chief" , "deputy" } ;
if ( adzone = = null )
{
adzones = new List < fl_adzone_info > ( ) ;
foreach ( var item in pidNames )
{
2023-04-06 01:07:55 +00:00
var adzoneInfo = CreateAdzoneInfo ( string . Empty , string . Empty , string . Empty , id , item , CpsType . 抖 音 联 盟 ) ;
2022-09-20 03:10:29 +00:00
session . SaveOrUpdate ( adzoneInfo ) ;
adzones . Add ( adzoneInfo ) ;
}
}
else
{
var unCreate = pidNames . FirstOrDefault ( f = > f ! = adzone . extend ) ; //获取数据库中不存在的(主/副)推广位数据,下方添加不存在的对象
2023-04-06 01:07:55 +00:00
var adzoneInfo = CreateAdzoneInfo ( string . Empty , string . Empty , string . Empty , id , unCreate , CpsType . 抖 音 联 盟 ) ;
2022-09-20 03:10:29 +00:00
session . SaveOrUpdate ( adzoneInfo ) ;
adzones . Add ( adzoneInfo ) ;
}
}
#endregion
#region 有 出 现 两 个 重 复 无 法 修 复 的 情 况 , 删 除 一 个
var repetAdzone = adzones . Where ( f = > f . extend = = pidName ) . ToList ( ) ;
if ( repetAdzone . Count > 1 )
{
for ( int i = 1 ; i < = repetAdzone . Count - 1 ; i + + )
{
session . Deleteable ( repetAdzone [ i ] ) . ExecuteCommand ( ) ;
}
adzones = session . FindAdzoneInfos ( true ) . Where ( f = > f . alliance_id = = ( int ) CpsType . 抖 音 联 盟 & & f . custom_type = = Resources . SoftwareType & & f . robot_id = = long . Parse ( id ) ) . ToList ( ) ;
}
#endregion
adzone = adzones . FirstOrDefault ( f = > f . extend = = pidName ) ;
if ( adzone ! = null ) //数据库中存在的情况
{
adzone . adzone_pid_cps_name = tgw . Member . username ;
adzone . adzone_pid = tgw . Pid ;
adzone . adzone_name = tgw . Name ;
session . SaveOrUpdate ( adzone ) ;
}
pageControl1 . GotoPage ( 1 ) ;
label1 . Visible = gridView1 . RowCount = = 0 ;
session . FindDyInfoTempGroups ( true ) ;
session . FindAdzoneInfos ( true ) ;
session . FindDouyinAutoBindPid ( 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 adzones = session . FindAdzoneInfos ( true ) . Where ( f = > f . alliance_id = = ( int ) CpsType . 抖 音 联 盟 & & f . custom_type = = Resources . SoftwareType & & f . robot_id = = long . Parse ( id ) ) . ToList ( ) ;
#region 这 里 判 断 存 在 两 个 推 广 位 ( 主 / 副 ) , 不 存 在 的 ( 主 副 数 据 将 创 建 对 象 )
if ( adzones ! = null & & adzones . Count < 2 )
{
var pidNames = new string [ ] { "chief" , "deputy" } ;
if ( adzones . Count = = 0 )
{
adzones = new List < fl_adzone_info > ( ) ;
foreach ( var item in pidNames )
{
2023-04-06 01:07:55 +00:00
var adzoneInfo = CreateAdzoneInfo ( string . Empty , string . Empty , string . Empty , id , item , CpsType . 抖 音 联 盟 , false ) ;
2022-09-20 03:10:29 +00:00
session . SaveOrUpdate ( adzoneInfo ) ;
adzones . Add ( adzoneInfo ) ;
}
}
else
{
var unCreate = pidNames . FirstOrDefault ( f = > f ! = adzones [ 0 ] . extend ) ; //获取数据库中不存在的(主/副)推广位数据,下方添加不存在的对象
2023-04-06 01:07:55 +00:00
var adzoneInfo = CreateAdzoneInfo ( string . Empty , string . Empty , string . Empty , id , unCreate , CpsType . 抖 音 联 盟 , adzones [ 0 ] . onoff ) ;
2022-09-20 03:10:29 +00:00
session . SaveOrUpdate ( adzoneInfo ) ;
adzones . Add ( adzoneInfo ) ;
}
}
#endregion
if ( adzones ! = null ) //数据库中存在
session . ExcuteSQL ( "update fl_adzone_info set onoff = @onoff where robot_id = @robot_id and alliance_id = @alliance_id and custom_type = @custom_type" , new { onoff = ! adzones [ 0 ] . onoff , robot_id = id , alliance_id = ( int ) CpsType . 抖 音 联 盟 , custom_type = Resources . SoftwareType } ) ;
session . FindDyInfoTempGroups ( true ) ;
pageControl1 . GotoPage ( 1 ) ;
label1 . Visible = gridView1 . RowCount = = 0 ;
session . FindAdzoneInfos ( true ) ;
session . FindDouyinAutoBindPid ( true ) ; //刷新推广位
}
}
#endregion
}
catch ( Exception ex )
{
ShowError ( ex ) ;
}
}
2023-04-06 01:07:55 +00:00
/// <summary>
/// 行单元格单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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 )
{
if ( e . Column . FieldName = = "pid_chief_name" | | e . Column . FieldName = = "pid_deputy_name" )
{
var tgwObj = CpsClient . SelectTuiguangwei ( CpsType . 抖 客 联 盟 ) ;
if ( tgwObj ! = null )
{
var tgw = tgwObj as Tuiguangwei ;
var session = ApiClient . GetSession ( ) ;
var adzones = session . FindAdzoneInfos ( true ) . Where ( f = > f . alliance_id = = ( int ) CpsType . 抖 客 联 盟 & & f . custom_type = = Resources . SoftwareTypeDouKe & & f . robot_id = = long . Parse ( id ) ) . ToList ( ) ;
var pidName = e . Column . FieldName = = "pid_chief_name" ? "chief" : "deputy" ;
var adzone = adzones . FirstOrDefault ( f = > f . extend = = pidName ) ;
#region 这 里 判 断 存 在 两 个 推 广 位 ( 主 / 副 ) , 不 存 在 的 ( 主 副 数 据 将 创 建 对 象 )
if ( adzones ! = null & & adzones . Count < 2 )
{
var pidNames = new string [ ] { "chief" , "deputy" } ;
if ( adzone = = null )
{
adzones = new List < fl_adzone_info > ( ) ;
foreach ( var item in pidNames )
{
var adzoneInfo = CreateAdzoneInfo ( string . Empty , string . Empty , string . Empty , id , item , CpsType . 抖 客 联 盟 ) ;
session . SaveOrUpdate ( adzoneInfo ) ;
adzones . Add ( adzoneInfo ) ;
}
}
else
{
var unCreate = pidNames . FirstOrDefault ( f = > f ! = adzone . extend ) ; //获取数据库中不存在的(主/副)推广位数据,下方添加不存在的对象
var adzoneInfo = CreateAdzoneInfo ( string . Empty , string . Empty , string . Empty , id , unCreate , CpsType . 抖 客 联 盟 ) ;
session . SaveOrUpdate ( adzoneInfo ) ;
adzones . Add ( adzoneInfo ) ;
}
}
#endregion
#region 有 出 现 两 个 重 复 无 法 修 复 的 情 况 , 删 除 一 个
var repetAdzone = adzones . Where ( f = > f . extend = = pidName ) . ToList ( ) ;
if ( repetAdzone . Count > 1 )
{
for ( int i = 1 ; i < = repetAdzone . Count - 1 ; i + + )
{
session . Deleteable ( repetAdzone [ i ] ) . ExecuteCommand ( ) ;
}
adzones = session . FindAdzoneInfos ( true ) . Where ( f = > f . alliance_id = = ( int ) CpsType . 抖 客 联 盟 & & f . custom_type = = Resources . SoftwareTypeDouKe & & f . robot_id = = long . Parse ( id ) ) . ToList ( ) ;
}
#endregion
adzone = adzones . FirstOrDefault ( f = > f . extend = = pidName ) ;
if ( adzone ! = null ) //数据库中存在的情况
{
adzone . adzone_pid_cps_name = tgw . Member . username ;
adzone . adzone_pid = tgw . Pid ;
adzone . adzone_name = tgw . Name ;
session . SaveOrUpdate ( adzone ) ;
}
pageControl2 . GotoPage ( 1 ) ;
label2 . Visible = gridView2 . RowCount = = 0 ;
session . FindDyInfoTempGroups ( true ) ;
session . FindAdzoneInfos ( true ) ;
session . FindDoukeAutoBindPid ( 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 adzones = session . FindAdzoneInfos ( true ) . Where ( f = > f . alliance_id = = ( int ) CpsType . 抖 客 联 盟 & & f . custom_type = = Resources . SoftwareType & & f . robot_id = = long . Parse ( id ) ) . ToList ( ) ;
#region 这 里 判 断 存 在 两 个 推 广 位 ( 主 / 副 ) , 不 存 在 的 ( 主 副 数 据 将 创 建 对 象 )
if ( adzones ! = null & & adzones . Count < 2 )
{
var pidNames = new string [ ] { "chief" , "deputy" } ;
if ( adzones . Count = = 0 )
{
adzones = new List < fl_adzone_info > ( ) ;
foreach ( var item in pidNames )
{
var adzoneInfo = CreateAdzoneInfo ( string . Empty , string . Empty , string . Empty , id , item , CpsType . 抖 客 联 盟 , false ) ;
session . SaveOrUpdate ( adzoneInfo ) ;
adzones . Add ( adzoneInfo ) ;
}
}
else
{
var unCreate = pidNames . FirstOrDefault ( f = > f ! = adzones [ 0 ] . extend ) ; //获取数据库中不存在的(主/副)推广位数据,下方添加不存在的对象
var adzoneInfo = CreateAdzoneInfo ( string . Empty , string . Empty , string . Empty , id , unCreate , CpsType . 抖 客 联 盟 , adzones [ 0 ] . onoff ) ;
session . SaveOrUpdate ( adzoneInfo ) ;
adzones . Add ( adzoneInfo ) ;
}
}
#endregion
if ( adzones ! = null ) //数据库中存在
session . ExcuteSQL ( "update fl_adzone_info set onoff = @onoff where robot_id = @robot_id and alliance_id = @alliance_id and custom_type = @custom_type" , new { onoff = ! adzones [ 0 ] . onoff , robot_id = id , alliance_id = ( int ) CpsType . 抖 客 联 盟 , custom_type = Resources . SoftwareType } ) ;
session . FindDkInfoTempGroups ( true ) ;
pageControl2 . GotoPage ( 1 ) ;
label2 . Visible = gridView2 . RowCount = = 0 ;
session . FindAdzoneInfos ( true ) ;
session . FindDoukeAutoBindPid ( true ) ; //刷新推广位
}
}
#endregion
}
catch ( Exception ex )
{
ShowError ( ex ) ;
}
}
2022-09-20 03:10:29 +00:00
/// <summary>
/// 修改显示内容的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridView1_CustomColumnDisplayText ( object sender , DevExpress . XtraGrid . Views . Base . CustomColumnDisplayTextEventArgs e )
{
try
{
if ( ( e . Column . FieldName = = "pid_chief_name" | | e . Column . FieldName = = "pid_deputy_name" ) & & ( e . Value = = null | | string . IsNullOrEmpty ( e . Value . ToString ( ) ) ) ) e . DisplayText = "双击设置" ;
}
catch ( Exception ex )
{
ShowError ( ex ) ;
return ;
}
}
2023-04-06 01:07:55 +00:00
/// <summary>
/// 修改显示内容的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridView2_CustomColumnDisplayText ( object sender , DevExpress . XtraGrid . Views . Base . CustomColumnDisplayTextEventArgs e )
{
try
{
if ( ( e . Column . FieldName = = "pid_chief_name" | | e . Column . FieldName = = "pid_deputy_name" ) & & ( e . Value = = null | | string . IsNullOrEmpty ( e . Value . ToString ( ) ) ) ) e . DisplayText = "双击设置" ;
}
catch ( Exception ex )
{
ShowError ( ex ) ;
return ;
}
}
2022-09-20 03:10:29 +00:00
/// <summary>
/// 创建fl_adzone_info对象
/// </summary>
/// <param name="adzone_name"></param>
/// <param name="adzone_pid"></param>
/// <param name="adzone_pid_cps_name"></param>
/// <param name="rid"></param>
/// <param name="item"></param>
/// <returns></returns>
2023-04-06 01:07:55 +00:00
private fl_adzone_info CreateAdzoneInfo ( string adzone_name , string adzone_pid , string adzone_pid_cps_name , string rid , string item , CpsType cpsType , bool onoff = false )
2022-09-20 03:10:29 +00:00
{
return new fl_adzone_info ( )
{
2023-04-06 01:07:55 +00:00
custom_type = cpsType = = CpsType . 抖 音 联 盟 ? Resources . SoftwareType : Resources . SoftwareTypeDouKe , //自定义类型
2022-09-20 03:10:29 +00:00
adzone_name = adzone_name , //推广位名称
adzone_pid = adzone_pid , //推广位pid
adzone_pid_cps_name = adzone_pid_cps_name , //推广位cps名称
2023-04-06 01:07:55 +00:00
alliance_id = ( int ) cpsType , //联盟id
2022-09-20 03:10:29 +00:00
robot_id = int . Parse ( rid ) , //机器人id
group_id = string . Empty , //群id
member_id = 0 , //私人id
is_download = false , //不下载
onoff = onoff , //不禁用
extend = item
} ;
}
private void MainForm_FormClosing_1 ( object sender , FormClosingEventArgs e )
{
try
{
Class1 . Config . ReceivingTimeCheck_Switch = buttonCheck2 . Checked ;
Class1 . Config . ReceivingTimeCheck_Hour = ( int ) numericUpDown1 . Value ;
Class1 . Config . ReceivingTimeCheck_OperateType = comboBox3 . SelectedIndex = = 0 ? OperateType . 拉 入 黑 名 单 : comboBox3 . SelectedIndex = = 1 ? OperateType . 通 知 钉 钉 群 : OperateType . 订 单 冻 结 ;
Class1 . Config . ReceivingTimeCheck_FreezeTime = ( int ) numericUpDown2 . Value ;
Class1 . Config . ReceivingTimeCheck_UserTop = checkBox3 . Checked ;
Class1 . Config . notice_robotname = comboBox4 . SelectedValue . ToString ( ) ;
Class1 . Config . ItemIDRestrictList = memoEdit5 . Text . Trim ( ) . Replace ( ", " , "," ) . Split ( new string [ ] { "," } , StringSplitOptions . RemoveEmptyEntries ) . Select ( f = > f . Trim ( ) ) . ToList ( ) ;
Util . Save ( Class1 . Config ) ;
OrderHelper . RefreshDyConfig ( true ) ;
}
catch ( Exception ex )
{
ShowError ( ex ) ;
}
}
private void comboBox3_SelectedIndexChanged ( object sender , EventArgs e )
{
labelControl7 . Visible = labelControl8 . Visible = numericUpDown2 . Visible = comboBox3 . SelectedIndex = = 2 ;
checkBox3 . Visible = comboBox3 . SelectedIndex = = 0 ;
}
}
}