old_flsystem/应用/PDDRebate/MainForm.cs

319 lines
16 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Api.Framework;
using Api.Framework.Cps;
using Api.Framework.Enums;
using Api.Framework.Model;
using Api.Framework.Tools;
using PDDRebate.Entitys;
using PDDRebate.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 PDDRebate
{
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.buttonCheck.Checked = Class1.Config.AShop_SameCommodity_Switch;
this.numericUpDown3.Value = Class1.Config.AShop_SameCommodity_Number;
this.comboBox1.SelectedIndex = Class1.Config.AShop_SameCommodity_OperateType == OperateType. ? 0 : 1;
this.buttonCheck1.Checked = Class1.Config.AShop_DifferentCommodity_Switch;
this.numericUpDown4.Value = Class1.Config.AShop_DifferentCommodity_Number;
this.comboBox2.SelectedIndex = Class1.Config.AShop_DifferentCommodity_OperateType == OperateType. ? 0 : 1;
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);
this.memoEdit6.Text = string.Join(",", Class1.Config.SellerIDRestrictlist);
#region
pageControl1.Bind((page, size) =>
{
var session = ApiClient.GetSession();
var parm = session.NewParamMap();
parm.setPageParamters(page, size);
var result = session.FindPage<pddinfo_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
}
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)
{
var adzoneInfo = CreateAdzoneInfo(string.Empty, string.Empty, string.Empty, id, item);
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);
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.FindPddInfoTempGroups(true);
session.FindAdzoneInfos(true);
session.FindPinduoduoAutoBindPid(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, 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, 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.FindPddInfoTempGroups(true);
pageControl1.GotoPage(1);
label1.Visible = gridView1.RowCount == 0;
session.FindAdzoneInfos(true);
session.FindPinduoduoAutoBindPid(true);//刷新推广位
}
}
#endregion
}
catch (Exception ex)
{
ShowError(ex);
}
}
/// <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;
}
}
/// <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>
private fl_adzone_info CreateAdzoneInfo(string adzone_name, string adzone_pid, string adzone_pid_cps_name, string rid, string item, bool onoff = false)
{
return new fl_adzone_info()
{
custom_type = Resources.SoftwareType, //自定义类型
adzone_name = adzone_name, //推广位名称
adzone_pid = adzone_pid, //推广位pid
adzone_pid_cps_name = adzone_pid_cps_name, //推广位cps名称
alliance_id = (int)CpsType., //联盟id
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(object sender, FormClosingEventArgs e)
{
Class1.Config.AShop_SameCommodity_Switch = buttonCheck.Checked;
Class1.Config.AShop_SameCommodity_Number = (int)numericUpDown3.Value;
Class1.Config.AShop_SameCommodity_OperateType = comboBox1.SelectedIndex == 0 ? OperateType. : OperateType.;
Class1.Config.AShop_DifferentCommodity_Switch = buttonCheck1.Checked;
Class1.Config.AShop_DifferentCommodity_Number = (int)numericUpDown4.Value;
Class1.Config.AShop_DifferentCommodity_OperateType = comboBox2.SelectedIndex == 0 ? OperateType. : OperateType.;
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.notice_robotname = comboBox4.SelectedValue.ToString();
Class1.Config.ItemIDRestrictList = memoEdit5.Text.Trim().Replace("", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
Class1.Config.SellerIDRestrictlist = memoEdit6.Text.Trim().Replace("", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
Util.Save(Class1.Config);
OrderHelper.RefreshPddConfig(true);
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
labelControl7.Visible = labelControl8.Visible = numericUpDown2.Visible = comboBox3.SelectedIndex == 2;
checkBox3.Visible = comboBox3.SelectedIndex == 0;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
checkBox1.Visible = comboBox1.SelectedIndex == 0;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
checkBox2.Visible = comboBox2.SelectedIndex == 0;
}
}
}