Exemple #1
0
        private void viewFieldToolStripMenuItem_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   = null;
            IFeatureDataSet dset = null;
            IFeatureClass   fc   = null;

            try
            {
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(set_name);
                fc   = dset.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)
                    {
                        ViewFieldInfoForm form = new ViewFieldInfoForm(fieldinfo);
                        form.Show();
                    }
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }
Exemple #2
0
        private void deleteFeatureClassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDataSource     ds   = null;
            IFeatureDataSet dset = null;

            try
            {
                myTreeNode      node = (myTreeNode)selectNode.Parent.Parent;
                IConnectionInfo ci   = node.con;
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(selectNode.Parent.Text);

                if (MessageBox.Show("该操作无法恢复,请确定是否删除要素类?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    String fcname = selectNode.Text;
                    if (dset.DeleteByName(fcname))
                    {
                        selectNode.Parent.Nodes.Remove(selectNode);
                    }
                    else
                    {
                        MessageBox.Show("删除失败");
                    }
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
            }
            catch (System.Exception ex)
            {
                if (ex.Source == "物理数据源不存在")
                {
                    this.treeView1.Nodes.Remove(selectNode.Parent.Parent);
                    MessageBox.Show(ex.Source);
                }
                else
                {
                    MessageBox.Show("删除失败");
                }

                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }
Exemple #3
0
        private void deleteDataSetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDataSource     ds   = null;
            IFeatureDataSet dset = null;

            try
            {
                if (MessageBox.Show("该操作无法恢复,请确定是否删除数据集?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    myTreeNode      node = (myTreeNode)selectNode.Parent;
                    IConnectionInfo ci   = node.con;
                    ds   = dsFactory.OpenDataSource(ci);
                    dset = ds.OpenFeatureDataset(selectNode.Text);

                    Array tem = dset.GetNamesByType(gviDataSetType.gviDataSetFeatureClassTable);
                    if (tem != null)
                    {
                        foreach (String strFC in tem)
                        {
                            IFeatureClass fc = dset.OpenFeatureClass(strFC);
                            dset.DeleteByName(strFC);
                            //Marshal.ReleaseComObject(fc);
                            fc = null;
                        }
                    }
                    ds.DeleteFeatureDataset(selectNode.Text);

                    // 从普通表里删除dataset对应的记录
                    DeleteLogicTree(ds, selectNode.Text);

                    // 从树上删节点
                    node.Nodes.Remove(selectNode);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
            }
        }
Exemple #4
0
        private void deleteFieldToolStripMenuItem_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   = null;
            IFeatureDataSet dset = null;
            IFeatureClass   fc   = null;

            try
            {
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(set_name);
                fc   = dset.OpenFeatureClass(fc_name);

                if (fieldInfo_name == "oid")
                {
                    MessageBox.Show("此字段不支持删除");
                    return;
                }

                if (MessageBox.Show("该操作无法恢复,请确定是否删除字段?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    fc.LockType = gviLockType.gviLockExclusiveSchema;
                    fc.DeleteField(fieldInfo_name);
                    fc.LockType = gviLockType.gviLockSharedSchema;

                    // 从树上删除节点
                    selectNode.Parent.Nodes.Remove(selectNode);
                    MessageBox.Show("删除成功");
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
                MessageBox.Show("删除失败");
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                MessageBox.Show("删除失败");
            }
            finally
            {
                fc.LockType = gviLockType.gviLockSharedSchema;
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }
Exemple #5
0
        private void createFieldToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string          fc_name  = selectNode.Text;
            string          set_name = selectNode.Parent.Text;
            myTreeNode      node     = (myTreeNode)selectNode.Parent.Parent;
            IConnectionInfo ci       = node.con;

            IDataSource     ds   = null;
            IFeatureDataSet dset = null;
            IFeatureClass   fc   = null;

            try
            {
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(set_name);
                fc   = dset.OpenFeatureClass(fc_name);

                OperateFieldInfoForm form = new OperateFieldInfoForm(null);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    IFieldInfoCollection fieldinfos   = fc.GetFields();
                    IFieldInfo           newFieldInfo = form.newFieldInfo;

                    for (int i = 0; i < fieldinfos.Count; i++)
                    {
                        IFieldInfo fieldinfo = fieldinfos.Get(i);
                        if (null == fieldinfo)
                        {
                            continue;
                        }
                        if (newFieldInfo.Name == fieldinfo.Name)
                        {
                            MessageBox.Show("已有同名字段,添加失败");
                            return;
                        }
                    }

                    fc.LockType = gviLockType.gviLockExclusiveSchema;
                    fc.AddField(newFieldInfo);
                    fc.LockType = gviLockType.gviLockSharedSchema;

                    // 往树上挂节点
                    TreeNode fieldNode = new TreeNode(newFieldInfo.Name, 1, 1);
                    selectNode.Nodes.Add(fieldNode);
                    fieldNode.ContextMenuStrip = this.contextMenuStrip4;
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
                MessageBox.Show("添加失败");
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                MessageBox.Show("添加失败");
            }
            finally
            {
                fc.LockType = gviLockType.gviLockSharedSchema;
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }
Exemple #6
0
        private void createFeatureClassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FeatureClassForm fcForm = new FeatureClassForm();

            if (fcForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            IDataSource     ds   = null;
            IFeatureDataSet dset = null;
            IFeatureClass   fc   = null;

            try
            {
                myTreeNode      node = (myTreeNode)selectNode.Parent;
                IConnectionInfo ci   = node.con;
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(selectNode.Text);

                // 定义字段
                IFieldInfoCollection fields = new FieldInfoCollection();
                IFieldInfo           field  = new FieldInfo();
                field.Name      = "Name";
                field.FieldType = gviFieldType.gviFieldString;
                field.Length    = 255;
                fields.Add(field);

                field                       = new FieldInfo();
                field.Name                  = "Groupid";
                field.FieldType             = gviFieldType.gviFieldInt32;
                field.RegisteredRenderIndex = true;  //为支持逻辑图层树控制图层显示,需要注册渲染索引
                fields.Add(field);

                field             = new FieldInfo();
                field.Name        = "Geometry";
                field.FieldType   = gviFieldType.gviFieldGeometry;
                field.GeometryDef = new GeometryDef();
                field.GeometryDef.GeometryColumnType = gviGeometryColumnType.gviGeometryColumnModelPoint; //模型
                field.RegisteredRenderIndex          = true;                                              //为支持空间列在RenderControl中显示出来,必须注册渲染索引
                fields.Add(field);

                fc = dset.CreateFeatureClass(fcForm.FeatureClassName, fields);

                //创建空间索引
                IGridIndexInfo index = new GridIndexInfo();
                //index.Name = fc.Guid;
                index.L1            = 500;
                index.L2            = 2000;
                index.L3            = 10000;
                index.GeoColumnName = "Geometry";
                fc.AddSpatialIndex(index as IIndexInfo);

                IRenderIndexInfo rInfo = new RenderIndexInfo();
                rInfo.GeoColumnName = "Geometry";
                rInfo.L1            = 500;
                fc.AddRenderIndex(rInfo);

                // 往树上挂节点
                TreeNode fcNode = new TreeNode(fcForm.FeatureClassName, 1, 1);
                fcNode.ContextMenuStrip = this.contextMenuStrip3;
                selectNode.Nodes.Add(fcNode);
                TreeNode fieldNode = new TreeNode("oid", 1, 1);
                fieldNode.ContextMenuStrip = this.contextMenuStrip4;
                fcNode.Nodes.Add(fieldNode);
                fieldNode = new TreeNode("Name", 1, 1);
                fieldNode.ContextMenuStrip = this.contextMenuStrip4;
                fcNode.Nodes.Add(fieldNode);
                fieldNode = new TreeNode("Groupid", 1, 1);
                fieldNode.ContextMenuStrip = this.contextMenuStrip4;
                fcNode.Nodes.Add(fieldNode);
                fieldNode = new TreeNode("Geometry", 1, 1);
                fieldNode.ContextMenuStrip = this.contextMenuStrip4;
                fcNode.Nodes.Add(fieldNode);
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// 创建数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void createDataSourceToolStripButton_Click(object sender, EventArgs e)
        {
            CreateDataSourceForm dsForm = new CreateDataSourceForm(true);

            if (dsForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            IConnectionInfo ci = new ConnectionInfo();

            switch (dsForm.ConnectionType)
            {
            case "gviConnectionMySql5x":
                ci.ConnectionType = gviConnectionType.gviConnectionMySql5x;
                break;

            case "gviConnectionFireBird2x":
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                break;

            case "gviConnectionSQLite3":
                ci.ConnectionType = gviConnectionType.gviConnectionSQLite3;
                break;
            }
            ci.Server   = dsForm.Server;
            ci.Port     = dsForm.Port;
            ci.Database = dsForm.Database;
            ci.UserName = dsForm.UserName;
            ci.Password = dsForm.Password;

            IDataSource ds = null;

            try
            {
                if (!dsFactory.HasDataSource(ci))
                {
                    ds = dsFactory.CreateDataSource(ci, null);
                    if (ds != null && CreateLogicTreeTable(ds))
                    {
                        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);
                        sourceNode.ContextMenuStrip = this.contextMenuStrip1;
                    }
                }
                else
                {
                    MessageBox.Show("数据源已存在");
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }
Exemple #8
0
        private void createDataSetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataSetForm setForm = new DataSetForm();

            if (setForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            IDataSource     ds   = null;
            IFeatureDataSet dset = null;

            try
            {
                myTreeNode      node = (myTreeNode)selectNode;
                IConnectionInfo ci   = node.con;
                ds = dsFactory.OpenDataSource(ci);
                ICoordinateReferenceSystem coorSys = coorFactory.CreateFromWKT(setForm.CoordString);
                dset = ds.CreateFeatureDataset(setForm.DatasetName, coorSys as SpatialCRS);

                //开起事务:往普通表里插入记录
                ds.StartEditing();
                bool saveEditing = false;
                if (CreateLCRecordOfFDS(ds, dset.Name))
                {
                    saveEditing = true;
                }
                else
                {
                    saveEditing = false;
                }
                ds.StopEditing(saveEditing);
                // 如果事务失败,则回退创建dataset动作
                if (saveEditing == false)
                {
                    ds.DeleteFeatureDataset(dset.Name);
                    MessageBox.Show("创建失败");
                    return;
                }

                // 往树上挂节点
                TreeNode setNode = new TreeNode(setForm.DatasetName, 1, 1);
                node.Nodes.Add(setNode);
                setNode.ContextMenuStrip = this.contextMenuStrip2;
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// 添加数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addDatasourceToolStripButton_Click(object sender, EventArgs e)
        {
            OpenDataSourceForm dsForm = new OpenDataSourceForm(false);

            if (dsForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            IConnectionInfo ci = new ConnectionInfo();

            switch (dsForm.ConnectionType)
            {
            case "gviConnectionMySql5x":
                ci.ConnectionType = gviConnectionType.gviConnectionMySql5x;
                break;

            case "gviConnectionFireBird2x":
                ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x;
                break;

            case "gviConnectionSQLite3":
                ci.ConnectionType = gviConnectionType.gviConnectionSQLite3;
                break;
            }
            ci.Server   = dsForm.Server;
            ci.Port     = dsForm.Port;
            ci.Database = dsForm.Database;
            ci.UserName = dsForm.UserName;
            ci.Password = dsForm.Password;

            IDataSource     ds      = null;
            IFeatureDataSet dataset = null;
            IFeatureClass   fc      = null;

            try
            {
                if (dsFactory == null)
                {
                    dsFactory = new DataSourceFactory();
                }
                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);
                }
                sourceNode.ContextMenuStrip = this.contextMenuStrip1;
                this.treeView1.Nodes.Add(sourceNode);

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

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

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

                        TreeNode fcNode = new TreeNode(fcname, 2, 2);
                        fcNode.ContextMenuStrip = this.contextMenuStrip3;
                        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.contextMenuStrip4;  // 绑定右键菜单
                            fcNode.Nodes.Add(fieldinfoNode);
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
                if (dataset != null)
                {
                    //Marshal.ReleaseComObject(dataset);
                    dataset = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
            }
        }
Exemple #10
0
        private void modifyFieldToolStripMenuItem_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           = null;
            IFeatureDataSet dset         = null;
            IFeatureClass   fc           = null;
            IFieldInfo      newFieldInfo = null;

            try
            {
                ds   = dsFactory.OpenDataSource(ci);
                dset = ds.OpenFeatureDataset(set_name);
                fc   = dset.OpenFeatureClass(fc_name);

                // 获取fieldinfo对象
                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)
                    {
                        newFieldInfo = fieldinfo;
                        break;
                    }
                }

                OperateFieldInfoForm form = new OperateFieldInfoForm(newFieldInfo);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    newFieldInfo = form.newFieldInfo;

                    fc.LockType = gviLockType.gviLockExclusiveSchema;
                    fc.ModifyField(newFieldInfo);
                    fc.LockType = gviLockType.gviLockSharedSchema;

                    // 修改树上的节点
                    selectNode.Text = newFieldInfo.Name;
                    MessageBox.Show("修改成功");
                }
            }
            catch (COMException comEx)
            {
                System.Diagnostics.Trace.WriteLine(comEx.Message);
                MessageBox.Show("修改失败");
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
                MessageBox.Show("修改失败");
            }
            finally
            {
                fc.LockType = gviLockType.gviLockSharedSchema;
                if (newFieldInfo != null)
                {
                    //Marshal.ReleaseComObject(newFieldInfo);
                    newFieldInfo = null;
                }
                if (fc != null)
                {
                    //Marshal.ReleaseComObject(fc);
                    fc = null;
                }
                if (dset != null)
                {
                    //Marshal.ReleaseComObject(dset);
                    dset = null;
                }
                if (ds != null)
                {
                    //Marshal.ReleaseComObject(ds);
                    ds = null;
                }
            }
        }