/// <summary>
        /// Handles the Click event of the btnOK control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            // Name cannot be empty
            if (!FormHelper.ValidateNotEmpty(txtName, Resources.MsgNameRequired))
            {   
                return;
            }

            if (this.Group == null)
            {
                // Name cannot be the built-in administrator group name
                if (GuiHelper.AdministratorGroupName.Equals(txtName.Text, StringComparison.OrdinalIgnoreCase))
                {
                    FormHelper.ShowError(Resources.MsgAdminGroupNameNotAllowed);
                    txtName.Focus();
                    return;
                }
            }

            using (SharedDbConnectionScope sharedConnectionScope = new SharedDbConnectionScope())
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {

                        if (Group == null)
                        {
                            // Name must be unique
                            Role searchRole = Role.SingleOrDefault(r => r.Name.ToLower() == txtName.Text.ToLower());
                            if (searchRole != null)
                            {
                                FormHelper.ShowError(Resources.MsgGroupNameNotUnique);
                                return;
                            }

                            // Create a new one
                            Role role = new Role();
                            role.Name = txtName.Text.Trim();
                            role.Desc = txtDescription.Text;
                            if (role.Name.Equals(GuiHelper.AdministratorGroupName))
                                role.CanBeDeleted = false;
                            else
                                role.CanBeDeleted = true;
                            role.Save();
                            this.Group = role;
                        }
                        else
                        {
                            if (!this.Group.Name.Equals(txtName.Text.Trim(), StringComparison.OrdinalIgnoreCase))
                            {
                                // Check for duplicate                        
                                Role searchRole = Role.SingleOrDefault(r => r.Name.ToLower() == txtName.Text.ToLower());
                                if (searchRole != null)
                                {
                                    FormHelper.ShowError(Resources.MsgGroupNameNotUnique);
                                    return;
                                }
                            }

                            // Update an existing one
                            this.Group.Name = txtName.Text.Trim();
                            this.Group.Desc = txtName.Text;
                            if (this.Group.Name.Equals(GuiHelper.AdministratorGroupName))
                                this.Group.CanBeDeleted = false;
                            else
                                this.Group.CanBeDeleted = true;
                            this.Group.Update();
                        }


                        // Delete user related to existing groups
                        UserRoleMap.Delete(urm => urm.RoleId == this.Group.Id);
                        
                        // Save the users for the existing groups
                        foreach (object item in lstUsersInGroup.Items)
                        {
                            string loginName = GetLoginName(item);
                            
                            // Get the user id and save the user group mapping
                            User user = User.SingleOrDefault(u => u.LoginName == loginName);
                            if (user != null)
                            {
                                UserRoleMap urm = new UserRoleMap();
                                urm.UserId = user.Id;
                                urm.RoleId = this.Group.Id;
                                urm.Save();
                            }
                        }

                        FormHelper.ShowInfo(Resources.MsgGroupSaved);
                    }
                    catch (Exception ex)
                    {
                        FormHelper.ShowError(ex.Message);
                    }
                    finally
                    {
                        try
                        {
                            ts.Complete();
                        }
                        catch (Exception) { }
                    }
                }
            } 

            this.DialogResult = DialogResult.OK;
            
        }