private void buttonExit_Click(object sender, EventArgs e)
 {
     this.IsValidLogin = false;
     this.ValidUser    = null;
     this.Close();
 }
        private void buttonSaveUser_Click(object sender, EventArgs e)
        {
            if (!this.textBoxUsername.ReadOnly) //Add operation
            {
                UserDAO objUser = new UserDAO();
                if (this.textBoxPassword.Text.Length < 4 || this.textBoxUsername.Text.Length < 4)
                {
                    MessageBox.Show("Password Length and username must be 4 characters or more !!!");
                    this.textBoxUsername.Focus();
                    return;
                }
                else if (!this.textBoxPassword.Text.Equals(this.textBoxConfPassword.Text))
                {
                    MessageBox.Show("Password & Confirm Password Doesn't match !!!");
                    this.textBoxConfPassword.Focus();
                    return;
                }
                else if (this.objUserManager.userTable.ContainsKey(this.textBoxUsername.Text.Trim()))
                {
                    MessageBox.Show("User " + this.textBoxUsername.Text + ", already exist in the system, try with different name");
                    this.textBoxUsername.Focus();
                    return;
                }
                objUser.Username = this.textBoxUsername.Text.Trim();
                objUser.Password = objUserManager.Sha1Encryption(this.textBoxPassword.Text);
                if (this.comboBoxStatus.SelectedItem.ToString().Equals("Disable"))
                {
                    MessageBox.Show("You canno't create a disabled user!");
                    this.comboBoxStatus.Focus();
                    return;
                }
                objUser.UserStatus = this.comboBoxStatus.SelectedItem.ToString();
                try
                {
                    objUser.AccessType = this.comboBoxAccess.SelectedItem.ToString();
                }
                catch (Exception) {
                    MessageBox.Show("Please select a access type !");
                    this.comboBoxAccess.Focus();
                    return;
                }
                objUser.EmpName        = this.textBoxEmployeeName.Text.Trim();
                objUser.EmpDesignation = this.textBoxDesignation.Text.Trim();
                this.objUserManager.userTable.Add(objUser.Username, objUser);
                this.objUserManager.saveXMLDocument();
                string[] gridValue = { objUser.Username, objUser.EmpName, objUser.AccessType, objUser.EmpDesignation, objUser.UserStatus, "Delete", "Edit" };
                this.dataGridViewUserList.Rows.Add(gridValue);
                this.colorGrid(dataGridViewUserList);
                clearNewUser();
            }
            else // Edit operation
            {
                if (this.objUserManager.userTable.ContainsKey(this.textBoxUsername.Text.Trim()))
                {
                    UserDAO objUser = (UserDAO)this.objUserManager.userTable[this.textBoxUsername.Text.Trim()];
                    if ((this.textBoxPassword.Text.Length > 0) && (this.textBoxPassword.Text.Length < 4))
                    {
                        MessageBox.Show("Password Length must be 4 characters or more !!!");
                        return;
                    }
                    else if ((this.textBoxPassword.Text.Length >= 4) && !(this.textBoxPassword.Text.Equals(this.textBoxConfPassword.Text)))
                    {
                        MessageBox.Show("Password & Confirm Password Doesn't match !!!");
                        return;
                    }
                    else if (this.textBoxPassword.Text.Length >= 4)
                    {
                        objUser.Password = this.objUserManager.Sha1Encryption(this.textBoxPassword.Text);
                    }

                    if (this.comboBoxStatus.Enabled)
                    {
                        objUser.UserStatus = this.comboBoxStatus.SelectedItem.ToString();
                    }
                    objUser.EmpName        = this.textBoxEmployeeName.Text;
                    objUser.EmpDesignation = this.textBoxDesignation.Text;
                    objUser.AccessType     = this.comboBoxAccess.SelectedItem.ToString();
                    this.objUserManager.saveXMLDocument();
                    clearNewUser();
                    fillUserList();
                }
                else
                {
                    MessageBox.Show("Error Saving User Information !");
                }
            }
        }