private void button12_Click(object sender, EventArgs e) { ILayer tocSelectedLayer = GetTocSelectedLayer(); if (tocSelectedLayer != null) { IDataset dataset = (tocSelectedLayer as IFeatureLayer).FeatureClass.FeatureDataset as IDataset; IVersionedObject verObj = dataset as IVersionedObject; if (verObj == null || !verObj.IsRegisteredAsVersioned) { try { verObj.RegisterAsVersioned(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show("未选择图层"); } }
/// <summary> /// 注册\反注册版本 /// </summary> /// <param name="pWorkspace">工作区</param> /// <param name="bRegist">注册\反注册版本</param> public static void RegistVersion(IWorkspace pWorkspace, bool bRegist) { IVersionedObject verObj = (IVersionedObject)pWorkspace; if (verObj != null && (!verObj.IsRegisteredAsVersioned)) { // 数据集可以被注册而且还没有被注册为版本数据集 // 下面的方法 如果使用参数 false 那么表示注册为没有版本的数据也就是反注册 verObj.RegisterAsVersioned(bRegist); // sde.Default } }
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); }
private void simpleButton3_Click(object sender, EventArgs e) { if (mEngineEditor.EditState == esriEngineEditState.esriEngineStateNotEditing) { AxMapControl mMap = this.axMapControl1; currentLayer = GetTocSelectedLayer(); if (currentLayer is IFeatureLayer) { IFeatureLayer featureLayer = currentLayer as IFeatureLayer; mLayerType = featureLayer.FeatureClass.ShapeType; IDataset dataset = featureLayer.FeatureClass as IDataset; IVersionedObject verObj = dataset as IVersionedObject; if (verObj != null) { try { verObj.RegisterAsVersioned(true); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //if (verObj != null) //{ // MessageBox.Show("数据集未注册为版本!"); // return; //} IWorkspace workspace; try { mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned; workspace = dataset.Workspace; mEngineEditor.StartEditing(workspace, mMap.Map); } catch (Exception ex) { try { mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeNonVersioned; workspace = dataset.Workspace; mEngineEditor.StartEditing(workspace, mMap.Map); } catch (Exception ex1) { XtraMessageBox.Show(ex1.Message, "提示信息", MessageBoxButtons.OK); } } ((IEngineEditLayers)mEngineEditor).SetTargetLayer(featureLayer, 0); } } }