Beispiel #1
0
        /// <summary>
        /// Fill in the ViewLayout with the current set of transformations, column widths, formats, etc.
        /// </summary>
        public ViewLayout PopulateLayout(ViewLayout newLayout)
        {
            var transformStack = BindingListView.TransformStack;

            newLayout = newLayout.ChangeRowTransforms(
                transformStack.RowTransforms.Skip(transformStack.StackIndex));
            var columnIds     = new HashSet <ColumnId>();
            var columnFormats = new List <Tuple <ColumnId, ColumnFormat> >();

            foreach (var pd in BindingListSource.ItemProperties)
            {
                var columnId = ColumnId.GetColumnId(pd);
                if (columnId == null)
                {
                    continue;
                }
                if (!columnIds.Add(columnId))
                {
                    continue;
                }
                var columnFormat = BindingListSource.ColumnFormats.GetFormat(columnId);
                if (columnFormat.IsEmpty)
                {
                    continue;
                }
                columnFormats.Add(Tuple.Create(columnId, columnFormat));
            }
            newLayout = newLayout.ChangeColumnFormats(columnFormats);
            return(newLayout);
        }
Beispiel #2
0
        public void AddColumnHeader()
        {
            var newColumns = GetSelectedProperties()
                             .Select(pd => new PivotSpec.Column(ColumnId.GetColumnId(pd)).ChangeVisible(false));

            PivotSpec = PivotSpec.ChangeColumnHeaders(PivotSpec.ColumnHeaders.Concat(newColumns));
        }
Beispiel #3
0
 private void formatToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (_columnFilterPropertyDescriptor == null)
     {
         return;
     }
     using (var dlg = new ChooseFormatDlg(BindingListSource.ViewInfo.DataSchema.DataSchemaLocalizer))
     {
         var columnId     = ColumnId.GetColumnId(_columnFilterPropertyDescriptor);
         var columnFormat =
             BindingListSource.ColumnFormats.GetFormat(ColumnId.GetColumnId(_columnFilterPropertyDescriptor));
         if (null != columnFormat.Format)
         {
             dlg.FormatText = columnFormat.Format;
         }
         if (dlg.ShowDialog(FormUtil.FindTopLevelOwner(this)) == DialogResult.OK)
         {
             if (string.IsNullOrEmpty(dlg.FormatText))
             {
                 columnFormat = columnFormat.ChangeFormat(null);
             }
             else
             {
                 columnFormat = columnFormat.ChangeFormat(dlg.FormatText);
             }
             BindingListSource.ColumnFormats.SetFormat(columnId, columnFormat);
         }
     }
 }
Beispiel #4
0
        private void btnClearFilter_Click(object sender, EventArgs e)
        {
            var columnId = ColumnId.GetColumnId(PropertyDescriptor);

            RowFilter = RowFilter.SetColumnFilters(
                RowFilter.ColumnFilters.Where(
                    columnFilter => !Equals(columnId, columnFilter.ColumnId)));
            DialogResult = DialogResult.OK;
        }
Beispiel #5
0
 private void clearFilterToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (null != _columnFilterPropertyDescriptor)
     {
         var columnId  = ColumnId.GetColumnId(_columnFilterPropertyDescriptor);
         var rowFilter = BindingListSource.RowFilter;
         rowFilter = rowFilter.SetColumnFilters(
             rowFilter.ColumnFilters.Where(spec => !Equals(spec.ColumnId, columnId)));
         BindingListSource.RowFilter = rowFilter;
     }
 }
Beispiel #6
0
        public void AddValue()
        {
            var aggregateOperation = comboAggregateOp.SelectedItem as AggregateOperation;

            if (aggregateOperation == null)
            {
                return;
            }
            var newColumns = GetSelectedProperties()
                             .Select(pd => new PivotSpec.AggregateColumn(ColumnId.GetColumnId(pd), aggregateOperation));

            PivotSpec = PivotSpec.ChangeValues(PivotSpec.Values.Concat(newColumns));
        }
Beispiel #7
0
        private RowFilter.ColumnFilter MakeColumnFilter(ComboBox comboOperation, TextBox text)
        {
            FilterItem filterItem = comboOperation.SelectedItem as FilterItem;

            if (null == filterItem || FilterOperations.OP_HAS_ANY_VALUE == filterItem.FilterOperation)
            {
                return(null);
            }
            var filterPredicate = FilterPredicate.CreateFilterPredicate(DataSchema, PropertyDescriptor.PropertyType,
                                                                        filterItem.FilterOperation, text.Text);

            return(new RowFilter.ColumnFilter(ColumnId.GetColumnId(PropertyDescriptor), filterPredicate));
        }
