void returnToMainWindow_Click(object sender, EventArgs e) { MainWindow window = (MainWindow)Application.Current.MainWindow; window.Refresh(); this.Close(); window.Show(); }
void save_Click(object sender, EventArgs e) { if ((password.Password != password2.Password) || name.Text == string.Empty) { //MBox error MessageBox.Show("ERROR! Passwords are not equal or name field is empty"); return; } PrincipalContext ctx = new PrincipalContext(ContextType.Machine); string userName = name.Text; string userDescription = description.Text; string userPassword = password.Password; GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "Shared"); GroupPrincipal group2; if ((group2 = GroupPrincipal.FindByIdentity(ctx, "Users")) == null) { group2 = GroupPrincipal.FindByIdentity(ctx, "Użytkownicy"); } UserPrincipal newUser = new UserPrincipal(ctx); newUser.Name = userName; newUser.Description = userDescription; newUser.SetPassword(userPassword); newUser.Enabled = true; newUser.Save(); group.Members.Add(newUser); group.Save(); group2.Members.Add(newUser); group2.Save(); this.Close(); MainWindow window = (MainWindow)Application.Current.MainWindow; window.Refresh(); //Application.Current.MainWindow. }