ArcGIS Engine开发的ArcGIS 版本管理的功能

这是以前的ArcGIS Engine开发成果,主要是Geodatabase方面的,模仿ArcGIS版本的流程
系统环境:

VS2010、ArcGIS Engine10、DevExpress721(第三方控件,比较常用易于下载)

------------------------------------------------------------------

我跟大家分享了存在#百度网盘#上的文件,“DXperienceEval-7.2.1.exe”,点击链接进行查看和下载。 http://t.cn/zWsdZRY  (分享自 @百度网盘官方微博)
------------------------------------------------------------------

系统的连接参数都写在代码里面了,如果有问题,跟踪一下代码即可解决

相关功能:

1:打开ArcSDE版本数据

2:切换版本

3:创建新版本

4:查看版本信息

5:协调版本

6:冲突解决

7:提交版本

8:历史归档管理


因为这是很早的东西了,是自己兴趣开发的,会有相关bug,如果有一定基础肯定可以顺利的进行参考!希望能给大家带来帮助!


仅供参考!


下图为系统界面



下图为创建子版本



下图为协调版本



下图为冲突对话框



核心代码冲突对话框

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using LSCommonHelper;
using LSGISHelper;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using DevExpress.XtraGrid.Views.Grid;
namespace LSVersion.Version
{
    public partial class ConflictsForm : Form
    {
        public ConflictsForm()
        {
            InitializeComponent();
        }
        private IVersion m_peditVersion=null;
        public IVersion EditVersion
        {
            get { return m_peditVersion; }
            set { m_peditVersion = value; }
        }
        private IVersion m_ptargetVersion = null;
        public IVersion TargetVersion
        {
            get { return m_ptargetVersion; }
            set { m_ptargetVersion = value; }
        }
        private void ConflictsForm_Load(object sender, EventArgs e)
        {
            Init();
        }
        private IFeatureWorkspace featureWorkspace = null;
        private IFeatureWorkspace commonAncestorFWorkspace = null;
        private IFeatureWorkspace preReconcileFWorkspace = null;
        private IFeatureWorkspace reconcileFWorkspace = null;
        private AxMapControl m_pMapControl = null;
        public AxMapControl MapControl
        {
            get { return m_pMapControl; }
            set { m_pMapControl = value; }
        }

