Exemple #1
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            CalculatedDbfColumn column = new CalculatedDbfColumn("CalculatedArea", DbfColumnType.Float, 20, 5, CalculatedDbfColumnType.Area, AreaUnit.Acres);

            featureLayer.Open();
            switch (featureLayer.FeatureSource.GetFirstFeaturesWellKnownType())
            {
            case WellKnownType.Invalid:
            case WellKnownType.GeometryCollection:
            case WellKnownType.Point:
            case WellKnownType.Multipoint:
                break;

            case WellKnownType.Line:
            case WellKnownType.Multiline:
                column = new CalculatedDbfColumn("CalculatedLength", DbfColumnType.Float, 20, 5, CalculatedDbfColumnType.Length, DistanceUnit.Meter);
                break;

            case WellKnownType.Polygon:
            case WellKnownType.Multipolygon:
                column = new CalculatedDbfColumn("CalculatedArea", DbfColumnType.Float, 20, 5, CalculatedDbfColumnType.Area, AreaUnit.Acres);
                break;
            }


            Collection <string> columns = new Collection <string>();

            columns.Add(column.ColumnName);
            string             alias  = featureLayer.FeatureSource.GetColumnAlias(column.ColumnName);
            AddDbfColumnWindow window = new AddDbfColumnWindow(column, columns, DbfColumnMode.Calculated, true, alias);

            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            window.Owner = Application.Current.MainWindow;
            if (window.ShowDialog().GetValueOrDefault())
            {
                CalculatedDbfColumn newColumn = window.DbfColumn as CalculatedDbfColumn;
                if (newColumn != null)
                {
                    if (CheckHasDuplicatedColumn(newColumn))
                    {
                        return;
                    }

                    if (CalculatedDbfColumn.CalculatedColumns.ContainsKey(featureLayer.FeatureSource.Id))
                    {
                        CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id].Add(newColumn);
                    }
                    else
                    {
                        CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id] = new Collection <CalculatedDbfColumn>();
                        CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id].Add(newColumn);
                    }
                    RefreshColumnList(featureLayer);
                }
            }
        }
Exemple #2
0
        private void RefreshColumnList(FeatureLayer featureLayer)
        {
            Collection <ViewColumnItem> viewColumnItems = new Collection <ViewColumnItem>();

            featureLayer.SafeProcess(() =>
            {
                foreach (var column in featureLayer.FeatureSource.GetColumns())
                {
                    if (!string.IsNullOrEmpty(column.ColumnName))
                    {
                        string alias        = featureLayer.FeatureSource.GetColumnAlias(column.ColumnName);
                        ViewColumnItem item = new ViewColumnItem(column, alias);
                        viewColumnItems.Add(item);
                    }
                }
            });

            if (CalculatedDbfColumn.CalculatedColumns.ContainsKey(featureLayer.FeatureSource.Id))
            {
                foreach (var column in CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id])
                {
                    string         alias = featureLayer.FeatureSource.GetColumnAlias(column.ColumnName);
                    ViewColumnItem item  = new ViewColumnItem(column, alias, true);
                    item.EditAction = c =>
                    {
                        DbfColumn           dbfColumn = (DbfColumn)c;
                        Collection <string> columns   = new Collection <string>();
                        columns.Add(c.ColumnName);
                        string             tempAlias = featureLayer.FeatureSource.GetColumnAlias(dbfColumn.ColumnName);
                        AddDbfColumnWindow window    = new AddDbfColumnWindow(dbfColumn, columns, DbfColumnMode.Calculated, true, tempAlias);
                        window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                        window.Owner = Application.Current.MainWindow;
                        if (window.ShowDialog().GetValueOrDefault())
                        {
                            CalculatedDbfColumn newColumn = window.DbfColumn as CalculatedDbfColumn;
                            if (newColumn != null)
                            {
                                //Check does edit
                                CalculatedDbfColumn tempColumn = (CalculatedDbfColumn)c;
                                if (newColumn.ColumnName == tempColumn.ColumnName &&
                                    newColumn.CalculationType == tempColumn.CalculationType &&
                                    newColumn.ColumnType == tempColumn.ColumnType &&
                                    newColumn.DecimalLength == tempColumn.DecimalLength &&
                                    newColumn.Length == tempColumn.Length &&
                                    newColumn.LengthUnit == tempColumn.LengthUnit &&
                                    newColumn.MaxLength == tempColumn.MaxLength &&
                                    newColumn.AreaUnit == tempColumn.AreaUnit &&
                                    newColumn.TypeName == tempColumn.TypeName)
                                {
                                    return;
                                }

                                if (CheckHasDuplicatedColumn(newColumn))
                                {
                                    return;
                                }

                                if (CalculatedDbfColumn.CalculatedColumns.ContainsKey(featureLayer.FeatureSource.Id))
                                {
                                    CalculatedDbfColumn calColumn = (CalculatedDbfColumn)c;
                                    if (CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id].Contains(calColumn))
                                    {
                                        CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id].Remove(calColumn);
                                    }
                                    CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id].Add(newColumn);
                                }
                                RefreshColumnList(featureLayer);
                            }
                        }
                    };

                    item.DeleteAction = c =>
                    {
                        if (CalculatedDbfColumn.CalculatedColumns.ContainsKey(featureLayer.FeatureSource.Id))
                        {
                            CalculatedDbfColumn calColumn = (CalculatedDbfColumn)c;
                            if (CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id].Contains(calColumn))
                            {
                                CalculatedDbfColumn.CalculatedColumns[featureLayer.FeatureSource.Id].Remove(calColumn);
                                RefreshColumnList(featureLayer);
                            }
                        }
                    };
                    viewColumnItems.Add(item);
                }
            }

            ColumnList.ItemsSource = viewColumnItems;
        }