Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
{
12
    public partial class AddUserAccount_Form : Form
13
    {
14
        private static AddUserAccount_Form AddUserAccount_Instance = null;
15
        // Modified singleton instance
16
        public static AddUserAccount_Form Add_User_Account_Instance
17
        {
18
            get
19
            {
20
                AddUserAccount_Instance = new AddUserAccount_Form();
21
                return AddUserAccount_Instance;
22
            }
23
        }
24
        public AddUserAccount_Form()
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
        {
69
            if (ManageUserAccounts.AddUser(txt_Username.Text, txt_Password.Text))
70
            {
71
                if (this.chk_Share.Checked == true)
53 Kevin 72
                    if (!ManageUserAccounts.CreateShareFolder(txt_Username.Text))
73
                    {
74
                        DebugText.appendText("Error occured while creating shared folder");
75
                        MessageBox.Show("Error occured when creating shared folder", "Error");
76
                    }
9 Kevin 77
                this.Close();
78
            }
79
            else
53 Kevin 80
            {
81
                DebugText.appendText("Error occured while creating new user account");
82
                MessageBox.Show("Error occured when creating new user account","Error");
9 Kevin 83
                resetForm();
53 Kevin 84
            }
9 Kevin 85
        }
86
    }
87
}