GuanDianBianGeng.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using WWPipeLine.MapBasic;
  12. using WeifenLuo.WinFormsUI.Docking;
  13. using SuperMap.Data;
  14. using SuperMap.Mapping;
  15. namespace WWPipeLine.MapTools.Conditions.EditGuanWang
  16. {
  17. public partial class GuanDianBianGeng : ConditionPanel
  18. {
  19. Point2D newPoint;
  20. private string yuanBSM = string.Empty;
  21. private string xinBSM = string.Empty;
  22. Recordset rdJSLKqsdh = null;
  23. Recordset rdJSLKzddh = null;
  24. public GuanDianBianGeng()
  25. {
  26. this.ConditionPanelName = "管点变更";
  27. InitializeComponent();
  28. this.SetSize(300, 200);
  29. IsShowResultWindow = false;
  30. }
  31. protected override void OnLoad(EventArgs e)
  32. {
  33. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, false);
  34. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  35. }
  36. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  37. {
  38. Point2D point = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  39. GeoPoint _clickPoint = new GeoPoint(point);
  40. Recordset rdJSJDPT = ComsStatic.gsGuanDian.Query(_clickPoint, 10, CursorType.Static);
  41. if (rdJSJDPT.RecordCount == 0)
  42. {
  43. Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线节点"); return;
  44. }
  45. double distance = 0.0D;
  46. double distance_temp = 0.0D;
  47. GeoPoint _rdPoint = null;//最终确认的管点
  48. GeoPoint _rdPoint_temp;
  49. int smid = 0;
  50. rdJSJDPT.MoveFirst();
  51. while (!rdJSJDPT.IsEOF)
  52. {
  53. _rdPoint_temp = new GeoPoint(rdJSJDPT.GetDouble("x"), rdJSJDPT.GetDouble("y"));
  54. distance_temp = Geometrist.Distance(_clickPoint, _rdPoint_temp);
  55. if (distance_temp <= distance || distance == 0.0D)
  56. {
  57. distance = distance_temp;
  58. _rdPoint = _rdPoint_temp;
  59. smid = rdJSJDPT.GetID();
  60. }
  61. rdJSJDPT.MoveNext();
  62. }
  63. rdJSJDPT.SeekID(smid);
  64. string bsm = rdJSJDPT.GetString("bsm");
  65. _rdPoint.Style = ComsStatic.geoStyle_Red_Mark5mm;
  66. if (string.IsNullOrEmpty(yuanBSM))
  67. {
  68. yuanBSM = bsm;
  69. MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_Start");
  70. MapControl.Map.RefreshTrackingLayer();
  71. uiLabelY.Text = string.Format("原节点:{0} 标识码:{1}", rdJSJDPT.GetString("fldm"), bsm);
  72. }
  73. else
  74. {
  75. xinBSM = bsm; newPoint = _rdPoint.InnerPoint;
  76. int index = MapControl.Map.TrackingLayer.IndexOf("GuanDianLianJie_End");
  77. if (index >= 0) { MapControl.Map.TrackingLayer.Remove(index); }
  78. MapControl.Map.TrackingLayer.Add(_rdPoint, "GuanDianLianJie_End");
  79. MapControl.Map.RefreshTrackingLayer();
  80. uiLabelX.Text = string.Format("新节点:{0} 标识码:{1}", rdJSJDPT.GetString("fldm"), bsm);
  81. }
  82. }
  83. public override object Do(DockPanel dockPanel = null)
  84. {
  85. if (string.IsNullOrEmpty(yuanBSM) || string.IsNullOrEmpty(xinBSM) || yuanBSM == xinBSM || (rdJSLKqsdh is null && rdJSLKzddh is null))
  86. {
  87. Sunny.UI.UIMessageTip.ShowError("请先选择原节点和新节点,然后点击“新管线预览”"); return false;
  88. }
  89. EditHistory m_EditHistory = new EditHistory();
  90. try
  91. {
  92. Recordset rdJSJDPT = null;
  93. string yuanBMS = string.Empty;
  94. //1 更改原管线的节点 起始点号
  95. if (rdJSLKqsdh.RecordCount > 0)
  96. {
  97. rdJSLKqsdh.MoveFirst();
  98. while (!rdJSLKqsdh.IsEOF)
  99. {
  100. rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKqsdh.GetString("zddh")), CursorType.Static);
  101. if (rdJSJDPT.RecordCount != 1) continue;
  102. Point2D p = new Point2D(rdJSJDPT.GetDouble("X"), rdJSJDPT.GetDouble("Y"));
  103. GeoLine newline = new GeoLine(new Point2Ds(newPoint, p));
  104. m_EditHistory.Add(EditType.Modify, rdJSLKqsdh, false);
  105. rdJSLKqsdh.Edit();
  106. rdJSLKqsdh.SetFieldValue("qsdh", xinBSM);
  107. rdJSLKqsdh.SetFieldValue("cd", ComsStatic.StringToDouble(newline.Length, 2));
  108. rdJSLKqsdh.SetFieldValue("shape_length", newline.Length);
  109. rdJSLKqsdh.SetGeometry(newline);
  110. if (rdJSLKqsdh.Update())
  111. {
  112. Commons.LogHelper.Info(string.Format("管点变更-更改原管线的起始点号成功!管线的SMID是{0}。", rdJSLKqsdh.GetID()));
  113. }
  114. else
  115. {
  116. ComsStatic.EditHistoryUndo(m_EditHistory);
  117. ComsStatic.ShowErrorLog("管点变更出错", "终点点号不变,更新起始点号 操作失败!"); return false;
  118. }
  119. rdJSLKqsdh.MoveNext();
  120. }
  121. }
  122. //2 更改原管线的节点 终点点号
  123. if (rdJSLKzddh.RecordCount > 0)
  124. {
  125. rdJSLKzddh.MoveFirst();
  126. while (!rdJSLKzddh.IsEOF)
  127. {
  128. rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKzddh.GetString("qsdh")), CursorType.Static);
  129. if (rdJSJDPT.RecordCount != 1) continue;
  130. Point2D p = new Point2D(rdJSJDPT.GetDouble("X"), rdJSJDPT.GetDouble("Y"));
  131. GeoLine newline = new GeoLine(new Point2Ds(p, newPoint));
  132. m_EditHistory.Add(EditType.Modify, rdJSLKzddh, false);
  133. rdJSLKzddh.Edit();
  134. rdJSLKzddh.SetFieldValue("zddh", xinBSM);
  135. rdJSLKzddh.SetFieldValue("cd", ComsStatic.StringToDouble(newline.Length, 2));
  136. rdJSLKzddh.SetFieldValue("shape_length", newline.Length);
  137. rdJSLKzddh.SetGeometry(newline);
  138. if (rdJSLKzddh.Update())
  139. {
  140. Commons.LogHelper.Info(string.Format("管点变更-更改原管线的终点点号成功!管线的SMID是{0}。", rdJSLKzddh.GetID()));
  141. }
  142. else
  143. {
  144. ComsStatic.EditHistoryUndo(m_EditHistory);
  145. ComsStatic.ShowErrorLog("管点变更出错", "起始管点不变,更新终点管点 操作失败!"); return false;
  146. }
  147. rdJSLKzddh.MoveNext();
  148. }
  149. }
  150. ComsStatic.ShowOKLog("管点变更成功", string.Format("原节点{0} 新节点{1} 变更起始点号的管线{2}根,变更终点点号的管线{3}根", yuanBSM, xinBSM, rdJSLKqsdh.RecordCount, rdJSLKzddh.RecordCount));
  151. }
  152. catch (Exception e)
  153. {
  154. ComsStatic.EditHistoryUndo(m_EditHistory);
  155. ComsStatic.ShowErrorLog("管点变更出错!", e.Message); return false;
  156. }
  157. return true;
  158. }
  159. private void uibtnLianjie_Click(object sender, EventArgs e)//生成新的管线
  160. {
  161. if (string.IsNullOrEmpty(yuanBSM) || string.IsNullOrEmpty(xinBSM) || yuanBSM == xinBSM)
  162. {
  163. Sunny.UI.UIMessageTip.ShowError("请先选择原节点和新节点"); return;
  164. }
  165. ComsStatic.TrackingLayerRemove("newLine");
  166. rdJSLKqsdh = ComsStatic.gsGuanXian.Query(string.Format(" qsdh='{0}' ", yuanBSM), CursorType.Dynamic);
  167. rdJSLKzddh = ComsStatic.gsGuanXian.Query(string.Format(" zddh='{0}' ", yuanBSM), CursorType.Dynamic);
  168. if (rdJSLKqsdh.RecordCount == 0 && rdJSLKzddh.RecordCount == 0)
  169. {
  170. Sunny.UI.UIMessageTip.ShowError("原节点未查询到管线信息!"); return;
  171. }
  172. Recordset rdJSJDPT = null;
  173. if (rdJSLKqsdh.RecordCount != 0)
  174. {
  175. rdJSLKqsdh.MoveFirst();
  176. while (!rdJSLKqsdh.IsEOF)
  177. {
  178. rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKqsdh.GetString("zddh")), CursorType.Static);
  179. if (rdJSJDPT.RecordCount != 1) rdJSLKqsdh.MoveNext();
  180. Point2D p = new Point2D(rdJSJDPT.GetDouble("X"), rdJSJDPT.GetDouble("Y"));
  181. GeoLine newLineqsdh = new GeoLine(new Point2Ds(newPoint, p));
  182. newLineqsdh.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  183. MapControl.Map.TrackingLayer.Add(newLineqsdh, "newLine");
  184. rdJSLKqsdh.MoveNext();
  185. }
  186. }
  187. if (rdJSLKzddh.RecordCount != 0)
  188. {
  189. rdJSLKzddh.MoveFirst();
  190. while (!rdJSLKzddh.IsEOF)
  191. {
  192. rdJSJDPT = ComsStatic.gsGuanDian.Query(string.Format(" bsm='{0}' ", rdJSLKzddh.GetString("qsdh")), CursorType.Static);
  193. if (rdJSJDPT.RecordCount != 1) rdJSLKzddh.MoveNext();
  194. Point2D p = new Point2D(rdJSJDPT.GetDouble("X"), rdJSJDPT.GetDouble("Y"));
  195. GeoLine newLinezddh = new GeoLine(new Point2Ds(p, newPoint));
  196. newLinezddh.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  197. MapControl.Map.TrackingLayer.Add(newLinezddh, "newLine");
  198. rdJSLKzddh.MoveNext();
  199. }
  200. }
  201. MapControl.Map.RefreshTrackingLayer();
  202. }
  203. private void uiButton2_Click(object sender, EventArgs e)
  204. {
  205. MapControl.Map.TrackingLayer.Clear(); MapControl.Map.RefreshTrackingLayer();
  206. rdJSLKqsdh = null; rdJSLKzddh = null; yuanBSM = string.Empty; xinBSM = string.Empty;
  207. newPoint = new Point2D(0, 0);
  208. uiLabelY.Text = "原节点:"; uiLabelX.Text = "新节点:";
  209. }
  210. public override void AfterClose()
  211. {
  212. ComsStatic.RecordsetDispose(rdJSLKqsdh); ComsStatic.RecordsetDispose(rdJSLKzddh);
  213. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  214. base.AfterClose();
  215. }
  216. }
  217. }