Example #1
0
        private void toolStripMenuItemFieldInfo_Click(object sender, EventArgs e)
        {
            string          fieldinfo_name = selectNode.Text;
            string          fc_name        = selectNode.Parent.Text;
            string          set_name       = selectNode.Parent.Parent.Text;
            myTreeNode      node           = (myTreeNode)selectNode.Parent.Parent.Parent;
            IConnectionInfo ci             = node.con;

            IDataSource          ds         = dsFactory.OpenDataSource(ci);
            IFeatureDataSet      dataset    = ds.OpenFeatureDataset(set_name);
            IFeatureClass        fc         = dataset.OpenFeatureClass(fc_name);
            IFieldInfoCollection fieldinfos = fc.GetFields();

            for (int i = 0; i < fieldinfos.Count; i++)
            {
                IFieldInfo fieldinfo = fieldinfos.Get(i);
                if (null == fieldinfo)
                {
                    continue;
                }
                if (fieldinfo_name == fieldinfo.Name)
                {
                    FieldInfoForm form = new FieldInfoForm(fieldinfo);
                    form.Show();
                }
            }
        }
Example #2
0
        // 公共方法
        private void bindDataToCatalogTree(IConnectionInfo ci)
        {
            try
            {
                if (dsFactory == null)
                {
                    dsFactory = new DataSourceFactory();
                }
                IDataSource ds = dsFactory.OpenDataSource(ci);

                myTreeNode sourceNode = null;
                if (ci.ConnectionType == gviConnectionType.gviConnectionMySql5x)
                {
                    sourceNode = new myTreeNode(ci.Database + "@" + ci.Server, ci);
                }
                else
                {
                    sourceNode = new myTreeNode(ci.Database, ci);
                }
                this.treeView1.Nodes.Add(sourceNode);

                // 获取dataset
                string[] setnames = (string[])ds.GetFeatureDatasetNames();
                if (setnames.Length == 0)
                {
                    return;
                }
                foreach (string setname in setnames)
                {
                    IFeatureDataSet dataset = ds.OpenFeatureDataset(setname);

                    TreeNode setNode = new TreeNode(setname, 1, 1);
                    sourceNode.Nodes.Add(setNode);

                    // 获取featureclass
                    string[] fcnames = (string[])dataset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (fcnames == null || fcnames.Length == 0)
                    {
                        continue;
                    }
                    foreach (string fcname in fcnames)
                    {
                        IFeatureClass fc = dataset.OpenFeatureClass(fcname);

                        TreeNode fcNode = new TreeNode(fcname, 2, 2);
                        setNode.Nodes.Add(fcNode);

                        // 获取属性字段
                        IFieldInfoCollection fieldinfos = fc.GetFields();
                        for (int i = 0; i < fieldinfos.Count; i++)
                        {
                            IFieldInfo fieldinfo = fieldinfos.Get(i);
                            if (null == fieldinfo)
                            {
                                continue;
                            }

                            TreeNode fieldinfoNode = new TreeNode(fieldinfo.Name);
                            fieldinfoNode.ContextMenuStrip = this.contextMenuStrip1;  // 绑定右键菜单
                            fcNode.Nodes.Add(fieldinfoNode);
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                return;
            }
        }