public override void OnClick() { if (!MoData.v_CurWorkspaceEdit.IsBeingEdited()) { return; } bool bHasEdits = false; MoData.v_CurWorkspaceEdit.HasEdits(ref bHasEdits); DateTime SaveTime = DateTime.Now;//////////////保存编辑时间 if (bHasEdits == true) { Exception eError = null; //bool bLock = true; //true获得锁 //bool bebortIfConflict = false; //检测到冲突时,版本协调是否停止,true停止,false不停止 bool bChildWin = false; //true替换上一个版本(冲突版本),false用上一个版本(冲突版本) //bool battributeCheck = false; //false若为true则只有修改同一个属性时才检测出冲突 bool beMerge = true; //对于产生冲突的要素是否融合 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; } MoData.v_CurWorkspaceEdit.StopEditing(true); //******************************************************************************************* //guozheng 2010-11-4 added //编辑完成,冲突处理完成后,写入更新日志表 #region 编辑完成,冲突处理完成后,写入更新日志表 bool SaveLOG = true; if (feaChangeDic != null) { //////////远程更新日志处理对象 clsUpdataEnvironmentOper UpLogOper = new clsUpdataEnvironmentOper(); UpLogOper.HisWs = (IWorkspace)MoData.v_CurWorkspaceEdit; foreach (KeyValuePair <string, Dictionary <int, List <IRow> > > item in feaChangeDic) { 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, MoData.DBVersion, sLayerName, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "更新编辑记录失败。\n原因:" + eError.Message); SaveLOG = false; break; } } if (SaveLOG == false) { break; } } } } UpLogOper.WriteDBVersion(MoData.DBVersion, SaveTime, out eError); if (eError != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "更新版本信息写入失败。\n原因:" + eError.Message); } } #endregion MoData.v_CurWorkspaceEdit.StartEditing(true); MoData.v_CurWorkspaceEdit.EnableUndoRedo(); if (bHasEdits == true && SaveLOG == true) { //******************************************************************************************* //guozheng 2010-11-4 added //保存成功后刷新版本信息 Exception ex = null; //////////远程更新日志处理对象 clsUpdataEnvironmentOper UpLogOper = new clsUpdataEnvironmentOper(); UpLogOper.HisWs = (IWorkspace)MoData.v_CurWorkspaceEdit; // UpLogOper.WriteDBVersion(MoData.DBVersion, SaveTime, out ex); MoData.DBVersion = UpLogOper.GetVersion(out ex); if (ex != null) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取数据库版本失败。\n原因:" + ex.Message); } //******************************************************************************************* } ////保存编辑后,发生更新变化的要素信息 //if (bChildWin == false) //{ // feaChangeSaveDic = pClsVersionReconcile.GetPureModifySaveInfo(feaChangeDic, conflictFeaClsDic, out eError); // if (eError != null) // { // SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message); // return; // } //} //else //{ // feaChangeSaveDic = feaChangeDic; //} } if (MoData.v_LogTable != null) { //保存日志记录表的修改 MoData.v_LogTable.EndTransaction(true); MoData.v_LogTable.CloseDbConnection(); MoData.v_LogTable = null; } m_Hook.MapControl.ActiveView.Refresh(); }
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); }