using Sunny.UI; using SuperMap.Data; using SuperMap.Mapping; using System; using System.Drawing; using WeifenLuo.WinFormsUI.Docking; using WWPipeLine.MapBasic.Conditions; using System.Windows.Forms; using WWPipeLine.MapBasic; using System.Data; using System.Text; namespace WWPipeLine.MapTools.Conditions.EditGuanWang { public class GuanXianDaDuan : ConditionPanel { private UIButton uiButton2; private UIButton uiButton1; private Point2D _duandianPoint = new Point2D(0, 0); private int smidGX = 0; private GeoLine _geoLineStart = null; private GeoLine _geoLineEnd = null; private Recordset rdJSLKdd; public GuanXianDaDuan() : base() { this.ConditionPanelName = "打断管线"; InitializeComponent(); this.SetSize(300, 200); IsShowResultWindow = false; } protected override void OnLoad(EventArgs e) { ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, true); MapControl.MouseDoubleClick += MapControl_MouseDoubleClick; } private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e) { _duandianPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y)); GeoPoint pointClick = new GeoPoint(_duandianPoint); Recordset rdJSLK = ComsStatic.gsGuanXian.Query(pointClick, 3, CursorType.Static); if (rdJSLK.RecordCount == 0) { Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线信息"); return; } double distance_temp = 0.0D; double distance = 0.0D; GeoLine _rd_temp; GeoLine _rd_line = new GeoLine(); rdJSLK.MoveFirst(); while (!rdJSLK.IsEOF) { _rd_temp = rdJSLK.GetGeometry() as GeoLine; distance_temp = Geometrist.Distance(pointClick, _rd_temp); if (distance_temp <= distance || distance == 0.0D) { distance = distance_temp; _rd_line = _rd_temp; smidGX = rdJSLK.GetID(); } rdJSLK.MoveNext(); } _duandianPoint = Geometrist.NearestPointToVertex(_duandianPoint, _rd_line); GeoPoint _geoPoint = new GeoPoint(_duandianPoint); _geoPoint.Style = ComsStatic.geoStyle_Red_Mark5mm; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.TrackingLayer.Add(_geoPoint, "GuanXianDaDuan"); MapControl.Map.RefreshTrackingLayer(); } private void uiButton1_Click(object sender, EventArgs e) { if (smidGX == 0) { Sunny.UI.UIMessageTip.ShowError("请在需要打断的管线上双击确认断点"); return; } rdJSLKdd = ComsStatic.gsGuanXian.Query(new int[] { smidGX }, CursorType.Dynamic); //if (rdJSLKdd.RecordCount != 1) //{ // Sunny.UI.UIMessageTip.ShowError("无法查询到选择管线的信息"); return; //} Recordset rdGuanDian = ComsStatic.gsGuanDian.Query(string.Format("bsm='{0}'", rdJSLKdd.GetString("qsdh")), CursorType.Static); if (rdGuanDian.RecordCount != 1) { Sunny.UI.UIMessageTip.ShowError("无法确认起始点号"); return; } Point2D startPoint = new Point2D(rdGuanDian.GetDouble("x"), rdGuanDian.GetDouble("y")); rdGuanDian = ComsStatic.gsGuanDian.Query(string.Format("bsm='{0}'", rdJSLKdd.GetString("zddh")), CursorType.Static); if (rdGuanDian.RecordCount != 1) { Sunny.UI.UIMessageTip.ShowError("无法确认终点点号"); return; } Point2D endPoint = new Point2D(rdGuanDian.GetDouble("x"), rdGuanDian.GetDouble("y")); MapControl.Map.TrackingLayer.Clear(); Point2Ds _geoPointsStart = new Point2Ds(new Point2D[] { startPoint, _duandianPoint }); _geoLineStart = new GeoLine(_geoPointsStart); _geoLineStart.Style = new GeoStyle { LineColor = Color.Yellow, LineWidth = 1 }; MapControl.Map.TrackingLayer.Add(_geoLineStart, "geoLineStart"); Point2Ds _geoPointEnd = new Point2Ds(new Point2D[] { _duandianPoint, endPoint }); _geoLineEnd = new GeoLine(_geoPointEnd); _geoLineEnd.Style = new GeoStyle { LineColor = Color.Brown, LineWidth = 1 }; MapControl.Map.TrackingLayer.Add(_geoLineEnd, "geoLineEnd"); MapControl.Map.RefreshTrackingLayer(); } public override object Do(DockPanel dockPanel = null) { EditHistory m_EditHistory = new EditHistory(); m_EditHistory.Capacity = 5; if (smidGX == 0 || _geoLineStart is null || _geoLineEnd is null) { Sunny.UI.UIMessageTip.ShowError("请先执行“打断管线”操作"); return false; } try { //1 新增 节点信息 Recordset rddvJSJDPT = ComsStatic.gsGuanDian.GetRecordset(true, CursorType.Dynamic); rddvJSJDPT.AddNew(new GeoPoint(_duandianPoint)); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, rddvJSJDPT, false); m_EditHistory.Add(SuperMap.Data.EditType.Modify, rddvJSJDPT, false); rddvJSJDPT.Edit(); rddvJSJDPT.SetFieldValue("x", _duandianPoint.X); rddvJSJDPT.SetFieldValue("y", _duandianPoint.Y); Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanDian, "objectid") + 1; string _duandian = "dvJD" + objID; rddvJSJDPT.SetFieldValue("objectid", objID); rddvJSJDPT.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); rddvJSJDPT.SetFieldValue("bsm", _duandian); rddvJSJDPT.SetFieldValue("fldm", "供水节点"); rddvJSJDPT.SetFieldValue("cqbh", "管线打断-新增节点"); if (rddvJSJDPT.Update()) { (ComsStatic.Datasource.Datasets["dvJD"] as DatasetVector).Append(rddvJSJDPT); ComsStatic.RecordsetDispose(rddvJSJDPT); Commons.LogHelper.Info(string.Format("管线打断-新增节点成功!新增的OBJECTID是{0}。", objID)); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("管线打断操作失败", "管线打断-新增节点操作失败!"); return false; } //2 新增 起始管线 Recordset _rd = ComsStatic.gsGuanXian.GetRecordset(true, CursorType.Dynamic); _rd.AddNew(_geoLineStart); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false); m_EditHistory.Add(SuperMap.Data.EditType.Modify, _rd, false); _rd.Edit(); _rd.SetFieldValue("qsdh", rdJSLKdd.GetFieldValue("qsdh")); _rd.SetFieldValue("zddh", _duandian); _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); _rd.SetFieldValue("gj", rdJSLKdd.GetFieldValue("gj")); objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "objectid") + 1; _rd.SetFieldValue("objectid", objID); _rd.SetFieldValue("fldm", ComsStatic.dvGXCaption); _rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID); _rd.SetFieldValue("cd", ComsStatic.StringToDouble(_geoLineStart.Length, 2)); _rd.SetFieldValue("shape_length", _geoLineStart.Length); _rd.SetFieldValue("cqbh", "管线打断-新增起始管线"); if (_rd.Update()) { Commons.LogHelper.Info(string.Format("管线打断-新增起始管线成功!新增的OBJECTID是{0}。", objID)); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("管线打断操作失败", "管线打断-新增起始管线操作失败!"); return false; } //3 新增 结束管线 _rd = ComsStatic.gsGuanXian.GetRecordset(true, CursorType.Dynamic); _rd.AddNew(_geoLineEnd); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false); m_EditHistory.Add(SuperMap.Data.EditType.Modify, _rd, false); _rd.Edit(); _rd.SetFieldValue("qsdh", _duandian); _rd.SetFieldValue("zddh", rdJSLKdd.GetFieldValue("zddh")); _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); _rd.SetFieldValue("gj", rdJSLKdd.GetFieldValue("gj")); objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "objectid") + 1; _rd.SetFieldValue("objectid", objID); _rd.SetFieldValue("fldm", ComsStatic.dvGXCaption); _rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID); _rd.SetFieldValue("cd", ComsStatic.StringToDouble(_geoLineEnd.Length, 2)); _rd.SetFieldValue("shape_length", _geoLineEnd.Length); _rd.SetFieldValue("cqbh", "管线打断-新增结束管线"); if (_rd.Update()) { Commons.LogHelper.Info(string.Format("管线打断-新增结束管线成功!新增的OBJECTID是{0}。", objID)); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("管线打断操作失败", "管线打断-新增结束管线操作失败!"); return false; } //4 删除 原管线 m_EditHistory.Add(SuperMap.Data.EditType.Delete, rdJSLKdd, false); if (rdJSLKdd.Delete()) { ComsStatic.ShowOKLog("操作成功", string.Format("删除管线{0},新增节点{1}", smidGX, _duandian)); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("管线打断操作失败", "原管线删除失败!"); return false; } } catch (Exception e) { ComsStatic.ShowErrorLog("管线打断出错!", e.Message); return false; } return true; } public override void AfterClose() { MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick; base.AfterClose(); } private void uiButton2_Click(object sender, EventArgs e) { _duandianPoint = new Point2D(0, 0); smidGX = 0; _geoLineStart = null; _geoLineEnd = null; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.RefreshTrackingLayer(); } private void InitializeComponent() { this.uiButton2 = new Sunny.UI.UIButton(); this.uiButton1 = new Sunny.UI.UIButton(); this.SuspendLayout(); // // uiButton2 // this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand; this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165))))); this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129))))); this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129))))); this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiButton2.Location = new System.Drawing.Point(167, 33); this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1); this.uiButton2.Name = "uiButton2"; this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165))))); this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129))))); this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129))))); this.uiButton2.Size = new System.Drawing.Size(123, 30); this.uiButton2.Style = Sunny.UI.UIStyle.Gray; this.uiButton2.TabIndex = 2; this.uiButton2.Text = "取消管线预览"; this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click); // // uiButton1 // this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand; this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165))))); this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129))))); this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129))))); this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiButton1.Location = new System.Drawing.Point(3, 33); this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1); this.uiButton1.Name = "uiButton1"; this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165))))); this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129))))); this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129))))); this.uiButton1.Size = new System.Drawing.Size(123, 30); this.uiButton1.Style = Sunny.UI.UIStyle.Gray; this.uiButton1.TabIndex = 1; this.uiButton1.Text = "预览打断管线"; this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click); // // GuanXianDaDuan // this.Controls.Add(this.uiButton2); this.Controls.Add(this.uiButton1); this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244))))); this.Name = "GuanXianDaDuan"; this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140))))); this.Size = new System.Drawing.Size(300, 115); this.Style = Sunny.UI.UIStyle.Gray; this.ResumeLayout(false); } } }