2021-12-31 19:53:53 +08:00
|
|
|
|
using CleanMachine.Model;
|
2022-05-05 20:42:02 +08:00
|
|
|
|
using CleanMachine.Model.BAS;
|
|
|
|
|
|
using CleanMachine.Model.CM;
|
2021-12-31 19:53:53 +08:00
|
|
|
|
using CleanMachineHMI.Domain.Enums;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
using CleanMachineHMI.Domain.Models.ViewModels;
|
|
|
|
|
|
using CleanMachineHMI.forms;
|
|
|
|
|
|
using CleanMachineHMI.frmChild;
|
|
|
|
|
|
using CleanMachineHMI.Utils;
|
2021-12-26 21:30:02 +08:00
|
|
|
|
using Krypton.Toolkit;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Data;
|
2022-03-18 19:06:26 +08:00
|
|
|
|
using System.IO;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace CleanMachineHMI
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 应用配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class GlobalHelper
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 主窗体_New
|
|
|
|
|
|
/// </summary>
|
2022-03-18 19:06:26 +08:00
|
|
|
|
public static frmMainNew MainFormNew { get; set; }
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 登陆窗体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static frmLogin LoginForm { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 基础信息窗体容器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static frmBase BaseForm { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public static frmIoMonitorNew IoMonitor_2 { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所有窗体模型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static List<FormModel<Type>> FrmModelList { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 语言编码
|
|
|
|
|
|
/// </summary>
|
2022-03-18 19:06:26 +08:00
|
|
|
|
public static string LanguageCode { get; set; } = AppConfigHelper.Get("LanguageCode");
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 语言字典
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static Dictionary<string, string> ThemeLanguage = null;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用户信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static UserInfo UserInfo { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 参数列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static DataTable ParameterList { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 角色菜单权限数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static DataTable RoleMenuPermission { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
2021-12-31 19:53:53 +08:00
|
|
|
|
public static List<PlcItem> PlcItemMdList { get; set; }
|
|
|
|
|
|
public static List<PlcItem> PlcItemMd_D_List { get; set; }
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
2021-12-31 19:53:53 +08:00
|
|
|
|
public static List<PlcItem> PlcItemMd_M_List { get; set; }
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
2021-12-31 19:53:53 +08:00
|
|
|
|
public static List<PlcItem> PlcItemMd_X_List { get; set; }
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
2021-12-31 19:53:53 +08:00
|
|
|
|
public static List<PlcItem> PlcItemMd_Y_List { get; set; }
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
|
|
|
|
|
public static List<Bas_WarningMd> BasWarningMd_List { get; set; }
|
|
|
|
|
|
|
2021-12-31 19:53:53 +08:00
|
|
|
|
public static List<WarningLog> CmWarningLogMd_List { get; set; }
|
2021-06-05 14:17:30 +08:00
|
|
|
|
|
2021-12-31 19:53:53 +08:00
|
|
|
|
public static List<WarningLog> CmWarningLogMd_List_1 { get; set; }
|
2022-03-18 19:06:26 +08:00
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 参数列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static bool CanOperate { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 系统是否运行
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static bool SysThIsRunFlag { get; set; }
|
|
|
|
|
|
#region 委托事件
|
|
|
|
|
|
//定义一个委托类型的事件
|
|
|
|
|
|
public static event EventHandler<EventArgs> OnShowX_Y_Status;
|
|
|
|
|
|
public static bool eventLock = false;
|
|
|
|
|
|
public static void ShowX_Y_Status(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!eventLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnShowX_Y_Status?.Invoke(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//定义一个委托类型的事件
|
|
|
|
|
|
public static event EventHandler<EventArgs> OnShowSensorStatus;
|
|
|
|
|
|
public static void ShowSensorStatus(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!eventLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnShowSensorStatus?.Invoke(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//定义一个委托类型的事件
|
|
|
|
|
|
public static event EventHandler<EventArgs> OnShowMainFrmAlarmMsg;
|
|
|
|
|
|
public static bool eventAlarmLock = false;
|
|
|
|
|
|
public static void ShowMainFrmAlarmMsg(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!eventAlarmLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnShowMainFrmAlarmMsg?.Invoke(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static frmPopupWarningMsg PopupWarningMsgForm { get; set; }
|
|
|
|
|
|
//定义一个委托类型的事件
|
|
|
|
|
|
public static event EventHandler<EventArgs> OnSyncFinishPalletData;
|
|
|
|
|
|
public static void SyncFinishPalletData(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
OnSyncFinishPalletData?.Invoke(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取拖盘号
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static string GetPalletCode()
|
|
|
|
|
|
{
|
|
|
|
|
|
string currDateStr = DateTime.Now.ToString("yyyyMMdd");
|
2022-03-18 19:06:26 +08:00
|
|
|
|
string PalletIndexPrefix = AppConfigHelper.Get("PalletIndexPrefix");
|
|
|
|
|
|
string PalletIndexDateMsg = AppConfigHelper.Get("PalletIndexDateMsg");
|
2021-06-05 14:17:30 +08:00
|
|
|
|
int PalletIndexLen = Convert.ToInt32(AppConfigHelper.Get("PalletIndexLen"));
|
|
|
|
|
|
int PalletIndexValue = Convert.ToInt32(AppConfigHelper.Get("PalletIndexValue"));
|
|
|
|
|
|
if (currDateStr == PalletIndexDateMsg)
|
|
|
|
|
|
{
|
|
|
|
|
|
PalletIndexValue++;
|
|
|
|
|
|
string tmpPalletCode = PalletIndexPrefix + currDateStr + PalletIndexValue.ToString().PadLeft(PalletIndexLen, '0');
|
|
|
|
|
|
AppConfigHelper.Update("PalletIndexValue", PalletIndexValue.ToString());
|
|
|
|
|
|
return tmpPalletCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PalletIndexValue = 1;
|
|
|
|
|
|
string tmpPalletCode = PalletIndexPrefix + currDateStr + PalletIndexValue.ToString().PadLeft(PalletIndexLen, '0');
|
|
|
|
|
|
AppConfigHelper.Update("PalletIndexValue", PalletIndexValue.ToString());
|
|
|
|
|
|
AppConfigHelper.Update("PalletIndexDateMsg", currDateStr);
|
|
|
|
|
|
return tmpPalletCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据自定义特性和窗体的绑定原理,
|
|
|
|
|
|
/// 自动加载所有的窗体数据。
|
|
|
|
|
|
/// </summary>
|
2022-03-18 19:06:26 +08:00
|
|
|
|
public static void LoadAllFormData()
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
var types = Assembly.GetExecutingAssembly().GetTypes().Where(x => x.GetCustomAttributes(typeof(FormTypeAttribute), false).Count() > 0);
|
|
|
|
|
|
FrmModelList = new List<FormModel<Type>>();
|
|
|
|
|
|
foreach (var item in types)
|
|
|
|
|
|
{
|
|
|
|
|
|
FormTypeAttribute tmpAttribute = (FormTypeAttribute)item.GetCustomAttribute(typeof(FormTypeAttribute));
|
|
|
|
|
|
FrmModelList.Add(new FormModel<Type>
|
|
|
|
|
|
{
|
|
|
|
|
|
//Form = (UserControl)Activator.CreateInstance(item),
|
|
|
|
|
|
Form = item,
|
|
|
|
|
|
FormType = tmpAttribute.Value
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
//MainForm = (frmMain)FrmModelList.Find(x => x.FormType == EnumFormType.Main).Form;
|
|
|
|
|
|
//MainFormNew = (frmMainNew)FrmModelList.Find(x => x.FormType == EnumFormType.Main).Form;
|
|
|
|
|
|
//LoginForm = (frmLogin)FrmModelList.Find(x => x.FormType == EnumFormType.Login).Form;
|
|
|
|
|
|
LoginForm = new frmLogin();
|
|
|
|
|
|
CanOperate = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-18 19:06:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载主题
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static void LoadTheme()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ThemeLanguage == null || ThemeLanguage.Count == 0)
|
|
|
|
|
|
{
|
2022-05-05 09:25:58 +08:00
|
|
|
|
// var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0];
|
|
|
|
|
|
var filePath = $"Lang\\{GlobalHelper.LanguageCode}.json";
|
2022-03-19 12:46:23 +08:00
|
|
|
|
var str = File.ReadAllText(filePath);
|
|
|
|
|
|
var lstLanguage = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
|
|
|
|
|
|
var tmpThemeLanguage = new Dictionary<string, string>();
|
|
|
|
|
|
lstLanguage.ForEach(item =>
|
2022-03-18 19:06:26 +08:00
|
|
|
|
{
|
2022-03-19 12:46:23 +08:00
|
|
|
|
if (item.options != null && item.options.Count > 0)
|
2022-03-18 19:06:26 +08:00
|
|
|
|
{
|
2022-03-19 12:46:23 +08:00
|
|
|
|
tmpThemeLanguage.Add(item.formCode + "|" + item.controlCode, string.Join(",", item.options));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
tmpThemeLanguage.Add(item.formCode + "|" + item.controlCode, item.controlName);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
ThemeLanguage = tmpThemeLanguage;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-18 19:06:26 +08:00
|
|
|
|
|
2022-03-19 12:46:23 +08:00
|
|
|
|
public static void LoadzhCN()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Utils.frmUtil.znCNLang == null || Utils.frmUtil.znCNLang.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var appPath = System.Windows.Forms.Application.StartupPath.Split(new string[] { @"bin\Debug" }, StringSplitOptions.RemoveEmptyEntries)[0];
|
|
|
|
|
|
var filePath = appPath + $"Lang\\zh-CN.json";
|
|
|
|
|
|
if (!File.Exists(filePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
2022-03-18 19:06:26 +08:00
|
|
|
|
}
|
2022-03-19 12:46:23 +08:00
|
|
|
|
var str = File.ReadAllText(filePath);
|
|
|
|
|
|
Utils.frmUtil.znCNLang = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ThemeLanguage>>(str);
|
|
|
|
|
|
|
2022-03-18 19:06:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|