-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enroll.xaml.cs
158 lines (149 loc) · 5.07 KB
/
Enroll.xaml.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace JBWally
{
/// <summary>
/// Interaction logic for Enroll.xaml
/// </summary>
public partial class Enroll : Page
{
public Enroll()
{
InitializeComponent();
}
/// <summary>
/// Checks if the given name contains all alpha characters or not
/// </summary>
/// <param name="FirstName"></param>
/// <param name="LastName"></param>
/// <returns>1 if first name is not all alpha, 2 if last name is not all alpha, -1 if firtname is null, -2 if last name is null
/// 0 if all valid</returns>
private int CheckName(String FirstName, String LastName)
{
if (FirstName == "")
return -1;
if (LastName == "")
return -2;
foreach (char c in FirstName)
{
if (char.IsDigit(c))
return 1;
}
foreach (char c in LastName)
{
if (char.IsDigit(c))
return 2;
}
return 0;
}
/// <summary>
/// Checks if the phone number contains all numbers
/// </summary>
/// <param name="PhoneNumber"></param>
/// <returns>true if all numbers, false for invalid input</returns>
private bool CheckNumber(String PhoneNumber)
{
if (PhoneNumber == "")
return false;
foreach (char c in PhoneNumber)
{
if (!char.IsDigit(c))
return false;
}
return true;
}
/// <summary>
/// Enrolls a customer
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click(object sender, RoutedEventArgs e)
{
String firstName = FirstName.Text.ToLower().Trim();
String lastName = LastName.Text.ToLower().Trim();
String PhoneNo = PhoneNumber.Text.Trim();
bool check = true;
bool checkCustomer = true;
//check if customer already exists
checkCustomer = Database.CheckCustomer(firstName, lastName);
if (checkCustomer == true)
{
MessageBox.Show("Customer Already Exists!");
}
else //check validity
{
if (CheckNumber(PhoneNo) == false)
{
PhoneError.Visibility = Visibility.Visible;
check = false;
}
else
{
PhoneError.Visibility = Visibility.Hidden;
}
if (CheckName(firstName, lastName) == 1)
{
firstNameError.Visibility = Visibility.Visible;
check = false;
}
else
{
firstNameError.Visibility = Visibility.Hidden;
}
if (CheckName(firstName, lastName) == 2)
{
lastNameError.Visibility = Visibility.Visible;
check = false;
}
else
{
lastNameError.Visibility = Visibility.Hidden;
}
if (CheckName(firstName, lastName) == -1)
{
firstNameError.Visibility = Visibility.Visible;
check = false;
}
if (CheckName(firstName, lastName) == -2)
{
lastNameError.Visibility = Visibility.Visible;
check = false;
}
if (check == true)
{
Database.firstName = firstName;
Database.lastName = lastName;
Database.phoneNo = PhoneNo;
// enroll customer
Database.EnrollCustomer(FirstName.Text.ToString().Trim(), LastName.Text.ToString().Trim(), PhoneNumber.Text.ToString().Trim());
success.Visibility = Visibility.Visible;
FirstName.Text = "";
LastName.Text = "";
PhoneNumber.Text = "";
}
}
}
/// <summary>
/// Goes back to Order page.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click_1(object sender, RoutedEventArgs e)
{
success.Visibility = Visibility.Hidden;
NavigationService.Navigate(new Uri("Order.xaml", UriKind.RelativeOrAbsolute));
}
}
}