//停止编辑 public static void StopEditing(AxMapControl axmap, ILayer player) { m_strOperator = ""; if (pWorkspaceEdit == null) { return; } // Check edit conditions before allowing edit to stop m_CurrentLayer = player; m_MapControl = axmap; if (m_CurrentLayer == null) { return; } IFeatureLayer pFeatureLayer = (IFeatureLayer)m_CurrentLayer; if (pFeatureLayer.FeatureClass == null) { return; } IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass; if (pDataset == null) { return; } // If the current document has been edited then prompt the user to save changes //IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; if (pWorkspaceEdit.IsBeingEdited()) { bool bHasEdits = false; pWorkspaceEdit.HasEdits(ref bHasEdits); bool bSave = false; if (bHasEdits) { DialogResult result; result = MessageBoxEx.Show("你想保存你的编辑吗?", "提示!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (DialogResult.Yes == result) { bSave = true; } } pWorkspaceEdit.StopEditing(bSave); } m_MapControl.Map.ClearSelection(); m_MapControl.ActiveView.Refresh(); }
//保存编辑 public static void SaveEditing(AxMapControl axmap, ILayer player) { // Check edit conditions before allowing edit to stop m_CurrentLayer = player; m_MapControl = axmap; if (m_CurrentLayer == null) { return; } IFeatureLayer pFeatureLayer = (IFeatureLayer)m_CurrentLayer; if (pFeatureLayer.FeatureClass == null) { return; } IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass; if (pDataset == null) { return; } // If the current document has been edited then prompt the user to save changes IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; bool bHasEdits = false; pWorkspaceEdit.HasEdits(ref bHasEdits); if (bHasEdits) { pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(bHasEdits); } }
/// <summary> /// 停止编辑,并将以前的编辑结果保存到数据文件中。 /// </summary> public void StopEditing() { bool bHasEdits = false; bool bSave = false; try { if (m_pCurrentLayer == null) { return; } IFeatureLayer pFeatureLayer = (IFeatureLayer)m_pCurrentLayer; if (pFeatureLayer.FeatureClass == null) { return; } IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass; if (pDataset == null) { return; } //如果数据已被修改,则提示用户是否保存 IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace; if (pWorkspaceEdit.IsBeingEdited()) { pWorkspaceEdit.HasEdits(ref bHasEdits); if (bHasEdits) { DialogResult result; result = MessageBox.Show("是否保存已做的修改?", "提示", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { bSave = true; } } pWorkspaceEdit.StopEditing(bSave); } m_pMap.ClearSelection(); IActiveView pActiveView = (IActiveView)m_pMap; pActiveView.Refresh(); } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } }
private void StartEdition(bool canUndo) { IWorkspaceEdit edit = _currentWorkspace as IWorkspaceEdit; bool hasEdits = false; edit.HasEdits(ref hasEdits); if (hasEdits && edit.IsBeingEdited()) { return; } edit.StartEditing(canUndo); edit.StartEditOperation(); // BeforeCommit += new EventHandler(UnitOfWork_BeforeCommit); }
//Function: Stop editing and save private void StopAndCommitEdit() { if (workspaceEdit == null || workspaceEdit.IsBeingEdited() == false) { return; } bool hasEdit = false; workspaceEdit.HasEdits(ref hasEdit); if (hasEdit) { workspaceEdit.StopEditing(true); } else { workspaceEdit.StopEditing(false); } }
public override void OnClick() { if (m_Hook == null) { return; } //LogFile log = new LogFile(m_Hook.tipRichBox, m_Hook.strLogFilePath); //if (log != null) //{ // log.Writelog("鹰眼图设置"); //} if (m_Hook.ArcGisMapControl.Map.LayerCount == 0) { MessageBox.Show("当前没有调阅数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { IWorkspaceEdit iWE = ((getEditLayer.isExistLayer(m_Hook.ArcGisMapControl.Map) as IFeatureLayer).FeatureClass as IDataset).Workspace as IWorkspaceEdit; if (iWE.IsBeingEdited()) { bool hasEdits = false; iWE.HasEdits(ref hasEdits); if (hasEdits && MessageBox.Show("是否保存编辑?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { iWE.StopEditing(true); Plugin.LogTable.Writelog("保存编辑"); } else { iWE.StopEditing(false); Plugin.LogTable.Writelog("未保存编辑"); } } m_Hook.ArcGisMapControl.ActiveView.Refresh(); iWE = null; } catch { } }
private void btnXOK_Click(object sender, EventArgs e) { IFeatureLayer pFL = getEditLayer.isExistLayer(inMap) as IFeatureLayer; if (pFL != null) { IFeatureSelection pFS = pFL as IFeatureSelection; pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); pFS.Clear(); pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } string cPath = Application.StartupPath + "\\..\\Res\\Xml\\EditLayer.xml"; if (!File.Exists(cPath)) { return; } if (this.WriteLog) { Plugin.LogTable.Writelog("设置" + pFL.Name + "为编辑图层"); } XmlDocument cXmlDoc = new XmlDocument(); if (cXmlDoc != null) { cXmlDoc.Load(cPath); string[] nm = cboLayers.Text.Split('(', ')'); XmlNodeList xnl = cXmlDoc.GetElementsByTagName("EditLayerInfo"); xnl.Item(0).Attributes["LayerName"].Value = nm[1]; xnl.Item(0).Attributes["FCName"].Value = nm[0]; } cXmlDoc.Save(cPath); IWorkspace curW = ((getEditLayer.isExistLayer(inMap) as IFeatureLayer).FeatureClass as IDataset).Workspace; if (preW != null && !curW.Equals(preW)) { IWorkspaceEdit preWE = preW as IWorkspaceEdit; bool hasEdit = false; preWE.HasEdits(ref hasEdit); if (hasEdit) { if (MessageBox.Show("您更改了工作空间,是否保存之前的编辑?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { preWE.StopEditing(true); } else { preWE.StopEditing(false); pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } } IWorkspaceEdit iWE = curW as IWorkspaceEdit; if (!iWE.IsBeingEdited()) { iWE.StartEditing(false); } }
private void EndEdit(IFeatureLayer pFeatureLayer) { IFeatureClass pFeatClass = pFeatureLayer.FeatureClass; IDataset pDataset = pFeatClass as IDataset; IWorkspaceEdit pWSEdit = pDataset.Workspace as IWorkspaceEdit; if (pWSEdit.IsBeingEdited()) { //判断该工作空间下在map上是否还有图层 bool bHasLay = false; if (myHook.MapControl.Map.LayerCount == 0) { bHasLay = false; } else { UID pUID = new UIDClass(); pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; //UID for IFeatureLayer IEnumLayer pEnumLayer = myHook.MapControl.Map.get_Layers(pUID, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) { IFeatureLayer pTempFeatureLayer = pLayer as IFeatureLayer; IDataset pTempDataset = pTempFeatureLayer.FeatureClass as IDataset; if (pTempDataset.Workspace == pDataset.Workspace) { bHasLay = true; break; } pLayer = pEnumLayer.Next(); } } //当有线程存在时是做入库操作应排除 if (bHasLay == false && myHook.CurrentThread == null) { bool bHasEdits = false; bool bSave = false; pWSEdit.HasEdits(ref bHasEdits); if (bHasEdits == true) { bSave = SysCommon.Error.ErrorHandle.ShowFrmInformation("是", "否", "图层已进行过编辑,是否需要保存?"); } pWSEdit.StopEditing(bSave); MoData.v_CurWorkspaceEdit = null; //保存日志记录表的修改 if (MoData.v_LogTable != null) { MoData.v_LogTable.EndTransaction(bSave); MoData.v_LogTable.CloseDbConnection(); MoData.v_LogTable = null; } myHook.CurrentTool = ""; myHook.MapControl.CurrentTool = null; myHook.MapControl.Map.ClearSelection(); myHook.MapControl.ActiveView.Refresh(); } } }