-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialNumberQuery.cs
More file actions
96 lines (77 loc) · 2.7 KB
/
Copy pathSerialNumberQuery.cs
File metadata and controls
96 lines (77 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
namespace EZcade_Client;
public class SerialNumberQuery
{
public string ProductModel { get; set; } = "";
public string? PcbModel { get; set; }
public string Type { get; set; } = ""; // "PR" or "PB"
public string CodeType { get; set; } = ""; // "SN" or "DM"
public int Count { get; set; }
public SerialNumberQuery(string input)
{
if (string.IsNullOrWhiteSpace(input))
throw new ArgumentException("Input cannot be null or empty.");
var parts = input.Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries);
Type = parts[0];
if (Type == "PR")
{
if (parts.Length != 4)
throw new FormatException("Input must contain exactly four parts: Model, Type, CodeType, and Count.");
ProductModel = parts[1];
CodeType = parts[2];
if (!int.TryParse(parts[3], out int count))
throw new FormatException("The last part must be a valid integer.");
Count = count;
}
else if (Type == "PB")
{
if (parts.Length != 5)
throw new FormatException("Input must contain exactly five parts: Model, PcbductModel, Type, CodeType, and Count.");
ProductModel = parts[1];
PcbModel = parts[2];
CodeType = parts[3];
if (!int.TryParse(parts[4], out int count))
throw new FormatException("The last part must be a valid integer.");
Count = count;
}
else if (Type == "CO")
{
if (parts.Length != 4)
throw new FormatException("Input must contain exactly four parts: Model, Type, CodeType, and Count.");
ProductModel = parts[1];
ProductModel = ProductModel.Replace("$" , " ");
CodeType = parts[2];
if (!int.TryParse(parts[3], out int count))
throw new FormatException("The last part must be a valid integer.");
Count = count;
}
else
{
throw new ArgumentException("Invalid Type. Expected 'PR' or 'PB' or 'DM'.");
}
}
public string GetSerialNumber(string serialNumber , string dmCode)
{
if (Type == "PR")
{
if (CodeType == "DM")
{
serialNumber = "PR" + serialNumber;
}
}
else if (Type == "PB")
{
if (CodeType == "DM")
{
serialNumber = "PB" + serialNumber;
}
}
else if (Type == "CO")
{
if (CodeType == "DM")
{
serialNumber = dmCode;
}
}
return serialNumber;
}
}