Пример #1
0
        private void FrmProgressBar_Load(object sender, EventArgs e)
        {
            progressBar.SetStep(1);
            progressBar.SetMax(maxCount);

            //获取主屏幕的宽高
            System.Drawing.Rectangle rect = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
            //宽(像素)
            int w = rect.Width;
            //高(像素)
            int h = rect.Height;

            //因为button只需要向左右偏移,所以在Y轴上就没有改变,继续保留了原来的大小
            this.Location = new Point(w / 2, h / 2);
        }
Пример #2
0
        private void buttonXCheck_Click(object sender, EventArgs e)
        {
            //进度条
            ClsBarSync pBarX1 = new ClsBarSync(progressBarX1);

            pBarX1.SetStep(1);
            pBarX1.SetMax(entiTable.RowCount(null));


            bool hasENTIID = false;

            if (entiTable == null)
            {
                return;
            }

            for (int i = 0; i < entiTable.Fields.FieldCount; i++)
            {
                if (entiTable.Fields.get_Field(i).Name == "ENTIID")
                {
                    hasENTIID = true;
                }
            }
            if (!hasENTIID)
            {
                MessageBox.Show("不存在实体编码字段!");
            }

            DataTable dtentble = ZJGISCommon.Classes.ClsITableDataTable.ToDataTable(entiTable);
            DataTable dtresult = new DataTable();

            dtresult = dtentble.Clone();
            //dt.PrimaryKey = new System.Data.DataColumn[] { dt.Columns["OBJECTID"] };
            //string entiid = null;
            //DataView dv = dt.DefaultView;
            //string entiid = "ENTIID";
            //dv.RowFilter = "select * "+"from " + entiTable + "group by " + entiid+ "WHERE " +"Count(" + entiid + ")>1" ;
            //int i = dv.Count;
            //string[] strarr = GetNamesFromDataTable(dt);
            var result = from t in dtentble.AsEnumerable()
                         group t by t.Field <string>("ENTIID") into g
                             where g.Count() > 1
                         select g;

            foreach (var item in result)
            {
                if (item == null)
                {
                    MessageBox.Show("实体表不存在重复的地理编码!");
                }
                else
                {
                    this.labelX2.Visible       = true;
                    this.progressBarX1.Visible = true;

                    int test = entiTable.RowCount(null);

                    for (int i = 0; i < dtentble.Rows.Count; i++)
                    {
                        string TES = dtentble.Rows[i]["ENTIID"].ToString();
                        if (dtentble.Rows[i]["ENTIID"].ToString() == item.Key)
                        {
                            //DataRow rowtemp = dtentble.Rows[i];

                            dtresult.Rows.Add(dtentble.Rows[i].ItemArray);
                        }
                        pBarX1.PerformOneStep();
                    }
                }
            }

            if (dtresult.Rows.Count > 1)
            {
                FrmResultDGV  frmResult = new ZJGISGCoding.Forms.FrmResultDGV();
                BindingSource bs        = new BindingSource();
                bs.DataSource = dtresult;
                frmResult.dataChild.DataSource = bs;
                frmResult.ShowDialog();
            }
            else
            {
                MessageBox.Show("实体表不存在重复的地理编码!");
            }
        }
