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 UILabel lbRemark; private UIButton uiButton2; private UIButton uiButton1; private UILabel uilbNew; private UILabel uiLabel1; private Selection[] _selection = null; private Panel plMain; private Point2D _duandianPoint = new Point2D(0, 0); private GeoPoint _geoPoint = null; private GeoLine _geoLineStart = null; private GeoLine _geoLineEnd = null; private DataTable dtJSLK = new DataTable(); public GuanXianDaDuan() : base() { this.ConditionPanelName = "打断管线"; InitializeComponent(); lbRemark.Text = "先选择一根需要打断的管线,\r\n 然后通过在管线上双击鼠标,标记断点。"; } protected override void OnLoad(EventArgs e) { ComsStatic.SetLayerIsEditableFalse(); ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true); MapControl.MouseDoubleClick += MapControl_MouseDoubleClick; } private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e) { _duandianPoint = this.MapControl.Map.PixelToMap(new Point(e.X, e.Y)); _geoPoint = new GeoPoint(_duandianPoint); _geoPoint.Style = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red }; ; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.TrackingLayer.Add(_geoPoint, "GuanXianDaDuan"); MapControl.Map.Refresh(); uiLabel1.Text = string.Format("断点X坐标:{0:F2},Y坐标:{1:F2}。", _duandianPoint.X, _duandianPoint.Y); } private void uiButton1_Click(object sender, EventArgs e) { uilbNew.Text = "打断后的管线信息:"; StringBuilder sb = new StringBuilder(); _selection = base.MapControl.Map.FindSelection(true); if (_selection.Length != 1 || _selection[0].Count != 1) { Sunny.UI.UIMessageTip.ShowError("选择需要打断的一根管线", 4000); return; } if (_duandianPoint.X == 0 || _duandianPoint.Y == 0) { Sunny.UI.UIMessageTip.ShowError("请在需要打断的管线上双击确认断点", 4000); return; } dtJSLK = ComsStatic.QueryDataTable(ComsStatic.dvJSLK, string.Format(" smid={0}", _selection[0][0])); if (dtJSLK.Rows.Count != 1) { Sunny.UI.UIMessageTip.ShowError("无法查询到选择管线的信息,请先确认管线的基本信息", 4000); return; } DataTable dtJSJDPT = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format("bsm='{0}'", dtJSLK.Rows[0]["qsdh"])); if (dtJSJDPT.Rows.Count != 1) { Sunny.UI.UIMessageTip.ShowError("当前选择的管线无法确认起始点号", 4000); 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}'", dtJSLK.Rows[0]["zddh"])); if (dtJSJDPT.Rows.Count != 1) { Sunny.UI.UIMessageTip.ShowError("当前选择的管线无法确认终点点号", 4000); 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"); sb.AppendFormat("\r\n起点管线为黄色 \r\n 起点X坐标:{0:F2},Y坐标:{1:F2}", startPoint.X, startPoint.Y); sb.AppendFormat("\r\n 终点X坐标:{0:F2},Y坐标:{1:F2}", _duandianPoint.X, _duandianPoint.Y); 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"); sb.AppendFormat("\r\n终点管线为棕色 \r\n 起点X坐标:{0:F2},Y坐标:{1:F2}", _duandianPoint.X, _duandianPoint.Y); sb.AppendFormat("\r\n 终点X坐标:{0:F2},Y坐标:{1:F2}", endPoint.X, endPoint.Y); uilbNew.Text = sb.ToString(); MapControl.Map.Refresh(); } public override object Do(DockPanel dockPanel = null) { EditHistory m_EditHistory = new EditHistory(); m_EditHistory.Capacity = 5; IsShowResultWindow = false; if (_geoPoint is null || _geoLineStart is null || _geoLineEnd is null) { Sunny.UI.UIMessageTip.ShowError("请先执行“管线打断”操作", 4000); return false; } try { Recordset _recordset = _selection[0].ToRecordset(); if (_recordset.RecordCount != 1) { Sunny.UI.UIMessageTip.ShowError("选择需要打断的一根管线", 4000); return false; } //1 新增 节点信息 Recordset rddvJSJDPT = ComsStatic.dvJSJDPT.GetRecordset(false, CursorType.Dynamic); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, rddvJSJDPT, true); rddvJSJDPT.AddNew(_geoPoint); rddvJSJDPT.SetFieldValue("x", _duandianPoint.X); rddvJSJDPT.SetFieldValue("y", _duandianPoint.Y); Int32 objID = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSJDPT, "OBJECTID").ToString()) + 1; string _duandian = "JSJDPT" + objID; rddvJSJDPT.SetFieldValue("ms", 0); rddvJSJDPT.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); rddvJSJDPT.SetFieldValue("enabled", 1); rddvJSJDPT.SetFieldValue("wth", _duandian); 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("管线断点操作失败!", 4000); return false; } //2 新增 起始管线 Recordset _rd = ComsStatic.dvJSLK.GetRecordset(false, CursorType.Dynamic); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, true); _rd.AddNew(_geoLineStart); _rd.SetFieldValue("qsdh", dtJSLK.Rows[0]["qsdh"]); _rd.SetFieldValue("zddh", _duandian); _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); _rd.SetFieldValue("enabled", 1); _rd.SetFieldValue("gj", _recordset.GetFieldValue("gj")); objID = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSLK, "OBJECTID").ToString()) + 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("管线的起始管线操作失败!", 4000); return false; } //3 新增 结束管线 m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, true); _rd.AddNew(_geoLineEnd); _rd.SetFieldValue("qsdh", _duandian); _rd.SetFieldValue("zddh", dtJSLK.Rows[0]["zddh"]); _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); _rd.SetFieldValue("enabled", 1); _rd.SetFieldValue("gj", _recordset.GetFieldValue("gj")); objID = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSLK, "OBJECTID").ToString()) + 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("管线的结束管线操作失败!", 4000); return false; } //4 删除 原管线 m_EditHistory.Add(SuperMap.Data.EditType.Delete, _recordset, true); if (_recordset.DeleteAll()) { } else { ComsStatic.EditHistoryUndo(m_EditHistory); Sunny.UI.UIMessageTip.ShowError("原管线删除失败!", 4000); return false; } } catch { ComsStatic.EditHistoryUndo(m_EditHistory); Sunny.UI.UIMessageTip.ShowError("管线打断出错!"); return false; } return true; } public override void AfterClose() { MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick; base.AfterClose(); } private void uiButton2_Click(object sender, EventArgs e) { uilbNew.Text = "打断后的管线信息:"; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.Refresh(); } private void InitializeComponent() { this.plMain = new System.Windows.Forms.Panel(); this.uiLabel1 = new Sunny.UI.UILabel(); this.uilbNew = new Sunny.UI.UILabel(); this.uiButton2 = new Sunny.UI.UIButton(); this.uiButton1 = new Sunny.UI.UIButton(); this.lbRemark = new Sunny.UI.UILabel(); this.plMain.SuspendLayout(); this.SuspendLayout(); // // plMain // this.plMain.AutoScroll = true; this.plMain.Controls.Add(this.uiLabel1); this.plMain.Controls.Add(this.uilbNew); this.plMain.Controls.Add(this.uiButton2); this.plMain.Controls.Add(this.uiButton1); this.plMain.Controls.Add(this.lbRemark); this.plMain.Dock = System.Windows.Forms.DockStyle.Fill; this.plMain.Location = new System.Drawing.Point(0, 0); this.plMain.Name = "plMain"; this.plMain.Size = new System.Drawing.Size(460, 306); this.plMain.TabIndex = 0; // // uiLabel1 // this.uiLabel1.AutoSize = true; this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiLabel1.Location = new System.Drawing.Point(4, 107); this.uiLabel1.Name = "uiLabel1"; this.uiLabel1.Size = new System.Drawing.Size(218, 21); this.uiLabel1.Style = Sunny.UI.UIStyle.Gray; this.uiLabel1.TabIndex = 4; this.uiLabel1.Text = "管线断点:在管线上双击确认"; this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // uilbNew // this.uilbNew.AutoSize = true; this.uilbNew.Font = new System.Drawing.Font("微软雅黑", 12F); this.uilbNew.Location = new System.Drawing.Point(3, 130); this.uilbNew.Name = "uilbNew"; this.uilbNew.Size = new System.Drawing.Size(154, 21); this.uilbNew.Style = Sunny.UI.UIStyle.Gray; this.uilbNew.TabIndex = 3; this.uilbNew.Text = "打断后的管线信息:"; this.uilbNew.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // 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(130, 58); 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(100, 35); 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(8, 58); 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(100, 35); this.uiButton1.Style = Sunny.UI.UIStyle.Gray; this.uiButton1.TabIndex = 1; this.uiButton1.Text = "打断管线"; this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click); // // lbRemark // this.lbRemark.AutoSize = true; this.lbRemark.Font = new System.Drawing.Font("微软雅黑", 12F); this.lbRemark.Location = new System.Drawing.Point(4, 4); this.lbRemark.Name = "lbRemark"; this.lbRemark.Size = new System.Drawing.Size(74, 21); this.lbRemark.Style = Sunny.UI.UIStyle.Gray; this.lbRemark.TabIndex = 0; this.lbRemark.Text = "要素信息"; this.lbRemark.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // GuanXianDaDuan // this.Controls.Add(this.plMain); 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(460, 306); this.Style = Sunny.UI.UIStyle.Gray; this.plMain.ResumeLayout(false); this.plMain.PerformLayout(); this.ResumeLayout(false); } } }