예제 #1
0
        public override void OnClick()
        {
            if (!MoData.v_CurWorkspaceEdit.IsBeingEdited())
            {
                return;
            }
            bool     bHasEdits = false;
            DateTime SaveTime  = DateTime.Now;                                     ////////////////////////////////////结束编辑的时间
            Dictionary <string, Dictionary <int, List <IRow> > > ChangeFea = null; ///更新变化的要素

            MoData.v_CurWorkspaceEdit.HasEdits(ref bHasEdits);
            bool bSave = false;

            if (bHasEdits == true)   //如果进行了编辑则提示是否保存
            {
                if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "是否对编辑进行保存") == true)
                {
                    bSave = true;
                }
            }

            if (bSave)
            {
                //bool bLock = true;                      //true获得锁
                //bool bebortIfConflict = false;           //检测到冲突时,版本协调是否停止,true停止,false不停止
                bool bChildWin = false;                //true替换上一个版本(冲突版本),false用上一个版本(冲突版本)
                //bool battributeCheck = false;          //false若为true则只有修改同一个属性时才检测出冲突
                bool beMerge = true;                   //对于产生冲突的要素是否融合

                Exception eError = null;

                frmConflictSet pfrmConflictSet = new frmConflictSet();
                if (pfrmConflictSet.ShowDialog() == DialogResult.OK)
                {
                    bChildWin = pfrmConflictSet.BECHILDWIM;
                    beMerge   = pfrmConflictSet.BEMERGE;
                }

                string pDefVerName = "";                                                       //默认版本名称
                Dictionary <string, Dictionary <int, List <int> > >  conflictFeaClsDic = null; //产生冲突的要素类信息
                Dictionary <string, Dictionary <int, List <IRow> > > feaChangeDic      = null; //更新变化的要素
                //Dictionary<string, Dictionary<int, List<IRow>>> feaChangeSaveDic = null;   //保存编辑后更新变化的要素

                ClsVersionReconcile pClsVersionReconcile = new ClsVersionReconcile(MoData.v_CurWorkspaceEdit);
                //获得默认版本名称
                pDefVerName = pClsVersionReconcile.GetDefautVersionName(out eError);
                if (eError != null || pDefVerName == "")
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message);
                    return;
                }

                //进行版本协调时产生冲突的要素类信息
                conflictFeaClsDic = pClsVersionReconcile.ReconcileVersion(pDefVerName, bChildWin, beMerge, out eError);
                if (eError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message);
                    return;
                }

                //获得发生更新变化的要素信息
                feaChangeDic = pClsVersionReconcile.GetModifyClsInfo(out eError);
                if (eError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message);
                    return;
                }
                ChangeFea = feaChangeDic;
            }

            MoData.v_CurWorkspaceEdit.StopEditing(bSave);
            if (bSave)
            {
                //更新日志记录表等
                //*******************************************************************************************
                //guozheng 2010-11-4 added
                //编辑完成,冲突处理完成后,写入更新日志表
                #region 编辑完成,冲突处理完成后,写入更新日志表
                Exception ex = null;
                if (ChangeFea != null)
                {
                    //////////远程更新日志处理对象
                    clsUpdataEnvironmentOper UpLogOper = new clsUpdataEnvironmentOper();
                    bool SaveLOG = true;
                    UpLogOper.HisWs = (IWorkspace)MoData.v_CurWorkspaceEdit;
                    foreach (KeyValuePair <string, Dictionary <int, List <IRow> > > item in ChangeFea)
                    {
                        string sLayerName = item.Key;
                        Dictionary <int, List <IRow> > FeatureDic = item.Value;
                        if (FeatureDic != null)
                        {
                            foreach (KeyValuePair <int, List <IRow> > item2 in FeatureDic)
                            {
                                int         iState  = item2.Key;
                                List <IRow> ListFea = item2.Value;
                                for (int count = 0; count < ListFea.Count; count++)
                                {
                                    IRow getRow = ListFea[count];
                                    UpLogOper.RecordLOG(getRow, iState, SaveTime, iState, sLayerName, out ex);
                                    if (ex != null)
                                    {
                                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "更新编辑记录失败。\n原因:" + ex.Message);
                                        SaveLOG = false;
                                        break;
                                    }
                                }
                                if (SaveLOG == false)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    if (SaveLOG)
                    {
                        UpLogOper.WriteDBVersion(MoData.DBVersion, SaveTime, out ex);
                        if (ex != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "版本信息写入失败,\n原因:" + ex.Message);
                            // return;
                        }
                    }
                }
                #endregion
                //*******************************************************************************************
                //写入版本信息
                //*******************************************************************************************
            }

            MoData.v_CurWorkspaceEdit = null;



            ////保存日志记录表的修改
            //MoData.v_LogTable.EndTransaction(bSave);
            //MoData.v_LogTable.CloseDbConnection();
            //MoData.v_LogTable = null;

            m_Hook.CurrentTool            = "";
            m_Hook.MapControl.CurrentTool = null;
            m_Hook.MapControl.Map.ClearSelection();
            m_Hook.MapControl.ActiveView.Refresh();
        }
