GuanDianLianJie.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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(500, 185);
  29. InitializeComponent();
  30. this.IsShowResultWindow = false;
  31. }
  32. protected override void OnLoad(EventArgs e)
  33. {
  34. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSJDPT.Name, true);
  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.dvJSJDPT.Query(_clickPoint, 30, 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. string bsm = "";
  51. rdJSJDPT.MoveFirst();
  52. while (!rdJSJDPT.IsEOF)
  53. {
  54. _rdPoint_temp = new GeoPoint((double)rdJSJDPT.GetFieldValue("x"), (double)rdJSJDPT.GetFieldValue("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. bsm = rdJSJDPT.GetFieldValue("bsm").ToString();
  61. }
  62. rdJSJDPT.MoveNext();
  63. }
  64. _rdPoint.Style = ComsStatic.geoStyle_Red_Mark5mm;
  65. if (_goeLinePoints.Count == 2)
  66. _goeLinePoints.Remove(1);
  67. _goeLinePoints.Add(new Point2D(_rdPoint.X, _rdPoint.Y));
  68. if (_goeLinePoints.Count == 1)
  69. {
  70. _qsdh = bsm;
  71. MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_Start");
  72. MapControl.Map.Refresh();
  73. uilbStart.Text = string.Format("起点坐标({0:F2},{1:F2}) 标识码:{2}", _rdPoint.X, _rdPoint.Y, _qsdh);
  74. }
  75. if (_goeLinePoints.Count == 2)
  76. {
  77. _zddh = bsm;
  78. int index = MapControl.Map.TrackingLayer.IndexOf("GuanDianLianJie_End");
  79. if (index >= 0) { MapControl.Map.TrackingLayer.Remove(index); }
  80. MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_End");
  81. MapControl.Map.Refresh();
  82. uilbEnd.Text = string.Format("终点坐标({0:F2},{1:F2}) 标识码:{2}", _rdPoint.X, _rdPoint.Y, _zddh);
  83. }
  84. }
  85. private void uibtnLianjie_Click(object sender, EventArgs e)
  86. {
  87. if (_goeLinePoints.Count != 2)
  88. {
  89. Sunny.UI.UIMessageTip.ShowError("必须在界面上标记需要连接的2个管点!"); return;
  90. }
  91. _geoLine = new GeoLine(_goeLinePoints); _goeLinePoints.Clear();
  92. _geoLine.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  93. MapControl.Map.TrackingLayer.Clear();
  94. MapControl.Map.TrackingLayer.Add(_geoLine, "GuanDianLianJie_geoLine");
  95. MapControl.Map.Refresh();
  96. }
  97. public override object Do(DockPanel dockPanel = null)
  98. {
  99. if (_qsdh == _zddh)
  100. {
  101. Sunny.UI.UIMessageTip.ShowError("起始点号和终点点号不能相同"); return false;
  102. }
  103. Recordset _rd = ComsStatic.dvJSLK.GetRecordset(false, CursorType.Dynamic);
  104. if (_geoLine is null)
  105. {
  106. Sunny.UI.UIMessageTip.ShowError("请先确认连接的管点和管线"); return false;
  107. }
  108. _rd.AddNew(_geoLine);
  109. _rd.SetFieldValue("qsdh", _qsdh);
  110. _rd.SetFieldValue("zddh", _zddh);
  111. _rd.SetFieldValue("lrrq", DateTime.Now);
  112. _rd.SetFieldValue("enabled", 1);
  113. _rd.SetFieldValue("cd", Math.Round(_geoLine.Length, 2));
  114. _rd.SetFieldValue("shape_length", _geoLine.Length);
  115. Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSLK, "OBJECTID") + 1;
  116. _rd.SetFieldValue("objectid", objID);
  117. _rd.SetFieldValue("fldm", "供水管线");
  118. _rd.SetFieldValue("bsm", "JSLK" + objID);
  119. _rd.SetFieldValue("cqbh", "管点连接");
  120. if (_rd.Update())
  121. {
  122. _rd.Close(); _rd.Dispose();
  123. ComsStatic.ShowOKLog("管点连接操作成功!");
  124. MapControl.Map.TrackingLayer.Clear(); _geoLine = null;
  125. return true;
  126. }
  127. else
  128. {
  129. ComsStatic.ShowErrorLog("管点连接更新失败!");
  130. MapControl.Map.TrackingLayer.Clear(); _geoLine = null;
  131. return false;
  132. }
  133. }
  134. private void uiButton2_Click(object sender, EventArgs e)
  135. {
  136. _goeLinePoints.Clear();
  137. MapControl.Map.TrackingLayer.Clear();
  138. base.AfterClose();
  139. }
  140. public override void AfterClose()
  141. {
  142. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  143. base.AfterClose();
  144. }
  145. private void InitializeComponent()
  146. {
  147. this.uilbEnd = new Sunny.UI.UILabel();
  148. this.uilbStart = new Sunny.UI.UILabel();
  149. this.uiButton2 = new Sunny.UI.UIButton();
  150. this.uibtnLianjie = new Sunny.UI.UIButton();
  151. this.SuspendLayout();
  152. //
  153. // uilbEnd
  154. //
  155. this.uilbEnd.AutoSize = true;
  156. this.uilbEnd.Font = new System.Drawing.Font("微软雅黑", 12F);
  157. this.uilbEnd.Location = new System.Drawing.Point(4, 36);
  158. this.uilbEnd.Name = "uilbEnd";
  159. this.uilbEnd.Size = new System.Drawing.Size(90, 21);
  160. this.uilbEnd.Style = Sunny.UI.UIStyle.Gray;
  161. this.uilbEnd.TabIndex = 4;
  162. this.uilbEnd.Text = "终点信息:";
  163. this.uilbEnd.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  164. //
  165. // uilbStart
  166. //
  167. this.uilbStart.AutoSize = true;
  168. this.uilbStart.Font = new System.Drawing.Font("微软雅黑", 12F);
  169. this.uilbStart.Location = new System.Drawing.Point(4, 8);
  170. this.uilbStart.Name = "uilbStart";
  171. this.uilbStart.Size = new System.Drawing.Size(90, 21);
  172. this.uilbStart.Style = Sunny.UI.UIStyle.Gray;
  173. this.uilbStart.TabIndex = 3;
  174. this.uilbStart.Text = "起点信息:";
  175. this.uilbStart.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  176. //
  177. // uiButton2
  178. //
  179. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
  180. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  181. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  182. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  183. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  184. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  185. this.uiButton2.Location = new System.Drawing.Point(279, 62);
  186. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  187. this.uiButton2.Name = "uiButton2";
  188. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  189. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  190. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  191. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  192. this.uiButton2.Size = new System.Drawing.Size(113, 30);
  193. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  194. this.uiButton2.TabIndex = 2;
  195. this.uiButton2.Text = "取消管线预览";
  196. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  197. //
  198. // uibtnLianjie
  199. //
  200. this.uibtnLianjie.Cursor = System.Windows.Forms.Cursors.Hand;
  201. this.uibtnLianjie.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  202. this.uibtnLianjie.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  203. this.uibtnLianjie.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  204. this.uibtnLianjie.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  205. this.uibtnLianjie.Font = new System.Drawing.Font("微软雅黑", 12F);
  206. this.uibtnLianjie.Location = new System.Drawing.Point(125, 62);
  207. this.uibtnLianjie.MinimumSize = new System.Drawing.Size(1, 1);
  208. this.uibtnLianjie.Name = "uibtnLianjie";
  209. this.uibtnLianjie.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  210. this.uibtnLianjie.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  211. this.uibtnLianjie.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  212. this.uibtnLianjie.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  213. this.uibtnLianjie.Size = new System.Drawing.Size(124, 30);
  214. this.uibtnLianjie.Style = Sunny.UI.UIStyle.Gray;
  215. this.uibtnLianjie.TabIndex = 1;
  216. this.uibtnLianjie.Text = "预览连接管线";
  217. this.uibtnLianjie.Click += new System.EventHandler(this.uibtnLianjie_Click);
  218. //
  219. // GuanDianLianJie
  220. //
  221. this.Controls.Add(this.uilbEnd);
  222. this.Controls.Add(this.uilbStart);
  223. this.Controls.Add(this.uiButton2);
  224. this.Controls.Add(this.uibtnLianjie);
  225. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  226. this.Name = "GuanDianLianJie";
  227. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  228. this.Size = new System.Drawing.Size(500, 100);
  229. this.Style = Sunny.UI.UIStyle.Gray;
  230. this.ResumeLayout(false);
  231. this.PerformLayout();
  232. }
  233. }
  234. }