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 GuanDianBianGeng : ConditionPanel { Point2D newPoint; private string yuanBSM = string.Empty; private string xinBSM = string.Empty; Recordset rdJSLKqsdh = null; Recordset rdJSLKzddh = null; public GuanDianBianGeng() { 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; } private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e) { Point2D point = MapControl.Map.PixelToMap(new Point(e.X, e.Y)); GeoPoint _clickPoint = new GeoPoint(point); Recordset rdJSJDPT = ComsStatic.gsGuanDian.Query(_clickPoint, 10, CursorType.Static); if (rdJSJDPT.RecordCount == 0) { Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线节点"); return; } double distance = 0.0D; double distance_temp = 0.0D; GeoPoint _rdPoint = null;//最终确认的管点 GeoPoint _rdPoint_temp; int smid = 0; rdJSJDPT.MoveFirst(); while (!rdJSJDPT.IsEOF) { _rdPoint_temp = new GeoPoint(rdJSJDPT.GetDouble("x"), rdJSJDPT.GetDouble("y")); distance_temp = Geometrist.Distance(_clickPoint, _rdPoint_temp); if (distance_temp <= distance || distance == 0.0D) { distance = distance_temp; _rdPoint = _rdPoint_temp; smid = rdJSJDPT.GetID(); } rdJSJDPT.MoveNext(); } rdJSJDPT.SeekID(smid); string bsm = rdJSJDPT.GetString("bsm"); _rdPoint.Style = ComsStatic.geoStyle_Red_Mark5mm; if (string.IsNullOrEmpty(yuanBSM)) { yuanBSM = bsm; MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_Start"); MapControl.Map.RefreshTrackingLayer(); uiLabelY.Text = string.Format("原节点:{0} 标识码:{1}", rdJSJDPT.GetString("fldm"), bsm); } else { xinBSM = bsm; newPoint = _rdPoint.InnerPoint; int index = MapControl.Map.TrackingLayer.IndexOf("GuanDianLianJie_End"); if (index >= 0) { MapControl.Map.TrackingLayer.Remove(index); } MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_End"); MapControl.Map.RefreshTrackingLayer(); uiLabelX.Text = string.Format("新节点:{0} 标识码:{1}", rdJSJDPT.GetString("fldm"), bsm); } } public override object Do(DockPanel dockPanel = null) { if (string.IsNullOrEmpty(yuanBSM) || string.IsNullOrEmpty(xinBSM) || yuanBSM == xinBSM || (rdJSLKqsdh is null && rdJSLKzddh is null)) { Sunny.UI.UIMessageTip.ShowError("请先选择原节点和新节点,然后点击“新管线预览”"); return false; } EditHistory m_EditHistory = new EditHistory(); try { Recordset rdJSJDPT = null; string yuanBMS = string.Empty; //1 更改原管线的节点 起始点号 if (rdJSLKqsdh.RecordCount > 0) { rdJSLKqsdh.MoveFirst(); while (!rdJSLKqsdh.IsEOF) { rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKqsdh.GetString("zddh")), CursorType.Static); if (rdJSJDPT.RecordCount != 1) continue; Point2D p = new Point2D(rdJSJDPT.GetDouble("X"), rdJSJDPT.GetDouble("Y")); GeoLine newline = new GeoLine(new Point2Ds(newPoint, p)); m_EditHistory.Add(EditType.Modify, rdJSLKqsdh, false); rdJSLKqsdh.Edit(); rdJSLKqsdh.SetFieldValue("qsdh", xinBSM); rdJSLKqsdh.SetFieldValue("cd", ComsStatic.StringToDouble(newline.Length, 2)); rdJSLKqsdh.SetFieldValue("shape_length", newline.Length); rdJSLKqsdh.SetGeometry(newline); if (rdJSLKqsdh.Update()) { Commons.LogHelper.Info(string.Format("管点变更-更改原管线的起始点号成功!管线的SMID是{0}。", rdJSLKqsdh.GetID())); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("管点变更出错", "终点点号不变,更新起始点号 操作失败!"); return false; } rdJSLKqsdh.MoveNext(); } } //2 更改原管线的节点 终点点号 if (rdJSLKzddh.RecordCount > 0) { rdJSLKzddh.MoveFirst(); while (!rdJSLKzddh.IsEOF) { rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKzddh.GetString("qsdh")), CursorType.Static); if (rdJSJDPT.RecordCount != 1) continue; Point2D p = new Point2D(rdJSJDPT.GetDouble("X"), rdJSJDPT.GetDouble("Y")); GeoLine newline = new GeoLine(new Point2Ds(p, newPoint)); m_EditHistory.Add(EditType.Modify, rdJSLKzddh, false); rdJSLKzddh.Edit(); rdJSLKzddh.SetFieldValue("zddh", xinBSM); rdJSLKzddh.SetFieldValue("cd", ComsStatic.StringToDouble(newline.Length, 2)); rdJSLKzddh.SetFieldValue("shape_length", newline.Length); rdJSLKzddh.SetGeometry(newline); if (rdJSLKzddh.Update()) { Commons.LogHelper.Info(string.Format("管点变更-更改原管线的终点点号成功!管线的SMID是{0}。", rdJSLKzddh.GetID())); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("管点变更出错", "起始管点不变,更新终点管点 操作失败!"); return false; } rdJSLKzddh.MoveNext(); } } ComsStatic.ShowOKLog("管点变更成功", string.Format("原节点{0} 新节点{1} 变更起始点号的管线{2}根,变更终点点号的管线{3}根", yuanBSM, xinBSM, rdJSLKqsdh.RecordCount, rdJSLKzddh.RecordCount)); } 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) || string.IsNullOrEmpty(xinBSM) || yuanBSM == xinBSM) { 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); if (rdJSLKqsdh.RecordCount == 0 && rdJSLKzddh.RecordCount == 0) { Sunny.UI.UIMessageTip.ShowError("原节点未查询到管线信息!"); return; } Recordset rdJSJDPT = null; if (rdJSLKqsdh.RecordCount != 0) { rdJSLKqsdh.MoveFirst(); while (!rdJSLKqsdh.IsEOF) { rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKqsdh.GetString("zddh")), CursorType.Static); if (rdJSJDPT.RecordCount != 1) rdJSLKqsdh.MoveNext(); Point2D p = new Point2D(rdJSJDPT.GetDouble("X"), rdJSJDPT.GetDouble("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.GetString("qsdh")), CursorType.Static); if (rdJSJDPT.RecordCount != 1) rdJSLKzddh.MoveNext(); Point2D p = new Point2D(rdJSJDPT.GetDouble("X"), rdJSJDPT.GetDouble("Y")); 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; yuanBSM = string.Empty; xinBSM = string.Empty; newPoint = new Point2D(0, 0); uiLabelY.Text = "原节点:"; uiLabelX.Text = "新节点:"; } public override void AfterClose() { ComsStatic.RecordsetDispose(rdJSLKqsdh); ComsStatic.RecordsetDispose(rdJSLKzddh); MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick; base.AfterClose(); } } }