123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- 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 UILabel lbRemark;
- private Selection[] _selection = null;
- private Panel plMain;
- private string _qsdh_new = "未确认";
- private string _zddh_new = "未确认";
- private UIButton uiButton1;
- private UILabel uilbNew;
- private UIButton uiButton2;
- private GeoLine _geoLine = null;
- private DatasetVectorEx _dvEx;
- private EditHistory m_EditHistory = new EditHistory();
- public GuanXianHeBing() : base()
- {
- this.ConditionPanelName = "管线合并";
- InitializeComponent();
- lbRemark.Text = "请依次选择需要合并的管线, 至少选择2根管线。\r\n 合并后管线的起点为第一根管线的起点,\r\n终点为最后一根管线的终点。";
- }
- protected override void OnLoad(EventArgs e)
- {
- ComsStatic.SetLayerIsEditableFalse();
- }
- 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 < 2)
- {
- Sunny.UI.UIMessageTip.ShowError("依次选择需要合并的管线,至少选择2跟管线。"); return;
- }
- DatasetVectorEx _dvExJSJDPT = new DatasetVectorEx(ComsStatic.dvJSJDPT.Name) { DatasetVector = ComsStatic.dvJSJDPT };
- _dvExJSJDPT.ResultFields.AddRange(new string[] { "x", "y", "fsw", "gg", "cz" });
- _dvEx = new DatasetVectorEx(dvJSLK_cp.Name) { DatasetVector = dvJSLK_cp };
- _qsdh_new = _dvEx.QueryGetValueByOnlyField(string.Format(" smid={0}", _selection[0][0]), "qsdh");
- if (string.IsNullOrEmpty(_qsdh_new))
- {
- Sunny.UI.UIMessageTip.ShowError("所选择管线不存在起始点号,请先修改管线信息!"); return;
- }
- DataTable dataTable = _dvExJSJDPT.Query(string.Format(" bsm = '{0}' ", _qsdh_new));
- if (dataTable.Rows.Count != 1)
- {
- Sunny.UI.UIMessageTip.ShowError("管线起始点号的管点信息不存在", 2000); return;
- }
- Point2D startPoint = new Point2D(double.Parse(dataTable.Rows[0]["x"].ToString()), double.Parse(dataTable.Rows[0]["y"].ToString()));
- sb.AppendFormat("\r\n起始点号:{0},为{1}附属物 规格是{2} 材质是{3}。", _qsdh_new, dataTable.Rows[0]["fsw"], dataTable.Rows[0]["gg"], dataTable.Rows[0]["cz"]);
- sb.AppendFormat("\r\n坐标:{0:F2}-{1:F2}\r\n", startPoint.X, startPoint.Y);
- _zddh_new = _dvEx.QueryGetValueByOnlyField(string.Format(" smid={0}", _selection[0][_selection[0].Count - 1]), "zddh");
- if (string.IsNullOrEmpty(_zddh_new))
- {
- Sunny.UI.UIMessageTip.ShowError("所选择管线不存在终点点号,请先修改管线信息!"); return;
- }
- dataTable = _dvExJSJDPT.Query(string.Format(" wth='{0}' ", _zddh_new));
- 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()));
- sb.AppendFormat("\r\n终点点号:{0},为{1}附属物 规格是{2} 材质是{3}。", _zddh_new, dataTable.Rows[0]["fsw"], dataTable.Rows[0]["gg"], dataTable.Rows[0]["cz"]);
- sb.AppendFormat("\r\n坐标:{0:F2}-{1:F2}\r\n", endPoint.X, endPoint.Y);
- Point2Ds _goeLinePoints = new Point2Ds(); _goeLinePoints.Add(startPoint); _goeLinePoints.Add(endPoint);
- _geoLine = new GeoLine(_goeLinePoints);
- _geoLine.Style = new GeoStyle { LineColor = Color.Red, LineWidth = 3 }; ;
- if (_geoLine.Length == 0)
- {
- Sunny.UI.UIMessageTip.ShowError("管线选择错误,请重新选择。目前选择的管线无法合并!", 2000); return;
- }
- sb.AppendFormat("\r\n新管线长度:{0:F2}\r\n", _geoLine.Length);
- uilbNew.Text = sb.ToString();
- int index = MapControl.Map.TrackingLayer.IndexOf("geoLineNew");
- if (index >= 0) MapControl.Map.TrackingLayer.Remove(index);
- MapControl.Map.TrackingLayer.Add(_geoLine, "geoLineNew");
- MapControl.Map.Refresh();
- #region 由于ToRecordset方法会将 Selection[] 按照SMID从小到大排序,打乱选择的顺序。无法根据选择的先后顺序进行合并管线。
- //Recordset _recordset = _selection[0].ToRecordset();//此处ToRecordset方法会将 Selection按照SMID从小到大排序,打乱选择的顺序
- ////验证 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)
- {
- Sunny.UI.UIMessageTip.ShowError("起始点号和终点点号不能相同"); return false;
- }
- m_EditHistory.Capacity = 3;
- this.IsShowResultWindow = false;
- if (_geoLine is null)
- {
- Sunny.UI.UIMessageTip.ShowError("未执行合并管线操作", 2000); return false;
- }
- try
- {
- //1 新增合并后的管线
- Recordset _rd = dvJSLK_cp.GetRecordset(false, 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 = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSLK, "OBJECTID").ToString()) + 1;
- _rd.SetFieldValue("objectid", objID);
- _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;
- }
- MapControl.Map.Refresh();
- return true;
- }
- public override void AfterClose()
- {
- m_EditHistory.Clear(); m_EditHistory.Dispose();
- base.AfterClose();
- }
- private void InitializeComponent()
- {
- this.plMain = new System.Windows.Forms.Panel();
- this.uiButton2 = new Sunny.UI.UIButton();
- this.uilbNew = new Sunny.UI.UILabel();
- 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.uiButton2);
- this.plMain.Controls.Add(this.uilbNew);
- 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(445, 317);
- this.plMain.TabIndex = 0;
- //
- // 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(181, 137);
- 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(146, 35);
- this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
- this.uiButton2.TabIndex = 3;
- this.uiButton2.Text = "重新选择管线";
- this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
- //
- // uilbNew
- //
- this.uilbNew.AutoSize = true;
- this.uilbNew.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uilbNew.Location = new System.Drawing.Point(10, 189);
- this.uilbNew.Margin = new System.Windows.Forms.Padding(0);
- this.uilbNew.Name = "uilbNew";
- this.uilbNew.Size = new System.Drawing.Size(138, 21);
- this.uilbNew.Style = Sunny.UI.UIStyle.Gray;
- this.uilbNew.TabIndex = 2;
- this.uilbNew.Text = "合并后的管线信息";
- this.uilbNew.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // 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(10, 137);
- 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(146, 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.Dock = System.Windows.Forms.DockStyle.Top;
- this.lbRemark.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.lbRemark.Location = new System.Drawing.Point(0, 0);
- this.lbRemark.Margin = new System.Windows.Forms.Padding(0);
- 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;
- //
- // GuanXianHeBing
- //
- this.Controls.Add(this.plMain);
- 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(445, 317);
- this.Style = Sunny.UI.UIStyle.Gray;
- this.plMain.ResumeLayout(false);
- this.plMain.PerformLayout();
- this.ResumeLayout(false);
- }
- private void uiButton2_Click(object sender, EventArgs e)
- {
- uilbNew.Text = "合并后的管线信息:";
- MapControl.Action = SuperMap.UI.Action.Pan;
- MapControl.Cursor = Cursors.Default;
- MapControl.Map.TrackingLayer.Clear();
- MapControl.Map.Refresh();
- }
- }
- }
|