123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- 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 Recordset rdSelect = null;
- private string _qsdh_new = "未确认";
- private string _zddh_new = "未确认";
- private UIButton uiButton1;
- private UIButton uiButton2;
- private GeoLine _geoLine = null;
- public GuanXianHeBing() : base()
- {
- this.ConditionPanelName = "管线合并";
- InitializeComponent();
- this.SetSize(300, 200);
- this.IsShowResultWindow = false;
- }
- protected override void OnLoad(EventArgs e)
- {
- ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, true);
- }
- private void uiButton1_Click(object sender, EventArgs e)
- {
- Selection[] _selection = MapControl.Map.FindSelection(true);
- if (_selection.Length != 1 || _selection[0].Count != 2)
- {
- Sunny.UI.UIMessageTip.ShowError("依次选择需要合并的两根管线");
- _selection[0].Clear();
- return;
- }
- rdSelect = _selection[0].ToRecordset();
- rdSelect.SeekID(_selection[0][0]);
- _qsdh_new = rdSelect.GetString("qsdh");
- //if (string.IsNullOrEmpty(_qsdh_new))
- //{
- // Sunny.UI.UIMessageTip.ShowError("第一根管线不存在起始点号"); return;
- //}
- Recordset rdGuanDian = ComsStatic.gsGuanDian.Query(string.Format(" bsm = '{0}' ", _qsdh_new), CursorType.Static);
- if (rdGuanDian.RecordCount != 1)
- {
- Sunny.UI.UIMessageTip.ShowError("无法找到管线起始点号的管点信息"); return;
- }
- Point2D startPoint = new Point2D(rdGuanDian.GetDouble("x"), rdGuanDian.GetDouble("y"));
- rdSelect.SeekID(_selection[0][1]);
- _zddh_new = rdSelect.GetString("zddh");
- //if (string.IsNullOrEmpty(_zddh_new))
- //{
- // Sunny.UI.UIMessageTip.ShowError("最后一根管线不存在终点点号"); return;
- //}
- rdGuanDian = ComsStatic.gsGuanDian.Query(string.Format(" bsm = '{0}' ", _zddh_new), CursorType.Static);
- if (rdGuanDian.RecordCount != 1)
- {
- Sunny.UI.UIMessageTip.ShowError("无法找到管线终点点号的管点信息"); return;
- }
- Point2D endPoint = new Point2D(rdGuanDian.GetDouble("x"), rdGuanDian.GetDouble("y"));
- ComsStatic.RecordsetDispose(rdGuanDian);
- Point2Ds _goeLinePoints = new Point2Ds(); _goeLinePoints.Add(startPoint); _goeLinePoints.Add(endPoint);
- _geoLine = new GeoLine(_goeLinePoints);
- _geoLine.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
- MapControl.Map.TrackingLayer.Clear();
- 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;
- }
- EditHistory m_EditHistory = new EditHistory();
- try
- {
- //1 新增合并后的管线
- Recordset _rd = ComsStatic.gsGuanXian.GetRecordset(true, CursorType.Dynamic);
- _rd.AddNew(_geoLine);
- m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false);
- m_EditHistory.Add(SuperMap.Data.EditType.Modify, _rd, false);
- _rd.Edit();
- _rd.SetFieldValue("qsdh", _qsdh_new);
- _rd.SetFieldValue("zddh", _zddh_new);
- _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
- _rd.SetFieldValue("cd", ComsStatic.StringToDouble(_geoLine.Length, 2));
- _rd.SetFieldValue("shape_length", _geoLine.Length);
- Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "OBJECTID") + 1;
- _rd.SetFieldValue("objectid", objID);
- _rd.SetFieldValue("fldm", ComsStatic.dvGXCaption);
- _rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID);
- _rd.SetFieldValue("cqbh", "管线合并");
- if (_rd.Update())
- {
- ComsStatic.RecordsetDispose(_rd);
- Commons.LogHelper.Info(string.Format("管线合并-新增合并后管线成功!新增的OBJECTID是{0}。", objID));
- }
- else
- {
- ComsStatic.EditHistoryUndo(m_EditHistory);
- ComsStatic.ShowErrorLog("新增合并后的管线操作失败"); return false;
- }
- //2 删除原管线 限制2条管线
- rdSelect.MoveFirst();
- while (!rdSelect.IsEOF)
- {
- m_EditHistory.Add(SuperMap.Data.EditType.Delete, rdSelect, true);
- if (rdSelect.Delete())
- {
- Commons.LogHelper.Info(string.Format("管线合并-删除原管线成功!smid={0}的管线", rdSelect.GetID()));
- }
- else
- {
- ComsStatic.EditHistoryUndo(m_EditHistory);
- ComsStatic.ShowErrorLog("原管线删除操作失败"); return false;
- }
- }
- ComsStatic.RecordsetDispose(rdSelect);
- ComsStatic.ShowOKLog("操作成功", string.Format("新增管线{0}", objID));
- }
- catch
- {
- ComsStatic.EditHistoryUndo(m_EditHistory);
- ComsStatic.ShowErrorLog("管线合并失败!"); return false;
- }
- return true;
- }
- 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(161, 43);
- 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(12, 43);
- 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(300, 115);
- this.Style = Sunny.UI.UIStyle.Gray;
- this.ResumeLayout(false);
- }
- private void uiButton2_Click(object sender, EventArgs e)
- {
- _qsdh_new = "未确认";
- _zddh_new = "未确认";
- rdSelect = null;
- MapControl.Map.TrackingLayer.Clear();
- MapControl.Map.RefreshTrackingLayer();
- }
- }
- }
|