Beispiel #8
0
 private void UpdateContextMenuItems()
 {
     clearAllFiltersToolStripMenuItem.Enabled = !BindingListSource.RowFilter.IsEmpty;
     if (null != _columnFilterPropertyDescriptor && IsSortable(_columnFilterPropertyDescriptor))
     {
         var columnId = ColumnId.GetColumnId(_columnFilterPropertyDescriptor);
         clearFilterToolStripMenuItem.Enabled =
             BindingListSource.RowFilter.ColumnFilters.Any(
                 filter => Equals(columnId, filter.ColumnId));
         filterToolStripMenuItem.Enabled = true;
         ListSortDirection?sortDirection = null;
         if (null != BindingListSource.SortDescriptions && BindingListSource.SortDescriptions.Count > 0)
         {
             var sortDescription = BindingListSource.SortDescriptions.OfType <ListSortDescription>().First();
             if (sortDescription.PropertyDescriptor.Name == _columnFilterPropertyDescriptor.Name)
             {
                 sortDirection = sortDescription.SortDirection;
             }
             clearSortToolStripMenuItem.Enabled = true;
         }
         else
         {
             clearSortToolStripMenuItem.Enabled = false;
         }
         sortAscendingToolStripMenuItem.Enabled  = true;
         sortDescendingToolStripMenuItem.Enabled = true;
         sortAscendingToolStripMenuItem.Checked  = ListSortDirection.Ascending == sortDirection;
         sortDescendingToolStripMenuItem.Checked = ListSortDirection.Descending == sortDirection;
     }
     else
     {
         clearSortToolStripMenuItem.Enabled      = false;
         clearFilterToolStripMenuItem.Enabled    = false;
         filterToolStripMenuItem.Enabled         = false;
         sortAscendingToolStripMenuItem.Enabled  = false;
         sortDescendingToolStripMenuItem.Enabled = false;
         sortAscendingToolStripMenuItem.Checked  = false;
         sortDescendingToolStripMenuItem.Checked = false;
     }
     if (IsFormattable(_columnFilterPropertyDescriptor))
     {
         formatToolStripMenuItem.Enabled = true;
     }
     else
     {
         formatToolStripMenuItem.Enabled = false;
     }
     fillDownToolStripMenuItem.Enabled = IsEnableFillDown();
 }
Beispiel #9
0
        protected override void OnColumnWidthChanged(DataGridViewColumnEventArgs e)
        {
            base.OnColumnWidthChanged(e);
            var pd = GetPropertyDescriptor(e.Column);

            if (pd == null)
            {
                return;
            }
            var columnId = ColumnId.GetColumnId(pd);

            if (columnId != null)
            {
                var columnFormat = _bindingListSource.ColumnFormats.GetFormat(columnId);
                columnFormat = columnFormat.ChangeWidth(e.Column.Width);
                _bindingListSource.ColumnFormats.SetFormat(columnId, columnFormat);
            }
        }
Beispiel #10
0
        private RowFilter GetCurrentFilter()
        {
            RowFilter rowFilter     = RowFilter;
            var       columnFilters = new List <RowFilter.ColumnFilter>();
            var       columnFilter  = MakeColumnFilter(comboOperation1, tbxOperand1);

            if (null != columnFilter)
            {
                columnFilters.Add(columnFilter);
            }
            columnFilter = MakeColumnFilter(comboOperation2, tbxOperand2);
            if (null != columnFilter)
            {
                columnFilters.Add(columnFilter);
            }
            var columnId = ColumnId.GetColumnId(PropertyDescriptor);

            columnFilters.AddRange(rowFilter.ColumnFilters.Where(
                                       filter => !Equals(filter.ColumnId, columnId)));
            return(rowFilter.SetColumnFilters(columnFilters));
        }
Beispiel #11
0
        private void FilterOutNaN(DocumentGridForm documentGrid)
        {
            var columnIdCv = new ColumnId(AggregateOperation.Cv.QualifyColumnCaption(new ColumnCaption("NormalizedArea")));
            DataGridViewColumn columnCv = null;

            RunUI(() =>
            {
                var pdCv = documentGrid.DataboundGridControl.BindingListSource.ItemProperties
                           .FirstOrDefault(pd => ColumnId.GetColumnId(pd).Equals(columnIdCv));
                Assert.IsNotNull(pdCv);
                columnCv = documentGrid.DataboundGridControl.DataGridView.Columns.OfType <DataGridViewColumn>()
                           .FirstOrDefault(col => col.DataPropertyName == pdCv.Name);
            });
            Assert.IsNotNull(columnCv);
            var quickFilterForm =
                ShowDialog <QuickFilterForm>(() => documentGrid.DataboundGridControl.QuickFilter(columnCv));

            RunUI(() =>
            {
                quickFilterForm.SetFilterOperation(0, FilterOperations.OP_NOT_EQUALS);
                quickFilterForm.SetFilterOperand(0, double.NaN.ToString(CultureInfo.CurrentCulture));
            });
            OkDialog(quickFilterForm, quickFilterForm.OkDialog);
        }
Beispiel #12
0
        public void AddRowHeader()
        {
            var newColumns = GetSelectedProperties().Select(pd => new PivotSpec.Column(ColumnId.GetColumnId(pd)));

            PivotSpec = PivotSpec.ChangeRowHeaders(PivotSpec.RowHeaders.Concat(newColumns));
        }
Beispiel #13
0
 private PropertyDescriptor FindPropertyDescriptor(ColumnId columnId)
 {
     return(AllProperties.FirstOrDefault(pd => Equals(columnId, ColumnId.GetColumnId(pd))));
 }
Beispiel #14
0
        public void UpdateUi()
        {
            bool wasInUpdateUi = _inUpdateUi;

            try
            {
                _inUpdateUi = true;
                rowHeadersList.ReplaceItems(PivotSpec.RowHeaders.Select(col => MakeListItem(col, caption => caption)));
                columnHeadersList.ReplaceItems(PivotSpec.ColumnHeaders.Select(col => MakeListItem(col, caption => caption)));
                valuesList.ReplaceItems(
                    PivotSpec.Values.Select(col => MakeListItem(col, col.AggregateOperation.QualifyColumnCaption)));
                _availableProperties = ImmutableList.ValueOf(_allProperties.Where(pd => PivotSpec.RowHeaders.Concat(PivotSpec.ColumnHeaders)
                                                                                  .All(col => !Equals(col.SourceColumn, ColumnId.GetColumnId(pd)))));
                availableColumnList.ReplaceItems(_availableProperties.Select(prop => new ListViewItem(prop.DisplayName)));
                UpdateButtons();
            }
            finally
            {
                _inUpdateUi = wasInUpdateUi;
            }
        }