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(500, 185); IsShowResultWindow = false; } protected override void OnLoad(EventArgs e) { ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.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.dvJSLK.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.dvJSLK.Query(new int[] { smidGX }, CursorType.Dynamic); if (rdJSLKdd.RecordCount != 1) { Sunny.UI.UIMessageTip.ShowError("无法查询到选择管线的信息,请先确认管线的基本信息"); return; } DataTable dtJSJDPT = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format("bsm='{0}'", rdJSLKdd.GetFieldValue("qsdh")));//dtJSLK.Rows[0]["qsdh"] if (dtJSJDPT.Rows.Count != 1) { Sunny.UI.UIMessageTip.ShowError("当前选择的管线无法确认起始点号"); return; } Point2D startPoint = new Point2D(double.Parse(dtJSJDPT.Rows[0]["x"].ToString()), double.Parse(dtJSJDPT.Rows[0]["y"].ToString())); dtJSJDPT = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format("bsm='{0}'", rdJSLKdd.GetFieldValue("zddh")));//dtJSLK.Rows[0]["zddh"] if (dtJSJDPT.Rows.Count != 1) { Sunny.UI.UIMessageTip.ShowError("当前选择的管线无法确认终点点号"); return; } Point2D endPoint = new Point2D(double.Parse(dtJSJDPT.Rows[0]["x"].ToString()), double.Parse(dtJSJDPT.Rows[0]["y"].ToString())); Point2Ds _geoPointsStart = new Point2Ds(new Point2D[] { startPoint, _duandianPoint }); _geoLineStart = new GeoLine(_geoPointsStart); _geoLineStart.Style = new GeoStyle { LineColor = Color.Yellow, LineWidth = 1 }; ; int index = MapControl.Map.TrackingLayer.IndexOf("geoLineStart"); if (index >= 0) MapControl.Map.TrackingLayer.Remove(index); 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 }; ; index = MapControl.Map.TrackingLayer.IndexOf("geoLineEnd"); if (index >= 0) MapControl.Map.TrackingLayer.Remove(index); 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 (_geoLineStart is null || _geoLineEnd is null) { Sunny.UI.UIMessageTip.ShowError("请先执行“管线打断”操作", 4000); return false; } try { //1 新增 节点信息 Recordset rddvJSJDPT = ComsStatic.dvJSJDPT.GetRecordset(true, CursorType.Dynamic); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, rddvJSJDPT, false); rddvJSJDPT.AddNew(new GeoPoint(_duandianPoint)); rddvJSJDPT.SetFieldValue("x", _duandianPoint.X); rddvJSJDPT.SetFieldValue("y", _duandianPoint.Y); Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSJDPT, "OBJECTID") + 1; string _duandian = "JSJDPT" + objID; rddvJSJDPT.SetFieldValue("ms", 0); rddvJSJDPT.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); rddvJSJDPT.SetFieldValue("enabled", 1); rddvJSJDPT.SetFieldValue("bsm", _duandian); rddvJSJDPT.SetFieldValue("fldm", "供水节点"); rddvJSJDPT.SetFieldValue("objectid", objID); rddvJSJDPT.SetFieldValue("cqbh", "管线打断"); if (rddvJSJDPT.Update()) { Commons.LogHelper.Error(string.Format("管线打断-新增管线节点成功!新增的OBJECTID是{0}。", objID)); } else { ComsStatic.EditHistoryUndo(m_EditHistory); Sunny.UI.UIMessageTip.ShowError("管线节点新增操作失败!"); return false; } //2 新增 起始管线 Recordset _rd = ComsStatic.dvJSLK.GetRecordset(true, CursorType.Dynamic); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false); _rd.AddNew(_geoLineStart); _rd.SetFieldValue("qsdh", rdJSLKdd.GetFieldValue("qsdh")); _rd.SetFieldValue("zddh", _duandian); _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); _rd.SetFieldValue("enabled", 1); _rd.SetFieldValue("gj", rdJSLKdd.GetFieldValue("gj")); objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSLK, "OBJECTID") + 1; _rd.SetFieldValue("objectid", objID); _rd.SetFieldValue("bsm", "JSLK" + objID); _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLineStart.Length))); _rd.SetFieldValue("shape_length", _geoLineStart.Length); _rd.SetFieldValue("fldm", "供水管线"); _rd.SetFieldValue("cqbh", "管线打断"); if (_rd.Update()) { Commons.LogHelper.Error(string.Format("管线打断-新增起始管线成功!新增的OBJECTID是{0}。", objID)); } else { ComsStatic.EditHistoryUndo(m_EditHistory); Sunny.UI.UIMessageTip.ShowError("管线的起始管线新增操作失败!"); return false; } //3 新增 结束管线 _rd = ComsStatic.dvJSLK.GetRecordset(true, CursorType.Dynamic); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false); _rd.AddNew(_geoLineEnd); _rd.SetFieldValue("qsdh", _duandian); _rd.SetFieldValue("zddh", rdJSLKdd.GetFieldValue("zddh")); _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); _rd.SetFieldValue("enabled", 1); _rd.SetFieldValue("gj", rdJSLKdd.GetFieldValue("gj")); objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSLK, "OBJECTID") + 1; _rd.SetFieldValue("objectid", objID); _rd.SetFieldValue("bsm", "JSLK" + objID); _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLineStart.Length))); _rd.SetFieldValue("shape_length", _geoLineStart.Length); _rd.SetFieldValue("fldm", "供水管线"); _rd.SetFieldValue("cqbh", "管线打断"); if (_rd.Update()) { Commons.LogHelper.Error(string.Format("管线打断-新增结束管线成功!新增的OBJECTID是{0}。", objID)); } else { ComsStatic.EditHistoryUndo(m_EditHistory); Sunny.UI.UIMessageTip.ShowError("管线的结束管线新增操作失败!"); return false; } //4 删除 原管线 m_EditHistory.Add(SuperMap.Data.EditType.Delete, rdJSLKdd, false); if (rdJSLKdd.Delete()) { Commons.LogHelper.Error(string.Format("管线打断-删除原管线成功。原管线SmID是{0}。", smidGX)); Sunny.UI.UIMessageTip.ShowOk("管线打断操作成功"); } else { ComsStatic.EditHistoryUndo(m_EditHistory); Sunny.UI.UIMessageTip.ShowError("原管线删除失败!"); return false; } } catch (Exception e) { ComsStatic.EditHistoryUndo(m_EditHistory); 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.Refresh(); } 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(263, 29); 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(99, 29); 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(500, 100); this.Style = Sunny.UI.UIStyle.Gray; this.ResumeLayout(false); } } }