Пример #3
0
        private List <ClsUpdateInfo> GetUpdateInfo(IFeatureLayer toUpdateLyr, IFeatureLayer updatedLyr)
        {
            List <ClsUpdateInfo> updateInfos = new List <ClsUpdateInfo>();

            string usourceField     = ClsConfig.LayerConfigs[(updatedLyr.FeatureClass as IDataset).Name].SourceName;
            string fromVersionField = ClsConfig.LayerConfigs[(updatedLyr.FeatureClass as IDataset).Name].StartVersion;
            string toVersionField   = ClsConfig.LayerConfigs[(updatedLyr.FeatureClass as IDataset).Name].EndVersion;
            string guidField        = ClsConfig.LayerConfigs[(updatedLyr.FeatureClass as IDataset).Name].GUID;
            //只查询一个字段
            //获取更新数据的当前版本号
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.WhereClause = "USOURSE = '" + usourceField + "'";
            ICursor rowCursor      = this._versionTable.Search(queryFilter, false);
            IRow    row            = rowCursor.NextRow();
            int     currentVersion = 0;

            while (row != null)
            {
                string version    = row.get_Value(row.Fields.FindField("VERSION_ID")).ToString();
                int    versionInt = Int32.Parse(version);
                if (versionInt > currentVersion)
                {
                    currentVersion = versionInt;
                }
                row = rowCursor.NextRow();
            }
            //查询两个字段
            //获取更新数据的版本号和当前版本号的关系
            IFeatureCursor pCursor  = null;
            IFeature       pFeature = null;

            queryFilter             = new QueryFilterClass();
            queryFilter.WhereClause = fromVersionField + " = '" + currentVersion.ToString() + "' or " + toVersionField + " = '" + currentVersion.ToString() + "'";
            pCursor = updatedLyr.FeatureClass.Search(queryFilter, false);
            if (pCursor != null)
            {
                pFeature = pCursor.NextFeature();
            }

            ClsBarSync pBarEntiUpdate = new ClsBarSync(progressBarXEntiUpdate);

            pBarEntiUpdate.SetMax(updatedLyr.FeatureClass.FeatureCount(queryFilter));

            //两个while循环遍历两个图层中的每一个要素
            while (pFeature != null)
            {
                string startVersion = pFeature.get_Value(pFeature.Fields.FindField(fromVersionField)).ToString();
                string endVersion   = pFeature.get_Value(pFeature.Fields.FindField(toVersionField)).ToString();
                string guid         = pFeature.get_Value(pFeature.Fields.FindField(guidField)).ToString();
                //起始号为当前版本,终止号为99999的话就是新增的要素
                if (startVersion == currentVersion.ToString() && endVersion == "99999")
                {
                    ClsUpdateInfo ui = new ClsUpdateInfo();
                    ui.UpdateState = "New";
                    ui.GUID        = guid;
                    ui.Feature     = pFeature;
                    ui.ToUpdateLyr = toUpdateLyr;
                    ui.UpdatedLyr  = updatedLyr;
                    updateInfos.Add(ui);
                }
                //起始号不同,终止号为当前版本,则为删除
                else if (startVersion != currentVersion.ToString() && endVersion == currentVersion.ToString())
                {
                    ClsUpdateInfo ui = new ClsUpdateInfo();
                    ui.UpdateState = "Delete";
                    ui.GUID        = guid;
                    ui.Feature     = pFeature;
                    ui.ToUpdateLyr = toUpdateLyr;
                    ui.UpdatedLyr  = updatedLyr;
                    updateInfos.Add(ui);
                }
                else
                {
                }

                pBarEntiUpdate.PerformOneStep();
                pFeature = pCursor.NextFeature();
            }

            return(updateInfos);
        }
