| 9 |
Kevin |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.ComponentModel;
|
|
|
4 |
using System.Data;
|
|
|
5 |
using System.Drawing;
|
|
|
6 |
using System.Linq;
|
|
|
7 |
using System.Text;
|
|
|
8 |
using System.Windows.Forms;
|
|
|
9 |
|
|
|
10 |
namespace SWAT_Office_App
|
|
|
11 |
{
|
| 63 |
Kevin |
12 |
public partial class Add_User_Account_Form : Form
|
| 9 |
Kevin |
13 |
{
|
| 63 |
Kevin |
14 |
private static Add_User_Account_Form _Add_User_Account_Instance = null;
|
| 9 |
Kevin |
15 |
// Modified singleton instance
|
| 63 |
Kevin |
16 |
public static Add_User_Account_Form Add_User_Account_Instance
|
| 9 |
Kevin |
17 |
{
|
|
|
18 |
get
|
|
|
19 |
{
|
| 63 |
Kevin |
20 |
_Add_User_Account_Instance = new Add_User_Account_Form();
|
|
|
21 |
return _Add_User_Account_Instance;
|
| 9 |
Kevin |
22 |
}
|
|
|
23 |
}
|
| 63 |
Kevin |
24 |
public Add_User_Account_Form()
|
| 9 |
Kevin |
25 |
{
|
|
|
26 |
InitializeComponent();
|
|
|
27 |
|
|
|
28 |
resetForm();
|
|
|
29 |
|
|
|
30 |
this.txt_Username.TextChanged += new EventHandler(txt_EmptyTxtBox);
|
|
|
31 |
this.txt_Password.TextChanged += new EventHandler(txt_EmptyTxtBox);
|
|
|
32 |
this.txt_Username.KeyPress += new KeyPressEventHandler(txt_Username_KeyPress);
|
|
|
33 |
}
|
|
|
34 |
private void resetForm()
|
|
|
35 |
{
|
|
|
36 |
this.btn_Add.Enabled = false;
|
|
|
37 |
this.txt_Username.Text = "";
|
|
|
38 |
this.txt_Password.Text = "";
|
|
|
39 |
this.txt_Username.Tag = false;
|
|
|
40 |
this.txt_Password.Tag = false;
|
|
|
41 |
this.txt_Username.Focus();
|
|
|
42 |
}
|
|
|
43 |
private void txt_EmptyTxtBox(object sender, EventArgs e)
|
|
|
44 |
{
|
|
|
45 |
TextBox tb = (TextBox)sender;
|
|
|
46 |
if (tb.Text.Length == 0)
|
|
|
47 |
tb.Tag = false;
|
|
|
48 |
else
|
|
|
49 |
tb.Tag = true;
|
|
|
50 |
ValidateBox();
|
|
|
51 |
}
|
|
|
52 |
private void ValidateBox()
|
|
|
53 |
{
|
|
|
54 |
this.btn_Add.Enabled = ((bool)(this.txt_Username.Tag) && (bool)(this.txt_Password.Tag));
|
|
|
55 |
}
|
|
|
56 |
private void txt_Username_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
57 |
{
|
|
|
58 |
// Blocks symbols that cannot be used in the username field
|
|
|
59 |
if ((e.KeyChar < 32 || e.KeyChar == 34 || (e.KeyChar > 41 && e.KeyChar < 45) || e.KeyChar == 47 ||
|
|
|
60 |
(e.KeyChar > 57 && e.KeyChar < 65) || (e.KeyChar > 90 && e.KeyChar < 94) || e.KeyChar > 122) && e.KeyChar != 8)
|
|
|
61 |
e.Handled = true;
|
|
|
62 |
}
|
|
|
63 |
private void btn_Cancel_Click(object sender, EventArgs e)
|
|
|
64 |
{
|
|
|
65 |
this.Close();
|
|
|
66 |
}
|
|
|
67 |
private void btn_Add_Click(object sender, EventArgs e)
|
|
|
68 |
{
|
| 63 |
Kevin |
69 |
if (Manage_User_Accounts.AddUser(txt_Username.Text, txt_Password.Text))
|
| 9 |
Kevin |
70 |
{
|
|
|
71 |
if (this.chk_Share.Checked == true)
|
| 63 |
Kevin |
72 |
if (!Manage_User_Accounts.CreateShareFolder(txt_Username.Text))
|
| 53 |
Kevin |
73 |
{
|
| 63 |
Kevin |
74 |
Debug.appendText("Error occured while creating shared folder");
|
| 53 |
Kevin |
75 |
MessageBox.Show("Error occured when creating shared folder", "Error");
|
|
|
76 |
}
|
| 9 |
Kevin |
77 |
this.Close();
|
|
|
78 |
}
|
|
|
79 |
else
|
| 53 |
Kevin |
80 |
{
|
| 63 |
Kevin |
81 |
Debug.appendText("Error occured while creating new user account");
|
| 53 |
Kevin |
82 |
MessageBox.Show("Error occured when creating new user account","Error");
|
| 9 |
Kevin |
83 |
resetForm();
|
| 53 |
Kevin |
84 |
}
|
| 9 |
Kevin |
85 |
}
|
|
|
86 |
}
|
|
|
87 |
}
|