GuanXianDaDuan.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 UILabel lbRemark;
  17. private UIButton uiButton2;
  18. private UIButton uiButton1;
  19. private UILabel uilbNew;
  20. private UILabel uiLabel1;
  21. private Selection[] _selection = null;
  22. private Panel plMain;
  23. private Point2D _duandianPoint = new Point2D(0, 0);
  24. private GeoPoint _geoPoint = null;
  25. private GeoLine _geoLineStart = null;
  26. private GeoLine _geoLineEnd = null;
  27. private DataTable dtJSLK = new DataTable();
  28. public GuanXianDaDuan() : base()
  29. {
  30. this.ConditionPanelName = "打断管线";
  31. InitializeComponent();
  32. lbRemark.Text = "先选择一根需要打断的管线,\r\n 然后通过在管线上双击鼠标,标记断点。";
  33. }
  34. protected override void OnLoad(EventArgs e)
  35. {
  36. ComsStatic.SetLayerIsEditableFalse();
  37. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true);
  38. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  39. }
  40. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  41. {
  42. _duandianPoint = this.MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  43. _geoPoint = new GeoPoint(_duandianPoint);
  44. _geoPoint.Style = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red }; ;
  45. MapControl.Map.TrackingLayer.Clear();
  46. MapControl.Map.TrackingLayer.Add(_geoPoint, "GuanXianDaDuan");
  47. MapControl.Map.Refresh();
  48. uiLabel1.Text = string.Format("断点X坐标:{0:F2},Y坐标:{1:F2}。", _duandianPoint.X, _duandianPoint.Y);
  49. }
  50. private void uiButton1_Click(object sender, EventArgs e)
  51. {
  52. uilbNew.Text = "打断后的管线信息:";
  53. StringBuilder sb = new StringBuilder();
  54. _selection = base.MapControl.Map.FindSelection(true);
  55. if (_selection.Length != 1 || _selection[0].Count != 1)
  56. {
  57. Sunny.UI.UIMessageTip.ShowError("选择需要打断的一根管线", 4000); return;
  58. }
  59. if (_duandianPoint.X == 0 || _duandianPoint.Y == 0)
  60. {
  61. Sunny.UI.UIMessageTip.ShowError("请在需要打断的管线上双击确认断点", 4000); return;
  62. }
  63. dtJSLK = ComsStatic.QueryDataTable(ComsStatic.dvJSLK, string.Format(" smid={0}", _selection[0][0]));
  64. if (dtJSLK.Rows.Count != 1)
  65. {
  66. Sunny.UI.UIMessageTip.ShowError("无法查询到选择管线的信息,请先确认管线的基本信息", 4000); return;
  67. }
  68. DataTable dtJSJDPT = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format("bsm='{0}'", dtJSLK.Rows[0]["qsdh"]));
  69. if (dtJSJDPT.Rows.Count != 1)
  70. {
  71. Sunny.UI.UIMessageTip.ShowError("当前选择的管线无法确认起始点号", 4000); return;
  72. }
  73. Point2D startPoint = new Point2D(double.Parse(dtJSJDPT.Rows[0]["x"].ToString()), double.Parse(dtJSJDPT.Rows[0]["y"].ToString()));
  74. dtJSJDPT = ComsStatic.QueryDataTable(ComsStatic.dvJSJDPT, string.Format("bsm='{0}'", dtJSLK.Rows[0]["zddh"]));
  75. if (dtJSJDPT.Rows.Count != 1)
  76. {
  77. Sunny.UI.UIMessageTip.ShowError("当前选择的管线无法确认终点点号", 4000); return;
  78. }
  79. Point2D endPoint = new Point2D(double.Parse(dtJSJDPT.Rows[0]["x"].ToString()), double.Parse(dtJSJDPT.Rows[0]["y"].ToString()));
  80. Point2Ds _geoPointsStart = new Point2Ds(new Point2D[] { startPoint, _duandianPoint });
  81. _geoLineStart = new GeoLine(_geoPointsStart);
  82. _geoLineStart.Style = new GeoStyle { LineColor = Color.Yellow, LineWidth = 1 }; ;
  83. int index = MapControl.Map.TrackingLayer.IndexOf("geoLineStart");
  84. if (index >= 0) MapControl.Map.TrackingLayer.Remove(index);
  85. MapControl.Map.TrackingLayer.Add(_geoLineStart, "geoLineStart");
  86. sb.AppendFormat("\r\n起点管线为黄色 \r\n 起点X坐标:{0:F2},Y坐标:{1:F2}", startPoint.X, startPoint.Y);
  87. sb.AppendFormat("\r\n 终点X坐标:{0:F2},Y坐标:{1:F2}", _duandianPoint.X, _duandianPoint.Y);
  88. Point2Ds _geoPointEnd = new Point2Ds(new Point2D[] { _duandianPoint, endPoint });
  89. _geoLineEnd = new GeoLine(_geoPointEnd);
  90. _geoLineEnd.Style = new GeoStyle { LineColor = Color.Brown, LineWidth = 1 }; ;
  91. index = MapControl.Map.TrackingLayer.IndexOf("geoLineEnd");
  92. if (index >= 0) MapControl.Map.TrackingLayer.Remove(index);
  93. MapControl.Map.TrackingLayer.Add(_geoLineEnd, "geoLineEnd");
  94. sb.AppendFormat("\r\n终点管线为棕色 \r\n 起点X坐标:{0:F2},Y坐标:{1:F2}", _duandianPoint.X, _duandianPoint.Y);
  95. sb.AppendFormat("\r\n 终点X坐标:{0:F2},Y坐标:{1:F2}", endPoint.X, endPoint.Y);
  96. uilbNew.Text = sb.ToString();
  97. MapControl.Map.Refresh();
  98. }
  99. public override object Do(DockPanel dockPanel = null)
  100. {
  101. EditHistory m_EditHistory = new EditHistory();
  102. m_EditHistory.Capacity = 5;
  103. IsShowResultWindow = false;
  104. if (_geoPoint is null || _geoLineStart is null || _geoLineEnd is null)
  105. {
  106. Sunny.UI.UIMessageTip.ShowError("请先执行“管线打断”操作", 4000); return false;
  107. }
  108. try
  109. {
  110. Recordset _recordset = _selection[0].ToRecordset();
  111. if (_recordset.RecordCount != 1)
  112. {
  113. Sunny.UI.UIMessageTip.ShowError("选择需要打断的一根管线", 4000); return false;
  114. }
  115. //1 新增 节点信息
  116. Recordset rddvJSJDPT = ComsStatic.dvJSJDPT.GetRecordset(false, CursorType.Dynamic);
  117. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, rddvJSJDPT, true);
  118. rddvJSJDPT.AddNew(_geoPoint);
  119. rddvJSJDPT.SetFieldValue("x", _duandianPoint.X);
  120. rddvJSJDPT.SetFieldValue("y", _duandianPoint.Y);
  121. Int32 objID = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSJDPT, "OBJECTID").ToString()) + 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("wth", _duandian);
  127. rddvJSJDPT.SetFieldValue("bsm", _duandian);
  128. rddvJSJDPT.SetFieldValue("fldm", "供水节点");
  129. rddvJSJDPT.SetFieldValue("objectid", objID);
  130. rddvJSJDPT.SetFieldValue("cqbh", "管线打断");
  131. if (rddvJSJDPT.Update())
  132. { Commons.LogHelper.Error(string.Format("管线打断-新增管线节点成功!新增的OBJECTID是{0}。", objID)); }
  133. else
  134. {
  135. ComsStatic.EditHistoryUndo(m_EditHistory);
  136. Sunny.UI.UIMessageTip.ShowError("管线断点操作失败!", 4000); return false;
  137. }
  138. //2 新增 起始管线
  139. Recordset _rd = ComsStatic.dvJSLK.GetRecordset(false, CursorType.Dynamic);
  140. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, true);
  141. _rd.AddNew(_geoLineStart);
  142. _rd.SetFieldValue("qsdh", dtJSLK.Rows[0]["qsdh"]);
  143. _rd.SetFieldValue("zddh", _duandian);
  144. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  145. _rd.SetFieldValue("enabled", 1);
  146. _rd.SetFieldValue("gj", _recordset.GetFieldValue("gj"));
  147. objID = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSLK, "OBJECTID").ToString()) + 1;
  148. _rd.SetFieldValue("objectid", objID);
  149. _rd.SetFieldValue("bsm", "JSLK" + objID);
  150. _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLineStart.Length)));
  151. _rd.SetFieldValue("shape_length", _geoLineStart.Length);
  152. _rd.SetFieldValue("fldm", "供水管线");
  153. _rd.SetFieldValue("cqbh", "管线打断");
  154. if (_rd.Update())
  155. { Commons.LogHelper.Error(string.Format("管线打断-新增起始管线成功!新增的OBJECTID是{0}。", objID)); }
  156. else
  157. {
  158. ComsStatic.EditHistoryUndo(m_EditHistory);
  159. Sunny.UI.UIMessageTip.ShowError("管线的起始管线操作失败!", 4000); return false;
  160. }
  161. //3 新增 结束管线
  162. m_EditHistory.Add(SuperMap.Data.EditType.AddNew, _rd, true);
  163. _rd.AddNew(_geoLineEnd);
  164. _rd.SetFieldValue("qsdh", _duandian);
  165. _rd.SetFieldValue("zddh", dtJSLK.Rows[0]["zddh"]);
  166. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  167. _rd.SetFieldValue("enabled", 1);
  168. _rd.SetFieldValue("gj", _recordset.GetFieldValue("gj"));
  169. objID = Int32.Parse(ComsStatic.GetMaxValue(ComsStatic.dvJSLK, "OBJECTID").ToString()) + 1;
  170. _rd.SetFieldValue("objectid", objID);
  171. _rd.SetFieldValue("bsm", "JSLK" + objID);
  172. _rd.SetFieldValue("cd", double.Parse(string.Format("{0:F2}", _geoLineStart.Length)));
  173. _rd.SetFieldValue("shape_length", _geoLineStart.Length);
  174. _rd.SetFieldValue("fldm", "供水管线");
  175. _rd.SetFieldValue("cqbh", "管线打断");
  176. if (_rd.Update())
  177. { Commons.LogHelper.Error(string.Format("管线打断-新增结束管线成功!新增的OBJECTID是{0}。", objID)); }
  178. else
  179. {
  180. ComsStatic.EditHistoryUndo(m_EditHistory);
  181. Sunny.UI.UIMessageTip.ShowError("管线的结束管线操作失败!", 4000); return false;
  182. }
  183. //4 删除 原管线
  184. m_EditHistory.Add(SuperMap.Data.EditType.Delete, _recordset, true);
  185. if (_recordset.DeleteAll())
  186. { }
  187. else
  188. {
  189. ComsStatic.EditHistoryUndo(m_EditHistory);
  190. Sunny.UI.UIMessageTip.ShowError("原管线删除失败!", 4000); return false;
  191. }
  192. }
  193. catch
  194. {
  195. ComsStatic.EditHistoryUndo(m_EditHistory);
  196. Sunny.UI.UIMessageTip.ShowError("管线打断出错!"); return false;
  197. }
  198. return true;
  199. }
  200. public override void AfterClose()
  201. {
  202. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  203. base.AfterClose();
  204. }
  205. private void uiButton2_Click(object sender, EventArgs e)
  206. {
  207. uilbNew.Text = "打断后的管线信息:";
  208. MapControl.Map.TrackingLayer.Clear();
  209. MapControl.Map.Refresh();
  210. }
  211. private void InitializeComponent()
  212. {
  213. this.plMain = new System.Windows.Forms.Panel();
  214. this.uiLabel1 = new Sunny.UI.UILabel();
  215. this.uilbNew = new Sunny.UI.UILabel();
  216. this.uiButton2 = new Sunny.UI.UIButton();
  217. this.uiButton1 = new Sunny.UI.UIButton();
  218. this.lbRemark = new Sunny.UI.UILabel();
  219. this.plMain.SuspendLayout();
  220. this.SuspendLayout();
  221. //
  222. // plMain
  223. //
  224. this.plMain.AutoScroll = true;
  225. this.plMain.Controls.Add(this.uiLabel1);
  226. this.plMain.Controls.Add(this.uilbNew);
  227. this.plMain.Controls.Add(this.uiButton2);
  228. this.plMain.Controls.Add(this.uiButton1);
  229. this.plMain.Controls.Add(this.lbRemark);
  230. this.plMain.Dock = System.Windows.Forms.DockStyle.Fill;
  231. this.plMain.Location = new System.Drawing.Point(0, 0);
  232. this.plMain.Name = "plMain";
  233. this.plMain.Size = new System.Drawing.Size(460, 306);
  234. this.plMain.TabIndex = 0;
  235. //
  236. // uiLabel1
  237. //
  238. this.uiLabel1.AutoSize = true;
  239. this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
  240. this.uiLabel1.Location = new System.Drawing.Point(4, 107);
  241. this.uiLabel1.Name = "uiLabel1";
  242. this.uiLabel1.Size = new System.Drawing.Size(218, 21);
  243. this.uiLabel1.Style = Sunny.UI.UIStyle.Gray;
  244. this.uiLabel1.TabIndex = 4;
  245. this.uiLabel1.Text = "管线断点:在管线上双击确认";
  246. this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  247. //
  248. // uilbNew
  249. //
  250. this.uilbNew.AutoSize = true;
  251. this.uilbNew.Font = new System.Drawing.Font("微软雅黑", 12F);
  252. this.uilbNew.Location = new System.Drawing.Point(3, 130);
  253. this.uilbNew.Name = "uilbNew";
  254. this.uilbNew.Size = new System.Drawing.Size(154, 21);
  255. this.uilbNew.Style = Sunny.UI.UIStyle.Gray;
  256. this.uilbNew.TabIndex = 3;
  257. this.uilbNew.Text = "打断后的管线信息:";
  258. this.uilbNew.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  259. //
  260. // uiButton2
  261. //
  262. this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
  263. this.uiButton2.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  264. this.uiButton2.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  265. this.uiButton2.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  266. this.uiButton2.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  267. this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
  268. this.uiButton2.Location = new System.Drawing.Point(130, 58);
  269. this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
  270. this.uiButton2.Name = "uiButton2";
  271. this.uiButton2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  272. this.uiButton2.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  273. this.uiButton2.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  274. this.uiButton2.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  275. this.uiButton2.Size = new System.Drawing.Size(100, 35);
  276. this.uiButton2.Style = Sunny.UI.UIStyle.Gray;
  277. this.uiButton2.TabIndex = 2;
  278. this.uiButton2.Text = "取消管线";
  279. this.uiButton2.Click += new System.EventHandler(this.uiButton2_Click);
  280. //
  281. // uiButton1
  282. //
  283. this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
  284. this.uiButton1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  285. this.uiButton1.FillHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  286. this.uiButton1.FillPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  287. this.uiButton1.FillSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  288. this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
  289. this.uiButton1.Location = new System.Drawing.Point(8, 58);
  290. this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
  291. this.uiButton1.Name = "uiButton1";
  292. this.uiButton1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  293. this.uiButton1.RectHoverColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(160)))), ((int)(((byte)(165)))));
  294. this.uiButton1.RectPressColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  295. this.uiButton1.RectSelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(121)))), ((int)(((byte)(123)))), ((int)(((byte)(129)))));
  296. this.uiButton1.Size = new System.Drawing.Size(100, 35);
  297. this.uiButton1.Style = Sunny.UI.UIStyle.Gray;
  298. this.uiButton1.TabIndex = 1;
  299. this.uiButton1.Text = "打断管线";
  300. this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click);
  301. //
  302. // lbRemark
  303. //
  304. this.lbRemark.AutoSize = true;
  305. this.lbRemark.Font = new System.Drawing.Font("微软雅黑", 12F);
  306. this.lbRemark.Location = new System.Drawing.Point(4, 4);
  307. this.lbRemark.Name = "lbRemark";
  308. this.lbRemark.Size = new System.Drawing.Size(74, 21);
  309. this.lbRemark.Style = Sunny.UI.UIStyle.Gray;
  310. this.lbRemark.TabIndex = 0;
  311. this.lbRemark.Text = "要素信息";
  312. this.lbRemark.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  313. //
  314. // GuanXianDaDuan
  315. //
  316. this.Controls.Add(this.plMain);
  317. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  318. this.Name = "GuanXianDaDuan";
  319. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  320. this.Size = new System.Drawing.Size(460, 306);
  321. this.Style = Sunny.UI.UIStyle.Gray;
  322. this.plMain.ResumeLayout(false);
  323. this.plMain.PerformLayout();
  324. this.ResumeLayout(false);
  325. }
  326. }
  327. }