Ejemplo n.º 1
0
        public ITable OpenCSVFile(string csvFullPath)
        {
            string            csvPath           = System.IO.Path.GetDirectoryName(csvFullPath); //csv文件的文件夹位置
            string            csvName           = System.IO.Path.GetFileName(csvFullPath);      //csv文件的文件名
            IWorkspaceFactory pWorkspaceFactory = new OLEDBWorkspaceFactory();
            IPropertySet      pPropSet          = new PropertySet();

            //注意如果csv文件的字符编码是utf-8
            //pPropSet.SetProperty("CONNECTSTRING", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + tablePath + ";Extended Properties='Text;HDR=Yes;IMEX=1;CharacterSet=65001;'");
            pPropSet.SetProperty("CONNECTSTRING", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvPath + ";Extended Properties='Text;HDR=Yes;IMEX=1;'");
            IWorkspace        pWorkspace         = pWorkspaceFactory.Open(pPropSet, 0);
            IFeatureWorkspace pFeatureWorkspace2 = (IFeatureWorkspace)pWorkspace;
            ITable            pTable             = pFeatureWorkspace2.OpenTable(csvName);

            return(pTable);
        }
Ejemplo n.º 2
0
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count != 0)
            {
                MyDoubleClickResult myDCRShowChildren;
                IGxObject           tag = this.listView1.SelectedItems[0].Tag as IGxObject;
                if ((this._gxObjectFilter != null) && (tag is IGxDatabase))
                {
                    myDCRShowChildren = MyDoubleClickResult.myDCRShowChildren;
                    this._gxObjectFilter.CanChooseObject(tag, ref myDCRShowChildren);
                    if (myDCRShowChildren == MyDoubleClickResult.myDCRChooseAndDismiss)
                    {
                        this.PassListItem();
                        return;
                    }
                }
                if (!(tag is IGxObjectContainer))
                {
                    if (tag is IGxNewDatabase)
                    {
                        IWorkspaceName name;
                        IGxObject      obj3;
                        ListViewItem   item;
                        if (tag.FullName == "添加OLE DB连接")
                        {
                            try
                            {
                                string path = Environment.SystemDirectory.Substring(0, 2) +
                                              @"\Documents and Settings\Administrator\Application Data\ESRI\ArcCatalog\";
                                string str2 = path + "OLE DB Connection.odc";
                                if (Directory.Exists(path))
                                {
                                    str2 = this.ChangeODCExtension(str2);
                                    IWorkspaceFactory factory = new OLEDBWorkspaceFactory() as IWorkspaceFactory;
                                    name = factory.Create(path, System.IO.Path.GetFileName(str2), null, 0);
                                    IGxObject gxDatabase = new GxDatabase() as IGxObject;
                                    (gxDatabase as IGxDatabase).WorkspaceName = name;
                                    gxDatabase.Attach(tag.Parent, this._gxCatalog);
                                    item = new ListViewItem(new string[] { gxDatabase.Name, gxDatabase.Category },
                                                            this.GetImageIndex(gxDatabase))
                                    {
                                        Tag = gxDatabase
                                    };
                                    this.listView1.Items.Add(item);
                                }
                            }
                            catch (Exception exception)
                            {
                                exception.ToString();
                            }
                        }
                        else if (tag.FullName == "添加空间数据库连接")
                        {
                            frmCreateGDBConnection connection = new frmCreateGDBConnection
                            {
                                TopMost = true
                            };
                            if (connection.ShowDialog() == DialogResult.OK)
                            {
                                IGxObject      oneObj = new GxDatabase() as IGxObject;
                                IWorkspaceName name2  = new WorkspaceName() as IWorkspaceName;
                                name2.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory";
                                name2.PathName = connection.ConnectionPath;

                                (oneObj as IGxDatabase).WorkspaceName = name2;
                                oneObj.Attach(tag.Parent, this._gxCatalog);
                                item = new ListViewItem(new string[] { oneObj.Name, oneObj.Category },
                                                        this.GetImageIndex(oneObj))
                                {
                                    Tag = oneObj
                                };
                                this.listView1.Items.Add(item);
                            }
                        }
                    }
                    else
                    {
                        this.PassListItem();
                    }
                }
                else
                {
                    GISDataComboItem ex;
                    if (tag is IGxDataset)
                    {
                        esriDatasetType type = (tag as IGxDataset).Type;
                        myDCRShowChildren = MyDoubleClickResult.myDCRShowChildren;
                        this._gxObjectFilter.CanChooseObject(tag, ref myDCRShowChildren);
                        if ((((type != esriDatasetType.esriDTFeatureDataset) &&
                              (type != esriDatasetType.esriDTContainer)) &&
                             ((type != esriDatasetType.esriDTRasterCatalog) &&
                              (type != esriDatasetType.esriDTCadDrawing))) &&
                            (type != esriDatasetType.esriDTRasterDataset))
                        {
                            this.PassListItem();
                            return;
                        }
                    }
                    this.LoadViewer(tag);
                    this._isFree = false;
                    if (tag.Parent is IGxCatalog)
                    {
                        for (int i = 0; i < this.gisDataComboBox1.Items.Count; i++)
                        {
                            ex = this.gisDataComboBox1.Items[i] as GISDataComboItem;
                            if (ex.Tag == tag)
                            {
                                this.gisDataComboBox1.SelectedIndex = i;
                                break;
                            }
                        }
                    }
                    else
                    {
                        ex = this.gisDataComboBox1.Items[this.gisDataComboBox1.SelectedIndex] as GISDataComboItem;
                        int degree = ex.Level;
                        ex = new GISDataComboItem(tag.Name, tag.FullName, this.GetImageIndex(tag), degree + 1)
                        {
                            Tag = tag
                        };
                        int selectedIndex = this.gisDataComboBox1.SelectedIndex;
                        this.gisDataComboBox1.AddChildNode(ex);
                        this.gisDataComboBox1.SelectedIndex = selectedIndex + 1;
                    }
                    this._isFree = true;
                }
            }
        }