Пример #4
0
        /// <summary>
        /// 遍历更新图层和待更新图层-获取更新信息-guid对比,未使用
        /// </summary>
        /// <param name="toUpdateLyr">原始图层</param>
        /// <param name="updatedLyr">待更新图层</param>
        /// <returns></returns>
        private List <ClsUpdateInfo> GetUpdateInfoDisposed(IFeatureLayer toUpdateLyr, IFeatureLayer updatedLyr)
        {
            string guidFieldTo = ClsConfig.LayerConfigs[(toUpdateLyr.FeatureClass as IDataset).Name].GUID;
            string fromFieldTo = ClsConfig.LayerConfigs[(toUpdateLyr.FeatureClass as IDataset).Name].StartVersion;
            string endFieldTo  = ClsConfig.LayerConfigs[(toUpdateLyr.FeatureClass as IDataset).Name].EndVersion;

            string guidFieldEd = ClsConfig.LayerConfigs[(updatedLyr.FeatureClass as IDataset).Name].GUID;
            string fromFieldEd = ClsConfig.LayerConfigs[(updatedLyr.FeatureClass as IDataset).Name].StartVersion;
            string endFieldEd  = ClsConfig.LayerConfigs[(updatedLyr.FeatureClass as IDataset).Name].EndVersion;

            List <ClsUpdateInfo> updateInfos = new List <ClsUpdateInfo>();

            IFeatureCursor pCursor  = null;
            IFeature       pFeature = null;

            pCursor = updatedLyr.FeatureClass.Search(null, false);
            if (pCursor != null)
            {
                pFeature = pCursor.NextFeature();
            }

            ClsBarSync pBarEntiUpdate = new ClsBarSync(progressBarXEntiUpdate);

            pBarEntiUpdate.SetMax(1);
            pBarEntiUpdate.SetMax(updatedLyr.FeatureClass.FeatureCount(null));

            //两个while循环遍历两个图层中的每一个要素
            while (pFeature != null)
            {
                string guid         = pFeature.get_Value(pFeature.Fields.FindField(guidFieldEd)).ToString();
                string startVersion = pFeature.get_Value(pFeature.Fields.FindField(fromFieldEd)).ToString();
                string endVersion   = pFeature.get_Value(pFeature.Fields.FindField(endFieldEd)).ToString();

                IFeatureCursor pCursorToUpdate  = null;
                IFeature       pFeatureToUpdate = null;
                //查询两个字段
                IQueryFilter queryFilter = new QueryFilterClass();
                queryFilter.WhereClause = guidFieldTo + " = '" + guid + "'";
                pCursorToUpdate         = toUpdateLyr.FeatureClass.Search(queryFilter, false);
                if (pCursorToUpdate != null)
                {
                    pFeatureToUpdate = pCursorToUpdate.NextFeature();
                }
                if (pFeatureToUpdate == null)//没找到GUID相同的,说明是新增的
                {
                    ClsUpdateInfo ui = new ClsUpdateInfo();
                    ui.UpdateState = "New";
                    ui.GUID        = guid;
                    ui.Feature     = pFeature;
                    ui.ToUpdateLyr = toUpdateLyr;
                    ui.UpdatedLyr  = updatedLyr;
                    updateInfos.Add(ui);
                }
                while (pFeatureToUpdate != null)
                {
                    string startVersionToUpdate = pFeatureToUpdate.get_Value(pFeatureToUpdate.Fields.FindField(fromFieldTo)).ToString();
                    string endVersionToUpdate   = pFeatureToUpdate.get_Value(pFeatureToUpdate.Fields.FindField(endFieldTo)).ToString();

                    if (startVersionToUpdate == startVersion && endVersionToUpdate == endVersion)//版本号没变
                    {
                        break;
                    }
                    else
                    {
                        if (startVersionToUpdate == startVersion)//起始号相同,终止号不同,说明要素被删除了
                        {
                            ClsUpdateInfo ui = new ClsUpdateInfo();
                            ui.UpdateState = "Delete";
                            ui.GUID        = guid;
                            ui.Feature     = pFeature;
                            ui.ToUpdateLyr = toUpdateLyr;
                            ui.UpdatedLyr  = updatedLyr;
                            updateInfos.Add(ui);
                            break;
                        }
                        else if (endVersionToUpdate == endVersion)//起始号不同,终止号相同,说明要素被更新了,因为更新的要素才可能出现guid相同,起始号不同
                        {
                            ClsUpdateInfo ui = new ClsUpdateInfo();
                            ui.UpdateState = "Update";
                            ui.GUID        = guid;
                            ui.Feature     = pFeature;
                            ui.ToUpdateLyr = toUpdateLyr;
                            ui.UpdatedLyr  = updatedLyr;
                            updateInfos.Add(ui);
                            break;
                        }
                        else
                        {
                            pFeatureToUpdate = pCursorToUpdate.NextFeature();
                        }
                    }
                }
                pBarEntiUpdate.PerformOneStep();
                pFeature = pCursor.NextFeature();
            }

            return(updateInfos);
        }
