|
|
@@ -4,6 +4,8 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Data; |
|
|
|
using System.Linq; |
|
|
|
using System.Management; |
|
|
|
using System.Net.NetworkInformation; |
|
|
|
using System.Text; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
|
|
|
@@ -60,7 +62,7 @@ namespace CnasSynchronusClient |
|
|
|
break; |
|
|
|
} |
|
|
|
if (dtTarget.Columns.Contains(syncInstrumentItem.CnasInstrumentColumn)) |
|
|
|
drNewTarget[syncInstrumentItem.CnasInstrumentColumn] = syncInstrumentItem.GUID; |
|
|
|
drNewTarget[syncInstrumentItem.CnasInstrumentColumn] = syncInstrumentItem.GUID + GetMachineCode(); |
|
|
|
else |
|
|
|
{ |
|
|
|
strErrorMsg = "设置的CNAS仪器信息列没有在库中找到,请重新配置"; |
|
|
@@ -79,7 +81,70 @@ namespace CnasSynchronusClient |
|
|
|
} |
|
|
|
return strErrorMsg; |
|
|
|
} |
|
|
|
private string GetMachineCode() |
|
|
|
{ |
|
|
|
StringBuilder machineCode = new StringBuilder(); |
|
|
|
|
|
|
|
// 获取CPU ID |
|
|
|
string cpuId = GetCPUId(); |
|
|
|
machineCode.Append(cpuId); |
|
|
|
|
|
|
|
// 获取所有MAC地址 |
|
|
|
List<string> macAddresses = GetMACAddresses(); |
|
|
|
foreach (string mac in macAddresses) |
|
|
|
{ |
|
|
|
machineCode.Append("_").Append(mac); |
|
|
|
} |
|
|
|
|
|
|
|
return machineCode.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
private string GetCPUId() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
using (ManagementClass mc = new ManagementClass("Win32_Processor")) |
|
|
|
{ |
|
|
|
ManagementObjectCollection moc = mc.GetInstances(); |
|
|
|
foreach (ManagementObject mo in moc) |
|
|
|
{ |
|
|
|
return mo.Properties["ProcessorId"].Value.ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
throw new Exception("获取CPU ID失败: " + ex.Message); |
|
|
|
} |
|
|
|
return string.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
private List<string> GetMACAddresses() |
|
|
|
{ |
|
|
|
List<string> macAddresses = new List<string>(); |
|
|
|
try |
|
|
|
{ |
|
|
|
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); |
|
|
|
foreach (NetworkInterface adapter in nics) |
|
|
|
{ |
|
|
|
// 只获取物理网卡的MAC地址 |
|
|
|
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet || |
|
|
|
adapter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211) |
|
|
|
{ |
|
|
|
string mac = adapter.GetPhysicalAddress().ToString(); |
|
|
|
if (!string.IsNullOrEmpty(mac)) |
|
|
|
{ |
|
|
|
macAddresses.Add(mac); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
throw new Exception("获取MAC地址失败: " + ex.Message); |
|
|
|
} |
|
|
|
return macAddresses; |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 获取日期字段 |
|
|
|
/// </summary> |
|
|
@@ -443,7 +508,6 @@ namespace CnasSynchronusClient |
|
|
|
AppLog.Error(ex.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 处理SubString类型固定值 |
|
|
|
/// </summary> |
|
|
@@ -458,24 +522,27 @@ namespace CnasSynchronusClient |
|
|
|
if (item.Value != null && item.Value.ToString() != "") |
|
|
|
{ |
|
|
|
string[] strValues = item.Value.ToString().Split(new string[] { "{", ",", "}" }, StringSplitOptions.RemoveEmptyEntries); |
|
|
|
|
|
|
|
if (strValues.Length == 2) |
|
|
|
{ |
|
|
|
string[] strInputValues = drNewTarget[item.ColumnName].ToString().Split(new string[] { strValues[0] }, StringSplitOptions.RemoveEmptyEntries); |
|
|
|
if (strInputValues.Length == 1) |
|
|
|
{ |
|
|
|
drNewTarget[item.ColumnName] = strInputValues[0]; |
|
|
|
} |
|
|
|
if (strInputValues.Length == 2) //只处理分割后有两部分的 |
|
|
|
{ |
|
|
|
if (strValues[1] == "L") |
|
|
|
{ |
|
|
|
drNewTarget[item.ColumnName] = strInputValues[0]; |
|
|
|
} |
|
|
|
else if (strValues[1] == "R") |
|
|
|
{ |
|
|
|
drNewTarget[item.ColumnName] = strInputValues[1]; |
|
|
|
} |
|
|
|
|
|
|
|
var list = strInputValues[0].Substring(Convert.ToInt32(strValues[0]), Convert.ToInt32(strValues[1])); |
|
|
|
drNewTarget[item.ColumnName] = list; |
|
|
|
} |
|
|
|
//if (strInputValues.Length == 2) //只处理分割后有两部分的 |
|
|
|
//{ |
|
|
|
// if (strValues[1] == "L") |
|
|
|
// { |
|
|
|
// drNewTarget[item.ColumnName] = strInputValues[0]; |
|
|
|
// } |
|
|
|
// else if (strValues[1] == "R") |
|
|
|
// { |
|
|
|
// drNewTarget[item.ColumnName] = strInputValues[1]; |
|
|
|
// } |
|
|
|
//} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|