Exemplo n.º 1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            if (!_blockContextIsValid)
            {
                return;
            }

            var dataContext = GetDataContext();

            var settings = OnStoreFilterSettings();

            var items = OnGetListDataSource(dataContext, settings, ListGridControl.SortProperty);

            ListGridControl.DataSource = items;

            ListGridControl.DataBind();

            // The Grid has built-in functionality to prevent deletion of system-protected items if the Data Source implements an "IsSystem" flag.
            // If this option is enforced, verify that the data source is correctly configured to support this feature.
            if (this.ShowItemDelete &&
                this.PreventSystemItemDelete &&
                items != null)
            {
                var enumerator = (( IEnumerable )items).GetEnumerator();

                if (enumerator.MoveNext())
                {
                    var item = enumerator.Current;

                    if (item != null)
                    {
                        var pi = item.GetType().GetProperty("IsSystem");

                        if (pi == null)
                        {
                            // Show a non-fatal configuration error.
                            ShowNotificationError("Configuration Error: Data Source should implement property \"IsSystem\".");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set the properties of the main grid.
        /// </summary>
        private void InitializeGrid()
        {
            ListGridControl.DataKeyNames = new string[] { "Id" };
            ListGridControl.RowItemText  = _entityType.FriendlyName;
            ListGridControl.ExportSource = ExcelExportSource.DataSource;

            ListGridControl.HideDeleteButtonForIsSystem = this.PreventSystemItemDelete;

            ListGridControl.Actions.AddClick += gList_Add;
            ListGridControl.GridRebind       += gList_GridRebind;

            ListGridControl.AllowSorting = !this.ShowItemReorder;

            // Show Reorder handle
            if (this.ShowItemReorder)
            {
                _reorderColumn = new ReorderField();

                ListGridControl.Columns.Insert(0, _reorderColumn);

                ListGridControl.GridReorder += gList_GridReorder;
            }

            // Verify block authorization
            bool canAddEditDelete = IsUserAuthorized(Authorization.EDIT);
            bool canAdministrate  = IsUserAuthorized(Authorization.ADMINISTRATE);

            ListGridControl.Actions.ShowAdd = this.ShowItemAdd && canAddEditDelete;

            if (canAddEditDelete)
            {
                ListGridControl.RowSelected += gList_Edit;
            }

            // Show Security button
            if (this.ShowItemSecurity &&
                canAdministrate)
            {
                _securityColumn = ListGridControl.ColumnsOfType <SecurityField>().FirstOrDefault();

                if (_securityColumn == null)
                {
                    _securityColumn = new SecurityField();

                    ListGridControl.Columns.Add(_securityColumn);
                }

                _securityColumn.EntityTypeId = _entityType.Id;
            }

            // Show Delete button
            ListGridControl.IsDeleteEnabled = this.ShowItemDelete && canAddEditDelete;

            if (this.ShowItemDelete &&
                canAddEditDelete)
            {
                _deleteColumn = ListGridControl.ColumnsOfType <DeleteField>().FirstOrDefault();

                if (_deleteColumn == null)
                {
                    _deleteColumn = new DeleteField();

                    _deleteColumn.Click += gList_Delete;

                    ListGridControl.Columns.Add(_deleteColumn);
                }
            }

            // Perform additional customization of the list grid if required.
            OnConfigureListGrid(this.ListGridControl);
        }