Esempio n. 1
0
        private void mgMapViewer1_SelectionChanged(object sender, EventArgs e)
        {
            MgSelectionBase           selection = mgMapViewer1.GetSelection();
            MgReadOnlyLayerCollection layers    = selection.GetLayers();

            if (layers != null)
            {
                for (int i = 0; i < layers.GetCount(); i++)
                {
                    MgLayerBase layer = layers.GetItem(i);
                    if (layer.Name == "Parcels") //The selected layer is parcels
                    {
                        //Check that we only have one selected object
                        int count = selection.GetSelectedFeaturesCount(layer, layer.FeatureClassName);
                        if (count == 1)
                        {
                            MgFeatureReader reader = null;
                            try
                            {
                                reader = selection.GetSelectedFeatures(layer, layer.FeatureClassName, false);
                                if (reader.ReadNext())
                                {
                                    //Address is in the RPROPAD property
                                    if (reader.IsNull("RPROPAD"))
                                    {
                                        MessageBox.Show("Selected parcel has no address");
                                    }
                                    else
                                    {
                                        MessageBox.Show("Address: " + reader.GetString("RPROPAD"));
                                    }
                                }
                            }
                            finally //Must close all readers, otherwise connections will leak
                            {
                                reader.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please select only one parcel");
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 2
0
        internal MgSelectionSet(MgSelectionBase selection, MgMapViewerProvider provider)
        {
            _agfRw    = new MgAgfReaderWriter();
            _features = new Dictionary <string, List <MgFeature> >();
            var selLayers = selection.GetLayers();

            if (selLayers != null)
            {
                for (int i = 0; i < selLayers.GetCount(); i++)
                {
                    var layer    = selLayers.GetItem(i);
                    var clsName  = layer.GetFeatureClassName();
                    int selCount = selection.GetSelectedFeaturesCount(layer, clsName);
                    if (selCount == 0)
                    {
                        System.Diagnostics.Trace.TraceWarning("No items in selection set for this layer (" + layer.GetName() + "). Layer shouldn't be here then");
                        continue;
                    }

                    NameValueCollection mappings = (provider != null) ? provider.GetPropertyMappings(layer) : null;
                    _features[layer.Name] = new List <MgFeature>();

                    var reader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false);
                    while (reader.ReadNext())
                    {
                        var feature = CreateFeatureFromReader(reader);
                        if (mappings != null)
                        {
                            PerformDisplayNameSubstitution(feature, mappings);
                        }
                        _features[layer.Name].Add(feature);
                    }
                    reader.Close();
                }
            }
        }
Esempio n. 3
0
        internal MgSelectionSet(MgSelectionBase selection, MgMapViewerProvider provider)
        {
            _agfRw = new MgAgfReaderWriter();
            _features = new Dictionary<string, List<MgFeature>>();
            var selLayers = selection.GetLayers();
            if (selLayers != null)
            {
                for (int i = 0; i < selLayers.GetCount(); i++)
                {
                    var layer = selLayers.GetItem(i);
                    var clsName = layer.GetFeatureClassName();
                    int selCount = selection.GetSelectedFeaturesCount(layer, clsName);
                    if (selCount == 0)
                    {
                        System.Diagnostics.Trace.TraceWarning("No items in selection set for this layer (" + layer.GetName() + "). Layer shouldn't be here then");
                        continue;
                    }

                    NameValueCollection mappings = (provider != null) ? provider.GetPropertyMappings(layer) : null;
                    _features[layer.Name] = new List<MgFeature>();
                    
                    var reader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false);
                    while (reader.ReadNext())
                    {
                        var feature = CreateFeatureFromReader(reader);
                        if (mappings != null)
                            PerformDisplayNameSubstitution(feature, mappings);
                        _features[layer.Name].Add(feature);
                    }
                    reader.Close();
                }
            }
        }
Esempio n. 4
0
        }        //method

        internal static void SelectionToDataGridView(MgSelectionBase _selection_base)
        {
            palette_window.links_control.is_suspended = true;         // информируем о заморозке
            palette_window.links_control.SuspendLayout();             // замораживаем логику
            palette_window.links_control.data_grid.Enabled = false;
            palette_window.links_control.data_grid.SuspendLayout();   // замораживаем логику DataGridView
            palette_window.links_control.layers_list.Enabled = false;

            palette_window.links_control.progressbar_in_status.Visible = true;             // включение ProgressBar
            palette_window.links_control.status_strip.Refresh();



            MgReadOnlyLayerCollection layers = _selection_base.GetLayers();

            int curr_features_count = 0, features_count = 0;

            // подсчет количества выбранных объектов
            foreach (MgLayerBase layer in layers)
            {
                features_count += _selection_base.GetSelectedFeaturesCount(layer, layer.FeatureClassName);
            }

            if (features_count == 0)
            {
                return;
            }

            // заполнение списка слоев
            palette_window.links_control.layers_list.Items.Clear();             // очищаем список

            if (layers.Count > 1)
            {
                palette_window.links_control.layers_list.Items.Add("(Все выбранные)");
            }

            foreach (MgLayerBase layer in layers)
            {
                palette_window.links_control.layers_list.Items.Add(layer.Name);
            }
            palette_window.links_control.layers_list.SelectedIndex = 0;

            // заполнение DataGridView
            palette_window.links_control.data_grid.Rows.Clear();              // очищаем строки

            foreach (MgLayerBase layer in layers)
            {
                int curr_ftr_class_idx = config.IndexOf(layer.FeatureClassName);
                if (curr_ftr_class_idx == -1)
                {
                    curr_features_count += _selection_base.GetSelectedFeaturesCount(layer, layer.FeatureClassName);;
                    palette_window.links_control.UpdateStatusRowCounterLabelAndProgressBar(curr_features_count, features_count);
                    continue;
                }
                FeatureClassLinkInfo curr_link_info = config.link_info_array[curr_ftr_class_idx];

                MgFeatureReader ftr_rdr = _selection_base.GetSelectedFeatures(layer, layer.FeatureClassName, false);

                MgPropertyDefinitionCollection identity_prop_defs = ftr_rdr.GetClassDefinition().GetIdentityProperties();                 // получаем набор идентификационных полей

                while (ftr_rdr.ReadNext())
                {
                    curr_features_count++;

                    DataGridViewRow link_row = new DataGridViewRow();   // новая строка

                    DataGridViewLinkCell link_cell;                     // ячейка

                    // формирование URL
                    link_cell = new DataGridViewLinkCell();

                    string title_str = ResolveLinkStringByValueFromReader(ftr_rdr, curr_link_info.LinkTitle);
                    link_cell.Value       = String.IsNullOrEmpty(title_str)? "<Null>": title_str;
                    link_cell.ToolTipText =
                        curr_link_info.LinkCommandPath
                        + command_splitter
                        + ResolveLinkStringByValueFromReader(ftr_rdr, curr_link_info.LinkURL);
                    link_row.Cells.Add(link_cell);                     // вставка ячейки

                    // формирование ID
                    MgPropertyCollection curr_identity_props = GetPropertiesFromReader(ftr_rdr, identity_prop_defs);

                    SelectedFeatureInfo sel_info = new SelectedFeatureInfo(layer, curr_identity_props);
                    link_cell       = new DataGridViewLinkCell();
                    link_cell.Value = sel_info;
                    link_row.Cells.Add(link_cell);                     // вставка ячейки

                    // добавлени строки в DataGridView
                    palette_window.links_control.data_grid.Rows.Add(link_row);

                    // обновление ProgressBar'а и счетчика строк
                    palette_window.links_control.UpdateStatusRowCounterLabelAndProgressBar(curr_features_count, features_count);
                }                                                                               /// while (ftr_rdr.ReadNext())
            }                                                                                   /// foreach (MgLayerBase layer in layers)

            palette_window.links_control.URL.SortMode = DataGridViewColumnSortMode.NotSortable; // сброс сортировки
            palette_window.links_control.URL.SortMode = DataGridViewColumnSortMode.Automatic;   // на исходную автоматическую

            palette_window.links_control.data_grid.SelectAll();                                 // выбираем все строки

            palette_window.links_control.progressbar_in_status.Visible = false;

            palette_window.links_control.layers_list.Enabled = true;
            palette_window.links_control.data_grid.Enabled   = true;
            palette_window.links_control.data_grid.ResumeLayout();   // размораживаем логику DataGridView
            palette_window.links_control.ResumeLayout();             // размораживаем логику
            palette_window.links_control.is_suspended = false;

            palette_window.links_control.UpdateStatusRowCounterLabel();             // обновляем строку статуса
        }
Esempio n. 5
0
 private static int GetSelectionTotal(MgSelectionBase sel)
 {
     int total = 0;
     var layers = sel.GetLayers();
     if (layers != null)
     {
         for (int i = 0; i < layers.GetCount(); i++)
         {
             var layer = layers.GetItem(i);
             total += sel.GetSelectedFeaturesCount(layer, layer.FeatureClassName);
         }
     }
     return total;
 }