Ejemplo n.º 3
0
        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            IWorkspaceName workspaceNameClass;
            IGxObject      gxDatabase;
            ListViewItem   listViewItem;

            string[]            name;
            ImageComboBoxItemEx item;

            if (this.listView1.SelectedItems.Count != 0)
            {
                IGxObject tag = this.listView1.SelectedItems[0].Tag as IGxObject;
                if (tag is IGxObjectContainer)
                {
                    this.SetListView(tag);
                    this.m_CanDo = false;
                    if (tag.Parent is IGxCatalog)
                    {
                        int num = 0;
                        while (num < this.imageComboBoxEdit1.Properties.Items.Count)
                        {
                            item = this.imageComboBoxEdit1.Properties.Items[num] as ImageComboBoxItemEx;
                            if (item.Tag != tag)
                            {
                                num++;
                            }
                            else
                            {
                                this.imageComboBoxEdit1.SelectedIndex = num;
                                break;
                            }
                        }
                    }
                    else
                    {
                        item =
                            this.imageComboBoxEdit1.Properties.Items[this.imageComboBoxEdit1.SelectedIndex] as
                            ImageComboBoxItemEx;
                        int degree = item.Degree;
                        item = new ImageComboBoxItemEx(tag.Name, tag.FullName, this.GetImageIndex(tag), degree + 1)
                        {
                            Tag = tag
                        };
                        int selectedIndex = this.imageComboBoxEdit1.SelectedIndex;
                        this.imageComboBoxEdit1.Properties.Items.Insert(selectedIndex + 1, item);
                        this.imageComboBoxEdit1.SelectedIndex = selectedIndex + 1;
                    }
                    this.m_CanDo = true;
                }
                else if (tag is IGxNewDatabase)
                {
                    if (tag.FullName == "添加OLE DB连接")
                    {
                        try
                        {
                            string str = string.Concat(Environment.SystemDirectory.Substring(0, 2),
                                                       "\\Documents and Settings\\Administrator\\Application Data\\ESRI\\ArcCatalog\\");
                            string finalFileName = string.Concat(str, "OLE DB Connection.odc");
                            if (Directory.Exists(str))
                            {
                                finalFileName = this.GetFinalFileName(finalFileName);
                                IWorkspaceFactory oLEDBWorkspaceFactoryClass = new OLEDBWorkspaceFactory();
                                workspaceNameClass = oLEDBWorkspaceFactoryClass.Create(str,
                                                                                       Path.GetFileName(finalFileName), null, 0);
                                gxDatabase = new GxDatabase();
                                (gxDatabase as IGxDatabase).WorkspaceName = workspaceNameClass;
                                gxDatabase.Attach(tag.Parent, this.GxCatalog);
                                name         = new string[] { gxDatabase.Name, gxDatabase.Category };
                                listViewItem = new ListViewItem(name, this.GetImageIndex(gxDatabase))
                                {
                                    Tag = gxDatabase
                                };
                                this.listView1.Items.Add(listViewItem);
                            }
                        }
                        catch (Exception exception)
                        {
                            exception.ToString();
                        }
                    }
                    else if (tag.FullName == "添加空间数据库连接")
                    {
                        frmCreateGDBConnection _frmCreateGDBConnection = new frmCreateGDBConnection()
                        {
                            TopMost = true
                        };
                        if (_frmCreateGDBConnection.ShowDialog() == DialogResult.OK)
                        {
                            gxDatabase         = new GxDatabase();
                            workspaceNameClass = new WorkspaceName() as IWorkspaceName;
                            workspaceNameClass.WorkspaceFactoryProgID = "esriDataSourcesGDB.SdeWorkspaceFactory";
                            workspaceNameClass.PathName = _frmCreateGDBConnection.ConnectionPath;
                            (gxDatabase as IGxDatabase).WorkspaceName = workspaceNameClass;
                            gxDatabase.Attach(tag.Parent, this.GxCatalog);
                            name         = new string[] { gxDatabase.Name, gxDatabase.Category };
                            listViewItem = new ListViewItem(name, this.GetImageIndex(gxDatabase))
                            {
                                Tag = gxDatabase
                            };
                            this.listView1.Items.Add(listViewItem);
                        }
                    }
                }
            }
        }