303 lines
8.7 KiB
C#
303 lines
8.7 KiB
C#
|
using Common.DbExtends.Extends;
|
|||
|
using Common.Models.JsonModels;
|
|||
|
using Common.Models.UnqTables;
|
|||
|
using Common.Utils;
|
|||
|
using EO.Base;
|
|||
|
using EO.WebEngine;
|
|||
|
using Microsoft.Win32;
|
|||
|
using Server.Winforms.LoginForms;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
using Action = System.Action;
|
|||
|
|
|||
|
namespace Server.Winforms
|
|||
|
{
|
|||
|
public partial class MainForm : DefaultForm
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
public MainForm()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private void linkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
|
|||
|
{
|
|||
|
//if (this.linkLabel1.Text == "显示")
|
|||
|
//{
|
|||
|
// this.linkLabel1.Text = "隐藏";
|
|||
|
// this.textBox1.Text = Client.Config.Appsecret;
|
|||
|
//}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// this.textBox1.Text = "***************";
|
|||
|
// this.linkLabel1.Text = "显示";
|
|||
|
//}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private bool IsCloseForm;
|
|||
|
Client Client;
|
|||
|
private void OpenUrl(string url)
|
|||
|
{
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\");
|
|||
|
string s = key.GetValue("").ToString();
|
|||
|
System.Diagnostics.Process.Start(s.Substring(0, s.Length - 8), url);
|
|||
|
return;
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
//调用系统默认的浏览器
|
|||
|
System.Diagnostics.Process.Start("explorer.exe", url);
|
|||
|
return;
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
//调用系统默认的浏览器
|
|||
|
System.Diagnostics.Process.Start(url);
|
|||
|
return;
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 初始化完成
|
|||
|
/// </summary>
|
|||
|
public Action InitCompleteAction { get; set; }
|
|||
|
|
|||
|
private void MainForm_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
Client = Client.SingleClient;
|
|||
|
Client.Form = this;
|
|||
|
this.notifyIcon1.Icon = this.Icon;
|
|||
|
|
|||
|
|
|||
|
//this.numericUpDown1.Value = Client.Config.Port;
|
|||
|
Client.InitSystem();
|
|||
|
|
|||
|
var Admin = Client.Db.Queryable<Staff>().Single(f => f.Id == 1);
|
|||
|
if (Admin == null)
|
|||
|
{
|
|||
|
InitCompleteAction?.Invoke();
|
|||
|
|
|||
|
var f = new SetDefaultuserForm();
|
|||
|
if (f.ShowDialog() != DialogResult.Yes)
|
|||
|
{
|
|||
|
|
|||
|
IsCloseForm = true;
|
|||
|
this.Close();
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
Admin = f.AdminEntity;
|
|||
|
}
|
|||
|
|
|||
|
this.Adminusername.Text = Admin.Username;
|
|||
|
this.Wangzhi.Text = Client.Url;
|
|||
|
|
|||
|
this.Mysqluser.Text = Client.Config.MysqlName;
|
|||
|
this.Webappsecret.Text = Client.Config.Appsecret;
|
|||
|
Client.Db.OnLog("服务端", "启动成功!");
|
|||
|
|
|||
|
|
|||
|
//初始化一个窗口,放着
|
|||
|
LianMengWebViewLoginHelper.Instance.InitDefaultWebview(3);
|
|||
|
InitCompleteAction?.Invoke();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
DialogResult = DialogResult.No;
|
|||
|
IsCloseForm = true;
|
|||
|
MessageBox.Show(ex.Message, "初始化失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
InitCompleteAction?.Invoke();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//退出时候,保存缓存
|
|||
|
private void Events_ExitWinform(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void linkLabel2_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
|
|||
|
{
|
|||
|
//var Rst = MessageBox.Show("重置后机器人客户端需要重新设置通行证", "您确定要重置吗?", MessageBoxButtons.YesNo,MessageBoxIcon.Question);
|
|||
|
//if (Rst == DialogResult.Yes)
|
|||
|
//{
|
|||
|
// Client.Config.Appsecret = Guid.NewGuid().ToString();
|
|||
|
// if (this.linkLabel1.Text == "隐藏")
|
|||
|
// {
|
|||
|
// this.textBox1.Text = Client.Config.Appsecret;
|
|||
|
// }
|
|||
|
// Client.Config.Ini.SetValue("终端","密钥", Client.Config.Appsecret);
|
|||
|
//}
|
|||
|
}
|
|||
|
|
|||
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|||
|
{
|
|||
|
if (!IsCloseForm)
|
|||
|
{
|
|||
|
var Rst = MessageBox.Show("退出后云端网页及API功能将无法正常加载", "您确定要退出吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|||
|
if (Rst == DialogResult.No)
|
|||
|
{
|
|||
|
this.WindowState = FormWindowState.Minimized;
|
|||
|
e.Cancel = true;
|
|||
|
return;
|
|||
|
}
|
|||
|
else
|
|||
|
this.notifyIcon1.Visible = false;
|
|||
|
|
|||
|
Client.SingleClient.Events.OnExitWinform(this);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
|
|||
|
{
|
|||
|
this.WindowState = FormWindowState.Normal;
|
|||
|
}
|
|||
|
|
|||
|
private int MinformCount;
|
|||
|
private void MainForm_SizeChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (this.WindowState == FormWindowState.Minimized)
|
|||
|
{
|
|||
|
MinformCount++;
|
|||
|
this.notifyIcon1.Visible = true;
|
|||
|
this.ShowInTaskbar = false;
|
|||
|
if (MinformCount == 1)
|
|||
|
{
|
|||
|
this.notifyIcon1.ShowBalloonTip(3000, "云控-最小化通知", "双击右下角云控图标,会再次显示出来", ToolTipIcon.None);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else if (this.WindowState == FormWindowState.Normal)
|
|||
|
{
|
|||
|
|
|||
|
this.notifyIcon1.Visible = false;
|
|||
|
this.ShowInTaskbar = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void notifyIcon1_BalloonTipShown(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void button2_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void button1_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var CerData = new
|
|||
|
{
|
|||
|
Ip = Client.InternetIP,
|
|||
|
Port = Client.Config.Port,
|
|||
|
Appsecret = Client.Config.Appsecret
|
|||
|
};
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void button4_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Clipboard.SetDataObject(this.Adminusername.Text);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void button5_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Clipboard.SetDataObject(this.Wangzhi.Text);
|
|||
|
}
|
|||
|
|
|||
|
private void button3_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
OpenUrl(Client.SingleClient.Url);
|
|||
|
}
|
|||
|
|
|||
|
private void button2_Click_1(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Clipboard.SetDataObject(this.Mysqluser.Text);
|
|||
|
}
|
|||
|
|
|||
|
private void button1_Click_1(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Clipboard.SetDataObject(this.Client.Config.Appsecret);
|
|||
|
}
|
|||
|
|
|||
|
private void button7_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var Rst = MessageBox.Show("重置后机器人客户端需要重新设置密钥", "您确定要重置吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|||
|
if (Rst == DialogResult.Yes)
|
|||
|
{
|
|||
|
Client.Config.Appsecret = Guid.NewGuid().ToString();
|
|||
|
this.Webappsecret.Text = Client.Config.Appsecret;
|
|||
|
Client.Config.Ini.SetValue("终端", "密钥", Client.Config.Appsecret);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void button6_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void timer1_Tick(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private Queue<LoginForms.LoginLianmengForm> LoginForms = new Queue<LoginLianmengForm>();
|
|||
|
public LoginForms.LoginLianmengForm GetLoginForm()
|
|||
|
{
|
|||
|
if (LoginForms.Count > 0)
|
|||
|
return LoginForms.Dequeue();
|
|||
|
else
|
|||
|
return new LoginLianmengForm();
|
|||
|
}
|
|||
|
|
|||
|
private void button8_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
var f = new SetDefaultuserForm();
|
|||
|
if (f.ShowDialog() == DialogResult.Yes)
|
|||
|
{
|
|||
|
this.Adminusername.Text = f.AdminEntity.Username;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|