/
RegisterNewUser.xaml.cs
172 lines (150 loc) · 6.88 KB
/
RegisterNewUser.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using myRequirements.ServiceReference1;
namespace myRequirements
{
public partial class RegisterNewUser : UserControl
{
public RegisterNewUser()
{
InitializeComponent();
}
private void click_goBackToMainMenu(object sender, RoutedEventArgs e)
{
PageSwitcher ps = this.Parent as PageSwitcher;
ps.Navigate(new LoginWindow());
}
private void registerNewUser(object sender, RoutedEventArgs e)
{
errorTextBlock.Text = "";
Boolean foundError = false;
VisualStateManager.GoToState(this, "VisualState", true);
VisualStateManager.GoToState(this, "VisualState2", true);
VisualStateManager.GoToState(this, "VisualState4", true);
VisualStateManager.GoToState(this, "VisualState6", true);
VisualStateManager.GoToState(this, "VisualState8", true);
VisualStateManager.GoToState(this, "VisualState10", true);
if (fullName.Text.Equals(""))
{
VisualStateManager.GoToState(this, "VisualState1", true);
errorTextBlock.Text += "- You need to set Full name\n";
foundError = true;
}
if (username.Text.Equals(""))
{
VisualStateManager.GoToState(this, "VisualState3", true);
errorTextBlock.Text += "- You need to set Username\n";
foundError = true;
}
if (email.Text.Equals(""))
{
VisualStateManager.GoToState(this, "VisualState5", true);
errorTextBlock.Text += "- You need to set e-mail\n";
foundError = true;
}
if (country.Text.Equals(""))
{
VisualStateManager.GoToState(this, "VisualState7", true);
errorTextBlock.Text += "- You need to set country\n";
foundError = true;
}
if (password.Password.Equals(""))
{
VisualStateManager.GoToState(this, "VisualState9", true);
errorTextBlock.Text += "- You need to set password\n";
foundError = true;
}
if (cpassword.Password.Equals(""))
{
VisualStateManager.GoToState(this, "VisualState9", true);
errorTextBlock.Text += "- You need to confirm password\n";
foundError = true;
}
else{
if(!password.Password.Equals(cpassword.Password)){
VisualStateManager.GoToState(this, "VisualState9", true);
errorTextBlock.Text += "- The passwords do not match\n";
foundError = true;
}
if(password.Password.Length < 8){
VisualStateManager.GoToState(this, "VisualState9", true);
errorTextBlock.Text += "- The password needs to be at least 8 characters\n";
foundError = true;
}
}
if (!foundError)
{
progressBar.Visibility = Visibility.Visible;
User user = new User() { Fullname = fullName.Text, Username = username.Text, Password = password.Password, Email = email.Text ,Country = country.Text};
ServiceReference1.WebServiceClient proxy = new ServiceReference1.WebServiceClient();
proxy.CreateNewUserCompleted += new EventHandler<CreateNewUserCompletedEventArgs>(proxy_CreateNewUserCompleted);
proxy.CreateNewUserAsync(user);
}
}
void proxy_CreateNewUserCompleted(object sender, CreateNewUserCompletedEventArgs e)
{
progressBar.Visibility = Visibility.Collapsed;
String headerText = "Something went wrong.";
try
{
infoMessagePanelControl.Visibility = System.Windows.Visibility.Visible;
if (e.Error == null && e.Result.Equals("Registration successfull")) //logged in ok
{
infoMessagePanelControl.header.Text = "Registration successfull!";
infoMessagePanelControl.message.Text = "You have now successfully created a new user! Click the \"Ok\" button to go back to the main page";
infoMessagePanelControl.okInfoMessageButotn.Click += new RoutedEventHandler(okInfoMessageButotn_Click);
}
else
{
if (e.Result.Equals("Username already exsists."))
{
VisualStateManager.GoToState(this, "VisualState3", true);
}
else if (e.Result.Equals("Email is not valid."))
{
VisualStateManager.GoToState(this, "VisualState5", true);
}
else if (e.Result.Equals("Username or email already exsists."))
{
VisualStateManager.GoToState(this, "VisualState3", true);
VisualStateManager.GoToState(this, "VisualState5", true);
}
showErrorMessage(headerText, e.Result);
}
}
catch (System.Reflection.TargetInvocationException)
{
showErrorMessage("Something went wrong!", "Could not connect to server, please try again later...");
}
catch (Exception)
{
showErrorMessage(headerText, e.Result);
}
}
private void showErrorMessage(String headerText, String messageText)
{
infoMessagePanelControl.header.Text = headerText;
infoMessagePanelControl.message.Text = messageText;
infoMessagePanelControl.okInfoMessageButotn.Click += new RoutedEventHandler(okInfoMessageButotn_Click2);
}
private void okInfoMessageButotn_Click(object sender, RoutedEventArgs e) //Go back to login page
{
infoMessagePanelControl.Visibility = System.Windows.Visibility.Collapsed;
PageSwitcher ps = this.Parent as PageSwitcher;
ps.Navigate(new LoginWindow());
}
private void okInfoMessageButotn_Click2(object sender, RoutedEventArgs e) //Just collaps message box
{
infoMessagePanelControl.Visibility = System.Windows.Visibility.Collapsed;
}
}
}