示例#1
0
        private void ActMoveUp_Click(System.Object sender, System.EventArgs e)
        {
            // ----- Move the selected column up one position.
            Object content;
            bool   selection;
            int    startIndex;

            // ----- Identify the base item to move.
            startIndex = IncludedColumns.SelectedIndex;
            if (startIndex <= 0)
            {
                return;
            }

            // ----- Move the content.
            content = IncludedColumns.Items[startIndex];
            IncludedColumns.Items[startIndex]     = IncludedColumns.Items[startIndex - 1];
            IncludedColumns.Items[startIndex - 1] = content;

            // ----- Move the inclusion marker.
            selection = IncludedColumns.GetItemChecked(startIndex);
            IncludedColumns.SetItemChecked(startIndex,
                                           IncludedColumns.GetItemChecked(startIndex - 1));
            IncludedColumns.SetItemChecked(startIndex - 1, selection);

            // ----- Move to the new position.
            IncludedColumns.SelectedIndex = startIndex - 1;
        }
示例#2
0
        public string ScriptCreate()
        {
            switch (Type)
            {
            case "CHECK":
                var notForReplicationOption = _isNotForReplication ? "NOT FOR REPLICATION" : "";
                return
                    ($"CONSTRAINT [{Name}] CHECK {notForReplicationOption} {_checkConstraintExpression}");

            case "INDEX":
                var sql =
                    $"CREATE{UniqueText}{IndexType.Space()} INDEX [{Name}] ON [{Table.Owner}].[{Table.Name}] ({string.Join(", ", Columns.Select(c => c.Script()).ToArray())})";
                if (IncludedColumns.Count > 0)
                {
                    sql += $" INCLUDE ([{string.Join("], [", IncludedColumns.ToArray())}])";
                }

                if (!string.IsNullOrEmpty(Filter))
                {
                    sql += $" WHERE {Filter}";
                }

                return(sql);
            }

            return((Table.IsType ? string.Empty : $"CONSTRAINT [{Name}] ") +
                   $"{Type}{IndexType.Space()} ({string.Join(", ", Columns.Select(c => c.Script()).ToArray())})");
        }
示例#3
0
        protected override TaskPlugin GetTaskPluginCore()
        {
            List <FeatureSource> featureSources = null;

            if (OnlyMergeSelectedFeatures)
            {
                SaveSelectedFeaturesToTempFile();
                featureSources = new List <FeatureSource> {
                    new ShapeFileFeatureSource(tempFilePath)
                };
            }
            else
            {
                featureSources = SelectedLayers.Select(featureLayer => featureLayer.FeatureSource).ToList();
                foreach (var featureSource in featureSources)
                {
                    featureSource.Close();
                    if (featureSource.Projection != null)
                    {
                        featureSource.Projection.Close();
                    }
                }
            }

            var columns = IncludedColumns.Select(c => c.ToFeatureSourceColumn()).ToArray();
            var plugin  = GisEditor.TaskManager.GetActiveTaskPlugins <MergeTaskPlugin>().FirstOrDefault();

            if (plugin != null)
            {
                InitializePlugin(plugin, featureSources, columns);
            }

            return(plugin);
        }
