コード例 #1
0
        /// <summary>
        /// Process clicks to the addGroup button
        /// </summary>
        /// <param name="sender">object from which the event was sent</param>
        /// <param name="e">Arguments to the event</param>
        private void addGroup_Click(object sender, EventArgs e)
        {
            if (newGroup.Text.Length > 0)
            {
                //Get the group by that name
                GroupPrincipal group    = ad.GetGroup(newGroup.Text);
                Boolean        abortAdd = false;

                if (group == null)
                {
                    //Group doesn't exist, create it?
                    DialogResult result = MessageBox.Show("Group doesn't exist, create it?", "Adding group...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        //Create the group
                        ad.CreateGroup(newGroup.Text);
                    }
                    else
                    {
                        //Don't add the non-existant group if we're not creating it
                        abortAdd = true;
                    }
                }

                //If we're still adding the group
                if (!abortAdd)
                {
                    //Add the group
                    currentUser.Groups.Add(newGroup.Text);

                    //Reset bindings to update the controls
                    userBinding.ResetBindings(false);

                    //Clear the newGroup text
                    newGroup.Clear();
                }
            }
        }