Exemple #1
0
        private void RefreshACICategoriesGrid(AccessControlItemCategory selectedItem)
        {
            bool foundSelection = false;

            try
            {
                #region General setup
                Application.DoEvents();
                dgvACICategories.SuspendLayout();
                _refreshingCategories = true;
                #endregion

                #region Datasource/Action handling
                List <AccessControlItemCategory> dataSourceList = null;

                var selectedUser = GetSelectedUser();
                if (selectedUser != null)
                {
                    dataSourceList = (from c in
                                      (from i in ACIItems
                                       join l in UserACIList.FindAll(ac => ac.UserId == selectedUser.Id) on i.Id equals l.AccessControlListId into il
                                       join x in GroupACIList.FindAll(ac => UserGroupList.Find(x => x.GroupId == ac.GroupId && x.UserId == selectedUser.Id) != null) on i.Id equals x.AccessControlListId into ix
                                       select new { i.Category, GrantedACI = il.Count(), GrantedGroupACI = ix.Count() })
                                      group c by c.Category
                                      into g
                                      select new AccessControlItemCategory(g.Key,
                                                                           g.Sum(c => c.GrantedACI) == 0 ? -1 : g.Sum(c => c.GrantedACI) == g.Count(c => c.Category != null) ? 1 : 0,
                                                                           g.Count(c => c.Category != null),
                                                                           g.Sum(c => c.GrantedACI),
                                                                           g.Sum(c => c.GrantedGroupACI)
                                                                           )).ToList();
                }
                else
                {
                    dataSourceList = (from c in ACIItems
                                      group c by c.Category
                                      into g
                                      select new AccessControlItemCategory(g.Key, -1, g.Count(c => c.Category != null), 0, 0)).ToList();
                }
                #endregion

                #region Datagrid filling and generation
                if (dataSourceList?.Count > 0)
                {
                    dgvACICategories.DataSource = new SortableBindingList <AccessControlItemCategory>(dataSourceList);

                    if (dgvACICategories.SortedColumn == null)
                    {
                        dgvACICategories.Sort(dgvACICategories.Columns[0], ListSortDirection.Ascending);
                    }

                    for (int i = 0; i < dgvACICategories.Rows.Count; i++)
                    {
                        var dataBoundItem = (AccessControlItemCategory)dgvACICategories.Rows[i].DataBoundItem;
                        if ((selectedItem != null) && (dataBoundItem.Category == selectedItem.Category))
                        {
                            dgvACICategories.Rows[i].Selected = true;
                            foundSelection = true;
                            break;
                        }
                    }
                }
                else
                {
                    dgvACICategories.DataSource = null;
                }
                #endregion
            }
            catch (Exception ex)
            {
                Trace.WriteError("()", Trace.GetMethodName(), CLASSNAME, ex);
                DisplayError(Trace.GetMethodName(), TranslationKey.CommonMessage_InternalError, ex);
            }
            finally
            {
                if (selectedItem == null || !foundSelection)
                {
                    dgvACICategories.ClearSelection();
                }

                dgvACICategories.ResumeLayout();
                _refreshingCategories = false;

                RefreshACIGrid(GetSelectedACI());
            }
        }
Exemple #2
0
        private void RefreshACIGrid(AccessControlItem selectedItem)
        {
            bool foundSelection = false;

            try
            {
                #region General setup
                Application.DoEvents();
                dgvACI.SuspendLayout();
                #endregion

                #region Datasource/Action handling
                List <AccessControlItemHelper> dataSourceList = null;

                var selectedUser     = GetSelectedUser();
                var selectedCategory = GetSelectedACICategory();

                if (selectedUser != null && selectedCategory != null)
                {
                    dataSourceList = (from i in ACIItems
                                      join l in UserACIList.FindAll(ac => ac.UserId == selectedUser.Id) on i.Id equals l.AccessControlListId into il
                                      join x in GroupACIList.FindAll(ac => UserGroupList.Find(x => x.GroupId == ac.GroupId && x.UserId == selectedUser.Id) != null) on i.Id equals x.AccessControlListId into ix
                                      where i.Category == selectedCategory.Category
                                      select new AccessControlItemHelper(i.Id, i.Category, i.Action, il.Any(), ix.Any())).ToList();
                }
                #endregion

                #region Datagrid filling and generation
                if (dataSourceList?.Count > 0)
                {
                    dgvACI.DataSource = new SortableBindingList <AccessControlItemHelper>(dataSourceList);

                    if (dgvACI.SortedColumn == null)
                    {
                        dgvACI.Sort(dgvACI.Columns[1], ListSortDirection.Ascending);
                    }

                    for (int i = 0; i < dgvACI.Rows.Count; i++)
                    {
                        var dataBoundItem = (AccessControlItem)dgvACI.Rows[i].DataBoundItem;

                        if ((selectedItem != null) && (dataBoundItem.Id == selectedItem.Id))
                        {
                            dgvACI.Rows[i].Selected = true;
                            foundSelection          = true;
                        }
                    }
                }
                else
                {
                    dgvACI.DataSource = null;
                }
                #endregion
            }
            catch (Exception ex)
            {
                Trace.WriteError("()", Trace.GetMethodName(), CLASSNAME, ex);
                DisplayError(Trace.GetMethodName(), TranslationKey.CommonMessage_InternalError, ex);
            }
            finally
            {
                if (selectedItem == null || !foundSelection)
                {
                    dgvACI.ClearSelection();
                }

                dgvACI.ResumeLayout();
            }
        }