Esempio n. 1
0
        /// <summary>
        /// 保存发生更新变化的所有的要素信息
        /// </summary>
        /// <param name="eError"></param>
        /// <returns></returns>
        public Dictionary <string, Dictionary <int, List <IRow> > > GetModifyClsInfo(out Exception eError)
        {
            eError = null;
            Dictionary <string, Dictionary <int, List <IRow> > > feaChangeDic = null;

            //获得命名空间下发生变化的信息
            IWorkspaceEdit2 pWSEdit2 = v_WSEdit as IWorkspaceEdit2;

            if (pWSEdit2 == null)
            {
                eError = new Exception("编辑工作空间为空!");
                return(null);
            }

            //获取在一个编辑会话中发生更新变化数据
            IDataChangesEx pDataChangeEx = pWSEdit2.get_EditDataChanges(esriEditDataChangesType.esriEditDataChangesWithinSession);

            if (pDataChangeEx == null)
            {
                eError = new Exception("未发现更新变化数据!");
                return(null);
            }

            feaChangeDic = new Dictionary <string, Dictionary <int, List <IRow> > >();

            //获取发生更新变化的要素类集合
            IEnumBSTR pEnumString = pDataChangeEx.ModifiedClasses;  //发生变化的要素类

            pEnumString.Reset();
            string pModifyClsName = "";//发生更新变化的要素类名称

            pModifyClsName = pEnumString.Next();
            //遍历发生更新变化的要素类,并将相关信息保存下来
            while (pModifyClsName != null)
            {
                IDifferenceCursorEx pDifCusorEx = null; //游标
                int        pFeaOid     = -1;            //要素OID
                IRow       pSourceRow  = null;          //正在编辑的冲突要素行
                IRow       pDifRow     = null;          //上一编辑版本的冲突要素行
                ILongArray pDifIndices = null;          //字段索引

                if (pModifyClsName.Contains("."))
                {
                    pModifyClsName = pModifyClsName.Substring(pModifyClsName.IndexOf('.') + 1);
                }
                Dictionary <int, List <IRow> > stateRowDic = new Dictionary <int, List <IRow> >();
                List <IRow> rowLst = null;

                #region 保存新增加的要素信息
                rowLst = new List <IRow>();
                //新增数据游标
                pDifCusorEx = pDataChangeEx.ExtractEx(pModifyClsName, esriDifferenceType.esriDifferenceTypeInsert);
                if (pDifCusorEx == null)
                {
                    eError = new Exception("获取新增数据的游标发生错误!");
                    return(null);
                }
                pDifCusorEx.Next(out pFeaOid, out pSourceRow, out pDifRow, out pDifIndices);//pDifRow=null
                //遍历新增加的要素oid,并将其保存起来
                while (pFeaOid != -1)
                {
                    //将新增数据保存起来
                    if (!rowLst.Contains(pSourceRow))
                    {
                        rowLst.Add(pSourceRow);
                    }
                    pDifCusorEx.Next(out pFeaOid, out pSourceRow, out pDifRow, out pDifIndices);
                }
                if (rowLst != null)
                {
                    if (rowLst.Count > 0)
                    {
                        stateRowDic.Add(1, rowLst);
                    }
                }
                #endregion

                #region 保存修改后的要素信息
                rowLst = new List <IRow>();
                //修改数据游标
                pDifCusorEx = pDataChangeEx.ExtractEx(pModifyClsName, esriDifferenceType.esriDifferenceTypeUpdateNoChange);
                if (pDifCusorEx == null)
                {
                    eError = new Exception("获取修改数据的游标发生错误!");
                    return(null);
                }
                pDifCusorEx.Next(out pFeaOid, out pSourceRow, out pDifRow, out pDifIndices);
                //遍历修改后的要素OID,并将其保存起来
                while (pFeaOid != -1)
                {
                    //将修改后的数据保存起来
                    if (!rowLst.Contains(pSourceRow))
                    {
                        rowLst.Add(pSourceRow);
                    }

                    pDifCusorEx.Next(out pFeaOid, out pSourceRow, out pDifRow, out pDifIndices);
                }
                if (rowLst != null)
                {
                    if (rowLst.Count > 0)
                    {
                        stateRowDic.Add(2, rowLst);
                    }
                }
                #endregion

                #region 保存删除的要素信息
                rowLst = new List <IRow>();
                //删除数据游标
                pDifCusorEx = pDataChangeEx.ExtractEx(pModifyClsName, esriDifferenceType.esriDifferenceTypeDeleteNoChange);
                if (pDifCusorEx == null)
                {
                    eError = new Exception("获取删除数据的游标发生错误!");
                    return(null);
                }
                pDifCusorEx.Next(out pFeaOid, out pSourceRow, out pDifRow, out pDifIndices);//pSourceRow
                //遍历删除的要素OID,并将其保存起来
                while (pFeaOid != -1)
                {
                    //将删除的数据保存起来(数据库版本数据)
                    if (!rowLst.Contains(pDifRow))
                    {
                        rowLst.Add(pDifRow);
                    }
                    pDifCusorEx.Next(out pFeaOid, out pSourceRow, out pDifRow, out pDifIndices);
                }
                if (rowLst != null)
                {
                    if (rowLst.Count > 0)
                    {
                        stateRowDic.Add(3, rowLst);
                    }
                }
                #endregion

                if (!feaChangeDic.ContainsKey(pModifyClsName))
                {
                    feaChangeDic.Add(pModifyClsName, stateRowDic);
                }
                pModifyClsName = pEnumString.Next();
            }

            return(feaChangeDic);
        }