Пример #5
0
        //private static IFeatureWorkspace m_FeatureWorkspace;

        /// <summary>
        /// 数据编码(自动赋值编码)
        /// </summary>
        /// <param name="source">源要素类</param>
        /// <param name="target">目标要素类</param>
        /// <param name="relation">匹配结果表</param>
        /// <param name="updateRela">欲更新的属性表字段</param>
        /// <param name="pProgressBarX"></param>
        /// <param name="targetFeatureWorkspace">待匹配图层路径</param>
        /// <returns></returns>
        //public static bool UpdateData(IFeatureClass sourceFcls, IFeatureClass targetFcls, ITable resultTable, Dictionary<string, string> updateRela
        //    , ProgressBarX pProgressBarX, IFeatureWorkspace targetFeatureWorkspace)
        public static bool UpdateData(IFeatureClass sourceFcls, IFeatureClass targetFcls, ITable resultTable,
                                      ProgressBarX pProgressBarX, IFeatureWorkspace targetFeatureWorkspace)
        {
            ClsBarSync progressBar = new ClsBarSync(pProgressBarX);

            progressBar.SetStep(1);
            progressBar.SetMax(resultTable.RowCount(null));

            //检查参数
            if (sourceFcls == null || targetFcls == null || resultTable == null)
            {
                return(false);
            }

            #region 原注释
            //当欲更新字段在目标要素类中不存在时,新建字段
            //foreach (string item in fields)
            //{
            //    if (target.FindField(item) == -1)
            //    {
            //        IField addedField = source.Fields.get_Field(source.FindField(item));
            //        target.AddField(addedField);
            //    }
            //}
            #endregion
            //20170914 注释掉

            ////当欲更新字段在目标要素类中不存在时,新建字段
            //foreach (KeyValuePair<string, string> item in updateRela)
            //{
            //    if (targetFcls.FindField(item.Value) == -1)
            //    {
            //        IField addedField = new FieldClass();
            //        IFieldEdit pFieldEdit = addedField as IFieldEdit;
            //        pFieldEdit.Name_2 = item.Value;
            //        pFieldEdit.AliasName_2 = item.Value;
            //        pFieldEdit.Editable_2 = true;
            //        pFieldEdit.Required_2 = false;
            //        pFieldEdit.IsNullable_2 = true;
            //        targetFcls.AddField(addedField);
            //    }
            //}
            IWorkspaceEdit2 pWorkspaceEdit = targetFeatureWorkspace as IWorkspaceEdit2;
            pWorkspaceEdit.StartEditing(false);
            pWorkspaceEdit.StartEditOperation();

            #region 20170515注释掉
            //ClsUpdateCommon.EnableAchive(target.AliasName, targetFeatureWorkspace);
            //IHistoricalWorkspace pHistoricalWorkspace = targetFeatureWorkspace as IHistoricalWorkspace;
            //DateTime dTime=DateTime.Now;
            //pHistoricalWorkspace.AddHistoricalMarker(dTime.ToString(), dTime);//严格应该为数据库时间
            #endregion

            #region 原来注释
            //foreach (KeyValuePair<string, string> item in updateRela)
            //{
            //    if (target.FindField(item.Value) == -1)
            //    {
            //        IField addedField = new FieldClass();
            //        IFieldEdit pFieldEdit = addedField as IFieldEdit;
            //        pFieldEdit.Name_2 = item.Value;
            //        pFieldEdit.AliasName_2 = item.Value;
            //        pFieldEdit.Editable_2 = true;
            //        pFieldEdit.Required_2 = false;
            //        pFieldEdit.IsNullable_2 = true;
            //        target.AddField(addedField);
            //    }
            //}
            #endregion

            //源图层要素的oid——1
            int pSrcOIDIndex = resultTable.FindField("源OID");
            //待匹配图层要素的oid——2
            int pTarOIDIndex = resultTable.FindField("待匹配OID");
            //变化标记的oid——3
            int pChangeTagIndex = resultTable.FindField("变化标记");

            ICursor rowCursor = resultTable.Search(null, false);
            IRow    tempRow   = null;
            tempRow = rowCursor.NextRow();
            while (tempRow != null)
            {
                //当没有匹配的项时或者未发生变化时不做任何更改
                if (tempRow.get_Value(pTarOIDIndex) == null || tempRow.get_Value(pChangeTagIndex).ToString() == "0")
                {
                    progressBar.PerformOneStep();
                    continue;
                }
                //获取源图层要素
                IFeature sourceFeature = sourceFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pSrcOIDIndex)));
                //变化标记字段值
                string pChangeContent = tempRow.get_Value(pChangeTagIndex).ToString();
                //获取源图层要素
                string[] fromids = tempRow.get_Value(pTarOIDIndex).ToString().Split(';');


                if (!(fromids.Length == 1 && fromids[0].Trim().Length == 0))
                {
                    //查找匹配与待匹配的要素
                    IFeature targetFeature = null;
                    //点和线匹配名称
                    string pSourceName = sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].NameField)).ToString();
                    string pTargetName = string.Empty;
                    //面匹配分类码
                    //string pSourceFCODE = sourceFeature.get_Value(sourceFeature.Fields.FindField("FCODE")).ToString().Trim();
                    string pTargetFCODE = string.Empty;

                    //不同形状的数据
                    if (sourceFcls.ShapeType != targetFcls.ShapeType)
                    {
                        if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                        {
                            //根据不同的匹配类型进行相关操作
                            switch (pChangeContent)
                            {
                            case "图形变化":    //图形变化
                            //case "一对一":
                            case ClsConstant.One2One:
                                //targetFeature.Shape = sourceFeature.Shape;
                                //plistString.Add(sourceFeature.get_Value(sourceFeature.Fields.FindField("ENTIID")).ToString());
                                //test
                                targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex)));
                                string test3 = ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField;
                                pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField)).ToString();
                                //test
                                string test1 = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID)).ToString();
                                string test2 = sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)).ToString();
                                if (ClsStatic.StringSameOrNot(pSourceName, pTargetName) > 1)
                                {
                                    targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                    targetFeature.Store();
                                }
                                //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")));
                                break;

                            //case "新增要素"://新添加要素
                            case ClsConstant.One2Zero:    //新添加要素
                                //targetFeature = target.CreateFeature();
                                //targetFeature.Shape = sourceFeature.ShapeCopy;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "一对多":
                            case ClsConstant.One2More:
                                //for (int i = 0; i < fromids.Length; i++)
                                //{
                                //    string test = fromids[i];
                                //    int test3 = Convert.ToInt32(fromids[i]);

                                //    targetFeature = target.GetFeature(Convert.ToInt32(fromids[i]));
                                //    pTargetName = targetFeature.get_Value(targetFeature.Fields.FindFieldByAliasName("名称")).ToString();
                                //    //targetFeature.Shape = sourceFeature.Shape;
                                //    if (ClsStatic.StringSameOrNot(pSourceName, pTargetName) > 1)
                                //    {
                                //        if (targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")).ToString().Trim().Length == 0)
                                //        {
                                //            targetFeature.set_Value(targetFeature.Fields.FindField("ENTIID"), sourceFeature.get_Value(sourceFeature.Fields.FindField("ENTIID")));
                                //            targetFeature.Store();
                                //        }
                                //    }
                                //}
                                //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //return false;
                                break;

                            case "属性变化":    //属性变化
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            case "属性图形变化":    //都变化
                                //targetFeature.Shape = sourceFeature.Shape;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "多对一"://多尺度更新
                            case ClsConstant.More2One:    //多尺度更新
                                //targetFeature.Shape = finalGeometry;
                                break;

                            default:
                                break;
                            }
                        }
                        else if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                        {
                            //根据不同的匹配类型进行相关操作
                            switch (pChangeContent)
                            {
                            case "图形变化":    //图形变化
                            //case "一对一":
                            case ClsConstant.One2One:
                                targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex)));
                                pTargetName   = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField)).ToString();
                                //targetFeature.Shape = sourceFeature.Shape;
                                if (pSourceName == pTargetName)
                                {
                                    targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                    targetFeature.Store();
                                }
                                //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")));
                                break;

                            //case "新增要素"://新添加要素
                            case ClsConstant.One2Zero:    //新添加要素
                                //targetFeature = target.CreateFeature();
                                //targetFeature.Shape = sourceFeature.ShapeCopy;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "一对多":
                            case ClsConstant.One2More:
                                //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //return false;
                                for (int i = 0; i < fromids.Length; i++)
                                {
                                    string test  = fromids[i];
                                    int    test2 = Convert.ToInt32(fromids[i]);

                                    targetFeature = targetFcls.GetFeature(Convert.ToInt32(fromids[i]));
                                    pTargetName   = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField)).ToString();
                                    //targetFeature.Shape = sourceFeature.Shape;
                                    if (pSourceName == pTargetName)
                                    {
                                        if (targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID)).ToString().Trim().Length == 0)
                                        {
                                            targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                            targetFeature.Store();
                                        }
                                    }
                                }

                                break;

                            case "属性变化":    //属性变化
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            case "属性图形变化":    //都变化
                                //targetFeature.Shape = sourceFeature.Shape;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "多对一"://多尺度更新
                            case ClsConstant.More2One:    //多尺度更新
                                //targetFeature.Shape = finalGeometry;
                                break;

                            default:
                                break;
                            }
                        }
                        else if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                        {
                            //根据不同的匹配类型进行相关操作
                            switch (pChangeContent)
                            {
                            case "图形变化":    //图形变化
                            //case "一对一":
                            case ClsConstant.One2One:
                                targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex)));
                                pTargetFCODE  = targetFeature.get_Value(targetFeature.Fields.FindField("FCODE")).ToString().Trim();
                                //targetFeature.Shape = sourceFeature.Shape;
                                //if (pSourceFCODE == pTargetFCODE)
                                //{
                                targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                targetFeature.Store();
                                //}
                                //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")));
                                break;

                            //case "新增要素"://新添加要素
                            case ClsConstant.One2Zero:    //新添加要素
                                //targetFeature = target.CreateFeature();
                                //targetFeature.Shape = sourceFeature.ShapeCopy;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "一对多":
                            case ClsConstant.One2More:
                                //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //return false;

                                //for (int i = 0; i < fromids.Length; i++)
                                //{
                                //    string test = fromids[i];
                                //    int test2 = Convert.ToInt32(fromids[i]);
                                //    targetFeature = targetFcls.GetFeature(Convert.ToInt32(fromids[i]));
                                //    pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField)).ToString();
                                //    //targetFeature.Shape = sourceFeature.Shape;
                                //    if (pSourceName == pTargetName)
                                //    {
                                //        if (targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID)).ToString().Trim().Length == 0)
                                //        {
                                //            targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                //            targetFeature.Store();
                                //        }
                                //    }
                                //}

                                break;

                            case "属性变化":    //属性变化
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            case "属性图形变化":    //都变化
                                //targetFeature.Shape = sourceFeature.Shape;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "多对一"://多尺度更新
                            case ClsConstant.More2More:    //多尺度更新
                                //targetFeature.Shape = finalGeometry;
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    //相同形状的数据
                    else
                    {
                        if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                        {
                            //根据不同的匹配类型进行相关操作
                            switch (pChangeContent)
                            {
                            case "图形变化":    //图形变化
                            //case "一对一":
                            case ClsConstant.One2One:
                                //targetFeature.Shape = sourceFeature.Shape;
                                //plistString.Add(sourceFeature.get_Value(sourceFeature.Fields.FindField("ENTIID")).ToString());
                                //test
                                targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex)));
                                //string test3 = ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField;
                                string test3 = ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField;
                                pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField)).ToString();
                                //test
                                string test1 = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID)).ToString();
                                string test2 = sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)).ToString();
                                //if (ClsStatic.StringSameOrNot(pSourceName, pTargetName) > 1)
                                //{
                                targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                targetFeature.Store();
                                //}
                                //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")));
                                break;

                            //case "新增要素"://新添加要素
                            case ClsConstant.One2Zero:    //新添加要素
                                //targetFeature = target.CreateFeature();
                                //targetFeature.Shape = sourceFeature.ShapeCopy;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "一对多":
                            case ClsConstant.One2More:
                                //for (int i = 0; i < fromids.Length; i++)
                                //{
                                //    string test = fromids[i];
                                //    int test3 = Convert.ToInt32(fromids[i]);

                                //    targetFeature = target.GetFeature(Convert.ToInt32(fromids[i]));
                                //    pTargetName = targetFeature.get_Value(targetFeature.Fields.FindFieldByAliasName("名称")).ToString();
                                //    //targetFeature.Shape = sourceFeature.Shape;
                                //    if (ClsStatic.StringSameOrNot(pSourceName, pTargetName) > 1)
                                //    {
                                //        if (targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")).ToString().Trim().Length == 0)
                                //        {
                                //            targetFeature.set_Value(targetFeature.Fields.FindField("ENTIID"), sourceFeature.get_Value(sourceFeature.Fields.FindField("ENTIID")));
                                //            targetFeature.Store();
                                //        }
                                //    }
                                //}
                                //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //return false;
                                break;

                            case "属性变化":    //属性变化
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            case "属性图形变化":    //都变化
                                //targetFeature.Shape = sourceFeature.Shape;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "多对一"://多尺度更新
                            case ClsConstant.More2One:    //多尺度更新
                                //targetFeature.Shape = finalGeometry;
                                break;

                            default:
                                break;
                            }
                        }
                        else if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                        {
                            //根据不同的匹配类型进行相关操作
                            switch (pChangeContent)
                            {
                            case "图形变化":    //图形变化
                            //case "一对一":
                            case ClsConstant.One2One:
                                targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex)));
                                pTargetName   = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField)).ToString();
                                //targetFeature.Shape = sourceFeature.Shape;
                                //if (pSourceName == pTargetName)
                                //{
                                targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                targetFeature.Store();
                                //}
                                //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")));
                                break;

                            //case "新增要素"://新添加要素
                            case ClsConstant.One2Zero:    //新添加要素
                                //targetFeature = target.CreateFeature();
                                //targetFeature.Shape = sourceFeature.ShapeCopy;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "一对多":
                            case ClsConstant.One2More:
                                //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //return false;
                                for (int i = 0; i < fromids.Length; i++)
                                {
                                    string test  = fromids[i];
                                    int    test2 = Convert.ToInt32(fromids[i]);

                                    targetFeature = targetFcls.GetFeature(Convert.ToInt32(fromids[i]));
                                    pTargetName   = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField)).ToString();
                                    //targetFeature.Shape = sourceFeature.Shape;
                                    if (pSourceName == pTargetName)
                                    {
                                        if (targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID)).ToString().Trim().Length == 0)
                                        {
                                            targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                            targetFeature.Store();
                                        }
                                    }
                                }

                                break;

                            case "属性变化":    //属性变化
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            case "属性图形变化":    //都变化
                                //targetFeature.Shape = sourceFeature.Shape;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "多对一"://多尺度更新
                            case ClsConstant.More2One:    //多尺度更新
                                //targetFeature.Shape = finalGeometry;
                                break;

                            default:
                                break;
                            }
                        }
                        else if (sourceFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                        {
                            //根据不同的匹配类型进行相关操作
                            switch (pChangeContent)
                            {
                            case "图形变化":    //图形变化
                            //case "一对一":
                            case ClsConstant.One2One:
                                targetFeature = targetFcls.GetFeature(Convert.ToInt32(tempRow.get_Value(pTarOIDIndex)));
                                pTargetFCODE  = targetFeature.get_Value(targetFeature.Fields.FindField("FCODE")).ToString().Trim();
                                //targetFeature.Shape = sourceFeature.Shape;
                                //if (pSourceFCODE == pTargetFCODE)
                                //{
                                targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                targetFeature.Store();
                                //}
                                //sourceFeature.set_Value(sourceFeature.Fields.FindField("ENTIID"), targetFeature.get_Value(targetFeature.Fields.FindField("ENTIID")));
                                break;

                            //case "新增要素"://新添加要素
                            case ClsConstant.One2Zero:    //新添加要素
                                //targetFeature = target.CreateFeature();
                                //targetFeature.Shape = sourceFeature.ShapeCopy;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "一对多":
                            case ClsConstant.One2More:
                                //MessageBox.Show("出现一对多情况,请校对匹配结果表后执行匹配", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //return false;

                                //for (int i = 0; i < fromids.Length; i++)
                                //{
                                //    string test = fromids[i];
                                //    int test2 = Convert.ToInt32(fromids[i]);
                                //    targetFeature = targetFcls.GetFeature(Convert.ToInt32(fromids[i]));
                                //    pTargetName = targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].NameField)).ToString();
                                //    //targetFeature.Shape = sourceFeature.Shape;
                                //    if (pSourceName == pTargetName)
                                //    {
                                //        if (targetFeature.get_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID)).ToString().Trim().Length == 0)
                                //        {
                                //            targetFeature.set_Value(targetFeature.Fields.FindField(ClsConfig.LayerConfigs[(targetFcls  as IDataset).Name].EntityID), sourceFeature.get_Value(sourceFeature.Fields.FindField(ClsConfig.LayerConfigs[(sourceFcls  as IDataset).Name].EntityID)));
                                //            targetFeature.Store();
                                //        }
                                //    }
                                //}

                                break;

                            case "属性变化":    //属性变化
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            case "属性图形变化":    //都变化
                                //targetFeature.Shape = sourceFeature.Shape;
                                //UpdateAttribute(sourceFeature, targetFeature, updateRela);
                                break;

                            //case "多对一"://多尺度更新
                            case ClsConstant.More2More:    //多尺度更新
                                //targetFeature.Shape = finalGeometry;
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    //targetFeature.Store();
                }

                progressBar.PerformOneStep();
                tempRow = rowCursor.NextRow();
            }

            //对待匹配图层中剩余的点()进行编码
            //CreatePOICodeRest(target, "ENTIID", plistString);

            pWorkspaceEdit.StopEditOperation();
            pWorkspaceEdit.StopEditing(true);
            return(true);
        }
