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

399 lines
18 KiB
C#
Raw Normal View History

2022-09-20 03:10:29 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using UI.Framework.Forms;
using Weixin.AccurateCircle.Properties;
using Api.Framework.Enums;
using Api.Framework;
using Api.Framework.Cps;
using Api.Framework.Model;
using Api.Framework.Tools;
using Weixin.AccurateCircle.Entitys;
using UI.Framework.Controls;
namespace Weixin.AccurateCircle
{
public partial class MainForm : BaseForm
{
public MainForm()
{
InitializeComponent();
this.Text = Resources.MainFormTitle;
}
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
{
try
{
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_accuratecircle_dataInfos>("select * from fl_plugin_accuratecircle_dataInfos 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();
int total = 0;
var result = session.Queryable<fl_robot_info>().Select<info_temp>(f => new info_temp()
{
ID = f.id,
chattype = f.type,
name = f.name,
nick = f.nick
}).ToPageList(1, 50, ref total);
if (result != null && result.Count != 0)
{
foreach (var robot in result)
{
var adzones = session.FindAdzoneInfos().Where(f => f.custom_type == Resources.SoftwareType && f.robot_id == robot.ID).ToList();
if (adzones != null && adzones.Count != 0)
{
robot.onoff = adzones[0].onoff;
foreach (var item in adzones)
{
if (item.alliance_id == (int)CpsType.)
{
robot.tb_adzone_name = item.adzone_name;
robot.tb_adzone_pid = item.adzone_pid;
robot.tb_adzone_pid_cps_name = item.adzone_pid_cps_name;
}
else if (item.alliance_id == (int)CpsType.)
{
robot.jd_adzone_name = item.adzone_name;
robot.jd_adzone_pid = item.adzone_pid;
robot.jd_adzone_pid_cps_name = item.adzone_pid_cps_name;
}
else if (item.alliance_id == (int)CpsType.)
{
robot.pdd_adzone_name = item.adzone_name;
robot.pdd_adzone_pid = item.adzone_pid;
robot.pdd_adzone_pid_cps_name = item.adzone_pid_cps_name;
}
}
}
}
}
return new PageControl.SerchResult() { Result = result, Total = total };
}, gridControl2, 40, true, true);
label1.Visible = gridView2.RowCount == 0;
#endregion
}
catch (Exception ex)
{
ShowError(ex);
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
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 广
if (e.Clicks >= 2)
{
if (e.Column.FieldName == "tb_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 == int.Parse(id));
if (adzone != null)//数据库中存在的情况
{
adzone.adzone_pid_cps_name = tgw.Member.username;
adzone.adzone_pid = tgw.Pid;
adzone.adzone_name = tgw.Name;
session.SaveOrUpdate(adzone);
}
else
{
try
{
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("对不起,推广位设置异常,请稍后重试!");
}
catch (Exception ex)
{
ShowError(ex);
}
}
pageControl2.GotoPage(1);
label2.Visible = gridView1.RowCount == 0;
session.FindAdzoneInfos(true);
}
}
else if (e.Column.FieldName == "jd_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 == int.Parse(id));
if (adzone != null)//数据库中存在的情况
{
adzone.adzone_pid_cps_name = tgw.Member.username;
adzone.adzone_pid = tgw.Pid;
adzone.adzone_name = tgw.Name;
session.SaveOrUpdate(adzone);
}
else
{
try
{
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("对不起,推广位设置异常,请稍后重试!");
}
catch (Exception ex)
{
ShowError(ex);
}
}
pageControl2.GotoPage(1);
label2.Visible = gridView1.RowCount == 0;
session.FindAdzoneInfos(true);
}
}
else if (e.Column.FieldName == "pdd_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 == int.Parse(id));
if (adzone != null)//数据库中存在的情况
{
adzone.adzone_pid_cps_name = tgw.Member.username;
adzone.adzone_pid = tgw.Pid;
adzone.adzone_name = tgw.Name;
session.SaveOrUpdate(adzone);
}
else
{
try
{
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("对不起,推广位设置异常,请稍后重试!");
}
catch (Exception ex)
{
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 adzones = session.FindAdzoneInfos().Where(f => f.custom_type == Resources.SoftwareType && f.robot_id == int.Parse(id)).ToList();
if (adzones != null && adzones.Count != 0)//数据库中存在
{
var onoff = adzones[0].onoff;
foreach (var item in adzones)
{
item.onoff = !onoff;
}
}
session.Saveable(adzones).ExecuteCommand();
pageControl2.GotoPage(1);
label2.Visible = gridView1.RowCount == 0;
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 == "tb_adzone_name" || e.Column.FieldName == "jd_adzone_name" || e.Column.FieldName == "pdd_adzone_name") && (e.Value == null || string.IsNullOrEmpty(e.Value.ToString()))) e.DisplayText = "双击设置";
}
catch (Exception ex)
{
ShowError(ex);
return;
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var rownumber = gridView1.GetSelectedRows().ToList();//获取选中行号;
if (rownumber != null & rownumber.Count != 0)
{
List<string> ids = new List<string>();
foreach (var item in rownumber)
{
ids.Add("'" + gridView1.GetRowCellValue(item, "id").ToString() + "'");//根据行号获取相应行的数据
}
var session = ApiClient.GetSession();
session.ExcuteSQL("delete from fl_plugin_accuratecircle_dataInfos where id in (" + string.Join(",", ids) + ")");
pageControl1.GotoPage(1);
ShowSuccess("删除成功");
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
RemoveGoodsInfos("delete from fl_plugin_accuratecircle_dataInfos where state = 0");
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
RemoveGoodsInfos("delete from fl_plugin_accuratecircle_dataInfos");
}
private void RemoveGoodsInfos(string sql)
{
try
{
var session = ApiClient.GetSession();
session.ExcuteSQL(sql);
pageControl1.GotoPage(1);
ShowSuccess("删除成功");
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Util.Save(Class1.Config);
}
private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
{
try
{
if (xtraTabControl1.SelectedTabPageIndex == 0)
pageControl1.GotoPage();
}
catch (Exception)
{ }
}
}
}