Exemple #1
0
        //确定添加连接
        private void buttonConOK_Click(object sender, EventArgs e)
        {
            treeView.Nodes.Clear();
            GetAllFeatures gaf     = new GetAllFeatures();
            ConnectDB      cd      = new ConnectDB();
            string         ConName = this.textBoxConName.Text;
            string         ConType = this.comboBoxConType.SelectedItem.ToString();
            string         ConPath = this.textBoxConPath.Text;

            ConPath = ConPath.Replace(@"\", @"\\");
            //插入信息到GISDATA_REGCONNECT
            bool isInsert = cd.Insert("insert into GISDATA_REGCONNECT (REG_NAME,REG_TYPE,REG_PATH) values ('" + ConName + "','" + ConType + "','" + ConPath + "')");

            if (isInsert)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Exemple #2
0
        //刷新注册连接树
        public void refreshTreeViewReg()
        {
            this.treeList1.ClearNodes();
            //加载注册数据连接
            DataTable dtable = new DataTable();

            dtable.Columns.Add("ParentID", typeof(string));
            dtable.Columns.Add("ID", typeof(string));
            dtable.Columns.Add("NAME", typeof(string));
            dtable.Columns.Add("PATH", typeof(string));
            dtable.Columns.Add("TYPE", typeof(string));
            ConnectDB      cd  = new ConnectDB();
            GetAllFeatures gaf = new GetAllFeatures();
            DataTable      dt  = cd.GetDataBySql("select * from GISDATA_REGCONNECT");

            DataRow[] dr = dt.Select("1=1");
            for (int i = 0; i < dr.Length; i++)
            {
                DataRow row     = dtable.NewRow();;
                string  regPath = dr[i]["REG_PATH"].ToString();
                string  regType = dr[i]["REG_TYPE"].ToString();
                string  name    = dr[i]["REG_NAME"].ToString();
                string  id      = dr[i]["ID"].ToString();
                row["ParentID"] = "";
                row["ID"]       = id;
                row["NAME"]     = name;
                row["PATH"]     = regPath;
                row["TYPE"]     = regType;
                dtable.Rows.Add(row);
                IFeatureWorkspace space;
                if (regType == "Access数据库")
                {
                    AccessWorkspaceFactory fac = new AccessWorkspaceFactoryClass();
                    try
                    {
                        space = (IFeatureWorkspace)fac.OpenFromFile(regPath, 0);
                    }
                    catch
                    {
                        continue;
                    }
                }
                else
                {
                    FileGDBWorkspaceFactoryClass fac = new FileGDBWorkspaceFactoryClass();
                    try
                    {
                        space = (IFeatureWorkspace)fac.OpenFromFile(regPath, 0);
                    }
                    catch
                    {
                        continue;
                    }
                }
                IWorkspace      iwk     = (IWorkspace)space;
                List <IDataset> ifcList = gaf.GetAllFeatureClass(iwk);
                for (int j = 0; j < ifcList.Count; j++)
                {
                    DataRow rowKid = dtable.NewRow();
                    rowKid["ParentID"] = id;
                    rowKid["ID"]       = int.Parse(id) * 100 + j;
                    rowKid["NAME"]     = ifcList[j].Name;
                    rowKid["PATH"]     = regPath;
                    rowKid["TYPE"]     = regType;
                    dtable.Rows.Add(rowKid);
                }
            }
            this.treeList1.DataSource = dtable;
            this.treeList1.OptionsView.ShowCheckBoxes = true;
        }