示例#4
0
        private void ActExtract_Click(System.Object sender, System.EventArgs e)
        {
            // ----- Create a new table based on the original.
            DataView  interimView;
            DataTable generatedTable = null;

            // ----- At least one column is required.
            if (IncludedColumns.CheckedItems.Count == 0)
            {
                MessageBox.Show("Please include at least one column.");
                IncludedColumns.Focus();
                return;
            }

            // ----- Clear the previous results.
            NewRecords.DataSource = null;

            // ----- Build a view that will generate the new table.
            interimView = new DataView(SampleData);

            // ----- Apply the optional filter.
            try
            {
                if (FilterExpression.Text.Trim().Length > 0)
                {
                    interimView.RowFilter = FilterExpression.Text.Trim();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not apply the filter: " + ex.Message);
                return;
            }

            // ----- Generate the new table.
            try
            {
                generatedTable = interimView.ToTable(true,
                                                     IncludedColumns.CheckedItems.Cast <string>().ToArray());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not build the new table: " + ex.Message);
                return;
            }

            // ----- Display the results.
            NewRecords.DataSource = generatedTable;
        }
示例#5
0
        public Retrieval <T> Include <TProperty>(Expression <Func <T, TProperty> > propertyExpr)
        {
            var propertyName = PropertyNameAttribute.GetFromType(propertyExpr);

            if (propertyName == "modifiedon" || propertyName == "createdon" || propertyName == "id")
            {
                return(this);
            }

            if (!IncludedColumns.Contains(propertyName.ToLower()))
            {
                IncludedColumns.Add(propertyName);
            }

            return(this);
        }
示例#6
0
        public bool TotallyEquals(IndexSet other)
        {
            if (Object.ReferenceEquals(other, null))
            {
                return(false);
            }
            if (Object.ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Equals(other) && IndexIsUnique.Equals(other.IndexIsUnique) && IndexType.Equals(other.IndexType) &&
                   Columns.Equals(other.Columns) && IncludedColumns.Equals(other.IncludedColumns) &&
                   HasFilter.Equals(other.HasFilter) && FilterDefinition.Equals(other.FilterDefinition) &&
                   KeyConstraintTypeCode.Equals(other.KeyConstraintTypeCode));
        }
示例#7
0
        public string GetDetailInfo()
        {
            var sb   = new StringBuilder();
            var name = $"[{SchemaName}].[{TableName}].[{IndexName}]";

            sb.AppendLine($"Name: {name} (Reads:{NotAvailableIfNull(UserReads)} Writes:{NotAvailableIfNull(UserWrites)} Size:{IndexSizeMB.ToString("N2")} MB)");
            sb.AppendLine($"Indexed Columns: {string.Join(", ", IndexedColumns.Select(c => c.ColumnName + (c.IsDescendingKey ? " (desc)" : "")))}");
            sb.AppendLine($"Included Columns: {string.Join(", ", IncludedColumns.Select(c => c.ColumnName))}");

            List <string> attribs = GetAttributes();

            sb.AppendLine($"Attributes: {string.Join(", ", attribs)}");

            sb.AppendLine($"Filter: {FilterDefinition}");

            return(sb.ToString());
        }
示例#8
0
        private void ActExtract_Click(System.Object sender, System.EventArgs e)
        {
            // ----- Create a new table based on the original.
            DataView  interimView;
            DataTable generatedTable = null;

            // ----- At least one column is required.
            if (IncludedColumns.CheckedItems.Count == 0)
            {
                MessageBox.Show("Please include at least one column.");
                IncludedColumns.Focus();
                return;
            }

            // ----- Clear the previous results.
            NewRecords.DataSource = null;

            // ----- Build a view that will generate the new table.

            // ----- Apply the optional filter.
            try
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not apply the filter: " + ex.Message);
                return;
            }

            // ----- Generate the new table.
            try
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not build the new table: " + ex.Message);
                return;
            }

            // ----- Display the results.
            NewRecords.DataSource = generatedTable;
        }
