Beispiel #1
0
        public ComboFilter()
        {
            _timer          = new Timer(600);
            _timer.Enabled  = false;
            _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);

            IGxViewContainer pGxViewContainer = _pGxApp as IGxViewContainer;
            IEnumGxView      pEnumGxView;

            pEnumGxView = pGxViewContainer.Views;

            IGxView pGxView;

            pGxView = pEnumGxView.Next();

            while (pGxView != null)
            {
                if (pGxView is IGxContentsView)
                {
                    pGxContentsView = pGxView as IGxContentsView;
                    _pGxView        = pGxView;
                    break;
                }
                pGxView = pEnumGxView.Next();
            }
        }
        public ComboFilter()
        {
            
            _timer = new Timer(600);
            _timer.Enabled = false;
            _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);

            IGxViewContainer pGxViewContainer = _pGxApp as IGxViewContainer;
            IEnumGxView pEnumGxView;
            pEnumGxView = pGxViewContainer.Views;
    
            IGxView pGxView;
            pGxView = pEnumGxView.Next();
    
            while(pGxView != null)
            {
                if(pGxView is IGxContentsView)
                {
                    pGxContentsView = pGxView as IGxContentsView;
                    _pGxView = pGxView;
                    break;
                }
                pGxView = pEnumGxView.Next();
            }
        }
Beispiel #3
0
        public void Import(string connectionString, string tableName)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                MessageBox.Show("Unable to obtain connection SQL 2008 information.", "Error", MessageBoxButtons.OK);
                return;
            }

            IGxApplication gxApp  = m_application as IGxApplication;
            IGxView        gxView = gxApp.View;

            if (gxApp.Selection.Count > 0)
            {
                if (gxApp.Selection.Count == 1)
                {
                    IGxObject gxObj  = gxApp.SelectedObject;
                    object    selObj = gxObj.InternalObjectName.Open();
                    if (selObj is IFeatureClass)
                    {
                        IFeatureClass featureClass = selObj as IFeatureClass;
                        //ConnectionStringSettings connStr = m_config.ConnectionStrings.ConnectionStrings[ "SQL2008" ];
                        SqlConnection sqlConnection = new SqlConnection(connectionString);
                        sqlConnection.Open();
                        SQL2008Database sqlDatabase = new SQL2008Database(connectionString);

                        DefaultAoGeometryTypeProvider aoGeometryTypeProvider = new DefaultAoGeometryTypeProvider();
                        string geometryType = aoGeometryTypeProvider.GetGeometryType(featureClass.ShapeType);

                        if (String.IsNullOrEmpty(geometryType))
                        {
                            MessageBox.Show("The geometry type of the source FeatureClass is not supported.", "Error", MessageBoxButtons.OK);
                            return;
                        }

                        System.Collections.IDictionary parameters = new System.Collections.Hashtable();
                        parameters.Add("featureClass", featureClass);
                        parameters.Add("layerName", tableName);
                        parameters.Add("keyFieldName", featureClass.OIDFieldName);
                        AoFCLayer shapeFileLayer = container.Resolve <AoFCLayer>("Ao" + geometryType, parameters);

                        if (shapeFileLayer == null)
                        {
                            MessageBox.Show("Unable to create the input framework layer for the FeatureClass. Please check the component configuration.", "Error", MessageBoxButtons.OK);
                            return;
                        }

                        if (sqlDatabase.ContainsTable(tableName))
                        {
                            if (MessageBox.Show("Overwrite existing table?", "Overwrite", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                sqlDatabase.DeleteTable(tableName);
                            }
                            else
                            {
                                MessageBox.Show("Exiting export operation", "Information", MessageBoxButtons.OK);
                                return;
                            }
                        }

                        ISupportsGISFields shapeFileFields = shapeFileLayer as ISupportsGISFields;
                        IGISFields         inputFields     = shapeFileFields.GetGISFields();

                        SqlCommand sqlCommand;

                        int?srid = null;
                        if (shapeFileLayer is ISupportsSRID)
                        {
                            srid = (shapeFileLayer as ISupportsSRID).Srid;
                        }

                        IGISLayer sql2008Layer = null;
                        //Create the dictionary with the parameters to create the corresponding SQL 2008 layer
                        System.Collections.IDictionary sqlParameters = new System.Collections.Hashtable();
                        sqlParameters.Add("tableName", tableName);
                        sqlParameters.Add("shapeFieldName", "SHAPE");
                        sqlParameters.Add("layerName", tableName);
                        sqlParameters.Add("keyFieldName", featureClass.OIDFieldName);

                        if (srid.HasValue && WKIDRanges.IsGeographic(srid.Value))
                        {
                            //Create the geography table with the fields from the FeatureClass
                            sqlDatabase.CreateGeographyTable(inputFields, tableName, "SHAPE");
                            sqlCommand = new SqlCommand("Select * from " + tableName, sqlConnection);
                            sqlParameters.Add("dbCommand", sqlCommand);
                            sql2008Layer = container.Resolve <IGISLayer>("Sql2008Geog" + geometryType, sqlParameters);
                        }
                        else
                        {
                            //Create the geometry table with the fields from the FeatureClass
                            sqlDatabase.CreateGeometryTable(inputFields, tableName, "SHAPE");
                            sqlCommand = new SqlCommand("Select * from " + tableName, sqlConnection);
                            sqlParameters.Add("dbCommand", sqlCommand);
                            sql2008Layer = container.Resolve <IGISLayer>("Sql2008Geom" + geometryType, sqlParameters);
                        }

                        //Get the editable layer reference to the destination sql table layer
                        IGISEditableLayer editableLayer = sql2008Layer as IGISEditableLayer;

                        //Quit the application if a valid editable layer reference could not be obtained
                        if (editableLayer == null)
                        {
                            MessageBox.Show("The destination is either invalid or does not support editing.", "Error", MessageBoxButtons.OK);
                            return;
                        }

                        shapeFileLayer.Search(null);
                        string keyFieldName = shapeFileLayer.KeyFieldName;
                        while (shapeFileLayer.MoveNext())
                        {
                            try
                            {
                                editableLayer.Add(shapeFileLayer.Current);
                            }
                            catch (Exception ex)
                            {
                                string msg = ex.Message + " Feature ID:- " + shapeFileLayer.Current.Attributes.GetValue(keyFieldName).ToString();
                                _log.Error(msg, ex);
                            }
                        }

                        MessageBox.Show("Import completed.", "Information", MessageBoxButtons.OK);
                    }
                    else
                    {
                        MessageBox.Show("Only FeatureClasses can be exported to SQL 2008", "Information", MessageBoxButtons.OK);
                    }
                }
                else
                {
                    MessageBox.Show("Please only one FeatureClass to export to SQL 2008.");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please select a FeatureClass to export to SQL 2008.");
                return;
            }
        }