GuanDianLianJie.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. using Sunny.UI;
  2. using SuperMap.Data;
  3. using SuperMap.Mapping;
  4. using SuperMap.UI;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Windows.Forms;
  10. using WeifenLuo.WinFormsUI.Docking;
  11. using WWPipeLine.MapBasic.Conditions;
  12. using WWPipeLine.MapBasic;
  13. namespace WWPipeLine.MapTools.Conditions.EditGuanWang
  14. {
  15. public class GuanDianLianJie : ConditionPanel
  16. {
  17. private UIButton uibtnLianjie;
  18. private UIButton uiButton2;
  19. private UILabel uilbStart;
  20. private GeoLine _geoLine = null;
  21. private Point2Ds _goeLinePoints = new Point2Ds();
  22. private string _qsdh = "未确认";
  23. private string _zddh = "未确认";
  24. private UILabel uilbEnd;
  25. public GuanDianLianJie() : base()
  26. {
  27. this.ConditionPanelName = "连接管点信息";
  28. this.SetSize(300, 200);
  29. InitializeComponent();
  30. this.IsShowResultWindow = false;
  31. }
  32. protected override void OnLoad(EventArgs e)
  33. {
  34. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, false);
  35. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  36. }
  37. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  38. {
  39. Point2D point = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  40. GeoPoint _clickPoint = new GeoPoint(point);
  41. Recordset rdJSJDPT = ComsStatic.gsGuanDian.Query(_clickPoint, 10, CursorType.Static);
  42. if (rdJSJDPT.RecordCount == 0)
  43. {
  44. Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线节点"); return;
  45. }
  46. double distance = 0.0D;
  47. double distance_temp = 0.0D;
  48. GeoPoint _rdPoint = null;//最终确认的管点
  49. GeoPoint _rdPoint_temp;
  50. int smid = 0;
  51. rdJSJDPT.MoveFirst();
  52. while (!rdJSJDPT.IsEOF)
  53. {
  54. _rdPoint_temp = new GeoPoint( rdJSJDPT.GetDouble("x"), rdJSJDPT.GetDouble("y"));
  55. distance_temp = Geometrist.Distance(_clickPoint, _rdPoint_temp);
  56. if (distance_temp <= distance || distance == 0.0D)
  57. {
  58. distance = distance_temp;
  59. _rdPoint = _rdPoint_temp;
  60. smid = rdJSJDPT.GetID();
  61. }
  62. rdJSJDPT.MoveNext();
  63. }
  64. rdJSJDPT.SeekID(smid);
  65. string bsm = rdJSJDPT.GetFieldValue("bsm").ToString();
  66. _rdPoint.Style = ComsStatic.geoStyle_Red_Mark5mm;
  67. if (_goeLinePoints.Count == 2)
  68. _goeLinePoints.Remove(1);
  69. _goeLinePoints.Add(new Point2D(_rdPoint.X, _rdPoint.Y));
  70. if (_goeLinePoints.Count == 1)
  71. {
  72. _qsdh = bsm;
  73. MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_Start");
  74. MapControl.Map.RefreshTrackingLayer();
  75. uilbStart.Text = string.Format("起点{0} 附属物:{1}", rdJSJDPT.GetString("fldm"), rdJSJDPT.GetString("fsw"));
  76. }
  77. if (_goeLinePoints.Count == 2)
  78. {
  79. _zddh = bsm;
  80. int index = MapControl.Map.TrackingLayer.IndexOf("GuanDianLianJie_End");
  81. if (index >= 0) { MapControl.Map.TrackingLayer.Remove(index); }
  82. MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_End");
  83. MapControl.Map.RefreshTrackingLayer();
  84. uilbEnd.Text = string.Format("终点{0} 附属物:{1}", rdJSJDPT.GetString("fldm"), rdJSJDPT.GetString("fsw"));
  85. }
  86. }
  87. private void uibtnLianjie_Click(object sender, EventArgs e)
  88. {
  89. if (_goeLinePoints.Count != 2)
  90. {
  91. Sunny.UI.UIMessageTip.ShowError("必须在界面上标记需要连接的2个管点!"); return;
  92. }
  93. _geoLine = new GeoLine(_goeLinePoints);
  94. _goeLinePoints.Clear();
  95. _geoLine.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  96. MapControl.Map.TrackingLayer.Clear();
  97. MapControl.Map.TrackingLayer.Add(_geoLine, "GuanDianLianJie_geoLine");
  98. MapControl.Map.RefreshTrackingLayer();
  99. }
  100. public override object Do(DockPanel dockPanel = null)
  101. {
  102. if (_qsdh == _zddh)
  103. {
  104. Sunny.UI.UIMessageTip.ShowError("起始点号和终点点号不能相同"); return false;
  105. }
  106. int index = MapControl.Map.TrackingLayer.IndexOf("GuanDianLianJie_geoLine");
  107. if (_geoLine is null || index != 0)
  108. {
  109. Sunny.UI.UIMessageTip.ShowError("请先确认预览连接管线"); return false;
  110. }
  111. Recordset _rd = ComsStatic.gsGuanXian.GetRecordset(false, CursorType.Dynamic);
  112. _rd.AddNew(_geoLine);
  113. _rd.SetFieldValue("qsdh", _qsdh);
  114. _rd.SetFieldValue("zddh", _zddh);
  115. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  116. _rd.SetFieldValue("shape_length", _geoLine.Length);
  117. _rd.SetFieldValue("cd", ComsStatic.StringToDouble(_geoLine.Length, 2));
  118. Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "objectid") + 1;
  119. _rd.SetFieldValue("objectid", objID);
  120. _rd.SetFieldValue("fldm", ComsStatic.dvGXCaption);
  121. _rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID);
  122. _rd.SetFieldValue("cqbh", "管点连接");
  123. if (_rd.Update())
  124. {
  125. ComsStatic.RecordsetDispose(_rd);
  126. ComsStatic.ShowOKLog("管点连接操作成功!", objID.ToString());
  127. }
  128. else
  129. {
  130. ComsStatic.ShowErrorLog("管点连接操作失败!");
  131. }
  132. MapControl.Map.TrackingLayer.Clear();
  133. MapControl.Map.RefreshEx(MapControl.Map.ViewBounds);
  134. _geoLine = null; _goeLinePoints.Clear();
  135. uilbStart.Text = "起点信息:"; uilbEnd.Text = "终点信息:";
  136. return null;
  137. }
  138. private void uiButton2_Click(object sender, EventArgs e)
  139. {
  140. MapControl.Map.TrackingLayer.Clear();
  141. MapControl.Map.RefreshTrackingLayer();
  142. _geoLine = null; _goeLinePoints.Clear();
  143. uilbStart.Text = "起点信息:"; uilbEnd.Text = "终点信息:";
  144. }
  145. public override void AfterClose()
  146. {
  147. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  148. base.AfterClose();
  149. }
  150. private void InitializeComponent()
  151. {
  152. this.uilbEnd = new Sunny.UI.UILabel();
  153. this.uilbStart = new Sunny.UI.UILabel();
  154. this.uiButton2 = new Sunny.UI.UIButton();
  155. this.uibtnLianjie = new Sunny.UI.UIButton();
  156. this.SuspendLayout();
  157. //
  158. // uilbEnd
  159. //
  160. this.uilbEnd.AutoSize = true;
  161. this.uilbEnd.Font = new System.Drawing.Font("微软雅黑", 12F);
  162. this.uilbEnd.Location = new System.Drawing.Point(4, 46);
  163. this.uilbEnd.Name = "uilbEnd";
  164. this.uilbEnd.Size = new System.Drawing.Size(90, 21);
  165. this.uilbEnd.Style = Sunny.UI.UIStyle.Gray;
  166. this.uilbEnd.TabIndex = 4;
  167. this.uilbEnd.Text = "终点信息:";
  168. this.uilbEnd.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  169. //
  170. // uilbStart
  171. //
  172. this.uilbStart.AutoSize = true;
  173. this.uilbStart.Font = new System.Drawing.Font("微软雅黑", 12F);
  174. this.uilbStart.Location = new System.Drawing.Point(4, 6);
  175. this.uilbStart.Name = "uilbStart";
  176. this.uilbStart.Size = new System.Drawing.Size(90, 21);
  177. this.uilbStart.Style = Sunny.UI.UIStyle.Gray;
  178. this.uilbStart.TabIndex = 3;
  179. this.uilbStart.Text = "起点信息:";
  180. this.uilbStart.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  181. //
  182. // uiButton2
  183. //
  184. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
  185. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  186. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  187. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  188. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  189. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  190. this.uiButton2.Location = new System.Drawing.Point(162, 82);
  191. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  192. this.uiButton2.Name = "uiButton2";
  193. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  194. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  195. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  196. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  197. this.uiButton2.Size = new System.Drawing.Size(113, 30);
  198. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  199. this.uiButton2.TabIndex = 2;
  200. this.uiButton2.Text = "取消管线预览";
  201. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  202. //
  203. // uibtnLianjie
  204. //
  205. this.uibtnLianjie.Cursor = System.Windows.Forms.Cursors.Hand;
  206. this.uibtnLianjie.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  207. this.uibtnLianjie.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  208. this.uibtnLianjie.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  209. this.uibtnLianjie.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  210. this.uibtnLianjie.Font = new System.Drawing.Font("微软雅黑", 12F);
  211. this.uibtnLianjie.Location = new System.Drawing.Point(8, 82);
  212. this.uibtnLianjie.MinimumSize = new System.Drawing.Size(1, 1);
  213. this.uibtnLianjie.Name = "uibtnLianjie";
  214. this.uibtnLianjie.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  215. this.uibtnLianjie.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  216. this.uibtnLianjie.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  217. this.uibtnLianjie.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  218. this.uibtnLianjie.Size = new System.Drawing.Size(113, 30);
  219. this.uibtnLianjie.Style = Sunny.UI.UIStyle.Gray;
  220. this.uibtnLianjie.TabIndex = 1;
  221. this.uibtnLianjie.Text = "预览连接管线";
  222. this.uibtnLianjie.Click += new System.EventHandler(this.uibtnLianjie_Click);
  223. //
  224. // GuanDianLianJie
  225. //
  226. this.Controls.Add(this.uilbEnd);
  227. this.Controls.Add(this.uilbStart);
  228. this.Controls.Add(this.uiButton2);
  229. this.Controls.Add(this.uibtnLianjie);
  230. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  231. this.Name = "GuanDianLianJie";
  232. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  233. this.Size = new System.Drawing.Size(300, 115);
  234. this.Style = Sunny.UI.UIStyle.Gray;
  235. this.ResumeLayout(false);
  236. this.PerformLayout();
  237. }
  238. }
  239. }