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 GuanXianHeBing : ConditionPanel { private Selection[] _selection = null; private string _qsdh_new = "未确认"; private string _zddh_new = "未确认"; private UIButton uiButton1; private UIButton uiButton2; private GeoLine _geoLine = null; private EditHistory m_EditHistory = new EditHistory(); public GuanXianHeBing() : base() { this.ConditionPanelName = "管线合并"; InitializeComponent(); this.SetSize(500, 185); this.IsShowResultWindow = false; } protected override void OnLoad(EventArgs e) { ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true); } private void uiButton1_Click(object sender, EventArgs e) { _selection = MapControl.Map.FindSelection(true); if (_selection.Length != 1 || _selection[0].Count != 2) { Sunny.UI.UIMessageTip.ShowError("依次选择需要合并的管线,只能选择两根管线。"); return; } _qsdh_new = ComsStatic.GetOnlyValueByField(ComsStatic.dvJSLK, string.Format(" smid={0}", _selection[0][0]), "qsdh")?.ToString(); if (string.IsNullOrEmpty(_qsdh_new)) { Sunny.UI.UIMessageTip.ShowError("所选择管线不存在起始点号,请先修改管线信息!"); return; } DataTable dataTable = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format(" bsm = '{0}' ", _qsdh_new), new string[] { "x", "y", "fsw", "gg", "cz" }); if (dataTable.Rows.Count != 1) { Sunny.UI.UIMessageTip.ShowError("管线起始点号的管点信息不存在"); return; } Point2D startPoint = new Point2D(double.Parse(dataTable.Rows[0]["x"].ToString()), double.Parse(dataTable.Rows[0]["y"].ToString())); _zddh_new = ComsStatic.GetOnlyValueByField(ComsStatic.dvJSLK, string.Format(" smid={0}", _selection[0][1]), "zddh")?.ToString(); if (string.IsNullOrEmpty(_zddh_new)) { Sunny.UI.UIMessageTip.ShowError("所选择管线不存在终点点号,请先修改管线信息!"); return; } dataTable = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format(" bsm = '{0}' ", _zddh_new), new string[] { "x", "y", "fsw", "gg", "cz" }); if (dataTable.Rows.Count != 1) { Sunny.UI.UIMessageTip.ShowError("管线终点点号的管点信息不存在"); return; } Point2D endPoint = new Point2D(double.Parse(dataTable.Rows[0]["x"].ToString()), double.Parse(dataTable.Rows[0]["y"].ToString())); Point2Ds _goeLinePoints = new Point2Ds(); _goeLinePoints.Add(startPoint); _goeLinePoints.Add(endPoint); _geoLine = new GeoLine(_goeLinePoints); _geoLine.Style = new GeoStyle { LineColor = Color.Red, LineWidth = 1.2 }; ; if (_geoLine.Length == 0) { Sunny.UI.UIMessageTip.ShowError("管线选择错误,请重新选择。目前选择的管线无法合并!"); return; } int index = MapControl.Map.TrackingLayer.IndexOf("geoLineNew"); if (index >= 0) MapControl.Map.TrackingLayer.Remove(index); MapControl.Map.TrackingLayer.Add(_geoLine, "geoLineNew"); MapControl.Map.RefreshTrackingLayer(); #region 由于ToRecordset方法会将 Selection[] 按照SMID从小到大排序,打乱选择的顺序。无法根据选择的先后顺序进行合并管线。 //Recordset _recordset = _selection[0].ToRecordset(); ////验证 ToRecordset方法会将 Selection按照SMID从小到大排序,打乱选择的顺序 ////for (int i = 0; i < _selection[0].Count; i++) ////{ //// uilbNew.Text += string.Format("\r\n _selection[0][{0}] value:{1}", i, _selection[0][i]); ////} ////_recordset.MoveFirst(); ////for (int i = 0; i < _recordset.RecordCount; i++) ////{ //// uilbNew.Text += string.Format("\r\n Recordset SmID:{0} 起始点号:{1} 终点点号:{2}", _recordset.GetFieldValue("smid"), _recordset.GetFieldValue("qsdh"), _recordset.GetFieldValue("zddh")); //// _recordset.MoveNext(); ////} ////验证 结束 #endregion } public override object Do(DockPanel dockPanel = null) { if (_qsdh_new == _zddh_new || _geoLine is null) { Sunny.UI.UIMessageTip.ShowError("未执行合并管线操作"); return false; } m_EditHistory.Capacity = 3; try { //1 新增合并后的管线 Recordset _rd = ComsStatic.dvJSLK.GetRecordset(true, CursorType.Dynamic); m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, true); _rd.AddNew(_geoLine); _rd.SetFieldValue("qsdh", _qsdh_new); _rd.SetFieldValue("zddh", _zddh_new); _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLine.Length))); _rd.SetFieldValue("enabled", 1); _rd.SetFieldValue("shape_length", _geoLine.Length); Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSLK, "OBJECTID") + 1; _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime()); _rd.SetFieldValue("objectid", objID); _rd.SetFieldValue("bsm", "JSLK" + objID); _rd.SetFieldValue("fldm", "供水管线"); _rd.SetFieldValue("cqbh", "管线合并"); if (_rd.Update()) { Commons.LogHelper.Error(string.Format("管线合并-新增合并后管线成功!新增的OBJECTID是{0}。", objID)); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("新增合并后的管线操作失败"); return false; } //2 删除原管线 至少2条 Recordset _recordset = _selection[0].ToRecordset(); m_EditHistory.Add(SuperMap.Data.EditType.Delete, _recordset, true); if (_recordset.DeleteAll()) { Commons.LogHelper.Error(string.Format("管线合并-删除原管线成功!")); } else { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("原管线删除操作失败"); return false; } } catch { ComsStatic.EditHistoryUndo(m_EditHistory); ComsStatic.ShowErrorLog("管线合并失败!"); return false; } return true; } public override void AfterClose() { m_EditHistory.Clear(); m_EditHistory.Dispose(); base.AfterClose(); } 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.Default; 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(247, 40); this.uiButton2.Margin = new System.Windows.Forms.Padding(30); 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(126, 30); this.uiButton2.Style = Sunny.UI.UIStyle.Gray; this.uiButton2.TabIndex = 3; this.uiButton2.Text = "取消管线预览"; this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click); // // uiButton1 // this.uiButton1.Cursor = System.Windows.Forms.Cursors.Default; 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(69, 40); this.uiButton1.Margin = new System.Windows.Forms.Padding(30); 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(126, 30); this.uiButton1.Style = Sunny.UI.UIStyle.Gray; this.uiButton1.TabIndex = 1; this.uiButton1.Text = "预览合并管线"; this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click); // // GuanXianHeBing // 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 = "GuanXianHeBing"; 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); } private void uiButton2_Click(object sender, EventArgs e) { _selection = null; MapControl.Action = SuperMap.UI.Action.Pan; MapControl.Map.TrackingLayer.Clear(); MapControl.Map.Refresh(); } } }