public ExternalSortWrapper(ViewsManager views, string databaseFilePath, ExternalSortOptions sortOptions, string groupByColumn, string sortGroupsByColumn, SortOrder sortGroupsByColumnDirection, bool showElapsedTime, bool showStartupMessage)
 {
     _views                       = views;
     _databaseFilePath            = databaseFilePath;
     _sortOptions                 = sortOptions;
     _groupByColumn               = groupByColumn;
     _sortGroupsByColumn          = sortGroupsByColumn;
     _sortGroupsByColumnDirection = sortGroupsByColumnDirection;
     _showElapsedTime             = showElapsedTime;
     _showStartupMessage          = showStartupMessage;
 }
示例#2
0
        public FormExternalSort(ViewsManager views, ExternalSortOptions sortOptions)
        {
            InitializeComponent();

            this.BackColor = MainForm.ColorBackground;

            _views = views;

            InitSortOptionControls();
            InitSortOptionValues(sortOptions);

            UpdateEnabledState();
        }
示例#3
0
        protected void InitSortOptionValues(ExternalSortOptions sortOptions)
        {
            if (sortOptions == null)
            {
                return;
            }

            chkbApplyEditsToGroup.Checked = sortOptions.ApplyEditsToGroup;

            chkbLeaveOneDocument.Checked = sortOptions.LeaveOneDocument;
            cmbLeaveOneDocumentCriteria.SelectedIndex = (int)sortOptions.LeaveOneDocumentCriteria;

            var columnIndex = !String.IsNullOrEmpty(sortOptions.LeaveOneDocumentColumn) ? cmbLeaveOneDocumentColumn.Items.IndexOf(sortOptions.LeaveOneDocumentColumn) : -1;

            if (columnIndex != -1)
            {
                cmbLeaveOneDocumentColumn.SelectedIndex = columnIndex;
            }

            ///////////////////////////////////////////////////////////////////////////////

            chkbSortGroupsOnClick.Checked = sortOptions.SortGroupsByCriteria != SortGroupsBy.None;
            rdbMin.Checked = sortOptions.SortGroupsByCriteria == SortGroupsBy.Min;
            rdbMax.Checked = sortOptions.SortGroupsByCriteria == SortGroupsBy.Max;
            rdbSum.Checked = sortOptions.SortGroupsByCriteria == SortGroupsBy.Sum || sortOptions.SortGroupsByCriteria == SortGroupsBy.None;

            ///////////////////////////////////////////////////////////////////////////////

            chkbShowGroupMinDocuments.Checked = sortOptions.ShowGroupsMinDocuments;
            txtMinDocuments.Value             = sortOptions.MinDocuments;

            ///////////////////////////////////////////////////////////////////////////////

            var controls = this.Controls.OfType <ExternalSortOptionsCtrl>().OrderBy(x => x.TabIndex).ToList();

            for (var index = 0; index < sortOptions.SortByColumns.Count; index++)
            {
                if (index >= controls.Count)
                {
                    break;
                }

                var opt  = sortOptions.SortByColumns[index];
                var ctrl = controls[index];
                ctrl.SortByColumn = opt;
            }
        }
        public static string FillGroupSize(ViewsManager views, string groupByColumnName, ExternalSortOptions sortOptions)
        {
            var filter = String.Empty;

            if (!String.IsNullOrEmpty(groupByColumnName) && sortOptions.ShowGroupsMinDocuments && sortOptions.MinDocuments > 0)
            {
                var groupSizeColumnIndex = views.MainForm.datasetMain.Documents.Columns.IndexOf(_groupSizeColumnName);
                if (groupSizeColumnIndex == -1)
                {
                    views.MainForm.datasetMain.Documents.Columns.Add(_groupSizeColumnName);
                    groupSizeColumnIndex = views.MainForm.datasetMain.Documents.Columns.IndexOf(_groupSizeColumnName);
                }

                ///////////////////////////////////////////////////////////////////////////////

                var groupByColumn      = views.MainForm.datasetMain.Documents.Columns[groupByColumnName];
                var groupByColumnIndex = groupByColumn.Ordinal;
                var defaultValue       = groupByColumn.DataType == typeof(string) ? String.Empty : Activator.CreateInstance(groupByColumn.DataType);

                var expr = views.MainForm.datasetMain.Documents.Cast <DataRow>().GroupBy(x => x.IsNull(groupByColumnIndex) ? defaultValue : x.ItemArray[groupByColumnIndex]);
                foreach (var g in expr)
                {
                    var count = g.Count();

                    foreach (var row in g)
                    {
                        row[groupSizeColumnIndex] = count;
                    }
                }

                views.MainForm.datasetMain.Documents.AcceptChanges();

                ///////////////////////////////////////////////////////////////////////////////

                filter = $"{_groupSizeColumnName} >= {sortOptions.MinDocuments}";
            }

            return(filter);
        }