GuanXianDaDuan.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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(500, 185);
  28. IsShowResultWindow = false;
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.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.dvJSLK.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.dvJSLK.Query(new int[] { smidGX }, CursorType.Dynamic);
  75. if (rdJSLKdd.RecordCount != 1)
  76. {
  77. Sunny.UI.UIMessageTip.ShowError("无法查询到选择管线的信息,请先确认管线的基本信息"); return;
  78. }
  79. DataTable dtJSJDPT = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format("bsm='{0}'", rdJSLKdd.GetFieldValue("qsdh")));//dtJSLK.Rows[0]["qsdh"]
  80. if (dtJSJDPT.Rows.Count != 1)
  81. {
  82. Sunny.UI.UIMessageTip.ShowError("当前选择的管线无法确认起始点号"); return;
  83. }
  84. Point2D startPoint = new Point2D(double.Parse(dtJSJDPT.Rows[0]["x"].ToString()), double.Parse(dtJSJDPT.Rows[0]["y"].ToString()));
  85. dtJSJDPT = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format("bsm='{0}'", rdJSLKdd.GetFieldValue("zddh")));//dtJSLK.Rows[0]["zddh"]
  86. if (dtJSJDPT.Rows.Count != 1)
  87. {
  88. Sunny.UI.UIMessageTip.ShowError("当前选择的管线无法确认终点点号"); return;
  89. }
  90. Point2D endPoint = new Point2D(double.Parse(dtJSJDPT.Rows[0]["x"].ToString()), double.Parse(dtJSJDPT.Rows[0]["y"].ToString()));
  91. Point2Ds _geoPointsStart = new Point2Ds(new Point2D[] { startPoint, _duandianPoint });
  92. _geoLineStart = new GeoLine(_geoPointsStart);
  93. _geoLineStart.Style = new GeoStyle { LineColor = Color.Yellow, LineWidth = 1 }; ;
  94. int index = MapControl.Map.TrackingLayer.IndexOf("geoLineStart");
  95. if (index >= 0) MapControl.Map.TrackingLayer.Remove(index);
  96. MapControl.Map.TrackingLayer.Add(_geoLineStart, "geoLineStart");
  97. Point2Ds _geoPointEnd = new Point2Ds(new Point2D[] { _duandianPoint, endPoint });
  98. _geoLineEnd = new GeoLine(_geoPointEnd);
  99. _geoLineEnd.Style = new GeoStyle { LineColor = Color.Brown, LineWidth = 1 }; ;
  100. index = MapControl.Map.TrackingLayer.IndexOf("geoLineEnd");
  101. if (index >= 0) MapControl.Map.TrackingLayer.Remove(index);
  102. MapControl.Map.TrackingLayer.Add(_geoLineEnd, "geoLineEnd");
  103. MapControl.Map.RefreshTrackingLayer();
  104. }
  105. public override object Do(DockPanel dockPanel = null)
  106. {
  107. EditHistory m_EditHistory = new EditHistory();
  108. m_EditHistory.Capacity = 5;
  109. if (_geoLineStart is null || _geoLineEnd is null)
  110. {
  111. Sunny.UI.UIMessageTip.ShowError("请先执行“管线打断”操作", 4000); return false;
  112. }
  113. try
  114. {
  115. //1 新增 节点信息
  116. Recordset rddvJSJDPT = ComsStatic.dvJSJDPT.GetRecordset(true, CursorType.Dynamic);
  117. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, rddvJSJDPT, false);
  118. rddvJSJDPT.AddNew(new GeoPoint(_duandianPoint));
  119. rddvJSJDPT.SetFieldValue("x", _duandianPoint.X);
  120. rddvJSJDPT.SetFieldValue("y", _duandianPoint.Y);
  121. Int32 objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSJDPT, "OBJECTID") + 1;
  122. string _duandian = "JSJDPT" + objID;
  123. rddvJSJDPT.SetFieldValue("ms", 0);
  124. rddvJSJDPT.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  125. rddvJSJDPT.SetFieldValue("enabled", 1);
  126. rddvJSJDPT.SetFieldValue("bsm", _duandian);
  127. rddvJSJDPT.SetFieldValue("fldm", "供水节点");
  128. rddvJSJDPT.SetFieldValue("objectid", objID);
  129. rddvJSJDPT.SetFieldValue("cqbh", "管线打断");
  130. if (rddvJSJDPT.Update())
  131. {
  132. Commons.LogHelper.Error(string.Format("管线打断-新增管线节点成功!新增的OBJECTID是{0}。", objID));
  133. }
  134. else
  135. {
  136. ComsStatic.EditHistoryUndo(m_EditHistory);
  137. Sunny.UI.UIMessageTip.ShowError("管线节点新增操作失败!"); return false;
  138. }
  139. //2 新增 起始管线
  140. Recordset _rd = ComsStatic.dvJSLK.GetRecordset(true, CursorType.Dynamic);
  141. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false);
  142. _rd.AddNew(_geoLineStart);
  143. _rd.SetFieldValue("qsdh", rdJSLKdd.GetFieldValue("qsdh"));
  144. _rd.SetFieldValue("zddh", _duandian);
  145. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  146. _rd.SetFieldValue("enabled", 1);
  147. _rd.SetFieldValue("gj", rdJSLKdd.GetFieldValue("gj"));
  148. objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSLK, "OBJECTID") + 1;
  149. _rd.SetFieldValue("objectid", objID);
  150. _rd.SetFieldValue("bsm", "JSLK" + objID);
  151. _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLineStart.Length)));
  152. _rd.SetFieldValue("shape_length", _geoLineStart.Length);
  153. _rd.SetFieldValue("fldm", "供水管线");
  154. _rd.SetFieldValue("cqbh", "管线打断");
  155. if (_rd.Update())
  156. {
  157. Commons.LogHelper.Error(string.Format("管线打断-新增起始管线成功!新增的OBJECTID是{0}。", objID));
  158. }
  159. else
  160. {
  161. ComsStatic.EditHistoryUndo(m_EditHistory);
  162. Sunny.UI.UIMessageTip.ShowError("管线的起始管线新增操作失败!"); return false;
  163. }
  164. //3 新增 结束管线
  165. _rd = ComsStatic.dvJSLK.GetRecordset(true, CursorType.Dynamic);
  166. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, false);
  167. _rd.AddNew(_geoLineEnd);
  168. _rd.SetFieldValue("qsdh", _duandian);
  169. _rd.SetFieldValue("zddh", rdJSLKdd.GetFieldValue("zddh"));
  170. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  171. _rd.SetFieldValue("enabled", 1);
  172. _rd.SetFieldValue("gj", rdJSLKdd.GetFieldValue("gj"));
  173. objID = ComsStatic.GetMaxValueInt(ComsStatic.dvJSLK, "OBJECTID") + 1;
  174. _rd.SetFieldValue("objectid", objID);
  175. _rd.SetFieldValue("bsm", "JSLK" + objID);
  176. _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLineStart.Length)));
  177. _rd.SetFieldValue("shape_length", _geoLineStart.Length);
  178. _rd.SetFieldValue("fldm", "供水管线");
  179. _rd.SetFieldValue("cqbh", "管线打断");
  180. if (_rd.Update())
  181. {
  182. Commons.LogHelper.Error(string.Format("管线打断-新增结束管线成功!新增的OBJECTID是{0}。", objID));
  183. }
  184. else
  185. {
  186. ComsStatic.EditHistoryUndo(m_EditHistory);
  187. Sunny.UI.UIMessageTip.ShowError("管线的结束管线新增操作失败!"); return false;
  188. }
  189. //4 删除 原管线
  190. m_EditHistory.Add(SuperMap.Data.EditType.Delete, rdJSLKdd, false);
  191. if (rdJSLKdd.Delete())
  192. {
  193. Commons.LogHelper.Error(string.Format("管线打断-删除原管线成功。原管线SmID是{0}。", smidGX));
  194. Sunny.UI.UIMessageTip.ShowOk("管线打断操作成功");
  195. }
  196. else
  197. {
  198. ComsStatic.EditHistoryUndo(m_EditHistory);
  199. Sunny.UI.UIMessageTip.ShowError("原管线删除失败!"); return false;
  200. }
  201. }
  202. catch (Exception e)
  203. {
  204. ComsStatic.EditHistoryUndo(m_EditHistory);
  205. ComsStatic.ShowErrorLog("管线打断出错!", e.Message); return false;
  206. }
  207. return true;
  208. }
  209. public override void AfterClose()
  210. {
  211. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  212. base.AfterClose();
  213. }
  214. private void uiButton2_Click(object sender, EventArgs e)
  215. {
  216. _duandianPoint = new Point2D(0, 0);
  217. smidGX = 0;
  218. _geoLineStart = null;
  219. _geoLineEnd = null;
  220. MapControl.Map.TrackingLayer.Clear();
  221. MapControl.Map.Refresh();
  222. }
  223. private void InitializeComponent()
  224. {
  225. this.uiButton2 = new Sunny.UI.UIButton();
  226. this.uiButton1 = new Sunny.UI.UIButton();
  227. this.SuspendLayout();
  228. //
  229. // uiButton2
  230. //
  231. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
  232. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  233. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  234. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  235. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  236. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  237. this.uiButton2.Location = new System.Drawing.Point(263, 29);
  238. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  239. this.uiButton2.Name = "uiButton2";
  240. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  241. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  242. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  243. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  244. this.uiButton2.Size = new System.Drawing.Size(123, 30);
  245. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  246. this.uiButton2.TabIndex = 2;
  247. this.uiButton2.Text = "取消管线预览";
  248. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  249. //
  250. // uiButton1
  251. //
  252. this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
  253. this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  254. this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  255. this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  256. this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  257. this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
  258. this.uiButton1.Location = new System.Drawing.Point(99, 29);
  259. this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
  260. this.uiButton1.Name = "uiButton1";
  261. this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  262. this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  263. this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  264. this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  265. this.uiButton1.Size = new System.Drawing.Size(123, 30);
  266. this.uiButton1.Style = Sunny.UI.UIStyle.Gray;
  267. this.uiButton1.TabIndex = 1;
  268. this.uiButton1.Text = "预览打断管线";
  269. this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
  270. //
  271. // GuanXianDaDuan
  272. //
  273. this.Controls.Add(this.uiButton2);
  274. this.Controls.Add(this.uiButton1);
  275. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  276. this.Name = "GuanXianDaDuan";
  277. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  278. this.Size = new System.Drawing.Size(500, 100);
  279. this.Style = Sunny.UI.UIStyle.Gray;
  280. this.ResumeLayout(false);
  281. }
  282. }
  283. }