old_flsystem/应用/CouponsSend/MainForm.cs

380 lines
15 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 CouponsSend.Properties;
using CouponsSend.Entitys;
using Api.Framework.Tools;
using Api.Framework;
using Api.Framework.Model;
using UI.Framework.Controls;
using Api.Framework.Enums;
using Api.Framework.Cps;
using static CouponsSend.Entitys.Enum;
using static Api.Framework.ApiClient;
namespace CouponsSend
{
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
{
bc_CJSwitch.Checked = Class1.Config.Switch == SwitchType.;
nud_GatherTouchNum.Value = Class1.Config.GatherTouchNum;
cb_GatherType.SelectedIndex = (int)Class1.Config.GatherType;
var times = Class1.Config.SendTaskTimes[0].Split('-');
dt_SendTaskTimes1.Value = DateTime.Parse($"2020-01-01 {times[0]}");
dt_SendTaskTimes2.Value = DateTime.Parse($"2020-01-01 {times[1]}");
nud_gInterval.Value = Class1.Config.IntervalTime_Group;
nud_qInterval.Value = Class1.Config.IntervalTime_Coupon;
cb_Model.SelectedIndex = (int)Class1.Config.qrImageType;
var shortType = EnumHelper.EnumToList<DwzType>();
cb_Short.Items.AddRange(shortType.Select(f => f.EnumName).ToArray());
cb_Short.SelectedIndex = (int)Class1.Config.SearchDwzType;
me_QQMsg.Text = Class1.Config.QQMsg;
me_WXMsg.Text = Class1.Config.WXMsg;
me_WhiteContent.Text = Class1.Config.WhiteContent;
me_BlackContent.Text = Class1.Config.BlackContent;
bc_AutoClearTask.Checked = Class1.Config.Auto_IsClear == SwitchType.;
dt_AutoClearTaskTimes.Value = DateTime.Parse(Class1.Config.AutoClearTaskTimes);
#region
pageControl1.Bind((page, size) =>
{
var session = ApiClient.GetSession();
var parm = session.NewParamMap();
parm.setPageParamters(page, size);
var result = session.FindPage<fl_plugin_couponssend_goodsinfos>("select * from fl_plugin_couponssend_goodsinfos order by state desc", parm);
return new PageControl.SerchResult() { Result = result.DataList, Total = result.Total };
}, gridControl1, 40, true, true);
#endregion
#region
pageControl2.Bind((page, size) =>
{
var session = ApiClient.GetSession();
var parm = session.NewParamMap();
parm.setPageParamters(page, size);
int totalNumber = 0;
var result = session.Queryable<fl_adzone_info>().Where(f => f.custom_type == Resources.SoftwareType).ToPageList(page, size, ref totalNumber);
label1.Visible = result.Count == 0;
return new PageControl.SerchResult() { Result = result, Total = totalNumber };
}, gridControl2, 40, true, true);
#endregion
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void Save(FormClosingEventArgs e)
{
try
{
if (dt_SendTaskTimes1.Value > dt_SendTaskTimes2.Value)
throw new Exception("发送任务时间段第一个值不能大于第二个值");
Class1.Config.Switch = bc_CJSwitch.Checked ? SwitchType. : SwitchType.;
Class1.Config.GatherTouchNum = (int)nud_GatherTouchNum.Value;
Class1.Config.GatherType = Util.ConvertEnum<GatherType>(cb_GatherType.SelectedIndex);
Class1.Config.SendTaskTimes = new string[] { (dt_SendTaskTimes1.Value.ToString("HH:mm") + "-" + dt_SendTaskTimes2.Value.ToString("HH:mm")) };
Class1.Config.IntervalTime_Group = (int)nud_gInterval.Value;
Class1.Config.IntervalTime_Coupon = (int)nud_qInterval.Value;
Class1.Config.qrImageType = Util.ConvertEnum<QrImageType>(cb_Model.SelectedIndex);
Class1.Config.ConditionType = cb_ConditionType.SelectedIndex;
Class1.Config.SearchDwzType = Util.ConvertEnum<DwzType>(cb_Short.SelectedIndex);
Class1.Config.QQMsg = me_QQMsg.Text;
Class1.Config.WXMsg = me_WXMsg.Text;
Class1.Config.WhiteContent = me_WhiteContent.Text;
Class1.Config.BlackContent = me_BlackContent.Text;
Class1.Config.Auto_IsClear = bc_AutoClearTask.Checked ? SwitchType. : SwitchType.;
Class1.Config.AutoClearTaskTimes = dt_AutoClearTaskTimes.Value.ToString("HH:mm");
}
catch (Exception ex)
{
e.Cancel = true;
BaseForm.ShowError(ex);
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Save(e);
Util.Save(Class1.Config);
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var rows = gridView2.GetSelectedRows();
if (rows != null && rows.Length != 0)
{
string id = this.gridView2.GetRowCellValue(rows[0], "id").ToString();//获取列的数据
if (!string.IsNullOrWhiteSpace(id))
{
var session = ApiClient.GetSession();
session.Deleteable<fl_adzone_info>().Where(f => f.id == int.Parse(id)).ExecuteCommand();
}
pageControl2.GotoPage();
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var rows = gridView2.GetSelectedRows();
if (rows != null && rows.Length != 0)
{
string id = this.gridView2.GetRowCellValue(rows[0], "id").ToString();//获取列的数据
var form = new EditGroupInfoForm(id);
form.ShowDialog();
pageControl2.GotoPage();
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = new EditGroupInfoForm();
form.ShowDialog();
pageControl2.GotoPage();
}
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);
}
}
private void gridView2_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
try
{
var rows = gridView2.GetSelectedRows();
if (rows != null && rows.Length != 0)
{
string id = this.gridView2.GetRowCellValue(rows[0], "id").ToString();//获取列的数据
#region 广
if (e.Clicks >= 2)
{
var session = ApiClient.GetSession();
if (e.Column.FieldName == "adzone_name")
{
var tgwObj = CpsClient.SelectTuiguangwei(CpsType.);
if (tgwObj != null)
{
var tgw = tgwObj as Tuiguangwei;
#region 广
var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.id == int.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);
}
#endregion
}
}
pageControl2.GotoPage(1);
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.id == int.Parse(id));
if (adzone != null)//数据库中存在的情况,并且推广位设置了
adzone.onoff = !adzone.onoff;
session.SaveOrUpdate(adzone);
pageControl2.GotoPage(1);
session.FindAdzoneInfos(true);
}
}
#endregion
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void cb_GatherType_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
cb_ConditionType.Items.Clear();
object[] objArr = null;
switch (cb_GatherType.SelectedIndex)
{
case 0:
objArr = new object[] {
"综合排序",
"商品上架时间从高到低",
"销量从高到低",
"领券量从高到低",
"佣金比例从高到低",
"价格(券后价)从高到低",
"价格(券后价)从低到高" };
break;
case 1:
objArr = new object[] {
"10-20元区",
"20-40元区",
"40元以上区"};
break;
case 2:
objArr = new object[] {
"实时榜",
"全天榜",
"热推榜",
"复购榜",
"热词飙升榜",
"热词排行榜",
"综合热搜榜"};
break;
case 3:
objArr = new object[] {
//"精选",
"5.9元区",
"9.9元区",
"19.9元区"};
break;
default:
break;
}
cb_ConditionType.Items.AddRange(objArr);
cb_ConditionType.SelectedIndex = 0;
if (cb_GatherType.SelectedIndex == (int)Class1.Config.GatherType)
cb_ConditionType.SelectedIndex = Class1.Config.ConditionType;
}
catch (Exception ex)
{
BaseForm.ShowErrorAutoClose($"异常:{ex.Message}");
}
}
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_couponssend_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_couponssend_goodsinfos where state = 0");
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
RemoveGoodsInfos("delete from fl_plugin_couponssend_goodsinfos");
}
private void RemoveGoodsInfos(string sql)
{
try
{
var session = ApiClient.GetSession();
session.ExcuteSQL(sql);
pageControl1.GotoPage(1);
ShowSuccess("删除成功");
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void xtraTabControl1_TabIndexChanged(object sender, EventArgs e)
{
if (xtraTabControl1.SelectedTabPageIndex == 1)
pageControl1.GotoPage(1);
}
}
}