예제 #2
0
        public override void OnClick()
        {
            IWorkspace pCurWorkspace = null;// m_CurWorkspace;

            //当工作空间为多个时需提供选择对话框
            if (m_AllLayers == null || m_AllLayers.Count == 0)
            {
                return;
            }
            if (m_AllLayers.Count > 1)
            {
                FrmStartEdit frmStarEdit = new FrmStartEdit();
                frmStarEdit.AllEditInfo = m_AllLayers;
                frmStarEdit.ShowDialog();
                if (frmStarEdit.DialogResult == DialogResult.OK)
                {
                    pCurWorkspace = frmStarEdit.SelectWorkspace;
                }
                else
                {
                    return;
                }
            }
            else
            {
                foreach (IWorkspace pWorkspace in m_AllLayers.Keys)
                {
                    pCurWorkspace = pWorkspace;
                }
            }

            if (pCurWorkspace == null)
            {
                return;
            }

            //================================================================
            //chenyafei  20110105  add:在编辑前注册版本
            //只针对SDE数据
            if (pCurWorkspace.WorkspaceFactory.WorkspaceType != esriWorkspaceType.esriRemoteDatabaseWorkspace)
            {
                //若不是SDE数据,则不允许编辑
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "请加载SDE数据进行编辑");
                return;
            }
            //只针对注册版本的数据
            IEnumDataset pEnumDataset = pCurWorkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);

            if (pEnumDataset == null)
            {
                return;
            }

            IDataset pFeaDt = pEnumDataset.Next();

            while (pFeaDt != null)
            {
                if (pFeaDt.Name.ToUpper().EndsWith("_GOH"))
                {
                    pFeaDt = pEnumDataset.Next();
                    continue;
                }
                IVersionedObject pVerObj = pFeaDt as IVersionedObject;
                if (!pVerObj.IsRegisteredAsVersioned)
                {
                    //注册版本
                    if (SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "该数据还未注册版本,是否注册版本以便进行编辑?"))
                    {
                        pVerObj.RegisterAsVersioned(true);
                        break;
                    }
                    else
                    {
                        return;
                    }
                }
                //else
                //{
                //    pVerObj.RegisterAsVersioned(false);
                //}
                pFeaDt = pEnumDataset.Next();
            }

            //==================================================================

            IWorkspaceEdit pWorkspaceEdit = pCurWorkspace as IWorkspaceEdit;

            if (!pWorkspaceEdit.IsBeingEdited())
            {
                try
                {
                    pWorkspaceEdit.StartEditing(true);
                    pWorkspaceEdit.EnableUndoRedo();
                }
                catch (Exception eError)
                {
                    //******************************************
                    //guozheng added System Exception log
                    if (SysCommon.Log.Module.SysLog == null)
                    {
                        SysCommon.Log.Module.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    }
                    SysCommon.Log.Module.SysLog.Write(eError);
                    //******************************************
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "不能编辑该工作空间,请检查是否为只读或被其它用户占用!");
                    return;
                }
            }

            MoData.v_CurWorkspaceEdit = pWorkspaceEdit;

            //将开启编辑的图层加到图层下拉框中
            if (Plugin.ModuleCommon.DicCommands.ContainsKey("GeoEdit.LayerControl"))
            {
                LayerControl pLayerControl = Plugin.ModuleCommon.DicCommands["GeoEdit.LayerControl"] as LayerControl;
                if (pLayerControl != null)
                {
                    pLayerControl.GetLayers();
                }
            }
            //******************************************************************
            //guozheng 2010-11-4 added 开启编辑成功后获取当前的数据库版本
            Exception ex = null;
            clsUpdataEnvironmentOper UpOper = new clsUpdataEnvironmentOper();

            UpOper.HisWs     = pCurWorkspace;
            MoData.DBVersion = UpOper.GetVersion(out ex);
            if (ex != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据库版本失败。\n原因:" + ex.Message);
            }
            //******************************************************************
            ////打开日志记录表,开启事务
            //Exception exError = null;
            //XmlNode DBNode = m_Hook.DBXmlDocument.SelectSingleNode(".//数据库工程");
            //XmlElement DBElement = DBNode as XmlElement;
            //string strLogMdbPath = DBElement.GetAttribute("路径") + "\\Log\\更新日志.mdb";
            //MoData.v_LogTable = new SysCommon.DataBase.SysTable();
            //MoData.v_LogTable.SetDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strLogMdbPath+";Mode=Share Deny None;Persist Security Info=False", SysCommon.enumDBConType.OLEDB, SysCommon.enumDBType.ACCESS, out exError);
            //MoData.v_LogTable.StartTransaction();

            //委托主窗体关闭事件
            Plugin.Application.IAppFormRef pAppFormRef = m_Hook as Plugin.Application.IAppFormRef;
            pAppFormRef.MainForm.FormClosing += new FormClosingEventHandler(MainForm_FormClosing);
        }