Пример #6
0
        /// <summary>
        /// 创建实体表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateEntiTable_Click(object sender, EventArgs e)
        {
            //显示进度条
            this.labelX1.Visible            = true;
            this.progressBarXEntiDB.Visible = true;

            IWorkspaceFactory2 pWorkspaceFactory = new FileGDBWorkspaceFactoryClass() as IWorkspaceFactory2;
            //20180131
            string path = System.IO.Path.GetDirectoryName(this.txbGdbPath.Text);
            //string entitableName = this.txbEntiName.Text.ToString();
            string entitableName = System.IO.Path.GetFileName(this.txbGdbPath.Text);

            IWorkspace2       pWorkspace       = pWorkspaceFactory.OpenFromFile(path, 0) as IWorkspace2;
            IFeatureWorkspace featureWorkspace = pWorkspace as IFeatureWorkspace;


            IMapControl4         pMainMapControl = ClsControl.MapControlMain;
            IMap                 pMap            = pMainMapControl.Map;
            List <IFeatureLayer> pFeatlayerList  = new List <IFeatureLayer>();

            //把dbf表转换成为ITable
            string dbfPath      = System.IO.Path.GetDirectoryName(this.txbVersionPath.Text);
            string dbfName      = System.IO.Path.GetFileName(this.txbVersionPath.Text);
            ITable versionTable = OpenDBFTable(dbfPath, dbfName);

            int pBarNumberTotal = 0;

            if (pMap != null)
            {
                ClsCommon pClsCommon = new ClsCommon();
                pFeatlayerList = pClsCommon.GetFeatureLayers(pMap);

                ITable entitable = null;

                //如果表存在,就删除数据
                if (pWorkspace.get_NameExists(esriDatasetType.esriDTTable, entitableName))
                {
                    entitable = featureWorkspace.OpenTable(entitableName);
                    //IWorkspaceEdit workspaceEdit = pWorkspace as IWorkspaceEdit;
                    //workspaceEdit.StartEditing(true);
                    //workspaceEdit.StartEditOperation();

                    //ICursor cursor = entitable.Search(null, false);
                    //IRow r = cursor.NextRow();
                    //while (r != null)
                    //{
                    //    r.Delete();
                    //    r = cursor.NextRow();
                    //}
                    //workspaceEdit.StopEditOperation();
                    //workspaceEdit.StopEditing(true);
                }
                //如果表不存在,就创建字段创建表
                else
                {
                    IFields fileds = null;
                    fileds    = CreateEntiTableFields(pWorkspace);
                    entitable = CreateTable(pWorkspace, entitableName, fileds);
                }

                //进度条
                ClsBarSync pBarEntiDB = new ClsBarSync(progressBarXEntiDB);
                pBarEntiDB.SetStep(1);

                foreach (IFeatureLayer pFeatureLay in pFeatlayerList)
                {
                    IFeatureClass pFeatureCls = pFeatureLay.FeatureClass;
                    int           pCount      = pFeatureCls.FeatureCount(null);
                    pBarNumberTotal += pCount;
                    //pBarEntiDB.PerformOneStep();
                }
                pBarEntiDB.SetMax(pBarNumberTotal);
                foreach (IFeatureLayer pFeatureLay in pFeatlayerList)
                {
                    IFeatureClass pFeatureCls     = pFeatureLay.FeatureClass;
                    string        pFeatureLayname = pFeatureLay.Name;
                    FillEntiTable(pFeatureCls, entitable, versionTable, pFeatureLayname, pBarEntiDB);
                    //pBarEntiDB.PerformOneStep();
                }
            }

            //DialogResult dr = MessageBox.Show("内容?", "对话框标题", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            DialogResult dr = MessageBox.Show("实体表创建成功!", "实体表提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                //点确定的代码
                this.Close();
            }
            else
            {
                //点取消的代码
            }
            //MessageBox.Show("实体表创建成功!");
        }