GuanDianLianJie.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 UILabel uilbRemark;
  18. private UIButton uibtnLianjie;
  19. private UIButton uiButton2;
  20. private UILabel uilbStart;
  21. private Panel plMain;
  22. private GeoLine _geoLine = null;
  23. private Point2Ds _goeLinePoints = new Point2Ds();
  24. private string _qsdh = "未确认";
  25. private string _zddh = "未确认";
  26. private UILabel uilbEnd;
  27. private GeoStyle m_GeoStyle = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red, LineWidth = 3 };
  28. public GuanDianLianJie() : base()
  29. {
  30. this.ConditionPanelName = "连接管点信息";
  31. InitializeComponent();
  32. uilbRemark.Text = "首先在界面上标记需要连接的管点。一般为2个,起点和终点。\r\n 在地图上双击选择管点";
  33. }
  34. protected override void OnLoad(EventArgs e)
  35. {
  36. ComsStatic.SetLayerIsEditableFalse();
  37. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  38. }
  39. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  40. {
  41. Point2D point = this.MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  42. GeoPoint _clickPoint = new GeoPoint(point);
  43. Recordset rdJSJDPT = ComsStatic.dvJSJDPT.Query(_clickPoint, 30, CursorType.Static);
  44. if (rdJSJDPT.RecordCount == 0)
  45. {
  46. Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线节点"); return;
  47. }
  48. double distance = 0.0D;
  49. double distance_temp = 0.0D;
  50. GeoPoint _rdPoint = new GeoPoint();
  51. GeoPoint _rdPoint_temp;
  52. string bsm = "";
  53. rdJSJDPT.MoveFirst();
  54. while (!rdJSJDPT.IsEOF)
  55. {
  56. _rdPoint_temp = new GeoPoint((double)rdJSJDPT.GetFieldValue("x"), (double)rdJSJDPT.GetFieldValue("y"));
  57. distance_temp = Geometrist.Distance(_clickPoint, _rdPoint_temp);
  58. if (distance_temp <= distance || distance == 0.0D)
  59. {
  60. distance = distance_temp;
  61. _rdPoint = _rdPoint_temp;
  62. bsm = rdJSJDPT.GetFieldValue("bsm").ToString();
  63. }
  64. rdJSJDPT.MoveNext();
  65. }
  66. if (_goeLinePoints.Count == 2)
  67. _goeLinePoints.Remove(1);
  68. _goeLinePoints.Add(new Point2D(_rdPoint.X, _rdPoint.Y));
  69. if (_goeLinePoints.Count == 1)
  70. {
  71. _qsdh = bsm;
  72. int index = MapControl.Map.TrackingLayer.IndexOf("GuanDianLianJie_Start");
  73. if (index >= 0) { MapControl.Map.TrackingLayer.Remove(index); }
  74. MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_Start");
  75. MapControl.Map.Refresh();
  76. uilbStart.Text = string.Format("起点X坐标:{0:F2},Y坐标:{1:F2}。\r\n 起点标识码:{2}", _rdPoint.X, _rdPoint.Y, _qsdh);
  77. }
  78. if (_goeLinePoints.Count == 2)
  79. {
  80. _zddh = bsm;
  81. int index = MapControl.Map.TrackingLayer.IndexOf("GuanDianLianJie_End");
  82. if (index >= 0) { MapControl.Map.TrackingLayer.Remove(index); }
  83. MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_End");
  84. MapControl.Map.Refresh();
  85. uilbEnd.Text = string.Format("终点X坐标:{0:F2},Y坐标:{1:F2}。\r\n 起点标识码:{2}", _rdPoint.X, _rdPoint.Y, _zddh);
  86. }
  87. }
  88. private void uibtnLianjie_Click(object sender, EventArgs e)
  89. {
  90. if (_goeLinePoints.Count != 2)
  91. {
  92. Sunny.UI.UIMessageTip.ShowError("必须在界面上标记需要连接的2个管点!"); return;
  93. }
  94. _geoLine = new GeoLine(_goeLinePoints); _goeLinePoints.Clear();
  95. _geoLine.Style = m_GeoStyle;
  96. MapControl.Map.TrackingLayer.Clear();
  97. MapControl.Map.TrackingLayer.Add(_geoLine, "GuanDianLianJie_geoLine");
  98. MapControl.Map.Refresh();
  99. }
  100. public override object Do(DockPanel dockPanel = null)
  101. {
  102. if (_qsdh == _zddh)
  103. {
  104. Sunny.UI.UIMessageTip.ShowError("起始点号和终点点号不能相同"); return false;
  105. }
  106. this.IsShowResultWindow = false;
  107. Recordset _rd = dvJSLK_cp.GetRecordset(false, CursorType.Dynamic);
  108. if (_geoLine is null)
  109. {
  110. Sunny.UI.UIMessageTip.ShowError("请先确认连接的管点和管线"); return false;
  111. }
  112. _rd.AddNew(_geoLine);
  113. _rd.SetFieldValue("qsdh", _qsdh);
  114. _rd.SetFieldValue("zddh", _zddh);
  115. _rd.SetFieldValue("lrrq", DateTime.Now);
  116. _rd.SetFieldValue("enabled", 1);
  117. _rd.SetFieldValue("cd", Math.Round(_geoLine.Length, 2));
  118. _rd.SetFieldValue("shape_length", _geoLine.Length);
  119. Int32 objID = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSLK, "OBJECTID").ToString()) + 1;
  120. _rd.SetFieldValue("objectid", objID);
  121. _rd.SetFieldValue("fldm", "供水管线");
  122. _rd.SetFieldValue("bsm", "JSLK" + objID);
  123. _rd.SetFieldValue("cqbh", "管点连接");
  124. if (_rd.Update())
  125. {
  126. _rd.Close(); _rd.Dispose();
  127. Sunny.UI.UIMessageTip.ShowOk("信息更新成功!");
  128. MapControl.Map.TrackingLayer.Clear();
  129. }
  130. else
  131. {
  132. Sunny.UI.UIMessageTip.ShowError("信息更新失败,请重新操作!");
  133. return false;
  134. }
  135. return true;
  136. }
  137. private void uiButton2_Click(object sender, EventArgs e)
  138. {
  139. _goeLinePoints.Clear();
  140. base.AfterClose();
  141. }
  142. public override void AfterClose()
  143. {
  144. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  145. base.AfterClose();
  146. }
  147. private void InitializeComponent()
  148. {
  149. this.plMain = new System.Windows.Forms.Panel();
  150. this.uilbEnd = new Sunny.UI.UILabel();
  151. this.uilbStart = new Sunny.UI.UILabel();
  152. this.uiButton2 = new Sunny.UI.UIButton();
  153. this.uibtnLianjie = new Sunny.UI.UIButton();
  154. this.uilbRemark = new Sunny.UI.UILabel();
  155. this.plMain.SuspendLayout();
  156. this.SuspendLayout();
  157. //
  158. // plMain
  159. //
  160. this.plMain.AutoScroll = true;
  161. this.plMain.Controls.Add(this.uilbEnd);
  162. this.plMain.Controls.Add(this.uilbStart);
  163. this.plMain.Controls.Add(this.uiButton2);
  164. this.plMain.Controls.Add(this.uibtnLianjie);
  165. this.plMain.Controls.Add(this.uilbRemark);
  166. this.plMain.Dock = System.Windows.Forms.DockStyle.Fill;
  167. this.plMain.Location = new System.Drawing.Point(0, 0);
  168. this.plMain.Name = "plMain";
  169. this.plMain.Size = new System.Drawing.Size(399, 268);
  170. this.plMain.TabIndex = 0;
  171. //
  172. // uilbEnd
  173. //
  174. this.uilbEnd.AutoSize = true;
  175. this.uilbEnd.Font = new System.Drawing.Font("微软雅黑", 12F);
  176. this.uilbEnd.Location = new System.Drawing.Point(7, 179);
  177. this.uilbEnd.Name = "uilbEnd";
  178. this.uilbEnd.Size = new System.Drawing.Size(74, 21);
  179. this.uilbEnd.Style = Sunny.UI.UIStyle.Gray;
  180. this.uilbEnd.TabIndex = 4;
  181. this.uilbEnd.Text = "终点信息";
  182. this.uilbEnd.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  183. //
  184. // uilbStart
  185. //
  186. this.uilbStart.AutoSize = true;
  187. this.uilbStart.Font = new System.Drawing.Font("微软雅黑", 12F);
  188. this.uilbStart.Location = new System.Drawing.Point(8, 104);
  189. this.uilbStart.Name = "uilbStart";
  190. this.uilbStart.Size = new System.Drawing.Size(74, 21);
  191. this.uilbStart.Style = Sunny.UI.UIStyle.Gray;
  192. this.uilbStart.TabIndex = 3;
  193. this.uilbStart.Text = "起点信息";
  194. this.uilbStart.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  195. //
  196. // uiButton2
  197. //
  198. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
  199. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  200. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  201. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  202. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  203. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  204. this.uiButton2.Location = new System.Drawing.Point(176, 53);
  205. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  206. this.uiButton2.Name = "uiButton2";
  207. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  208. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  209. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  210. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  211. this.uiButton2.Size = new System.Drawing.Size(100, 35);
  212. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  213. this.uiButton2.TabIndex = 2;
  214. this.uiButton2.Text = "取消连接";
  215. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  216. //
  217. // uibtnLianjie
  218. //
  219. this.uibtnLianjie.Cursor = System.Windows.Forms.Cursors.Hand;
  220. this.uibtnLianjie.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  221. this.uibtnLianjie.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  222. this.uibtnLianjie.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  223. this.uibtnLianjie.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  224. this.uibtnLianjie.Font = new System.Drawing.Font("微软雅黑", 12F);
  225. this.uibtnLianjie.Location = new System.Drawing.Point(33, 53);
  226. this.uibtnLianjie.MinimumSize = new System.Drawing.Size(1, 1);
  227. this.uibtnLianjie.Name = "uibtnLianjie";
  228. this.uibtnLianjie.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  229. this.uibtnLianjie.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  230. this.uibtnLianjie.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  231. this.uibtnLianjie.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  232. this.uibtnLianjie.Size = new System.Drawing.Size(100, 35);
  233. this.uibtnLianjie.Style = Sunny.UI.UIStyle.Gray;
  234. this.uibtnLianjie.TabIndex = 1;
  235. this.uibtnLianjie.Text = "管点连接";
  236. this.uibtnLianjie.Click += new System.EventHandler(this.uibtnLianjie_Click);
  237. //
  238. // uilbRemark
  239. //
  240. this.uilbRemark.AutoSize = true;
  241. this.uilbRemark.Font = new System.Drawing.Font("微软雅黑", 12F);
  242. this.uilbRemark.Location = new System.Drawing.Point(4, 4);
  243. this.uilbRemark.Name = "uilbRemark";
  244. this.uilbRemark.Size = new System.Drawing.Size(74, 21);
  245. this.uilbRemark.Style = Sunny.UI.UIStyle.Gray;
  246. this.uilbRemark.TabIndex = 0;
  247. this.uilbRemark.Text = "操作步骤";
  248. this.uilbRemark.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  249. //
  250. // GuanDianLianJie
  251. //
  252. this.Controls.Add(this.plMain);
  253. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  254. this.Name = "GuanDianLianJie";
  255. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  256. this.Size = new System.Drawing.Size(399, 268);
  257. this.Style = Sunny.UI.UIStyle.Gray;
  258. this.plMain.ResumeLayout(false);
  259. this.plMain.PerformLayout();
  260. this.ResumeLayout(false);
  261. }
  262. }
  263. }