|
|
@@ -41,34 +41,40 @@ namespace BulkPrinting
|
|
41
|
41
|
return Encoding.ASCII.GetString(HexStringToBytes(hex));
|
|
42
|
42
|
}
|
|
43
|
43
|
|
|
|
44
|
+ public static string TrimRepeats(string value, string substring)
|
|
|
45
|
+ {
|
|
|
46
|
+ var step = substring.Length;
|
|
|
47
|
+ if (step == 0)
|
|
|
48
|
+ return value;
|
|
|
49
|
+
|
|
|
50
|
+ int start = 0;
|
|
|
51
|
+ int end = value.Length;
|
|
|
52
|
+ while ((start <= end - step) && (value.Substring(start, step) == substring))
|
|
|
53
|
+ start += step;
|
|
|
54
|
+
|
|
|
55
|
+ while ((end >= start + step) && (value.Substring(end - step, step) == substring))
|
|
|
56
|
+ end -= step;
|
|
|
57
|
+
|
|
|
58
|
+ return value.Substring(start, end - start);
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
44
|
61
|
public static string GetHDDSerial()
|
|
45
|
62
|
{
|
|
46
|
|
- ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
|
|
47
|
|
- string result;
|
|
48
|
|
- ManagementObjectCollection.ManagementObjectEnumerator enumerator = null;
|
|
49
|
|
- try
|
|
|
63
|
+ using (var managementObjectSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia"))
|
|
50
|
64
|
{
|
|
51
|
|
- enumerator = managementObjectSearcher.Get().GetEnumerator();
|
|
52
|
|
- while (enumerator.MoveNext())
|
|
|
65
|
+ using (var enumerator = managementObjectSearcher.Get().GetEnumerator())
|
|
53
|
66
|
{
|
|
54
|
|
- string text = ((ManagementObject)enumerator.Current)["SerialNumber"].ToString();
|
|
55
|
|
- text = text.Replace(" ", "").Replace(".", "");
|
|
56
|
|
- if (text != "")
|
|
|
67
|
+ while (enumerator.MoveNext())
|
|
57
|
68
|
{
|
|
58
|
|
- result = text;
|
|
59
|
|
- return result.Length > 15 ? result.Substring(result.Length - 15, 15) : result;
|
|
|
69
|
+ string text = TrimRepeats(enumerator.Current["SerialNumber"].ToString().Replace(" ", "").Replace(".", ""), "20");
|
|
|
70
|
+ if (text != "")
|
|
|
71
|
+ {
|
|
|
72
|
+ return text;
|
|
|
73
|
+ }
|
|
60
|
74
|
}
|
|
61
|
75
|
}
|
|
62
|
76
|
}
|
|
63
|
|
- finally
|
|
64
|
|
- {
|
|
65
|
|
- if (enumerator != null)
|
|
66
|
|
- {
|
|
67
|
|
- ((IDisposable)enumerator).Dispose();
|
|
68
|
|
- }
|
|
69
|
|
- }
|
|
70
|
|
- result = "SERIAL ERROR";
|
|
71
|
|
- return result.Length > 15 ? result.Substring(result.Length - 15, 15) : result;
|
|
|
77
|
+ return "SERIAL ERROR";
|
|
72
|
78
|
}
|
|
73
|
79
|
|
|
74
|
80
|
public static DBHelper OpenDBConnection()
|