/******************************
* 说明:系统全局类
* 创建人:龚宇超
* 创建日期:2017-08-09
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Management;
using DevExpress.XtraTab;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Net.NetworkInformation;
using System.Net.Sockets;
namespace Lskj.Model
{
///
/// 系统全局类
///
public sealed class ERPInfo
{
private static ERPInfo _instance = null;
///
/// ERPInfo静态单例对象
///
/// The instance.
public static ERPInfo Instance
{
get
{
if (_instance == null)
{
_instance = new ERPInfo();
}
return _instance;
}
}
///
/// 是否为超级管理员
///
/// true if this instance is user manager; otherwise, false.
public bool IsUserManager { get { return UserManager.Equals(UserName); } }
///
/// 登录帐套
///
public string AccountBook;
///
/// 输入的密码
///
public string InPassWord;
///
/// 员工ID
///
public string UserId;
///
/// 员工编号
///
public string LoginAccount;
///
/// 员工姓名
///
public string UserName;
///
/// 密码
///
public string Password;
///
/// 菜单GroupId
///
public string GroupId;
///
/// 子系统
///
public string SubSysId;
///
/// 子系统名称
///
public string SubSysName;
///
/// 主界面page界面
///
public XtraTabControl PageControl;
///
/// 主界面page界面字典
///
public Dictionary ModuleForms;
///
/// 登录人联系电话
///
public string UserLinkPhone;
///
/// 主界面page界面
///
public Form MainControl;
///
/// 主页面焦点
///
public PictureBox pic_search;
///
/// 是否阻止回车事件
///
public bool IsExecute = false;
///
/// 是否根据模块id判断是否设置不能同时打开多个相同模块
///
public bool SingleOpenMode = false;
///
/// 登录IP
///
public string LoginIP
{
get
{
try
{
return Dns.GetHostAddresses(WindowName)[0] + "";
}
catch (Exception)
{
}
return string.Empty;
}
}
///
/// 登录IP
///
public string LoginIPV4
{
get
{
try
{
string text = string.Empty;
IPAddress[] ip = Dns.GetHostAddresses(WindowName);
foreach (IPAddress address in ip)
{
if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
text = address + "";
}
}
return text;
}
catch (Exception)
{
}
return "";
}
}
///
/// 用户电脑名
///
public string WindowName
{
get { return Dns.GetHostName(); }
}
///
/// 子系统数量
///
public int SubMenuCount;
///
/// 超级管理员
///
public string UserManager = "管理员";
///
/// 用户皮肤字段
///
/// The name of the skin.
public string SkinFieldName = "SkinName";
///
/// 默认新增判断行
///
public string isAddRows = "xxxxx_isAddRows";
///
/// 用户皮肤
///
public string SkinName;
///
/// 模块编号
///
public string WorkModid;
///
/// 当前选中的方案id
///
/// The mac address.
public string SeriesId;
///
/// 车间
///
public string WorkCJ;
///
/// 车间ID
///
public string WorkCJId;
///
/// 机台
///
public string WorkJT;
///
/// 机台ID
///
public string WorkJTId;
///
/// 班次
///
public string WorkBZ;
///
/// 班次ID
///
public string WorkBZId;
///
/// 班组
///
public string ClassName;
///
/// The work no
///
public string WorkNo;
///
/// 是否显示
///
public static bool ShowMsg = true;
///
/// 当前登录Mac地址
///
/// The mac address.
public string MacAddress
{
get {
if (!string.IsNullOrWhiteSpace(RecordMAC)) return RecordMAC;
return GetMacAddress();
}
}
///
/// 客户名称
///
public string ClientName = "";
///
/// 如果无法连接则后面不在继续连接了
///
public bool bSmartClientIsOK = true;
///
/// 文件升级ip
///
public string UpdateIP = "";
///
/// 登录结果
///
public bool LoginResult = false;
///
/// Mrp当前切换状态
///
public string MrpTag = "";
///
/// 记录本机MAC地址(只记录初始获取的,每次获取导致速度很慢)
///
public string RecordMAC = "";
///
/// 获取本机MAC地址
///
/// 本机MAC地址
private string GetMacAddress()
{
try
{
string fallbackMac = string.Empty;
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
if (ni == null)
{
continue;
}
if (ni.OperationalStatus != OperationalStatus.Up)
{
continue;
}
if (ni.NetworkInterfaceType == NetworkInterfaceType.Loopback ||
ni.NetworkInterfaceType == NetworkInterfaceType.Tunnel)
{
continue;
}
PhysicalAddress physicalAddress = ni.GetPhysicalAddress();
if (physicalAddress == null || physicalAddress.GetAddressBytes().Length == 0)
{
continue;
}
string mac = FormatMacAddress(physicalAddress);
if (string.IsNullOrEmpty(fallbackMac))
{
fallbackMac = mac;
}
IPInterfaceProperties properties = ni.GetIPProperties();
foreach (UnicastIPAddressInformation ipInfo in properties.UnicastAddresses)
{
if (ipInfo.Address.AddressFamily != AddressFamily.InterNetwork)
{
continue;
}
if (!string.IsNullOrEmpty(LoginIPV4) &&
ipInfo.Address.ToString() == LoginIPV4)
{
RecordMAC = mac;
return mac;
}
}
}
RecordMAC = fallbackMac;
return fallbackMac;
}
catch
{
return "";
}
}
private string FormatMacAddress(PhysicalAddress physicalAddress)
{
byte[] bytes = physicalAddress.GetAddressBytes();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
if (i > 0)
{
sb.Append("-");
}
sb.Append(bytes[i].ToString("X2"));
}
return sb.ToString();
}
///
/// 加密狗id
///
public int[] keyHandles = new int[8];
///
/// 加密狗编号
///
public int[] keyNumber = new int[8];
///
/// 是否需要U盾密码验证
///
public bool isDogVerifyPassword = true;
///
/// U盾密码默认值
///
public string dogVerifyPasswordDefault
{
get
{
byte[] bytes = new byte[256];
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = 255;
}
return Encoding.Default.GetString(bytes);
}
}
///
/// 当前选中页签模块编号
///
public string selectFormModleId;
#region 判断windows版本
[StructLayout(LayoutKind.Sequential)]
private struct OSVERSIONINFOEX
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[DllImport("ntdll.dll", SetLastError = true)]
private static extern int RtlGetVersion(ref OSVERSIONINFOEX versionInfo);
private static OSVERSIONINFOEX GetOSVersion()
{
OSVERSIONINFOEX versionInfo = new OSVERSIONINFOEX();
versionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
int result = RtlGetVersion(ref versionInfo);
if (result != 0)
{
throw new Exception("Failed to get OS version");
}
return versionInfo;
}
public string SystemVersion
{
get
{
string systemVersion = "";
OSVERSIONINFOEX osVersionInfo = GetOSVersion();
// 判断具体的Windows版本
if (osVersionInfo.dwPlatformId == 2) // 2 is VER_PLATFORM_WIN32_NT
{
if (osVersionInfo.dwMajorVersion == 10)
{
systemVersion = "Windows 10 或 Windows 11";
}
else
{
switch (osVersionInfo.dwMajorVersion)
{
case 6:
switch (osVersionInfo.dwMinorVersion)
{
case 3:
systemVersion = "Windows 8.1";
break;
case 2:
systemVersion = "Windows 8";
break;
case 1:
systemVersion = "Windows 7";
break;
case 0:
systemVersion = "Windows Vista";
break;
}
break;
case 5:
switch (osVersionInfo.dwMinorVersion)
{
case 2:
systemVersion = "Windows Server 2003; Windows XP x64 Edition";
break;
case 1:
systemVersion = "Windows XP";
break;
case 0:
systemVersion = "Windows 2000";
break;
}
break;
default:
systemVersion = "未知版本";
break;
}
}
}
else
{
systemVersion = "非Windows NT系列操作系统";
}
return systemVersion;
}
}
#endregion
///
/// 使用winfrom自带浏览器
///
public bool PrimitiveBrowser;
///
/// 当前程序使用的语言
///
public string LanguageName;
///
/// 是否改变存储过程参数类型(越南语要用Nvarchar)
///
public bool ChangeParameterType
{
get
{
if (!string.IsNullOrWhiteSpace(this.LanguageName))
{
return true;
}
return false;
}
}
///
/// 页面水印层
///
public Form WatermarkForm;
///
/// 单据水印 草稿替换值
///
public string DraftReplacementValue="";
///
/// 是否有可翻译的文本
///
public bool Translatable;
///
/// 翻译文本存放字典
///
public Dictionary ContrastiveLanguage;
///
/// 传入文本,获取对应语言的翻译文本
///
///
///
public string GetTranslatedText(string text)
{
string value = text;
if (this.ContrastiveLanguage.ContainsKey(text))
{
value = this.ContrastiveLanguage[text];
}
return value;
}
}
}