using CircleFriendsTools; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using UI.Framework.Forms; namespace Weixin.CircleTools { public partial class SetSendModelForm : BaseForm { public SetSendModelForm() { InitializeComponent(); } /// /// 更新 /// /// /// private void button1_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(textBox1.Text)) throw new Exception("名称不能为空"); if (string.IsNullOrWhiteSpace(memoEdit1.Text)) throw new Exception("文案不能为空"); var result = Class1.Config.send_templates.FirstOrDefault(f => f.ModelName.Trim() == textBox1.Text.Trim()); if (result == null) throw new Exception("该模板找不到"); result.Content = memoEdit1.Text; Api.Framework.Tools.Util.Save(Class1.Config); ShowSuccess("更新成功"); } catch (Exception ex) { ShowError(ex); } finally { ShowContentModel(); } } private void SetSendModelForm_Load(object sender, EventArgs e) { ShowContentModel(); } /// /// 显示一键发送模板(刷新) /// private void ShowContentModel() { try { List obj = new List(); foreach (var item in Class1.Config.send_templates) { obj.Add(new { ModelName = item.ModelName }); } gridControl3.DataSource = obj; } catch (Exception ex) { ShowError(ex); } } private void gridView3_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) { try { var selectRow = gridView3.GetSelectedRows()[0]; var modelName = this.gridView3.GetRowCellValue(selectRow, "ModelName").ToString();//获取列的数据 textBox1.Text = modelName; var sendModel = Class1.Config.send_templates.FirstOrDefault(f => f.ModelName == modelName); if (sendModel != null) memoEdit1.Text = sendModel.Content; } catch (Exception ex) { ShowError(ex); } } private void button2_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(textBox1.Text)) throw new Exception("名称不能为空"); if (string.IsNullOrWhiteSpace(memoEdit1.Text)) throw new Exception("文案不能为空"); var result = Class1.Config.send_templates.FirstOrDefault(f => f.ModelName.Trim() == textBox1.Text.Trim()); if (result != null) throw new Exception("已存在该名称"); Class1.Config.send_templates.Add(new ContentModel { ModelName = textBox1.Text.Trim(), Content = memoEdit1.Text.Trim() }); Api.Framework.Tools.Util.Save(Class1.Config); ShowSuccess("添加成功"); } catch (Exception ex) { ShowError(ex); } finally { ShowContentModel(); } } private void button3_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(textBox1.Text)) throw new Exception("请选择要删除的模板"); var result = Class1.Config.send_templates.FirstOrDefault(f => f.ModelName.Trim() == textBox1.Text.Trim()); if (result == null) throw new Exception("模板不存在"); Class1.Config.send_templates.Remove(result); Api.Framework.Tools.Util.Save(Class1.Config); ShowSuccess("删除成功!"); } catch (Exception ex) { ShowError(ex); } finally { ShowContentModel(); } } } }