GuanXianHeBing.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using Sunny.UI;
  2. using SuperMap.Data;
  3. using SuperMap.Mapping;
  4. using System;
  5. using System.Drawing;
  6. using WeifenLuo.WinFormsUI.Docking;
  7. using WWPipeLine.MapBasic.Conditions;
  8. using System.Windows.Forms;
  9. using WWPipeLine.MapBasic;
  10. using System.Data;
  11. using System.Text;
  12. namespace WWPipeLine.MapTools.Conditions.EditGuanWang
  13. {
  14. public class GuanXianHeBing : ConditionPanel
  15. {
  16. private Selection[] _selection = null;
  17. private string _qsdh_new = "未确认";
  18. private string _zddh_new = "未确认";
  19. private UIButton uiButton1;
  20. private UIButton uiButton2;
  21. private GeoLine _geoLine = null;
  22. private EditHistory m_EditHistory = new EditHistory();
  23. public GuanXianHeBing() : base()
  24. {
  25. this.ConditionPanelName = "管线合并";
  26. InitializeComponent();
  27. this.SetSize(500, 185);
  28. this.IsShowResultWindow = false;
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true);
  33. }
  34. private void uiButton1_Click(object sender, EventArgs e)
  35. {
  36. _selection = MapControl.Map.FindSelection(true);
  37. if (_selection.Length != 1 || _selection[0].Count != 2)
  38. {
  39. Sunny.UI.UIMessageTip.ShowError("依次选择需要合并的管线,只能选择两根管线。"); return;
  40. }
  41. _qsdh_new = ComsStatic.GetOnlyValueByField(ComsStatic.dvJSLK, string.Format(" smid={0}", _selection[0][0]), "qsdh")?.ToString();
  42. if (string.IsNullOrEmpty(_qsdh_new))
  43. {
  44. Sunny.UI.UIMessageTip.ShowError("所选择管线不存在起始点号,请先修改管线信息!"); return;
  45. }
  46. DataTable dataTable = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format(" bsm = '{0}' ", _qsdh_new), new string[] { "x", "y", "fsw", "gg", "cz" });
  47. if (dataTable.Rows.Count != 1)
  48. {
  49. Sunny.UI.UIMessageTip.ShowError("管线起始点号的管点信息不存在"); return;
  50. }
  51. Point2D startPoint = new Point2D(double.Parse(dataTable.Rows[0]["x"].ToString()), double.Parse(dataTable.Rows[0]["y"].ToString()));
  52. _zddh_new = ComsStatic.GetOnlyValueByField(ComsStatic.dvJSLK, string.Format(" smid={0}", _selection[0][1]), "zddh")?.ToString();
  53. if (string.IsNullOrEmpty(_zddh_new))
  54. {
  55. Sunny.UI.UIMessageTip.ShowError("所选择管线不存在终点点号,请先修改管线信息!"); return;
  56. }
  57. dataTable = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format(" bsm = '{0}' ", _zddh_new), new string[] { "x", "y", "fsw", "gg", "cz" });
  58. if (dataTable.Rows.Count != 1)
  59. {
  60. Sunny.UI.UIMessageTip.ShowError("管线终点点号的管点信息不存在"); return;
  61. }
  62. Point2D endPoint = new Point2D(double.Parse(dataTable.Rows[0]["x"].ToString()), double.Parse(dataTable.Rows[0]["y"].ToString()));
  63. Point2Ds _goeLinePoints = new Point2Ds(); _goeLinePoints.Add(startPoint); _goeLinePoints.Add(endPoint);
  64. _geoLine = new GeoLine(_goeLinePoints);
  65. _geoLine.Style = new GeoStyle { LineColor = Color.Red, LineWidth = 1.2 }; ;
  66. if (_geoLine.Length == 0)
  67. {
  68. Sunny.UI.UIMessageTip.ShowError("管线选择错误,请重新选择。目前选择的管线无法合并!"); return;
  69. }
  70. int index = MapControl.Map.TrackingLayer.IndexOf("geoLineNew");
  71. if (index >= 0) MapControl.Map.TrackingLayer.Remove(index);
  72. MapControl.Map.TrackingLayer.Add(_geoLine, "geoLineNew");
  73. MapControl.Map.RefreshTrackingLayer();
  74. #region 由于ToRecordset方法会将 Selection[] 按照SMID从小到大排序,打乱选择的顺序。无法根据选择的先后顺序进行合并管线。
  75. //Recordset _recordset = _selection[0].ToRecordset();
  76. ////验证 ToRecordset方法会将 Selection按照SMID从小到大排序,打乱选择的顺序
  77. ////for (int i = 0; i < _selection[0].Count; i++)
  78. ////{
  79. //// uilbNew.Text += string.Format("\r\n _selection[0][{0}] value:{1}", i, _selection[0][i]);
  80. ////}
  81. ////_recordset.MoveFirst();
  82. ////for (int i = 0; i < _recordset.RecordCount; i++)
  83. ////{
  84. //// uilbNew.Text += string.Format("\r\n Recordset SmID:{0} 起始点号:{1} 终点点号:{2}", _recordset.GetFieldValue("smid"), _recordset.GetFieldValue("qsdh"), _recordset.GetFieldValue("zddh"));
  85. //// _recordset.MoveNext();
  86. ////}
  87. ////验证 结束
  88. #endregion
  89. }
  90. public override object Do(DockPanel dockPanel = null)
  91. {
  92. if (_qsdh_new == _zddh_new || _geoLine is null)
  93. {
  94. Sunny.UI.UIMessageTip.ShowError("未执行合并管线操作"); return false;
  95. }
  96. m_EditHistory.Capacity = 3;
  97. try
  98. {
  99. //1 新增合并后的管线
  100. Recordset _rd = ComsStatic.dvJSLK.GetRecordset(true, CursorType.Dynamic);
  101. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, true);
  102. _rd.AddNew(_geoLine);
  103. _rd.SetFieldValue("qsdh", _qsdh_new);
  104. _rd.SetFieldValue("zddh", _zddh_new);
  105. _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLine.Length)));
  106. _rd.SetFieldValue("enabled", 1);
  107. _rd.SetFieldValue("shape_length", _geoLine.Length);
  108. Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSLK, "OBJECTID") + 1;
  109. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  110. _rd.SetFieldValue("objectid", objID);
  111. _rd.SetFieldValue("bsm", "JSLK" + objID);
  112. _rd.SetFieldValue("fldm", "供水管线");
  113. _rd.SetFieldValue("cqbh", "管线合并");
  114. if (_rd.Update())
  115. { Commons.LogHelper.Error(string.Format("管线合并-新增合并后管线成功!新增的OBJECTID是{0}。", objID)); }
  116. else
  117. {
  118. ComsStatic.EditHistoryUndo(m_EditHistory);
  119. ComsStatic.ShowErrorLog("新增合并后的管线操作失败"); return false;
  120. }
  121. //2 删除原管线 至少2条
  122. Recordset _recordset = _selection[0].ToRecordset();
  123. m_EditHistory.Add(SuperMap.Data.EditType.Delete, _recordset, true);
  124. if (_recordset.DeleteAll())
  125. { Commons.LogHelper.Error(string.Format("管线合并-删除原管线成功!")); }
  126. else
  127. {
  128. ComsStatic.EditHistoryUndo(m_EditHistory);
  129. ComsStatic.ShowErrorLog("原管线删除操作失败"); return false;
  130. }
  131. }
  132. catch
  133. {
  134. ComsStatic.EditHistoryUndo(m_EditHistory);
  135. ComsStatic.ShowErrorLog("管线合并失败!"); return false;
  136. }
  137. return true;
  138. }
  139. public override void AfterClose()
  140. {
  141. m_EditHistory.Clear(); m_EditHistory.Dispose();
  142. base.AfterClose();
  143. }
  144. private void InitializeComponent()
  145. {
  146. this.uiButton2 = new Sunny.UI.UIButton();
  147. this.uiButton1 = new Sunny.UI.UIButton();
  148. this.SuspendLayout();
  149. //
  150. // uiButton2
  151. //
  152. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Default;
  153. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  154. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  155. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  156. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  157. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  158. this.uiButton2.Location = new System.Drawing.Point(247, 40);
  159. this.uiButton2.Margin = new System.Windows.Forms.Padding(30);
  160. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  161. this.uiButton2.Name = "uiButton2";
  162. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  163. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  164. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  165. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  166. this.uiButton2.Size = new System.Drawing.Size(126, 30);
  167. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  168. this.uiButton2.TabIndex = 3;
  169. this.uiButton2.Text = "取消管线预览";
  170. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  171. //
  172. // uiButton1
  173. //
  174. this.uiButton1.Cursor = System.Windows.Forms.Cursors.Default;
  175. this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  176. this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  177. this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  178. this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  179. this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
  180. this.uiButton1.Location = new System.Drawing.Point(69, 40);
  181. this.uiButton1.Margin = new System.Windows.Forms.Padding(30);
  182. this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
  183. this.uiButton1.Name = "uiButton1";
  184. this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  185. this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  186. this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  187. this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  188. this.uiButton1.Size = new System.Drawing.Size(126, 30);
  189. this.uiButton1.Style = Sunny.UI.UIStyle.Gray;
  190. this.uiButton1.TabIndex = 1;
  191. this.uiButton1.Text = "预览合并管线";
  192. this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
  193. //
  194. // GuanXianHeBing
  195. //
  196. this.Controls.Add(this.uiButton2);
  197. this.Controls.Add(this.uiButton1);
  198. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  199. this.Name = "GuanXianHeBing";
  200. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  201. this.Size = new System.Drawing.Size(500, 100);
  202. this.Style = Sunny.UI.UIStyle.Gray;
  203. this.ResumeLayout(false);
  204. }
  205. private void uiButton2_Click(object sender, EventArgs e)
  206. {
  207. _selection = null;
  208. MapControl.Action = SuperMap.UI.Action.Pan;
  209. MapControl.Map.TrackingLayer.Clear();
  210. MapControl.Map.Refresh();
  211. }
  212. }
  213. }