490 lines
22 KiB
C#
490 lines
22 KiB
C#
using Api.Framework;
|
|
using Api.Framework.Cps;
|
|
using Api.Framework.Enums;
|
|
using Api.Framework.Model;
|
|
using Api.Framework.Tools;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using UI.Framework.Controls;
|
|
using UI.Framework.Forms;
|
|
using Weixin.TBCirclePromotion.Entitys;
|
|
using Weixin.TBCirclePromotion.Properties;
|
|
using static Api.Framework.ApiClient;
|
|
using static Weixin.TBCirclePromotion.Enums;
|
|
|
|
namespace Weixin.TBCirclePromotion
|
|
{
|
|
public partial class MainForm : BaseForm
|
|
{
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
this.Text = Resources.MainFormTitle;
|
|
}
|
|
|
|
public void CloseForm()
|
|
{
|
|
if (!this.IsDisposed)
|
|
{
|
|
this.Invoke(new Action(delegate
|
|
{
|
|
this.Close();
|
|
this.Dispose();
|
|
}));
|
|
}
|
|
}
|
|
|
|
private void Bind()
|
|
{
|
|
try
|
|
{
|
|
|
|
bc_CJSwitch.Checked = Class1.Config.HDK_Switch == SwitchType.开启;
|
|
nud_GatherTouchNum.Value = Class1.Config.HDK_GatherTouchNum;
|
|
cb_GatherType.SelectedIndex = (int)Class1.Config.HDK_GatherType;
|
|
cb_Category.SelectedIndex = (int)Class1.Config.HDK_Category;
|
|
cb_Stage.SelectedIndex = ((int)Class1.Config.HDK_Stage) + 1;
|
|
nud_Price1.Value = (decimal)(Class1.Config.HDK_Price1 ?? 0);
|
|
nud_Price2.Value = (decimal)(Class1.Config.HDK_Price2 ?? 0);
|
|
nud_Rate.Value = (decimal)(Class1.Config.HDK_Rate ?? 0);
|
|
nud_Brokerage.Value = (decimal)(Class1.Config.HDK_Brokerage ?? 0);
|
|
nud_CouponMoney.Value = (decimal)(Class1.Config.HDK_CouponMoney ?? 0);
|
|
nud_Sales.Value = (decimal)(Class1.Config.HDK_Sales ?? 0);
|
|
nud_Avgmin.Value = (decimal)(Class1.Config.HDK_Avgmin ?? 0);
|
|
cb_Model.SelectedIndex = (int)Class1.Config.HDK_Model;
|
|
rb_duo.Checked = true;
|
|
if (Class1.Config.HDK_SendMode == SendModeType.多产品)
|
|
rb_duo.Checked = true;
|
|
else
|
|
rb_shao.Checked = true;
|
|
|
|
var times = Class1.Config.HDK_SendTaskTimes[0].Split('-');
|
|
dt_SendTaskTimes1.Value = DateTime.Parse($"2020-01-01 {times[0]}");
|
|
dt_SendTaskTimes2.Value = DateTime.Parse($"2020-01-01 {times[1]}");
|
|
nud_IntervalCircle.Value = (decimal)Class1.Config.HDK_Interval_Circle;
|
|
nud_SendGoodsImageNum.Value = (decimal)Class1.Config.HDK_Multi_SendGoodsImageNum;
|
|
me_MultiContentCircle.Text = Class1.Config.HDK_Multi_ContentCircle;
|
|
me_MultiGoodsDesc.Text = Class1.Config.HDK_Multi_GoodsDesc;
|
|
me_MultiAdditionalComment.Text = Class1.Config.HDK_Multi_AdditionalComment;
|
|
bc_SingleIsSynthCoupon.Checked = Class1.Config.HDK_Single_IsSynthCoupon == SwitchType.开启;
|
|
bc_SingleIsQRCodePic.Checked = Class1.Config.HDK_Single_IsQRCodePic == SwitchType.开启;
|
|
me_SingleGoodsQRCodePicDesc.Text = Class1.Config.HDK_Single_GoodsQRCodePicDesc;
|
|
me_SingleContentCircle.Text = Class1.Config.HDK_Single_ContentCircle;
|
|
me_SingleAdditionalComment.Text = Class1.Config.HDK_Single_AdditionalComment;
|
|
bc_AutoClearTask.Checked = Class1.Config.HDK_Auto_IsClear == SwitchType.开启;
|
|
dt_AutoClearTaskTimes.Value = DateTime.Parse(Class1.Config.HDK_AutoClearTaskTimes);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
|
|
|
|
|
|
private void Save(FormClosingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (nud_Price1.Value > nud_Price2.Value)
|
|
throw new Exception("商品售价第一个值不能大于第二个值");
|
|
|
|
if (dt_SendTaskTimes1.Value > dt_SendTaskTimes2.Value)
|
|
throw new Exception("发送任务时间段第一个值不能大于第二个值");
|
|
|
|
Class1.Config.HDK_Price1 = nud_Price1.Value == 0 ? null : (double?)nud_Price1.Value;
|
|
Class1.Config.HDK_Price2 = nud_Price2.Value == 0 ? null : (double?)nud_Price2.Value;
|
|
|
|
|
|
Class1.Config.HDK_Switch = bc_CJSwitch.Checked ? SwitchType.开启 : SwitchType.关闭;
|
|
Class1.Config.HDK_GatherTouchNum = (int)nud_GatherTouchNum.Value;
|
|
Class1.Config.HDK_GatherType = (GatherType)cb_GatherType.SelectedIndex;
|
|
Class1.Config.HDK_Category = (CategoryType)cb_Category.SelectedIndex;
|
|
Class1.Config.HDK_Stage = (StageType)(cb_Stage.SelectedIndex - 1);
|
|
Class1.Config.HDK_Rate = nud_Rate.Value == 0 ? null : (double?)nud_Rate.Value;
|
|
Class1.Config.HDK_Brokerage = nud_Brokerage.Value == 0 ? null : (double?)nud_Brokerage.Value;
|
|
Class1.Config.HDK_CouponMoney = nud_CouponMoney.Value == 0 ? null : (double?)nud_CouponMoney.Value;
|
|
Class1.Config.HDK_Sales = nud_Sales.Value == 0 ? null : (int?)nud_Sales.Value;
|
|
Class1.Config.HDK_Avgmin = nud_Avgmin.Value == 0 ? null : (double?)nud_Avgmin.Value;
|
|
Class1.Config.HDK_Model = (QrImageType)cb_Model.SelectedIndex;
|
|
Class1.Config.HDK_SendMode = rb_duo.Checked ? SendModeType.多产品 : SendModeType.单产品;
|
|
Class1.Config.HDK_SendTaskTimes = new string[] { (dt_SendTaskTimes1.Value.ToString("HH:mm") + "-" + dt_SendTaskTimes2.Value.ToString("HH:mm")) };
|
|
Class1.Config.HDK_Interval_Circle = (int)nud_IntervalCircle.Value;
|
|
Class1.Config.HDK_Multi_SendGoodsImageNum = (int)nud_SendGoodsImageNum.Value;
|
|
Class1.Config.HDK_Multi_ContentCircle = me_MultiContentCircle.Text;
|
|
Class1.Config.HDK_Multi_GoodsDesc = me_MultiGoodsDesc.Text;
|
|
Class1.Config.HDK_Multi_AdditionalComment = me_MultiAdditionalComment.Text;
|
|
Class1.Config.HDK_Single_IsSynthCoupon = bc_SingleIsSynthCoupon.Checked ? SwitchType.开启 : SwitchType.关闭;
|
|
Class1.Config.HDK_Single_IsQRCodePic = bc_SingleIsQRCodePic.Checked ? SwitchType.开启 : SwitchType.关闭;
|
|
Class1.Config.HDK_Single_GoodsQRCodePicDesc = me_SingleGoodsQRCodePicDesc.Text;
|
|
Class1.Config.HDK_Single_ContentCircle = me_SingleContentCircle.Text;
|
|
Class1.Config.HDK_Single_AdditionalComment = me_SingleAdditionalComment.Text;
|
|
Class1.Config.HDK_Auto_IsClear = bc_AutoClearTask.Checked ? SwitchType.开启 : SwitchType.关闭;
|
|
Class1.Config.HDK_AutoClearTaskTimes = dt_AutoClearTaskTimes.Value.ToString("HH:mm");
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
e.Cancel = true;
|
|
BaseForm.ShowError(ex);
|
|
}
|
|
}
|
|
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//settingControl1.Bind(Class1.Config, 120); //绑定控件
|
|
|
|
Bind();
|
|
|
|
#region 加载所有采集到的商品
|
|
pageControl1.Bind((page, size) =>
|
|
{
|
|
var session = ApiClient.GetSession();
|
|
var parm = session.NewParamMap();
|
|
parm.setPageParamters(page, size);
|
|
var result = session.FindPage<fl_plugin_tbcirclepromotion_goodsinfos>("select * from fl_plugin_tbcirclepromotion_goodsinfos order by state desc", parm);
|
|
return new PageControl.SerchResult() { Result = result.DataList, Total = result.Total };
|
|
}, gridControl1, 40, true, true);
|
|
|
|
label2.Visible = gridView1.RowCount == 0;
|
|
|
|
#endregion
|
|
|
|
#region 加载所有的账号
|
|
|
|
pageControl2.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.onoff as onoff,flag.adzone_pid_cps_name as adzone_pid_cps_name 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 where ri.type = 2", parm);
|
|
return new PageControl.SerchResult() { Result = result.DataList, Total = result.Total };
|
|
}, gridControl2, 40, true, true);
|
|
|
|
label1.Visible = gridView2.RowCount == 0;
|
|
|
|
#endregion
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Save(e);
|
|
Api.Framework.Tools.Util.Save(Class1.Config);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.Column.Caption == "数据来源")
|
|
{
|
|
var value = e.Value.ToString().ToLower();
|
|
if (value == "0")
|
|
e.DisplayText = "文件导入";
|
|
else if (value == "1")
|
|
e.DisplayText = "接口采集";
|
|
}
|
|
if (e.Column.Caption == "发送状态")
|
|
{
|
|
var value = e.Value.ToString().ToLower();
|
|
if (value == "true")
|
|
e.DisplayText = "未推广";
|
|
else if (value == "false")
|
|
e.DisplayText = "已推广";
|
|
}
|
|
if (e.Column.Caption == "佣金比例")
|
|
e.DisplayText = e.Value.ToString() + "%";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
/// <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 == "adzone_name" && (e.Value == null || string.IsNullOrEmpty(e.Value.ToString()))) e.DisplayText = "双击设置";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
return;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 行单元格单击事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void gridView2_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var selectRow = gridView2.GetSelectedRows()[0];
|
|
var id = this.gridView2.GetRowCellValue(selectRow, "ID").ToString();//获取列的数据
|
|
|
|
#region 双击单元格设置推广位
|
|
//点击数大于2弹出窗体进行推广位的选择
|
|
if (e.Clicks >= 2)
|
|
{
|
|
if (e.Column.FieldName == "adzone_name")
|
|
{
|
|
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.阿里妈妈);
|
|
if (tgwObj != null)
|
|
{
|
|
var tgw = tgwObj as Tuiguangwei;
|
|
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)//数据库中存在的情况
|
|
{
|
|
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.Insertable(adzone).ExecuteReturnEntity();
|
|
if (0 == adzone.id)
|
|
throw new Exception("对不起,推广位设置异常,请稍后重试!");
|
|
//else session.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//session.Rollback();
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
pageControl2.GotoPage(1);
|
|
label2.Visible = gridView1.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);
|
|
pageControl2.GotoPage(1);
|
|
label2.Visible = gridView1.RowCount == 0;
|
|
session.FindAdzoneInfos(true);
|
|
//session.FindTBCirclePromotions(true);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void 删除选中项ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var rownumber = gridView1.GetSelectedRows().ToList();//获取选中行号;
|
|
if (rownumber != null & rownumber.Count != 0)
|
|
{
|
|
List<string> goodsids = new List<string>();
|
|
foreach (var item in rownumber)
|
|
{
|
|
goodsids.Add("'" + gridView1.GetRowCellValue(item, "goods_id").ToString() + "'");//根据行号获取相应行的数据
|
|
}
|
|
var session = ApiClient.GetSession();
|
|
session.ExcuteSQL("delete from fl_plugin_tbcirclepromotion_goodsinfos where goods_id in (" + string.Join(",", goodsids) + ")");
|
|
pageControl1.GotoPage(1);
|
|
ShowSuccess("删除成功");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void 删除所有已发ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
RemoveGoodsInfos("delete from fl_plugin_tbcirclepromotion_goodsinfos where state = 0");
|
|
}
|
|
|
|
private void 删除所有数据ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
RemoveGoodsInfos("delete from fl_plugin_tbcirclepromotion_goodsinfos");
|
|
}
|
|
|
|
private void RemoveGoodsInfos(string sql)
|
|
{
|
|
try
|
|
{
|
|
var session = ApiClient.GetSession();
|
|
session.ExcuteSQL(sql);
|
|
pageControl1.GotoPage(1);
|
|
ShowSuccess("删除成功");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测是否与发单推广位有重复
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void simpleButton1_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var session = ApiClient.GetSession();
|
|
var adzones = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.阿里妈妈 && f.custom_type == Resources.SoftwareType).ToList();//发单推广位集合
|
|
var circleToolsAdzones = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.阿里妈妈 && f.custom_type == Resources.CricleToolsSoftwareType).ToList();//朋友圈推广位集合
|
|
|
|
var tbCricleAdzones = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.阿里妈妈 && f.custom_type == Resources.TbRebateSoftwareType).ToList();//淘宝返利
|
|
adzones.AddRange(circleToolsAdzones);
|
|
|
|
if (tbCricleAdzones != null && adzones != null)
|
|
{
|
|
StringBuilder strb = new StringBuilder();
|
|
foreach (var item in tbCricleAdzones)
|
|
{
|
|
foreach (var moment in adzones)
|
|
{
|
|
if (item.adzone_pid == moment.adzone_pid)
|
|
strb.AppendLine(moment.adzone_name);
|
|
}
|
|
}
|
|
if (strb.Length != 0)
|
|
ShowSuccess(@"以下推广位和淘宝返利推广设置有冲突
|
|
请及时处理,否则订单将无法自动绑定
|
|
" + strb.ToString());
|
|
else ShowSuccess("不存在冲突推广位");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void simpleButton2_Click(object sender, EventArgs e)
|
|
{
|
|
var importData = new ImportDataForm();
|
|
importData.ShowDialog();
|
|
pageControl1.GotoPage(1);
|
|
}
|
|
|
|
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
panel1.Enabled = cb_GatherType.SelectedIndex == 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
BaseForm.ShowError(ex);
|
|
}
|
|
}
|
|
|
|
private void rb_duo_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (rb_duo.Checked)
|
|
{
|
|
panel3.Enabled = false;
|
|
panel2.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void rb_shao_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (rb_shao.Checked)
|
|
{
|
|
panel2.Enabled = false;
|
|
panel3.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void labelControl31_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |