289 lines
13 KiB
C#
289 lines
13 KiB
C#
|
using Api.Framework;
|
|||
|
using Api.Framework.Tools;
|
|||
|
using FreeActivity.Entitys;
|
|||
|
using FreeActivity.Properties;
|
|||
|
using SqlSugar;
|
|||
|
using System;
|
|||
|
using System.Linq;
|
|||
|
using System.Windows.Forms;
|
|||
|
using UI.Framework.Controls;
|
|||
|
using UI.Framework.Forms;
|
|||
|
|
|||
|
namespace FreeActivity
|
|||
|
{
|
|||
|
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)
|
|||
|
{
|
|||
|
settingControl1.Bind(Class1.Config);
|
|||
|
gridView1_DoubleClick(null, null);
|
|||
|
|
|||
|
#region 加载所有的任务
|
|||
|
|
|||
|
pageControl1.Bind((page, size) =>
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var parm = session.NewParamMap();
|
|||
|
parm.setPageParamters(page, size);
|
|||
|
var result = session.FindPage<fl_plugin_freeactivity_info>($"select * from fl_plugin_freeactivity_info order by activity_time_end", parm);
|
|||
|
return new PageControl.SerchResult() { Result = result.DataList, Total = result.Total };
|
|||
|
}, gridControl1, 50, true, true);
|
|||
|
|
|||
|
label7.Visible = gridView1.RowCount == 0;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 加载时间
|
|||
|
|
|||
|
pageControl2.Bind((page, size) =>
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var parm = session.NewParamMap();
|
|||
|
parm.setPageParamters(page, size);
|
|||
|
parm.setOrderFields("exchange_time", false);
|
|||
|
var result = session.FindPage<temp_freeactivity_exchange_info>($@"select
|
|||
|
fu.id as fuid,
|
|||
|
r.id as rid,
|
|||
|
r.type as robot_type,
|
|||
|
r.nick as robot_nick,
|
|||
|
m.id as uid,
|
|||
|
m.username as username,
|
|||
|
m.usernick as usernick,
|
|||
|
f.id as activityid,
|
|||
|
f.name as activityname,
|
|||
|
fu.get_time as get_time,
|
|||
|
fu.exchange_time as exchange_time,
|
|||
|
fu.is_exchange as is_exchange
|
|||
|
from
|
|||
|
fl_plugin_freeactivity_user_info fu INNER JOIN fl_plugin_freeactivity_info f on fu.activityid = f.id INNER JOIN fl_member_info m on fu.uid = m.id INNER JOIN fl_robot_info r on m.robot_name = r.name", parm);
|
|||
|
return new PageControl.SerchResult() { Result = result.DataList, Total = result.Total };
|
|||
|
}, gridControl2, 100, true, true);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
private void simpleButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (string.IsNullOrWhiteSpace(text_name.Text)) throw new Exception("活动名不能给空");
|
|||
|
if (string.IsNullOrWhiteSpace(checkedComboBoxEdit_ChatType.Text)) throw new Exception("请选择活动机器人");
|
|||
|
if (time_begin.Value >= time_end.Value) throw new Exception("领取结束时间不能晚于领取开始时间");
|
|||
|
if (!(check_order_num.Checked || check_point_num.Checked || check_invite_num.Checked)) throw new Exception("请选择活动条件");
|
|||
|
if (check_order_num.Checked)
|
|||
|
if (numericUpDown1.Value == 0)
|
|||
|
throw new Exception("条件订单数量不能为0");
|
|||
|
if (check_point_num.Checked)
|
|||
|
if (numericUpDown2.Value == 0)
|
|||
|
throw new Exception("条件返利金额不能为0");
|
|||
|
if (check_invite_num.Checked)
|
|||
|
if (numericUpDown3.Value == 0)
|
|||
|
throw new Exception("条件邀请人数不能为0");
|
|||
|
if (string.IsNullOrWhiteSpace(textBox1.Text)) throw new Exception("请填写商品链接");
|
|||
|
if (string.IsNullOrWhiteSpace(memoEdit1.Text)) throw new Exception("请填写免单商品介绍");
|
|||
|
|
|||
|
var name = text_name.Text.Trim();
|
|||
|
var mess = string.Empty;
|
|||
|
var freeactivity_info = session.Find<fl_plugin_freeactivity_info>("name = @name", new { name = name }).FirstOrDefault();
|
|||
|
if (freeactivity_info == null)
|
|||
|
{
|
|||
|
freeactivity_info = new fl_plugin_freeactivity_info()
|
|||
|
{
|
|||
|
name = name,
|
|||
|
robots = checkedComboBoxEdit_ChatType.Text.Trim(),
|
|||
|
activity_time_begin = time_begin.Value,
|
|||
|
activity_time_end = time_end.Value,
|
|||
|
condition_relation = radio_and.Checked,//选中为并且关系
|
|||
|
|
|||
|
check_ordernum = check_order_num.Checked,
|
|||
|
ordernum = (int)numericUpDown1.Value,
|
|||
|
|
|||
|
check_pointsum = check_point_num.Checked,
|
|||
|
pointsum = (int)numericUpDown2.Value,
|
|||
|
|
|||
|
check_invitenum = check_invite_num.Checked,
|
|||
|
invitenum = (int)numericUpDown3.Value,
|
|||
|
goods_url = textBox1.Text,
|
|||
|
goods_detail = memoEdit1.Text
|
|||
|
};
|
|||
|
mess = "免单任务增加成功";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
freeactivity_info.name = name;
|
|||
|
freeactivity_info.robots = checkedComboBoxEdit_ChatType.Text.Trim();
|
|||
|
freeactivity_info.activity_time_begin = time_begin.Value;
|
|||
|
freeactivity_info.activity_time_end = time_end.Value;
|
|||
|
freeactivity_info.condition_relation = radio_and.Checked;//选中为并且关系
|
|||
|
|
|||
|
freeactivity_info.check_ordernum = check_order_num.Checked;
|
|||
|
freeactivity_info.ordernum = (int)numericUpDown1.Value;
|
|||
|
|
|||
|
freeactivity_info.check_pointsum = check_point_num.Checked;
|
|||
|
freeactivity_info.pointsum = (int)numericUpDown2.Value;
|
|||
|
|
|||
|
freeactivity_info.check_invitenum = check_invite_num.Checked;
|
|||
|
freeactivity_info.invitenum = (int)numericUpDown3.Value;
|
|||
|
freeactivity_info.goods_url = textBox1.Text;
|
|||
|
freeactivity_info.goods_detail = memoEdit1.Text;
|
|||
|
|
|||
|
mess = "免单任务修改成功";
|
|||
|
}
|
|||
|
session.Saveable<fl_plugin_freeactivity_info>(freeactivity_info).ExecuteCommand();
|
|||
|
ShowSuccess(mess);
|
|||
|
pageControl1.GotoPage();
|
|||
|
label7.Visible = gridView1.RowCount == 0;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void gridView1_DoubleClick(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
#region 将enum的值加载到列表中 修改的将勾选
|
|||
|
checkedComboBoxEdit_ChatType.Properties.Items.Clear();
|
|||
|
var clients = Chat.Framework.ChatClient.WXClient;
|
|||
|
if (gridView1.GetSelectedRows().Length != 0)
|
|||
|
{
|
|||
|
var selectRow = gridView1.GetSelectedRows()[0];
|
|||
|
var id = this.gridView1.GetRowCellValue(selectRow, "id").ToString();//获取列的数据
|
|||
|
var freeactivity_info = session.Find<fl_plugin_freeactivity_info>($"select * from fl_plugin_freeactivity_info where id = '{id}'").FirstOrDefault();
|
|||
|
var chatList = freeactivity_info.robots.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
|||
|
foreach (var item in clients.Values)
|
|||
|
{
|
|||
|
if (chatList.FirstOrDefault(f => f == item.WeixinHao) != null)
|
|||
|
checkedComboBoxEdit_ChatType.Properties.Items.Add(item.WeixinHao.ToString(), string.Empty, CheckState.Checked, true);
|
|||
|
else
|
|||
|
checkedComboBoxEdit_ChatType.Properties.Items.Add(item.WeixinHao.ToString(), string.Empty, CheckState.Unchecked, true);
|
|||
|
}
|
|||
|
|
|||
|
text_name.Text = freeactivity_info.name;
|
|||
|
checkedComboBoxEdit_ChatType.Text = freeactivity_info.robots;
|
|||
|
time_begin.Value = freeactivity_info.activity_time_begin;
|
|||
|
time_end.Value = freeactivity_info.activity_time_end;
|
|||
|
if (freeactivity_info.condition_relation)
|
|||
|
radio_and.Checked = true;
|
|||
|
else
|
|||
|
radio_or.Checked = true;
|
|||
|
check_order_num.Checked = freeactivity_info.check_ordernum;
|
|||
|
numericUpDown1.Value = freeactivity_info.ordernum;
|
|||
|
|
|||
|
check_point_num.Checked = freeactivity_info.check_pointsum;
|
|||
|
numericUpDown2.Value = (decimal)freeactivity_info.pointsum;
|
|||
|
|
|||
|
check_invite_num.Checked = freeactivity_info.check_invitenum;
|
|||
|
numericUpDown3.Value = freeactivity_info.invitenum;
|
|||
|
textBox1.Text = freeactivity_info.goods_url;
|
|||
|
memoEdit1.Text = freeactivity_info.goods_detail;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
foreach (var item in clients.Values)
|
|||
|
{
|
|||
|
//if (item.WeixinType == Chat.Framework.WXSdk.Implement.WeixinType.Grpc微信)
|
|||
|
checkedComboBoxEdit_ChatType.Properties.Items.Add(item.WeixinHao.ToString(), string.Empty, CheckState.Unchecked, true);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (e.Column.Caption == "活动状态")
|
|||
|
{
|
|||
|
var activity_time_begin = DateTime.Parse(gridView1.GetRowCellDisplayText(e.ListSourceRowIndex, "activity_time_begin"));
|
|||
|
var activity_time_end = DateTime.Parse(gridView1.GetRowCellDisplayText(e.ListSourceRowIndex, "activity_time_end"));
|
|||
|
var now = DateTime.Now;
|
|||
|
if (now >= activity_time_end)
|
|||
|
e.DisplayText = "活动已结束";
|
|||
|
else if (now < activity_time_begin)
|
|||
|
e.DisplayText = "活动未开始";
|
|||
|
else if (activity_time_begin <= now && now < activity_time_end)
|
|||
|
e.DisplayText = "活动进行中";
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
Api.Framework.Tools.Util.Save(Class1.Config);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void 修改为兑换ToolStripMenuItem_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
checkedComboBoxEdit_ChatType.Properties.Items.Clear();
|
|||
|
var clients = Chat.Framework.ChatClient.WXClient;
|
|||
|
if (gridView2.GetSelectedRows().Length != 0)
|
|||
|
{
|
|||
|
var selectRow = gridView2.GetSelectedRows()[0];
|
|||
|
var is_exchange = this.gridView2.GetRowCellValue(selectRow, "is_exchange").ToString();//获取列的数据
|
|||
|
if (is_exchange == "是") throw new Exception("已经兑换,无法处理");
|
|||
|
var id = this.gridView2.GetRowCellValue(selectRow, "fuid").ToString();//获取列的数据
|
|||
|
var usernick = this.gridView2.GetRowCellValue(selectRow, "usernick").ToString();//获取列的数据
|
|||
|
var username = this.gridView2.GetRowCellValue(selectRow, "username").ToString();//获取列的数据
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
if (MessageBox.Show($"确定要兑换 {usernick}({username}) 吗?", "确定提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|||
|
{
|
|||
|
session.ExcuteSQL("update fl_plugin_freeactivity_user_info set is_exchange = @is_exchange,exchange_time = @exchange_time where id = @id", new { is_exchange = true, exchange_time = DateTime.Now, id = id });
|
|||
|
pageControl2.GotoPage();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|