150 lines
6.7 KiB
C#
150 lines
6.7 KiB
C#
|
using Api.Framework;
|
|||
|
using Api.Framework.Tools;
|
|||
|
using DevExpress.XtraEditors;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using System.Windows.Forms;
|
|||
|
using UI.Framework.Forms;
|
|||
|
using Weixin.CircleTools.Entitys;
|
|||
|
using Weixin.CircleTools.Properties;
|
|||
|
using static CircleFriendsTools.Enums;
|
|||
|
|
|||
|
namespace Weixin.CircleTools
|
|||
|
{
|
|||
|
public partial class SendTaskForm : BaseForm
|
|||
|
{
|
|||
|
public SendTaskForm()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
this.Text = Resources.PluginFormAddSendTask;
|
|||
|
taskinfo = null;
|
|||
|
}
|
|||
|
|
|||
|
private fl_plugin_circletools_taskinfos taskinfo = null;
|
|||
|
|
|||
|
public SendTaskForm(fl_plugin_circletools_taskinfos taskinfo)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
this.Text = Resources.PluginFormUpdateSendTask;
|
|||
|
this.taskinfo = taskinfo;
|
|||
|
|
|||
|
#region 将要修改的对象复制到控件中
|
|||
|
textEdit1.Text = taskinfo.task_name;
|
|||
|
dateTimePicker1.Value = DateTime.Parse(taskinfo.task_time);
|
|||
|
textBox1.Text = taskinfo.task_sendtext;
|
|||
|
checkEdit1.Checked = (taskinfo.is_circulate == ChooseType.是);
|
|||
|
textBox2.Text = taskinfo.task_comment;
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void SendTaskForm_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
foreach (WorkingDayType item in Enum.GetValues(typeof(WorkingDayType)))
|
|||
|
{
|
|||
|
checkedComboBoxEdit1.Properties.Items.Add(item.ToString());
|
|||
|
}
|
|||
|
if (taskinfo != null)
|
|||
|
checkedComboBoxEdit1.Text = taskinfo.task_working_day;//赋值
|
|||
|
|
|||
|
_RefreshRobotList(taskinfo == null ? null : taskinfo.robotnames.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList());
|
|||
|
}
|
|||
|
|
|||
|
private void _RefreshRobotList(List<string> data = null)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
checkedComboBoxEdit_ChatType.Properties.Items.Clear();
|
|||
|
var clients = Chat.Framework.ChatClient.WXClient;
|
|||
|
foreach (var item in clients.Values)
|
|||
|
{
|
|||
|
if (item.WeixinType == Chat.Framework.WXSdk.Implement.WeixinType.Grpc微信 || item.WeixinType == Chat.Framework.WXSdk.Implement.WeixinType.Hook微信)
|
|||
|
{
|
|||
|
if (data != null && data.FirstOrDefault(f => f == item.WeixinHao) != null)
|
|||
|
checkedComboBoxEdit_ChatType.Properties.Items.Add(item.WeixinHao, item.User.Nick, CheckState.Checked, true);
|
|||
|
else
|
|||
|
checkedComboBoxEdit_ChatType.Properties.Items.Add(item.WeixinHao, item.User.Nick, CheckState.Unchecked, true);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SendTaskForm_FormClosing(object sender, FormClosingEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (string.IsNullOrWhiteSpace(textEdit1.Text))
|
|||
|
{
|
|||
|
e.Cancel = true;
|
|||
|
throw new Exception("请填写任务名称!");
|
|||
|
}
|
|||
|
else if (string.IsNullOrWhiteSpace(checkedComboBoxEdit1.Text))
|
|||
|
{
|
|||
|
e.Cancel = true;
|
|||
|
throw new Exception("请勾选工作日!");
|
|||
|
}
|
|||
|
else if (string.IsNullOrWhiteSpace(dateTimePicker1.Text))
|
|||
|
{
|
|||
|
e.Cancel = true;
|
|||
|
throw new Exception("请设置发送时间点!");
|
|||
|
}
|
|||
|
else if (string.IsNullOrWhiteSpace(textBox1.Text))
|
|||
|
{
|
|||
|
e.Cancel = true;
|
|||
|
throw new Exception("请填写发送的内容!");
|
|||
|
}
|
|||
|
if (!e.Cancel)
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
if (taskinfo == null)
|
|||
|
taskinfo = new fl_plugin_circletools_taskinfos();
|
|||
|
|
|||
|
//taskinfo.task_name = textEdit1.Text.Trim();
|
|||
|
//taskinfo.task_working_day = checkedComboBoxEdit1.Text.Trim();
|
|||
|
//taskinfo.task_time = dateTimePicker1.Value.ToString("HH:mm");
|
|||
|
//taskinfo.task_sendtext = richTextBox1.Text.Trim();
|
|||
|
//taskinfo.task_comment = richTextBox2.Text;
|
|||
|
//taskinfo.is_circulate = checkEdit1.Checked ? ChooseType.是 : ChooseType.否;
|
|||
|
|
|||
|
//session.Saveable(taskinfo).ExecuteCommand(); //使用这个会出现转换失败
|
|||
|
|
|||
|
taskinfo.is_circulate = checkEdit1.Checked ? ChooseType.是 : ChooseType.否;
|
|||
|
taskinfo.task_name = textEdit1.Text.Trim();
|
|||
|
taskinfo.task_working_day = checkedComboBoxEdit1.Text.Trim();
|
|||
|
taskinfo.task_time = dateTimePicker1.Value.ToString("HH:mm");
|
|||
|
taskinfo.task_sendtext = textBox1.Text;
|
|||
|
taskinfo.task_comment = textBox2.Text;
|
|||
|
taskinfo.robotnames = checkedComboBoxEdit_ChatType.EditValue.ToString();
|
|||
|
|
|||
|
|
|||
|
var sql = string.Empty;
|
|||
|
if (taskinfo.id == 0)
|
|||
|
{
|
|||
|
//sql = "insert into fl_plugin_circletools_taskinfos (task_name,task_working_day,task_time,task_sendtext,is_circulate,task_comment,robotnames) values('" + textEdit1.Text.Trim() + "','" + checkedComboBoxEdit1.Text.Trim() + "','" + dateTimePicker1.Value.ToString("HH:mm") + "','" + content + "','" + (checkEdit1.Checked ? 1 : 0) + "','" + comment + "','" + checkedComboBoxEdit_ChatType.EditValue + "')";
|
|||
|
session.Insertable(taskinfo).ExecuteCommand();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//sql = "update fl_plugin_circletools_taskinfos set task_name = '" + textEdit1.Text.Trim() + "',task_working_day = '" + checkedComboBoxEdit1.Text.Trim() + "',task_time = '" + dateTimePicker1.Value.ToString("HH:mm") + "',task_sendtext = '" + content + "',is_circulate = '" + (checkEdit1.Checked ? 1 : 0) + "',task_comment = '" + comment + "',robotnames = '" + checkedComboBoxEdit_ChatType.EditValue + "' where id = " + taskinfo.id;
|
|||
|
|
|||
|
session.Updateable(taskinfo).ExecuteCommand();
|
|||
|
}
|
|||
|
|
|||
|
//session.ExcuteSQL(sql, new { });
|
|||
|
this.DialogResult = DialogResult.OK;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
if (XtraMessageBox.Show(ex.Message + " 是否继续?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) == DialogResult.No)
|
|||
|
e.Cancel = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|