old_flsystem/应用/Weixin.JDCirclePromotion/MainForm.cs

328 lines
14 KiB
C#
Raw 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.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using UI.Framework.Controls;
using UI.Framework.Forms;
using Weixin.JDCirclePromotion.Entitys;
using Weixin.JDCirclePromotion.Properties;
namespace Weixin.JDCirclePromotion
{
public partial class MainForm : BaseForm
{
public MainForm()
{
InitializeComponent();
}
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
{
this.Text = Resources.MainFormTitle;
settingControl1.Bind(Class1.Config, 120);
#region
pageControl1.Bind((page, size) =>
{
var session = ApiClient.GetSession();
var parm = session.NewParamMap();
parm.setPageParamters(page, size);
var result = session.FindPage<fl_plugin_jdcirclepromotion_goodsinfos>("select * from fl_plugin_jdcirclepromotion_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<jdinfo_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);
}
}
/// <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();//获取列的数据
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
{
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);
}
}
pageControl2.GotoPage(1);
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);
pageControl2.GotoPage(1);
label1.Visible = gridView2.RowCount == 0;
session.FindAdzoneInfos(true);
}
}
#endregion
}
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;
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Util.Save(Class1.Config);
}
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() + "%";
if (e.Column.Caption == "所有者")
e.DisplayText = (e.Value.ToString() == "g" ? "自营" : "第三方");
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void xtraTabControl1_TabIndexChanged(object sender, EventArgs e)
{
try
{
pageControl1.GotoPage(1);
label2.Visible = gridView1.RowCount == 0;
}
catch (Exception)
{ }
}
private void xtraTabControl1_Selected(object sender, DevExpress.XtraTab.TabPageEventArgs e)
{
try
{
if (e.PageIndex == 0)
{
pageControl1.GotoPage();
label2.Visible = gridView1.RowCount == 0;
}
else if (e.PageIndex == 1)
{
pageControl2.GotoPage();
label1.Visible = gridView2.RowCount == 0;
}
}
catch (Exception)
{ }
}
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, "skuId").ToString() + "'");//根据行号获取相应行的数据
}
var session = ApiClient.GetSession();
session.ExcuteSQL("delete from fl_plugin_jdcirclepromotion_goodsinfos where skuId 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_jdcirclepromotion_goodsinfos where state = 0");
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
RemoveGoodsInfos("delete from fl_plugin_jdcirclepromotion_goodsinfos");
}
private void RemoveGoodsInfos(string sql)
{
try
{
var session = ApiClient.GetSession();
session.ExcuteSQL(sql);
pageControl1.GotoPage(1);
ShowSuccess("删除成功");
}
catch (Exception ex)
{
ShowError(ex);
}
}
}
}