-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidation.cs
193 lines (182 loc) · 5.24 KB
/
Validation.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace Finance_Management
{
class Validation
{
public bool USN(string usn)
{
if (usn.Length == 10)
{
Regex usnExp = new Regex("^1BM\\d{2}[A-Z]{2}\\d{3}$");
if (usnExp.Match(usn).Success)
{
return true;
}
}
return false;
}
public bool Leap_Year_Check(int year)
{
if ((year % 100 == 0 && year % 400 == 0) || year % 4 == 0)
{
return true;
}
return false;
}
public int Maximum_Days_Month(int month, int year)
{
switch (month)
{
case 1:
return 31;
case 2:
if (Leap_Year_Check(year))
{
return 29;
}
else
{
return 28;
}
case 3:
return 31;
case 4:
return 30;
case 5:
return 31;
case 6:
return 30;
case 7:
return 31;
case 8:
return 31;
case 9:
return 30;
case 10:
return 31;
case 11:
return 30;
case 12:
return 31;
}
return 0;
}
public bool DOB(string dob)
{
DateTime today = DateTime.Today;
if (dob.Length == 10)
{
int year, month, day;
try
{
year = int.Parse(dob.Substring(0, 4));
month = int.Parse(dob.Substring(5, 2));
day = int.Parse(dob.Substring(8, 2));
}
catch (System.FormatException)
{
return false;
}
int max_days = 0;
if (1920 < year && year < (today.Year - 16) && day > 0)
{
max_days = Maximum_Days_Month(month, today.Year);
if (day < max_days)
{
return true;
}
}
}
return false;
}
public bool Name(string name)
{
Regex nameExp = new Regex("^[a-zA-Z \\.]+$");
if (nameExp.Match(name).Success)
{
return true;
}
return false;
}
public bool EmployeeID(string id)
{
if (id.Length == 7)
{
Regex idExp = new Regex("^\\d{4}[CEHNST]{3}$");
if (idExp.Match(id).Success)
{
return true;
}
}
return false;
}
public bool ListBox(string listItem)
{
if (listItem == "")
{
return false;
}
return true;
}
public bool ScholarshipID(string id)
{
if (id.Length > 4 && id.Length < 10)
{
Regex idExp = new Regex("^[A-Z]+_[A-Z]+$");
if (idExp.Match(id).Success)
{
return true;
}
}
return false;
}
public bool Amount(string amount)
{
try
{
if (int.Parse(amount) > 0)
{
return true;
}
}
catch (FormatException)
{
}
return false;
}
public string Get_Timestamp(ListBox year, ListBox month, ListBox day, ListBox hour, ListBox minute, ListBox AMPM)
{
if (year.Text == "")
{
return "";
}
else
{
string timestamp = year.Text;
if (month.Text != "")
{
timestamp += "-" + month.Text;
if (day.Text != "")
{
timestamp += "-" + day.Text;
if (hour.Text != "")
{
if (AMPM.Text == "PM")
{
timestamp += " " + (int.Parse(hour.Text) + 12).ToString();
}
else
{
timestamp += " " + hour.Text;
}
timestamp += ":" + minute.Text + ":0";
}
}
}
return timestamp;
}
}
}
}