old_flsystem/应用/MessageForwarder/MainForm.cs

126 lines
3.5 KiB
C#

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 MessageForwarder.Properties;
using Chat.Framework.WXSdk.Implement;
using Api.Framework.Tools;
namespace MessageForwarder
{
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);
}
}
Dictionary<string, object> result = null;
private void MainForm_Load(object sender, EventArgs e)
{
try
{
textBox1.Text = Class1.Config.ClusterId;
textBox2.Text = Class1.Config.ListeningAccount;
var weixinBases = Chat.Framework.ChatClient.WXClient.Values.ToList();
gridControl1.DataSource = weixinBases;
result = CsharpHttpHelper.HttpExtend.JsonToDictionary(Class1.Config.Data);
if (result == null) result = new Dictionary<string, object>();
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void labelControl3_Click(object sender, EventArgs e)
{
}
private void gridControl1_Click(object sender, EventArgs e)
{
try
{
var rows = gridView1.GetSelectedRows();
if (rows != null && rows.Length != 0)
{
var row = gridView1.GetRow(rows[0]) as WeixinBase;
if (row != null)
{
textEdit1.Text = row.WeixinHao;
if (result != null && result.Count != 0)
memoEdit1.Text = (result.ContainsKey(row.WeixinHao)) ? result[row.WeixinHao].ToString() : string.Empty;
}
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
Class1.Config.ClusterId = textBox1.Text.Trim();
Class1.Config.ListeningAccount = textBox2.Text.Trim();
Class1.Config.Data = CsharpHttpHelper.HttpHelper.ObjectToJson(result);
Util.Save(Class1.Config);
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void simpleButton1_Click(object sender, EventArgs e)
{
try
{
var wxh = textEdit1.Text.Trim();
if (result.ContainsKey(wxh))
result[wxh] = memoEdit1.Text;
else
result.Add(wxh, memoEdit1.Text);
ShowSuccessAutoClose("保存成功");
}
catch (Exception ex)
{
ShowError(ex);
}
}
}
}