DeviceManager/DeviceRepairAndOptimization/Program.cs

107 lines
4.4 KiB
C#
Raw Normal View History

2024-05-28 14:36:38 +00:00
using AutoUpdaterDotNET;
using DeviceRepair.Models;
using DeviceRepairAndOptimization;
2024-06-02 16:38:52 +00:00
using DeviceRepairAndOptimization.Common;
2024-05-28 14:36:38 +00:00
using Newtonsoft.Json;
using System;
using System.Drawing;
using System.IO;
2024-06-02 16:38:52 +00:00
using System.Threading;
2024-05-28 14:36:38 +00:00
using System.Windows.Forms;
namespace DeviceRepairAndOptimization
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
2024-06-02 16:38:52 +00:00
bool isAppRunning;
2024-05-28 14:36:38 +00:00
2024-07-01 16:52:48 +00:00
using (Mutex mutex = new Mutex(true, "设备管理软件", out isAppRunning))
2024-05-28 14:36:38 +00:00
{
2024-06-02 16:38:52 +00:00
if (!isAppRunning)
2024-05-28 14:36:38 +00:00
{
2024-06-02 16:38:52 +00:00
// 如果应用程序已在运行,则显示一个消息框并退出。
XtraMessageBoxHelper.Error("应用程序已运行。");
return;
2024-05-28 14:36:38 +00:00
}
2024-07-01 16:52:48 +00:00
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
2024-06-02 16:38:52 +00:00
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
2024-05-28 14:36:38 +00:00
2024-07-01 16:52:48 +00:00
// 测试其他的窗口
//Form f = new Form() { Size = new Size(480, 850), StartPosition = FormStartPosition.CenterScreen };
//f.Controls.Add(new Pages.Tag.xueTagForm() { Dock = DockStyle.Fill });
2024-07-17 02:32:45 +00:00
//Application.Run(new Pages.Plan.pageMaintenanceRecord());
2024-07-01 16:52:48 +00:00
//return;
2024-06-02 16:38:52 +00:00
#region , config中的数据库连接字符串 &
if (args != null && args.Length > 0)
2024-05-28 14:36:38 +00:00
{
2024-06-02 16:38:52 +00:00
//UserInfoModel us1 = JsonConvert.DeserializeObject<UserInfoModel>("{\"AutoID\": 1,\"LoginCode\": \"myl\",\"PassWord\": \"Kanghui2\",\"RealName\": \"管理员\",\"Gender\": 1,\"Birthday\": \"/Date(1693471604770)/\",\"Phone\": \"13800000000\",\"RuleGroup\": 0}");
//string aa = JWT.JsonWebToken.Encode(us1, GlobalInfo.SecureKey, JWT.JwtHashAlgorithm.HS256);
AutoUpdater.AppTitle = "Device Repair And Optimization";
var vUpdateDir = Path.Combine(Application.StartupPath, "Update");
if (!Directory.Exists(vUpdateDir))
2024-05-28 14:36:38 +00:00
{
2024-06-02 16:38:52 +00:00
Directory.CreateDirectory(vUpdateDir);
2024-05-28 14:36:38 +00:00
}
2024-06-02 16:38:52 +00:00
// 指定下载文件的存储目录
AutoUpdater.DownloadPath = vUpdateDir;
AutoUpdater.UpdateFormSize = new Size(800, 600);
2024-05-28 14:36:38 +00:00
2024-06-02 16:38:52 +00:00
AutoUpdater.Synchronous = true;
AutoUpdater.ShowSkipButton = false;
AutoUpdater.ShowRemindLaterButton = false;
AutoUpdater.Start($"http://{DeviceRepair.Utils.Config.Configurations.Properties.ServiceIP}/{DeviceRepair.Utils.Config.Configurations.Properties.ServiceName}/Update/DOAutoUpdater.xml");
try
{
string argsValue = string.Join("|", args);
string usValue = JWT.JsonWebToken.Decode(argsValue, DeviceRepair.Utils.Config.Configurations.Properties.SecureKey, true);
UserInfoModel us = JsonConvert.DeserializeObject<UserInfoModel>(usValue);
2024-05-28 14:36:38 +00:00
2024-06-02 16:38:52 +00:00
if (us != null)
{
GlobalInfo.token = argsValue;
GlobalInfo.CurrentUser = us;
Application.Run(new frm_Launch());
return;
}
}
catch (Exception ex)
{
2024-09-26 02:47:56 +00:00
XtraMessageBoxHelper.Error(ex.Message);
2024-06-02 16:38:52 +00:00
return;
}
}
2024-05-28 14:36:38 +00:00
2024-06-02 16:38:52 +00:00
#endregion
2024-05-28 14:36:38 +00:00
2024-06-02 16:38:52 +00:00
frmLogin login = new frmLogin();
if (login.ShowDialog() == DialogResult.OK)
{
Application.Run(new frm_Launch());
}
2024-05-28 14:36:38 +00:00
}
}
2024-07-01 16:52:48 +00:00
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
//1记录日志信息
Exception ex = e.Exception;
//2 弹出提示
XtraMessageBoxHelper.Error(ex.Message);
}
2024-05-28 14:36:38 +00:00
}
}