void ListBoxGroups_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ListBoxGroups.SelectedIndex >= 0) { m_selectedGroup = (Group)ListBoxGroups.SelectedItem; ListBoxCurrentGroupUsers.ItemsSource = m_selectedGroup.CurrentGroupUsers = CommonFunctions.GetCurrentGroupUsers(null, m_selectedGroup.ID); ListBoxPossibleGroupUsers.ItemsSource = m_selectedGroup.PossibleGroupUsers = CommonFunctions.GetPossibleGroupUsers(null, m_selectedGroup.ID); GridManageGroups.DataContext = m_selectedGroup; ButtonSaveGroup.Tag = "Update"; m_editGroupMode = true; ChangeGroupsUsersVisualization(); } else ClearGroupInformation(); }
void ButtonSaveGroup_Click(object sender, RoutedEventArgs e) { SystemMessages sm; try { if (ValidateGroupInfo()) { string result; Group group = new Group(); group.Name = TextBoxGroupName.Text.CleanText(); group.Description = TextBoxGroupDescription.Text.CleanText(); group.UpdatedBy = ((App)Application.Current).Principal.Identity.Name; if (m_editGroupMode) { group.ID = m_selectedGroup.ID; group.UpdatedOn = DateTime.UtcNow; group.CreatedBy = m_selectedGroup.CreatedBy; group.CreatedOn = m_selectedGroup.CreatedOn; result = CommonFunctions.SaveGroup(null, group, false); } else { group.CreatedBy = ((App)Application.Current).Principal.Identity.Name; result = CommonFunctions.SaveGroup(null, group, true); } sm = new SystemMessages(new Message() { UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.ShowPopup(); GetGroups(); ClearGroupInformation(); //If role is selected when a group was being added or updated then refresh current users, possible users list for role. if (m_selectedRole != null && m_editRoleMode) { ListBoxCurrentRoleGroups.ItemsSource = m_selectedRole.CurrentRoleGroups = CommonFunctions.GetCurrentRoleGroups(null, m_selectedRole.ID); ListBoxPossibleRoleGroups.ItemsSource = m_selectedRole.PossibleRoleGroups = CommonFunctions.GetPossibleRoleGroups(null, m_selectedRole.ID); } } } catch (Exception ex) { CommonFunctions.LogException(null, "WPF.SaveGroup", ex); sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Group Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.ShowPopup(); } }
void ClearGroupInformation() { m_selectedGroup = null; GridManageGroups.DataContext = new Group(); ButtonSaveGroup.Tag = "Add"; m_editGroupMode = false; ListBoxGroups.SelectedIndex = -1; TextBlockGroupUsersMessage.Visibility = Visibility.Collapsed; ChangeGroupsUsersVisualization(); }
public static string SaveGroup(DataConnection connection, Group group, bool isNew) { bool createdConnection = false; try { if (connection == null) { connection = new DataConnection(); createdConnection = true; } IDbCommand command = connection.Connection.CreateCommand(); command.CommandType = CommandType.Text; if (isNew) command.CommandText = "Insert Into SecurityGroup (Name, Description, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) Values (@name, @description, @updatedBy, @updatedOn, @createdBy, @createdOn)"; else command.CommandText = "Update SecurityGroup Set Name = @name, Description = @description, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id"; command.Parameters.Add(AddWithValue(command, "@name", group.Name)); command.Parameters.Add(AddWithValue(command, "@description", group.Description)); command.Parameters.Add(AddWithValue(command, "@updatedBy", s_currentUser)); command.Parameters.Add(AddWithValue(command, "@updatedOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow)); if (isNew) { command.Parameters.Add(AddWithValue(command, "@createdBy", s_currentUser)); command.Parameters.Add(AddWithValue(command, "@createdOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow)); } else command.Parameters.Add(AddWithValue(command, "@id", group.ID)); command.ExecuteNonQuery(); return "Group Information Saved Successfully"; } finally { if (createdConnection && connection != null) connection.Dispose(); } }