using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WWPipeLine.MapBasic.Conditions; using WWPipeLine.MapBasic; using WeifenLuo.WinFormsUI.Docking; using SuperMap.Data; using SuperMap.Mapping; namespace WWPipeLine.MapTools.Conditions.EditGuanWang { public partial class GuanDianXian : ConditionPanel { Point2D newPoint = new Point2D(0, 0); GeoPoint newGeoPoint = null; Recordset _rdSelect = null; string yuanBSM = string.Empty; Recordset rdJSLKqsdh = null; Recordset rdJSLKzddh = null; public GuanDianXian() { this.ConditionPanelName = "点线联动"; InitializeComponent(); this.SetSize(300, 200); IsShowResultWindow = false; } protected override void OnLoad(EventArgs e) { ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, false); MapControl.MouseDoubleClick += MapControl_MouseDoubleClick; MapControl.GeometrySelected += MapControl_GeometrySelected; } private void MapControl_GeometrySelected(object sender, SuperMap.UI.GeometrySelectedEventArgs e) { Selection[] _selection = MapControl.Map.FindSelection(true); _rdSelect = _selection[0].ToRecordset(); if (!_rdSelect.Dataset.Name.ToLower().Contains("dv") || _selection.Length != 1 || _selection[0].Count != 1) { Sunny.UI.UIMessageTip.ShowError("仅可以选择一个节点"); return; } _rdSelect.MoveFirst(); yuanBSM = _rdSelect.GetFieldValue("bsm").ToString(); uilbStart.Text = string.Format("原节点({0},{1})", ComsStatic.StringToDouble(_rdSelect.GetFieldValue("x"), 2), ComsStatic.StringToDouble(_rdSelect.GetFieldValue("y"), 2)); } private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e) { newPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y)); newGeoPoint = new GeoPoint(newPoint.X, newPoint.Y); newGeoPoint.Style = ComsStatic.geoStyle_Red_Mark5mm; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.TrackingLayer.Add(newGeoPoint, "MapControl_MouseDoubleClick"); MapControl.Map.RefreshTrackingLayer(); uilbEnd.Text = string.Format("新节点({0},{1})", Math.Round(newPoint.X, 2), Math.Round(newPoint.Y, 2)); } public override object Do(DockPanel dockPanel = null) { if (string.IsNullOrEmpty(yuanBSM) || newGeoPoint == null || (rdJSLKqsdh is null && rdJSLKzddh is null)) { Sunny.UI.UIMessageTip.ShowError("请先选择原节点和新节点,然后点击“新管线预览”"); return false; } EditHistory m_EditHistory = new EditHistory(); try { //1 增加新节点 此处是直接新增了 供水节点, 可能还有 只改变坐标 不改变节点分类代码的需求 Recordset rddvJSJDPT = ComsStatic.gsGuanDian.GetRecordset(true, CursorType.Dynamic); m_EditHistory.Add(EditType.AddNew, rddvJSJDPT, false); rddvJSJDPT.AddNew(newGeoPoint); rddvJSJDPT.SetFieldValue("x", newGeoPoint.X); rddvJSJDPT.SetFieldValue("y", newGeoPoint.Y); rddvJSJDPT.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanDian, "objectid") + 1; string _duandian = ComsStatic.dvJDDatasetName + objID; rddvJSJDPT.SetFieldValue("objectid", objID); rddvJSJDPT.SetFieldValue("bsm", _duandian); rddvJSJDPT.SetFieldValue("fldm", ComsStatic.dvJDCaption); rddvJSJDPT.SetFieldValue("cqbh", "管线联动"); if (rddvJSJDPT.Update()) { Commons.LogHelper.Info(string.Format("管线联动-新增管线节点成功!新增的OBJECTID是{0}。", objID)); (ComsStatic.Datasource.Datasets[ComsStatic.dvJDDatasetName] as DatasetVector).Append(rddvJSJDPT); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("新节点新增 操作失败!"); return false; } Recordset rdJSJDPT = null; if (rdJSLKqsdh.RecordCount > 0)//2 更改原管线的节点 起始点号 { rdJSLKqsdh.MoveFirst(); while (!rdJSLKqsdh.IsEOF) { rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKqsdh.GetFieldValue("zddh")), CursorType.Static); if (rdJSJDPT.RecordCount != 1) continue; Point2D p = ComsStatic.GetPoint2D(rdJSJDPT.GetFieldValue("x"), rdJSJDPT.GetFieldValue("y")); GeoLine newline = new GeoLine(new Point2Ds(newPoint, p)); m_EditHistory.Add(EditType.Modify, rdJSLKqsdh, false); rdJSLKqsdh.Edit(); rdJSLKqsdh.SetFieldValue("qsdh", _duandian); rdJSLKqsdh.SetFieldValue("cd", ComsStatic.StringToDouble(newline.Length, 2)); rdJSLKqsdh.SetFieldValue("shape_length", newline.Length); rdJSLKqsdh.SetGeometry(newline); if (rdJSLKqsdh.Update()) { Commons.LogHelper.Error(string.Format("管线联动-更改原管线的起始点号成功!管线的SMID是{0}。", rdJSLKqsdh.GetID())); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("终点点号不变,更新起始点号 操作失败!"); return false; } rdJSLKqsdh.MoveNext(); } } if (rdJSLKzddh.RecordCount > 0)//3 更改原管线的节点 终点点号 { rdJSLKzddh.MoveFirst(); while (!rdJSLKzddh.IsEOF) { rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKzddh.GetFieldValue("qsdh")), CursorType.Static); if (rdJSJDPT.RecordCount != 1) continue; Point2D p = ComsStatic.GetPoint2D(rdJSJDPT.GetFieldValue("x"), rdJSJDPT.GetFieldValue("y")); GeoLine newline = new GeoLine(new Point2Ds(newPoint, p)); m_EditHistory.Add(EditType.Modify, rdJSLKzddh, false); rdJSLKzddh.Edit(); rdJSLKzddh.SetFieldValue("zddh", _duandian); rdJSLKzddh.SetFieldValue("cd", ComsStatic.StringToDouble(newline.Length, 2)); rdJSLKzddh.SetFieldValue("shape_length", newline.Length); rdJSLKzddh.SetGeometry(newline); if (rdJSLKzddh.Update()) { Commons.LogHelper.Error(string.Format("管线联动-更改原管线的终点点号成功!管线的SMID是{0}。", rdJSLKqsdh.GetID())); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("起始管点不变,更新终点管点 操作失败!"); return false; } rdJSLKzddh.MoveNext(); } } //4 删除 原节点 m_EditHistory.Add(EditType.Delete, _rdSelect, false); if (_rdSelect.Delete()) { Commons.LogHelper.Error(string.Format("管线联动-删除原节点成功!原节点的SMID是{0}。", yuanBSM)); ComsStatic.ShowOKLog("点线联动操作成功"); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("原节点删除失败!"); return false; } } catch (Exception e) { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("点线联动出错!", e.Message); return false; } return true; } private void uibtnLianjie_Click(object sender, EventArgs e)//生成新的管线 { if (string.IsNullOrEmpty(yuanBSM) || newGeoPoint is null) { Sunny.UI.UIMessageTip.ShowError("请先选择原节点和新节点"); return; } ComsStatic.TrackingLayerRemove("newLine"); rdJSLKqsdh = ComsStatic.gsGuanXian.Query(string.Format(" qsdh='{0}' ", yuanBSM), CursorType.Dynamic); rdJSLKzddh = ComsStatic.gsGuanXian.Query(string.Format(" zddh='{0}' ", yuanBSM), CursorType.Dynamic); Recordset rdJSJDPT = null; if (rdJSLKqsdh.RecordCount == 0 && rdJSLKzddh.RecordCount == 0) { Sunny.UI.UIMessageTip.ShowError("原节点未查询到管线信息!"); return; } if (rdJSLKqsdh.RecordCount != 0) { rdJSLKqsdh.MoveFirst(); while (!rdJSLKqsdh.IsEOF) { //rdJSJDPT = ComsStatic.QueryRecordset(ComsStatic.dvJSJDPT, string.Format(" bsm='{0}' ", rdJSLKqsdh.GetFieldValue("zddh"))); rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKqsdh.GetFieldValue("zddh")), CursorType.Static); if (rdJSJDPT.RecordCount != 1) rdJSLKqsdh.MoveNext(); Point2D p = new Point2D(double.Parse(rdJSJDPT.GetFieldValue("X").ToString()), double.Parse(rdJSJDPT.GetFieldValue("Y").ToString())); //Point2D p = ComsStatic.GetPoint2D(rdJSJDPT.GetFieldValue("x"), rdJSJDPT.GetFieldValue("y")); GeoLine newLineqsdh = new GeoLine(new Point2Ds(newPoint, p)); newLineqsdh.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate; MapControl.Map.TrackingLayer.Add(newLineqsdh, "newLine"); rdJSLKqsdh.MoveNext(); } } if (rdJSLKzddh.RecordCount != 0) { rdJSLKzddh.MoveFirst(); while (!rdJSLKzddh.IsEOF) { rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKzddh.GetFieldValue("qsdh")), CursorType.Static); if (rdJSJDPT.RecordCount != 1) rdJSLKzddh.MoveNext(); Point2D p = new Point2D(double.Parse(rdJSJDPT.GetFieldValue("X").ToString()), double.Parse(rdJSJDPT.GetFieldValue("Y").ToString())); GeoLine newLinezddh = new GeoLine(new Point2Ds(p, newPoint)); newLinezddh.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate; MapControl.Map.TrackingLayer.Add(newLinezddh, "newLine"); rdJSLKzddh.MoveNext(); } } MapControl.Map.RefreshTrackingLayer(); } private void uiButton2_Click(object sender, EventArgs e) { MapControl.Map.TrackingLayer.Clear(); MapControl.Map.RefreshTrackingLayer(); rdJSLKqsdh = null; rdJSLKzddh = null; newGeoPoint = null; yuanBSM = string.Empty; newPoint = new Point2D(0, 0); uilbStart.Text = ""; uilbEnd.Text = ""; } public override void AfterClose() { ComsStatic.RecordsetDispose(rdJSLKqsdh); ComsStatic.RecordsetDispose(rdJSLKzddh); MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick; MapControl.GeometrySelected -= MapControl_GeometrySelected; base.AfterClose(); } } }