-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate Account.cs
358 lines (271 loc) · 11 KB
/
Create Account.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Hospital_Management_System_1
{
public partial class Create_Account : Form
{
public Create_Account()
{
InitializeComponent();
}
private void Create_Account_Load(object sender, EventArgs e)
{
this.ActiveControl = label1;
}
private void textBoxFirstName_Enter(object sender, EventArgs e)
{
String fname = textBoxFirstName.Text;
if (fname.Equals("First Name"))
{
textBoxFirstName.Text = "";
textBoxFirstName.ForeColor = Color.Black;
}
}
private void textBoxFirstName_Leave(object sender, EventArgs e)
{
String fname = textBoxFirstName.Text;
if (fname.ToLower().Trim().Equals("First Name") || fname.Trim().Equals(""))
{
textBoxFirstName.Text = "First Name";
textBoxFirstName.ForeColor = Color.Gray;
}
}
private void textBoxLastName_Enter(object sender, EventArgs e)
{
String lname = textBoxLastName.Text;
if (lname.Equals("Last Name"))
{
textBoxLastName.Text = "";
textBoxLastName.ForeColor = Color.Black;
}
}
private void textBoxLastName_Leave(object sender, EventArgs e)
{
String lname = textBoxLastName.Text;
if (lname.ToLower().Trim().Equals("Last Name") || lname.Trim().Equals(""))
{
textBoxLastName.Text = "Last Name";
textBoxLastName.ForeColor = Color.Gray;
}
}
private void textBoxEmail_Enter(object sender, EventArgs e)
{
String email = textBoxEmail.Text;
if (email.Equals("Email"))
{
textBoxEmail.Text = "";
textBoxEmail.ForeColor = Color.Black;
}
}
private void textBoxEmail_Leave(object sender, EventArgs e)
{
String email = textBoxEmail.Text;
if (email.ToLower().Trim().Equals("Email") || email.Trim().Equals(""))
{
textBoxEmail.Text = "Email";
textBoxEmail.ForeColor = Color.Gray;
}
}
private void textBoxUsername_Enter(object sender, EventArgs e)
{
String username = textBoxUsername.Text;
if (username.Equals("Username"))
{
textBoxUsername.Text = "";
textBoxUsername.ForeColor = Color.Black;
}
}
private void textBoxUsername_Leave(object sender, EventArgs e)
{
String username = textBoxUsername.Text;
if (username.ToLower().Trim().Equals("Username") || username.Trim().Equals(""))
{
textBoxUsername.Text = "Username";
textBoxUsername.ForeColor = Color.Gray;
}
}
private void textBoxPassword_Enter(object sender, EventArgs e)
{
String password = textBoxPassword.Text;
if (password.Equals("Password"))
{
textBoxPassword.Text = "";
textBoxPassword.UseSystemPasswordChar = true;
textBoxPassword.ForeColor = Color.Black;
}
}
private void textBoxPassword_Leave(object sender, EventArgs e)
{
String password = textBoxPassword.Text;
if (password.ToLower().Trim().Equals("Password") || password.Trim().Equals(""))
{
textBoxPassword.Text = "Password";
textBoxPassword.UseSystemPasswordChar = false;
textBoxPassword.ForeColor = Color.Gray;
}
}
private void textBoxConfirmPassword_Enter(object sender, EventArgs e)
{
String cpassword = textBoxConfirmPassword.Text;
if (cpassword.Equals("Confirm Password"))
{
textBoxConfirmPassword.Text = "";
textBoxConfirmPassword.UseSystemPasswordChar = true;
textBoxConfirmPassword.ForeColor = Color.Black;
}
}
private void textBoxConfirmPassword_Leave(object sender, EventArgs e)
{
String cpassword = textBoxConfirmPassword.Text;
if (cpassword.ToLower().Trim().Equals("Confirm Password") ||
cpassword.ToLower().Trim().Equals("Confirm Password") || cpassword.Trim().Equals(""))
{
textBoxConfirmPassword.Text = "Confirm Password";
textBoxConfirmPassword.UseSystemPasswordChar = false;
textBoxConfirmPassword.ForeColor = Color.Gray;
}
}
private void labelClose_Click(object sender, EventArgs e)
{
this.Close();
Admin admin = new Admin();
admin.Show();
}
private void labelClose_Enter(object sender, EventArgs e)
{
}
private void labelClose_Leave(object sender, EventArgs e)
{
}
private void labelClose_MouseEnter(object sender, EventArgs e)
{
labelClose.ForeColor = Color.Black;
}
private void labelClose_MouseLeave(object sender, EventArgs e)
{
labelClose.ForeColor = Color.White;
}
private void buttonCreateAccount_Click(object sender, EventArgs e)
{
DB db = new DB();
MySqlCommand command = new MySqlCommand("INSERT INTO `user`(`FirstName`, `LastName`, `Email`, `username`, `password`,'authentication') VALUES (@fn, @ln, @email, @usn, @pass,@au)", db.GetConnection());
command.Parameters.Add("@fn", MySqlDbType.VarChar).Value = textBoxFirstName.Text;
command.Parameters.Add("@ln", MySqlDbType.VarChar).Value = textBoxLastName.Text;
command.Parameters.Add("@email", MySqlDbType.VarChar).Value = textBoxEmail.Text;
command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = textBoxUsername.Text;
command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = textBoxPassword.Text;
command.Parameters.Add("@au", MySqlDbType.VarChar).Value = comboBox1.Text;
//open connection
db.OpenConnection();
//Check if the textboxes contain the default values
if(!checkTextBoxesValues())
{
//check if the password equals the confirm password
if(textBoxPassword.Text.Equals(textBoxConfirmPassword.Text))
{
//check if this username already exist
if (checkUsername())
{
MessageBox.Show("This Username Already Exist, Select a Different One", "Duplicate Username", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
}
else
{
//execute the qeuery
if (command.ExecuteNonQuery() == 1)
{
MessageBox.Show("Your Account has been Created","Account Created", MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("ERROR");
}
}
}
else
{
MessageBox.Show("Password Do Not Match","Password Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Enter Your Details First","Empty Data",MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
}
//close connection
db.CloseConnection();
}
//check if the username already exist
public Boolean checkUsername()
{
DB db = new DB();
string username = textBoxUsername.Text;
string authentication = comboBox1.Text;
DataTable table = new DataTable();
MySqlDataAdapter Adapter = new MySqlDataAdapter();
MySqlCommand Command = new MySqlCommand("SELECT * FROM `user` WHERE `username` = @usn and 'authentication'= @au", db.GetConnection());
Command.Parameters.Add("@usn", MySqlDbType.VarChar).Value = username;
Command.Parameters.Add("@au", MySqlDbType.VarChar).Value = authentication;
Adapter.SelectCommand = Command;
Adapter.Fill(table);
if (table.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
//check if the textboxes contain a default value
public Boolean checkTextBoxesValues()
{
string fname = textBoxFirstName.Text;
string lname = textBoxLastName.Text;
string email = textBoxEmail.Text;
string uname = textBoxUsername.Text;
string pass = textBoxPassword.Text;
string au = comboBox1.Text;
if (fname.Equals("First Name") || lname.Equals("Last Name") || email.Equals("Email") ||
uname.Equals("Username") || pass.Equals("Password")|| au.Equals("authentication"))
{
return true;
}else
{
return false;
}
}
private void labelGoToLogin_MouseEnter(object sender, EventArgs e)
{
}
private void labelGoToLogin_MouseLeave(object sender, EventArgs e)
{
}
private void labelGoToLogin_Click(object sender, EventArgs e)
{
this.Hide();
LoginForm loginForm = new LoginForm();
loginForm.Show();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void textBoxPassword_TextChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Add("Doc");
comboBox1.Items.Add("Nurse");
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}