GuanXianDaDuan.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 GuanXianDaDuan : ConditionPanel
  15. {
  16. private UIButton uiButton2;
  17. private UIButton uiButton1;
  18. private Point2D _duandianPoint = new Point2D(0, 0);
  19. private int smidGX = 0;
  20. private GeoLine _geoLineStart = null;
  21. private GeoLine _geoLineEnd = null;
  22. private Recordset rdJSLKdd;
  23. public GuanXianDaDuan() : base()
  24. {
  25. this.ConditionPanelName = "打断管线";
  26. InitializeComponent();
  27. this.SetSize(300, 200);
  28. IsShowResultWindow = false;
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.gsGuanXian.Name, true);
  33. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  34. }
  35. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  36. {
  37. _duandianPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  38. GeoPoint pointClick = new GeoPoint(_duandianPoint);
  39. Recordset rdJSLK = ComsStatic.gsGuanXian.Query(pointClick, 3, CursorType.Static);
  40. if (rdJSLK.RecordCount == 0)
  41. {
  42. Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线信息"); return;
  43. }
  44. double distance_temp = 0.0D;
  45. double distance = 0.0D;
  46. GeoLine _rd_temp;
  47. GeoLine _rd_line = new GeoLine();
  48. rdJSLK.MoveFirst();
  49. while (!rdJSLK.IsEOF)
  50. {
  51. _rd_temp = rdJSLK.GetGeometry() as GeoLine;
  52. distance_temp = Geometrist.Distance(pointClick, _rd_temp);
  53. if (distance_temp <= distance || distance == 0.0D)
  54. {
  55. distance = distance_temp;
  56. _rd_line = _rd_temp;
  57. smidGX = rdJSLK.GetID();
  58. }
  59. rdJSLK.MoveNext();
  60. }
  61. _duandianPoint = Geometrist.NearestPointToVertex(_duandianPoint, _rd_line);
  62. GeoPoint _geoPoint = new GeoPoint(_duandianPoint);
  63. _geoPoint.Style = ComsStatic.geoStyle_Red_Mark5mm;
  64. MapControl.Map.TrackingLayer.Clear();
  65. MapControl.Map.TrackingLayer.Add(_geoPoint, "GuanXianDaDuan");
  66. MapControl.Map.RefreshTrackingLayer();
  67. }
  68. private void uiButton1_Click(object sender, EventArgs e)
  69. {
  70. if (smidGX == 0)
  71. {
  72. Sunny.UI.UIMessageTip.ShowError("请在需要打断的管线上双击确认断点"); return;
  73. }
  74. rdJSLKdd = ComsStatic.gsGuanXian.Query(new int[] { smidGX }, CursorType.Dynamic);
  75. //if (rdJSLKdd.RecordCount != 1)
  76. //{
  77. // Sunny.UI.UIMessageTip.ShowError("无法查询到选择管线的信息"); return;
  78. //}
  79. Recordset rdGuanDian = ComsStatic.gsGuanDian.Query(string.Format("bsm='{0}'", rdJSLKdd.GetString("qsdh")), CursorType.Static);
  80. if (rdGuanDian.RecordCount != 1)
  81. {
  82. Sunny.UI.UIMessageTip.ShowError("无法确认起始点号"); return;
  83. }
  84. Point2D startPoint = new Point2D(rdGuanDian.GetDouble("x"), rdGuanDian.GetDouble("y"));
  85. rdGuanDian = ComsStatic.gsGuanDian.Query(string.Format("bsm='{0}'", rdJSLKdd.GetString("zddh")), CursorType.Static);
  86. if (rdGuanDian.RecordCount != 1)
  87. {
  88. Sunny.UI.UIMessageTip.ShowError("无法确认终点点号"); return;
  89. }
  90. Point2D endPoint = new Point2D(rdGuanDian.GetDouble("x"), rdGuanDian.GetDouble("y"));
  91. MapControl.Map.TrackingLayer.Clear();
  92. Point2Ds _geoPointsStart = new Point2Ds(new Point2D[] { startPoint, _duandianPoint });
  93. _geoLineStart = new GeoLine(_geoPointsStart);
  94. _geoLineStart.Style = new GeoStyle { LineColor = Color.Yellow, LineWidth = 1 };
  95. MapControl.Map.TrackingLayer.Add(_geoLineStart, "geoLineStart");
  96. Point2Ds _geoPointEnd = new Point2Ds(new Point2D[] { _duandianPoint, endPoint });
  97. _geoLineEnd = new GeoLine(_geoPointEnd);
  98. _geoLineEnd.Style = new GeoStyle { LineColor = Color.Brown, LineWidth = 1 };
  99. MapControl.Map.TrackingLayer.Add(_geoLineEnd, "geoLineEnd");
  100. MapControl.Map.RefreshTrackingLayer();
  101. }
  102. public override object Do(DockPanel dockPanel = null)
  103. {
  104. EditHistory m_EditHistory = new EditHistory();
  105. m_EditHistory.Capacity = 5;
  106. if (smidGX == 0 || _geoLineStart is null || _geoLineEnd is null)
  107. {
  108. Sunny.UI.UIMessageTip.ShowError("请先执行“打断管线”操作"); return false;
  109. }
  110. try
  111. {
  112. //1 新增 节点信息
  113. Recordset rddvJSJDPT = ComsStatic.gsGuanDian.GetRecordset(true, CursorType.Dynamic);
  114. rddvJSJDPT.AddNew(new GeoPoint(_duandianPoint));
  115. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, rddvJSJDPT, false);
  116. m_EditHistory.Add(SuperMap.Data.EditType.Modify, rddvJSJDPT, false);
  117. rddvJSJDPT.Edit();
  118. rddvJSJDPT.SetFieldValue("x", _duandianPoint.X);
  119. rddvJSJDPT.SetFieldValue("y", _duandianPoint.Y);
  120. Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanDian, "objectid") + 1;
  121. string _duandian = "dvJD" + objID;
  122. rddvJSJDPT.SetFieldValue("objectid", objID);
  123. rddvJSJDPT.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  124. rddvJSJDPT.SetFieldValue("bsm", _duandian);
  125. rddvJSJDPT.SetFieldValue("fldm", "供水节点");
  126. rddvJSJDPT.SetFieldValue("cqbh", "管线打断-新增节点");
  127. if (rddvJSJDPT.Update())
  128. {
  129. (ComsStatic.Datasource.Datasets["dvJD"] as DatasetVector).Append(rddvJSJDPT);
  130. ComsStatic.RecordsetDispose(rddvJSJDPT);
  131. Commons.LogHelper.Info(string.Format("管线打断-新增节点成功!新增的OBJECTID是{0}。", objID));
  132. }
  133. else
  134. {
  135. ComsStatic.EditHistoryUndo(m_EditHistory);
  136. ComsStatic.ShowErrorLog("管线打断操作失败", "管线打断-新增节点操作失败!"); return false;
  137. }
  138. //2 新增 起始管线
  139. Recordset _rd = ComsStatic.gsGuanXian.GetRecordset(true, CursorType.Dynamic);
  140. _rd.AddNew(_geoLineStart);
  141. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false);
  142. m_EditHistory.Add(SuperMap.Data.EditType.Modify, _rd, false);
  143. _rd.Edit();
  144. _rd.SetFieldValue("qsdh", rdJSLKdd.GetFieldValue("qsdh"));
  145. _rd.SetFieldValue("zddh", _duandian);
  146. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  147. _rd.SetFieldValue("gj", rdJSLKdd.GetFieldValue("gj"));
  148. objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "objectid") + 1;
  149. _rd.SetFieldValue("objectid", objID);
  150. _rd.SetFieldValue("fldm", ComsStatic.dvGXCaption);
  151. _rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID);
  152. _rd.SetFieldValue("cd", ComsStatic.StringToDouble(_geoLineStart.Length, 2));
  153. _rd.SetFieldValue("shape_length", _geoLineStart.Length);
  154. _rd.SetFieldValue("cqbh", "管线打断-新增起始管线");
  155. if (_rd.Update())
  156. {
  157. Commons.LogHelper.Info(string.Format("管线打断-新增起始管线成功!新增的OBJECTID是{0}。", objID));
  158. }
  159. else
  160. {
  161. ComsStatic.EditHistoryUndo(m_EditHistory);
  162. ComsStatic.ShowErrorLog("管线打断操作失败", "管线打断-新增起始管线操作失败!"); return false;
  163. }
  164. //3 新增 结束管线
  165. _rd = ComsStatic.gsGuanXian.GetRecordset(true, CursorType.Dynamic);
  166. _rd.AddNew(_geoLineEnd);
  167. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false);
  168. m_EditHistory.Add(SuperMap.Data.EditType.Modify, _rd, false);
  169. _rd.Edit();
  170. _rd.SetFieldValue("qsdh", _duandian);
  171. _rd.SetFieldValue("zddh", rdJSLKdd.GetFieldValue("zddh"));
  172. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  173. _rd.SetFieldValue("gj", rdJSLKdd.GetFieldValue("gj"));
  174. objID = ComsStatic.GetMaxValueInt(ComsStatic.gsGuanXian, "objectid") + 1;
  175. _rd.SetFieldValue("objectid", objID);
  176. _rd.SetFieldValue("fldm", ComsStatic.dvGXCaption);
  177. _rd.SetFieldValue("bsm", ComsStatic.dvGXDatasetName + objID);
  178. _rd.SetFieldValue("cd", ComsStatic.StringToDouble(_geoLineEnd.Length, 2));
  179. _rd.SetFieldValue("shape_length", _geoLineEnd.Length);
  180. _rd.SetFieldValue("cqbh", "管线打断-新增结束管线");
  181. if (_rd.Update())
  182. {
  183. Commons.LogHelper.Info(string.Format("管线打断-新增结束管线成功!新增的OBJECTID是{0}。", objID));
  184. }
  185. else
  186. {
  187. ComsStatic.EditHistoryUndo(m_EditHistory);
  188. ComsStatic.ShowErrorLog("管线打断操作失败", "管线打断-新增结束管线操作失败!"); return false;
  189. }
  190. //4 删除 原管线
  191. m_EditHistory.Add(SuperMap.Data.EditType.Delete, rdJSLKdd, false);
  192. if (rdJSLKdd.Delete())
  193. {
  194. ComsStatic.ShowOKLog("操作成功", string.Format("删除管线{0},新增节点{1}", smidGX, _duandian));
  195. }
  196. else
  197. {
  198. ComsStatic.EditHistoryUndo(m_EditHistory);
  199. ComsStatic.ShowErrorLog("管线打断操作失败", "原管线删除失败!"); return false;
  200. }
  201. }
  202. catch (Exception e)
  203. {
  204. ComsStatic.ShowErrorLog("管线打断出错!", e.Message); return false;
  205. }
  206. return true;
  207. }
  208. public override void AfterClose()
  209. {
  210. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  211. base.AfterClose();
  212. }
  213. private void uiButton2_Click(object sender, EventArgs e)
  214. {
  215. _duandianPoint = new Point2D(0, 0);
  216. smidGX = 0;
  217. _geoLineStart = null;
  218. _geoLineEnd = null;
  219. MapControl.Map.TrackingLayer.Clear();
  220. MapControl.Map.RefreshTrackingLayer();
  221. }
  222. private void InitializeComponent()
  223. {
  224. this.uiButton2 = new Sunny.UI.UIButton();
  225. this.uiButton1 = new Sunny.UI.UIButton();
  226. this.SuspendLayout();
  227. //
  228. // uiButton2
  229. //
  230. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
  231. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  232. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  233. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  234. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  235. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  236. this.uiButton2.Location = new System.Drawing.Point(167, 33);
  237. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  238. this.uiButton2.Name = "uiButton2";
  239. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  240. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  241. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  242. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  243. this.uiButton2.Size = new System.Drawing.Size(123, 30);
  244. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  245. this.uiButton2.TabIndex = 2;
  246. this.uiButton2.Text = "取消管线预览";
  247. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  248. //
  249. // uiButton1
  250. //
  251. this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
  252. this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  253. this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  254. this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  255. this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  256. this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
  257. this.uiButton1.Location = new System.Drawing.Point(3, 33);
  258. this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
  259. this.uiButton1.Name = "uiButton1";
  260. this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  261. this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  262. this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  263. this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  264. this.uiButton1.Size = new System.Drawing.Size(123, 30);
  265. this.uiButton1.Style = Sunny.UI.UIStyle.Gray;
  266. this.uiButton1.TabIndex = 1;
  267. this.uiButton1.Text = "预览打断管线";
  268. this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
  269. //
  270. // GuanXianDaDuan
  271. //
  272. this.Controls.Add(this.uiButton2);
  273. this.Controls.Add(this.uiButton1);
  274. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  275. this.Name = "GuanXianDaDuan";
  276. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  277. this.Size = new System.Drawing.Size(300, 115);
  278. this.Style = Sunny.UI.UIStyle.Gray;
  279. this.ResumeLayout(false);
  280. }
  281. }
  282. }