示例#9
0
        /// <summary>
        /// Gets the column names
        /// </summary>
        /// <remarks>Because DbfExporter is forward-reading, calling this method multiple times or calling it after <see cref="GetRowFields"/> will throw an exception.</remarks>
        /// <returns>Returns the columns of a Dbf as a <see cref="IEnumerable{T}"/> where T is a <see cref="string"/></returns>
        public IEnumerable <string> GetColumns()
        {
            if (FieldCount == 0)
            {
                ReadHeader();
            }
            if (Columns.Count > 0)
            {
                throw new Exception("Column names have already been read");
            }
            ColumnRenames   = ColumnRenames.ToDictionary(d => d.Key.ToUpper(), d => d.Value);
            IncludedColumns = IncludedColumns.Select(s => s.ToUpper()).ToList();
            bool          addColumn   = IncludedColumns.Count == 0;
            List <string> columnNames = new List <string>();

            byte[] columnHeader = new byte[FieldArraySize];
            DbfFile.Read(columnHeader, 0, FieldArraySize);
            int    baseOffset;
            int    numericDecimal;
            int    columnOffset = 0;
            string pgColumnType;

            for (int i = 0; i < FieldCount; ++i)
            {
                baseOffset = i * FieldDefinitionSize;
                byte[] nameBytes = new byte[FieldNameLength];
                Array.Copy(columnHeader, baseOffset, nameBytes, 0, FieldNameLength);
                string columnName = Encoding.ASCII.GetString(nameBytes).Replace("\0", string.Empty);
                if (ColumnRenames.ContainsKey(columnName))
                {
                    columnName = ColumnRenames[columnName];
                }
                if (ReservedWords.Contains(columnName))
                {
                    int increment = 0;
                    while (IncludedColumns.Contains($"{columnName}_{++increment}"))
                    {
                        ;
                    }
                    columnName = $"{columnName}_{increment}";
                }
                if (addColumn)
                {
                    IncludedColumns.Add(columnName);
                }
                var       dbfColumnType = Convert.ToChar(columnHeader[baseOffset + FieldTypeOffset]);
                DbfColumn column        = dbfColumnType == 'M' ? new MemoColumn() : new DbfColumn();
                column.Export = IncludedColumns.Contains(columnName) || addColumn;
                column.Type   = dbfColumnType;
                column.Length = columnHeader[baseOffset + FieldLengthOffset];
                column.Offset = columnOffset;
                columnOffset += column.Length;
                Columns.Add(column);
                if (CreateTable)
                {
                    pgColumnType = "TEXT";
                    if (column.Type == 'N' || column.Type == 'F')
                    {
                        if (ConvertNumericToText)
                        {
                            pgColumnType = "TEXT";
                        }
                        else
                        {
                            numericDecimal = columnHeader[baseOffset + FieldDecimalsOffset];
                            pgColumnType   = numericDecimal == 0 ?
                                             $"NUMERIC({column.Length})" :
                                             $"NUMERIC({column.Length},{numericDecimal})";
                        }
                    }
                    else if (column.Type == 'L')
                    {
                        if (ConvertBoolToVarChar)
                        {
                            column.Type  = 'C';
                            pgColumnType = "VARCHAR(1)";
                        }
                        else
                        {
                            pgColumnType = "BOOLEAN";
                        }
                    }
                    else if (column.Type == 'M')
                    {
                        pgColumnType = "TEXT";
                    }
                    else
                    {
                        pgColumnType = $"VARCHAR({column.Length})";
                    }
                    if (column.Export)
                    {
                        columnNames.Add(columnName + " " + pgColumnType);
                    }
                }
                else if (column.Export)
                {
                    columnNames.Add(columnName);
                }
            }
            InitMemoFile();
            DbfFile.Seek(SkipBytes + 1, SeekOrigin.Current);
            return(columnNames);
        }
        /// <inheritdoc/>
        /// <exception cref="ValidationException">Empty secondary key columns collection.</exception>
        protected override void ValidateState()
        {
            using (var ea = new ExceptionAggregator()) {
                ea.Execute(base.ValidateState);

                // Secondary key columns: empty set, duplicates
                var keyColumns = KeyColumns.Select(valueRef => valueRef.Value).ToList();
                if (keyColumns.Count == 0)
                {
                    ea.Execute(() => {
                        throw new ValidationException(Strings.ExEmptyKeyColumnsCollection, Path);
                    });
                }
                foreach (var group in keyColumns
                         .GroupBy(keyColumn => keyColumn)
                         .Where(g => g.Count() > 1))
                {
                    ea.Execute((_column) => {
                        throw new ValidationException(
                            string.Format(Strings.ExMoreThenOneKeyColumnReferenceToColumnX, _column.Name),
                            Path);
                    }, group.Key);
                }

                // Primary key columns
                if (Parent.PrimaryIndex != null && PrimaryKeyColumns.Count != Parent.PrimaryIndex.KeyColumns.Count)
                {
                    ea.Execute(() => {
                        throw new ValidationException(Strings.ExInvalidPrimaryKeyColumnsCollection, Path);
                    });
                }
                for (int i = 0; i < PrimaryKeyColumns.Count; i++)
                {
                    var ref1 = PrimaryKeyColumns[i];
                    var ref2 = Parent.PrimaryIndex.KeyColumns[i];
                    if (ref1.Value != ref2.Value || ref1.Direction != ref2.Direction)
                    {
                        ea.Execute(() => {
                            throw new ValidationException(Strings.ExInvalidPrimaryKeyColumnsCollection, Path);
                        });
                    }
                }

                // Included columns
                var fullKeySet =
                    KeyColumns
                    .Select(cr => cr.Value)
                    .Concat(PrimaryKeyColumns.Select(cr => cr.Value))
                    .ToHashSet();
                foreach (var columnRef in IncludedColumns)
                {
                    if (fullKeySet.Contains(columnRef.Value))
                    {
                        ea.Execute(() => {
                            throw new ValidationException(Strings.ExInvalidIncludedColumnsCollection, Path);
                        });
                    }
                }

                foreach (var group in IncludedColumns
                         .GroupBy(keyColumn => keyColumn)
                         .Where(g => g.Count() > 1))
                {
                    ea.Execute((_column) => {
                        throw new ValidationException(
                            string.Format(Strings.ExMoreThenOneIncludedColumnReferenceToColumnX, _column.Name),
                            Path);
                    }, group.Key);
                }

                ea.Complete();
            }
        }
示例#11
0
 public override string ToString()
 {
     return($"{IndexName} Cols:{string.Join(", ", IndexedColumns.Select(c => c.ColumnName))} Includes:{string.Join(", ", IncludedColumns.Select(c => c.ColumnName))}");
 }