-
Notifications
You must be signed in to change notification settings - Fork 3
/
DataUtils.cs
59 lines (55 loc) · 2.23 KB
/
DataUtils.cs
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
using MSR_100_Magnetic_Stripe_Parser;
namespace Repos.MSR100Controller
{
internal static class DataUtils
{
internal static void SetNameData(ref Track01Info cardinfoTrack1, string nameInfo)
{
cardinfoTrack1.Name = nameInfo;
var namesplit = cardinfoTrack1.Name.Split('/');
cardinfoTrack1.LastName = namesplit[0].Trim();
cardinfoTrack1.FirstName = string.Empty;
if (namesplit.Length > 1)
{
cardinfoTrack1.FirstName = namesplit[1].Trim();
}
cardinfoTrack1.Name = $"{cardinfoTrack1.FirstName} {cardinfoTrack1.LastName}";
}
internal static System.DateTime ExpirationDate(string date)
{
var year = System.Convert.ToInt16(date.Substring(0, 2)) + 2000;
var month = System.Convert.ToInt16(date.Substring(2, 2));
return new System.DateTime(year, month, 1);
}
internal static void SetDiscretionaryData(ref Track01Info cardinfoTrack1, string[] fieldsTrack01)
{
cardinfoTrack1.ExpirationDate = new System.DateTime();
cardinfoTrack1.ServiceCode = null;
if (fieldsTrack01.Length == 3)
{
cardinfoTrack1.ExpirationDate = ExpirationDate(fieldsTrack01[2]);
cardinfoTrack1.ServiceCode = fieldsTrack01[2].Substring(4, 3);
cardinfoTrack1.DiscretionaryData = fieldsTrack01[2].Substring(7);
}
else
{
if (fieldsTrack01.Length == 4)
{
if (fieldsTrack01[2].Length > 1) //has date
{
cardinfoTrack1.ExpirationDate = ExpirationDate(fieldsTrack01[2]);
}
else // has service code
{
cardinfoTrack1.ServiceCode = fieldsTrack01[3];
}
cardinfoTrack1.DiscretionaryData = fieldsTrack01[3];
}
else if (fieldsTrack01.Length == 5)
{
cardinfoTrack1.DiscretionaryData = fieldsTrack01[4];
}
}
}
}
}