old_flsystem/应用/Main/MainForm.cs

198 lines
6.5 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.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Api.Framework;
using Api.Framework.Model;
using Api.Framework.Tools;
using Chat.Framework;
using DevExpress.XtraGrid.Views.Grid;
using Main.Entitys;
using UI.Framework.Forms;
namespace Main
{
public partial class MainForm : BaseForm
{
public MainForm()
{
InitializeComponent();
this.gridView1.CustomDrawRowIndicator += gridView1_CustomDrawRowIndicator;
}
public void CloseForm()
{
try
{
if (!this.IsDisposed)
{
this.Invoke(new Action(delegate
{
this.Close();
this.Dispose();
}));
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
private void MainForm_Load(object sender, EventArgs e)
{
radioButton3.Checked = true;
switch (Class1.Config.SendType)
{
case SendTemplateType.:
radioButton1.Checked = true;
break;
case SendTemplateType.:
radioButton2.Checked = true;
break;
case SendTemplateType.:
radioButton3.Checked = true;
break;
default:
break;
}
textBox1.Text = Class1.Config.CustomContent;
textBox2.Text = Class1.Config.NewFriendMess;
buttonCheck1.Checked = Class1.Config.AcceptFriend;
Refresh();
}
private new void Refresh()
{
try
{
this.gridControl1.DataSource = null;
#region
var db = ApiClient.GetSession();
//所有机器人列表
var robotList = db.FindRobots(true);
List<ShowTmp> list = new List<ShowTmp>();
if (robotList != null && robotList.Count != 0)
{
var loginWxs = ChatClient.WXClient.Values.Where(f => f.Status == Chat.Framework.WXSdk.WxStatus.线).ToList();
//在线集合
var robotTemp_online = robotList.Where(f => loginWxs.FirstOrDefault(z => z.WeixinHao == f.name) != null).OrderBy(f => f.type).ToList();
//离线集合
var robotTemp_offline = robotList.Where(f => loginWxs.FirstOrDefault(z => z.WeixinHao == f.name) == null).ToList();
robotTemp_online.AddRange(robotTemp_offline);
robotList = robotTemp_online;
var tbList = db.Find<fl_plugin_tb>("select * from fl_plugin_tb");
foreach (var item in robotList)
{
var info = tbList.FirstOrDefault(f => f.rid == item.id);
list.Add(new ShowTmp() { ID = item.id, name = item.name, nick = item.nick, chattype = item.type, invitecode = info == null ? string.Empty : info.invitecode });
}
}
this.gridControl1.DataSource = list;
#endregion
}
catch (Exception)
{
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
Refresh();
}
private void gridView1_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
try
{
if (e.Column.Caption == "邀请码【直接输入】")
{
var value = e.Value?.ToString();
if (!string.IsNullOrWhiteSpace(value) && value.Length == 9)
{
var selectRow = gridView1.GetSelectedRows()[0];
var id = this.gridView1.GetRowCellValue(selectRow, "ID").ToString();//获取ID列的数据
var session = ApiClient.GetSession();
var result = session.FindSingle<fl_plugin_tb>("select * from fl_plugin_tb where rid = @id", new { id = id });
if (result == null)
result = new fl_plugin_tb() { rid = int.Parse(id) };
result.invitecode = e.Value?.ToString();
session.Saveable(result).ExecuteCommand();
ShowSuccess("成功");
Refresh();
}
}
}
catch (Exception ex)
{
ShowError(ex);
}
}
private void CheckedChanged(object sender, EventArgs e)
{
try
{
var rb = sender as RadioButton;
groupBox1.Visible = rb.Text == "自定义模式";
}
catch (Exception ex)
{ }
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Class1.Config.CustomContent = textBox1.Text;
Class1.Config.SendType = radioButton1.Checked ? SendTemplateType. : (radioButton2.Checked ? SendTemplateType. : SendTemplateType.);
Class1.Config.NewFriendMess = textBox2.Text;
Class1.Config.AcceptFriend = buttonCheck1.Checked;
Util.Save(Class1.Config);
MessageBox.Show("保存成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void label3_Click(object sender, EventArgs e)
{
try
{
var label = sender as Label;
if (label.Text == "[商品图片消息]")
textBox1.Text = textBox1.Text + "[图片=[商品图片]]";
else
textBox1.Text = textBox1.Text + label.Text;
}
catch (Exception ex)
{ }
}
}
}