        IFeature featurePreReconcile = null;
        IFeature featureReconcile = null;
        IFeature featureCommonAncestor = null;
        private void ClickID(string sLayerName, int sOID, TreeNode sSelNode)
        {
            IFeatureClass featureClassPreReconcile =
                    preReconcileFWorkspace.OpenFeatureClass(sLayerName);
            IFeatureClass featureClassReconcile =
              reconcileFWorkspace.OpenFeatureClass(sLayerName);
            IFeatureClass featureClassCommonAncestor =
              commonAncestorFWorkspace.OpenFeatureClass(sLayerName);
          
        
            this.axMapControl1.ClearLayers();
            this.axMapControl2.ClearLayers();
            this.axMapControl3.ClearLayers();

            this.listView1.Items.Clear();
            int flag = -1;
            if (sSelNode.Parent.Text == "更新-更新冲突")
            {
                flag = 0;
            }
            else if (sSelNode.Parent.Text == "删除-更新冲突")
            {
                flag = 1;
            }
            else if (sSelNode.Parent.Text == "更新-删除冲突")
            {
                flag = 2;
            }
            IFeatureLayer PreReconcileFL = new FeatureLayerClass();
            PreReconcileFL.FeatureClass = featureClassPreReconcile;

            IFeatureLayer ReconcileFL = new FeatureLayerClass();
            ReconcileFL.FeatureClass = featureClassReconcile;

            IFeatureLayer CommonAncestorFL = new FeatureLayerClass();
            CommonAncestorFL.FeatureClass = featureClassCommonAncestor;

            this.axMapControl1.Map.AddLayer(ReconcileFL as ILayer);
            this.axMapControl2.Map.AddLayer(PreReconcileFL as ILayer);
            this.axMapControl3.Map.AddLayer(CommonAncestorFL as ILayer);


         
            try
            {
                featurePreReconcile =
                                   featureClassPreReconcile.GetFeature(sOID);
            }
            catch { this.axMapControl2.ClearLayers(); }
            try
            {
                featureReconcile = featureClassReconcile.GetFeature(sOID);
            }
            catch { this.axMapControl1.ClearLayers(); }
            try
            {
                featureCommonAncestor =
                 featureClassCommonAncestor.GetFeature(sOID);
            }
            catch { this.axMapControl3.ClearLayers(); }
            IField pField = null;
            if (flag == 0)
            {
                for (int i = 0; i < featureReconcile.Fields.FieldCount; i++)
                {
                    pField = featureReconcile.Fields.get_Field(i);
                    ListViewItem lv = new ListViewItem();
                    lv.SubItems.Add(pField.AliasName);
                    lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
                    lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featurePreReconcile, pField.AliasName));
                    lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
                    lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
                    this.listView1.Items.Add(lv);
                }
            }
            else if (flag == 1)
            {
                for (int i = 0; i < featureReconcile.Fields.FieldCount; i++)
                {
                    pField = featureReconcile.Fields.get_Field(i);
                    ListViewItem lv = new ListViewItem();
                    lv.SubItems.Add(pField.AliasName);
                    if (i == 0)
                    {
                     
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
                        lv.SubItems.Add("Deleted");
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
                    }
                    else
                    {

                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
                        lv.SubItems.Add("");
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureReconcile, pField.AliasName));
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
                    }
                    this.listView1.Items.Add(lv);
                }
            }
            else if (flag == 2)
            {
                for (int i = 0; i < featurePreReconcile.Fields.FieldCount; i++)
                {
                    pField = featurePreReconcile.Fields.get_Field(i);
                    ListViewItem lv = new ListViewItem();
                    lv.SubItems.Add(pField.AliasName);
                    if (i == 0)
                    {
                        lv.SubItems.Add("Deleted");
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featurePreReconcile, pField.AliasName));
                        lv.SubItems.Add("Deleted");
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
                    }
                    else
                    {
                        lv.SubItems.Add("");
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featurePreReconcile, pField.AliasName));
                        lv.SubItems.Add("");
                        lv.SubItems.Add(LSGISHelper.FeatureHelper.GetFeatureStringValue(featureCommonAncestor, pField.AliasName));
                    }
                    this.listView1.Items.Add(lv);
                }
            }
            Flash(this.axMapControl1, featureReconcile);
            Flash(this.axMapControl2, featurePreReconcile);
            Flash(this.axMapControl3, featureCommonAncestor);

            #region//Display
            pageCon = this.m_pMapControl.ActiveView.GraphicsContainer;
            pageCon.DeleteAllElements();
            Display(featureReconcile);
            Display(featurePreReconcile);
            Display(featureCommonAncestor);
          
            #endregion

        }
        IGraphicsContainer pageCon = null;
        private void Display(IFeature pFea)
        {
            IFillShapeElement pPEle = new PolygonElementClass();
            IFillSymbol pFillSym = new SimpleFillSymbolClass();
            RgbColorClass rgbClr = new RgbColorClass();
            rgbClr.Transparency = 0;

            ILineSymbol pLineSym = new SimpleLineSymbolClass();
            pLineSym.Color = LSGISHelper.ColorHelper.CreateRandomColor();
            pLineSym.Width = 4;

            pFillSym.Color = rgbClr;
            pFillSym.Outline = pLineSym;
            pPEle.Symbol = pFillSym;
            IElement pEle = pPEle as IElement;
            pEle.Geometry = pFea.ShapeCopy;


      
            this.m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            pageCon.AddElement(pEle, 0);

        }
        private void Flash(AxMapControl axMapControl3, IFeature pFea)
        {
            if (pFea != null)
            {
                axMapControl3.Extent = pFea.Shape.Envelope;
                axMapControl3.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                axMapControl3.FlashShape(pFea.ShapeCopy);
            }
        }
        private void Init()
        {
            this.myTreeView1.Nodes.Clear();
            this.listView1.Items.Clear();
          
            try
            {
                IWorkspaceEdit workspaceEdit = (IWorkspaceEdit2)m_peditVersion;
                IVersionEdit4 versionEdit4 = (IVersionEdit4)workspaceEdit;
                 featureWorkspace = m_peditVersion as IFeatureWorkspace;
                // Get the various versions on which to output information.
                 commonAncestorFWorkspace = (IFeatureWorkspace)
                  versionEdit4.CommonAncestorVersion;
                 preReconcileFWorkspace = (IFeatureWorkspace)
                  versionEdit4.PreReconcileVersion;
                 reconcileFWorkspace = (IFeatureWorkspace)
                  versionEdit4.ReconcileVersion;

                IEnumConflictClass enumConflictClass = versionEdit4.ConflictClasses;

                TreeNode pRootNode = new TreeNode();
                pRootNode.Text = "Conflicts";
                this.myTreeView1.Nodes.Add(pRootNode);

                IConflictClass conflictClass = null;
                while ((conflictClass = enumConflictClass.Next()) != null)
                {
                    IDataset dataset = (IDataset)conflictClass;

                    // Make sure class is a feature class.
                    if (dataset.Type == esriDatasetType.esriDTFeatureClass)
                    {
                        String datasetName = dataset.Name;
                        TreeNode pRoot2Node = new TreeNode();
                        pRoot2Node.Text = datasetName;
                        this.myTreeView1.Nodes[0].Nodes.Add(pRoot2Node);

                        IFeatureClass featureClass = featureWorkspace.OpenFeatureClass
                          (datasetName);

                      //  Console.WriteLine("Conflicts on feature class {0}", datasetName);
                        // Get conflict feature classes on the three reconcile versions.
                  

                        // Get all UpdateUpdate conflicts.
                        ISelectionSet updateUpdates = conflictClass.UpdateUpdates;
                        if (updateUpdates.Count > 0)
                        {
                            TreeNode pUUNode = new TreeNode();
                            pUUNode.Text = "更新-更新冲突";
                            pRoot2Node.Nodes.Add(pUUNode);
                            #region 更新更新
                            // Iterate through each OID, outputting information.
                            IEnumIDs enumIDs = updateUpdates.IDs;
                            int oid =  enumIDs.Next();
                        
                                while (oid != -1)
                                //loop through all conflicting features
                                {
                                    // Console.WriteLine("UpdateUpdate conflicts on feature {0}", oid);
                                    // Get conflict feature on the three reconcile versions.
                                    TreeNode pOidNode = new TreeNode();
                                    pOidNode.Text ="OID:"+ oid.ToString();
                                    pUUNode.Nodes.Add(pOidNode);
                                    #region---处理
                                    // Check to make sure each shape is different than the common ancestor (conflict is on shape field).

                                
                                    #endregion
                                    oid = enumIDs.Next();
                                }
                           
                            #endregion
                        }
                          ISelectionSet deleteUpdates = conflictClass.DeleteUpdates;
                          if (deleteUpdates.Count > 0)
                          {
                              TreeNode pDUNode = new TreeNode();
                              pDUNode.Text = "删除-更新冲突";
                              pRoot2Node.Nodes.Add(pDUNode);
                              #region 删除更新
                              // Iterate through each OID, outputting information.
                              IEnumIDs enumIDs = deleteUpdates.IDs;
                              int oid = enumIDs.Next();

                              while (oid != -1)
                              //loop through all conflicting features
                              {
                                  // Console.WriteLine("UpdateUpdate conflicts on feature {0}", oid);
                                  // Get conflict feature on the three reconcile versions.
                                  TreeNode pOidNode = new TreeNode();
                                  pOidNode.Text = "OID:" + oid.ToString();
                                  pDUNode.Nodes.Add(pOidNode);
                    
                                  oid = enumIDs.Next();
                              }
                              #endregion
                          }
                          ISelectionSet Updatedeletes = conflictClass.UpdateDeletes;
                          if (Updatedeletes.Count > 0)
                          {
                              TreeNode pUDNode = new TreeNode();
                              pUDNode.Text = "更新-删除冲突";
                              pRoot2Node.Nodes.Add(pUDNode);
                              #region 更新删除
                              // Iterate through each OID, outputting information.
                              IEnumIDs enumIDs = Updatedeletes.IDs;
                              int oid = enumIDs.Next();

                              while (oid != -1)
                              //loop through all conflicting features
                              {
                              
                                  TreeNode pOidNode = new TreeNode();
                                  pOidNode.Text = "OID:" + oid.ToString();
                                  pUDNode.Nodes.Add(pOidNode);

                                  oid = enumIDs.Next();
                              }
                              #endregion
                          }
                    }
                }
                this.myTreeView1.ExpandAll();
            }
            catch (System.Runtime.InteropServices.COMException comExc)
            {
                Console.WriteLine("Error Message: {0}, Error Code: {1}", comExc.Message,
                  comExc.ErrorCode);
            }
        }

        // Method to determine if shape field is in conflict.
        private bool IsShapeInConflict(IFeature commonAncestorFeature, IFeature
          preReconcileFeature, IFeature reconcileFeature)
        {
            // 1st check: Common Ancestor with PreReconcile.
            // 2nd check: Common Ancestor with Reconcile.
            // 3rd check: Reconcile with PreReconcile (case of same change on both versions)
            if (IsGeometryEqual(commonAncestorFeature.ShapeCopy,
              preReconcileFeature.ShapeCopy) || IsGeometryEqual
              (commonAncestorFeature.ShapeCopy, reconcileFeature.ShapeCopy) ||
              IsGeometryEqual(reconcileFeature.ShapeCopy, preReconcileFeature.ShapeCopy)
              )
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        // Method returning if two shapes are equal to one another.
        private bool IsGeometryEqual(IGeometry shape1, IGeometry shape2)
        {
            if (shape1 == null & shape2 == null)
            {
                return true;
            }
            else if (shape1 == null ^ shape2 == null)
            {
                return false;
            }
            else
            {
                IClone clone1 = (IClone)shape1;
                IClone clone2 = (IClone)shape2;
                return clone1.IsEqual(clone2);
            }
        }

        private void myTreeView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.myTreeView1.Nodes.Count > 0)
            {
                TreeNode sSelNode = this.myTreeView1.SelectedNode;
                if (sSelNode != null)
                {
                    string sSel = sSelNode.Text;
                    if (LSCommonHelper.OtherHelper.GetLeftName(sSel, ":") == "OID")
                    {
                        string sLayerName = sSelNode.Parent.Parent.Text;
                        int sOID = LSCommonHelper.ConvertHelper.ObjectToInt(
                            LSCommonHelper.OtherHelper.GetRightName(sSel, ":"));
                        ClickID(sLayerName, sOID, sSelNode);
                    }
                }

            }
        }

        private void ConflictsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            pageCon.DeleteAllElements();
        }
        private void replaceObjectWith(IFeature pfea,
            TreeNode pNode )
        {
            pageCon.DeleteAllElements();
            TreeNode sSelNode = this.myTreeView1.SelectedNode;
            if (sSelNode != null)
            {
                string sSel = sSelNode.Text;
                if (LSCommonHelper.OtherHelper.GetLeftName(sSel, ":") == "OID")
                {
                    string sLayerName = sSelNode.Parent.Parent.Text;
                    int sOID = LSCommonHelper.ConvertHelper.ObjectToInt(
                        LSCommonHelper.OtherHelper.GetRightName(sSel, ":"));
                    IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(sLayerName);
                 
                   
                    IFeature feature = featureClass.GetFeature(sOID);
                    feature.Shape = pfea.ShapeCopy;
                    feature.Store();
                    m_pMapControl.ActiveView.Refresh();
                }
            }
            
        }
        private TreeNode sSelNode = null;
        private void myTreeView1_MouseDown(object sender, MouseEventArgs e)
        {
             sSelNode = this.myTreeView1.GetNodeAt(e.X, e.Y);
            if (sSelNode == null) return;

            if (e.Button == MouseButtons.Left)
            {//左键

            }
            else
            {
                System.Drawing.Point aPt = new System.Drawing.Point(e.X, e.Y);
             //   TreeNode sSelNode = this.myTreeView1.SelectedNode;
                if (sSelNode != null)
                {
                    string sSel = sSelNode.Text;
                    if (LSCommonHelper.OtherHelper.GetLeftName(sSel, ":") == "OID")
                    {

                    this.contextMenuStrip1.Show(this.myTreeView1, aPt);
                    }
                }
               
            }
        }

        private void replaceObjectWithCommonAncestorVersionToolStripMenuItem_Click(object sender, EventArgs e)
        {

            replaceObjectWith(featureCommonAncestor,  sSelNode);
        }

        private void replaceObjectWithPreReconcileVersionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            replaceObjectWith(featurePreReconcile, sSelNode);
        }

        private void replaceObjectWithConflictsVersionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            replaceObjectWith(featureReconcile, sSelNode);
        }

        private void mergeGeometryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MergeGeometry(featureCommonAncestor, featurePreReconcile, featureReconcile, sSelNode);
        }

        private void MergeGeometry(IFeature featureCommonAncestor
            , IFeature featurePreReconcile, IFeature featureReconcile,TreeNode pNode)
        {
             pageCon.DeleteAllElements();
            TreeNode sSelNode = this.myTreeView1.SelectedNode;
            if (sSelNode != null)
            {
                string sSel = sSelNode.Text;
                if (LSCommonHelper.OtherHelper.GetLeftName(sSel, ":") == "OID")
                {
                    string sLayerName = sSelNode.Parent.Parent.Text;
                    int sOID = LSCommonHelper.ConvertHelper.ObjectToInt(
                        LSCommonHelper.OtherHelper.GetRightName(sSel, ":"));
                    IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(sLayerName);
                    // Check to make sure each shape is different than the common ancestor (conflict is on shape field).
                    if (IsShapeInConflict(featureCommonAncestor,
                        featurePreReconcile, featureReconcile))
                    {
                        //Console.WriteLine(
                        //    " Shape attribute has changed on both versions...");

                        // Geometries are in conflict ... merge geometries.
                        try
                        {
                            IConstructMerge constructMerge = new
                                GeometryEnvironmentClass();
                            IGeometry newGeometry =
                                constructMerge.MergeGeometries
                                (featureCommonAncestor.ShapeCopy,
                                featureReconcile.ShapeCopy,
                                featurePreReconcile.ShapeCopy);

                            // Setting new geometry as a merge between the two versions.
                            IFeature feature = featureClass.GetFeature(sOID);
                            feature.Shape = newGeometry;
                            feature.Store();
                            //updateUpdates.RemoveList(1, ref oid);
                            //conflictsRemoved = true;
                        }
                        catch (System.Runtime.InteropServices.COMException comExc)
                        {
                            // Check if the error is from overlapping edits.
                            if (comExc.ErrorCode == (int)
                                fdoError.FDO_E_WORKSPACE_EXTENSION_DATASET_CREATE_FAILED || comExc.ErrorCode == (int)fdoError.FDO_E_WORKSPACE_EXTENSION_DATASET_DELETE_FAILED)
                            {
                                // Edited areas overlap.
                             LSCommonHelper.MessageBoxHelper.ShowMessageBox(
                                    "Error from overlapping edits on feature {0}"+
                                    " Can't merge overlapping edits to same feature.");
                            }
                            else
                            {
                                // Unexpected COM exception, throw this to the exception handler.
                                throw comExc;
                            }
                        }
                    }
                }
            }

        }

    }
}

相关代码下载地址,下载完毕后,请使用kuaiya解压即可,WINRAR不行


-------------------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
------------------------------------------------------------------------------------------------------

  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值