GuanDianXinZeng.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. namespace WWPipeLine.MapTools.Conditions.EditGuanWang
  11. {
  12. public class GuanDianXinZeng : ConditionPanel
  13. {
  14. private GeoPoint _geoPoint = null;
  15. private GroupBox groupBoxLayer;
  16. private UICheckBox uiCBpol;
  17. private UICheckBox uiCheckBox1;
  18. private LayerWithDataListPanel LayerPanel;
  19. public GuanDianXinZeng() : base()
  20. {
  21. this.ConditionPanelName = "新增管点信息";
  22. InitializeComponent();
  23. LayerPanel = new LayerWithDataListPanel();
  24. LayerPanel.LoadToVector(false, false);
  25. groupBoxLayer.Controls.Add(LayerPanel);
  26. }
  27. protected override void OnLoad(EventArgs e)
  28. {
  29. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  30. }
  31. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  32. {
  33. if (LayerPanel.SelectLayers.Count != 1)
  34. {
  35. Sunny.UI.UIMessageTip.ShowError("请选择需要编辑的图层"); return;
  36. }
  37. Point2D pClick = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  38. if (uiCBpol.Checked)//限制线上点
  39. {
  40. GeoPoint pointClick = new GeoPoint(pClick);
  41. Recordset rdJSLK = ComsStatic.dvJSLK.Query(pointClick, 3, CursorType.Static);
  42. if (rdJSLK.RecordCount == 0)
  43. {
  44. Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到管线信息"); return;
  45. }
  46. double distance_temp = 0.0D;
  47. double distance = 0.0D;
  48. GeoLine _rd_temp;
  49. GeoLine _rd_line = new GeoLine();
  50. rdJSLK.MoveFirst();
  51. while (!rdJSLK.IsEOF)
  52. {
  53. _rd_temp = rdJSLK.GetGeometry() as GeoLine;
  54. distance_temp = Geometrist.Distance(pointClick, _rd_temp);
  55. if (distance_temp <= distance || distance == 0.0D)
  56. {
  57. distance = distance_temp;
  58. _rd_line = _rd_temp;
  59. }
  60. rdJSLK.MoveNext();
  61. }
  62. pClick = Geometrist.NearestPointToVertex(pClick, _rd_line);
  63. //bool PointOnLine = Geometrist.HasCommonPoint(new GeoPoint(pClick), _rd_line);
  64. }
  65. if (uiCheckBox1.Checked)//限制于节点重合
  66. {
  67. GeoPoint pointClick = new GeoPoint(pClick);
  68. Recordset rdJSJDPT = ComsStatic.dvJSJDPT.Query(pointClick, 3, CursorType.Static);
  69. if (rdJSJDPT.RecordCount == 0)
  70. {
  71. Sunny.UI.UIMessageTip.ShowError("当前鼠标双击点附近没有找到节点信息"); return;
  72. }
  73. double distance_temp = 0.0D;
  74. double distance = 0.0D;
  75. GeoPoint p_temp;
  76. rdJSJDPT.MoveFirst();
  77. while (!rdJSJDPT.IsEOF)
  78. {
  79. p_temp = rdJSJDPT.GetGeometry() as GeoPoint;
  80. distance_temp = Geometrist.Distance(pointClick, p_temp);
  81. if (distance_temp <= distance || distance == 0.0D)
  82. {
  83. distance = distance_temp;
  84. pClick = p_temp.InnerPoint;
  85. }
  86. rdJSJDPT.MoveNext();
  87. }
  88. }
  89. _geoPoint = new GeoPoint(pClick);
  90. _geoPoint.Style = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red };
  91. MapControl.Map.TrackingLayer.Clear();
  92. MapControl.Map.TrackingLayer.Add(_geoPoint, "jiedian");
  93. MapControl.Map.RefreshEx(MapControl.Map.ViewBounds);
  94. }
  95. public override object Do(DockPanel dockPanel = null)
  96. {
  97. this.IsShowResultWindow = false;
  98. if (LayerPanel.SelectLayers.Count != 1 || _geoPoint is null)
  99. {
  100. Sunny.UI.UIMessageTip.ShowError("请选择需要编辑的图层,并在界面中点选节点位置"); return false;
  101. }
  102. DatasetVector _dv = LayerPanel.SelectLayers[0].Dataset as DatasetVector;
  103. Recordset _rd = _dv.GetRecordset(true, CursorType.Dynamic);
  104. Int32 objID = ComsStatic.GetMaxValueInt(_dv, "OBJECTID") + 1;
  105. _rd.AddNew(_geoPoint);
  106. _rd.SetFieldValue("x", _geoPoint.X);
  107. _rd.SetFieldValue("y", _geoPoint.Y);
  108. _rd.SetFieldValue("ms", 0);
  109. _rd.SetFieldValue("lrrq", DateTime.Now.ToLocalTime());
  110. _rd.SetFieldValue("enabled", 1);
  111. _rd.SetFieldValue("bsm", _dv.Name + objID);
  112. _rd.SetFieldValue("fldm", LayerPanel.SelectLayers[0].Caption);
  113. _rd.SetFieldValue("objectid", objID);
  114. _rd.SetFieldValue("cqbh", "管点新增");
  115. if (_rd.Update())
  116. {
  117. ComsStatic.ShowOKLog(LayerPanel.SelectLayers[0].Caption + "新增成功");
  118. MapControl.Map.TrackingLayer.Clear();
  119. //Int32 smid = _dvEx.QueryGetSMID(string.Format(" objectid={0}", objID - 1));
  120. //Selection selection = new Selection() { Dataset = _layer.Dataset as DatasetVector };
  121. //selection.Add(smid);
  122. //_layer.Selection = selection;
  123. //MapControl.Map.Refresh();
  124. //if (selection.Count == 1)
  125. //{
  126. // this.ParentForm.Close();
  127. // XiuGai xiugaiForm = new XiuGai();
  128. // xiugaiForm.Show();
  129. //}
  130. }
  131. else
  132. {
  133. ComsStatic.ShowErrorLog(LayerPanel.SelectLayers[0].Caption + "新增失败");
  134. }
  135. return null;
  136. }
  137. public override void AfterClose()
  138. {
  139. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  140. base.AfterClose();
  141. }
  142. private void InitializeComponent()
  143. {
  144. this.groupBoxLayer = new System.Windows.Forms.GroupBox();
  145. this.uiCBpol = new Sunny.UI.UICheckBox();
  146. this.uiCheckBox1 = new Sunny.UI.UICheckBox();
  147. this.SuspendLayout();
  148. //
  149. // groupBoxLayer
  150. //
  151. this.groupBoxLayer.Dock = System.Windows.Forms.DockStyle.Top;
  152. this.groupBoxLayer.Location = new System.Drawing.Point(0, 0);
  153. this.groupBoxLayer.Name = "groupBoxLayer";
  154. this.groupBoxLayer.Size = new System.Drawing.Size(500, 236);
  155. this.groupBoxLayer.TabIndex = 26;
  156. this.groupBoxLayer.TabStop = false;
  157. this.groupBoxLayer.Text = "管点图层";
  158. //
  159. // uiCBpol
  160. //
  161. this.uiCBpol.CheckBoxColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  162. this.uiCBpol.Cursor = System.Windows.Forms.Cursors.Hand;
  163. this.uiCBpol.Font = new System.Drawing.Font("微软雅黑", 12F);
  164. this.uiCBpol.Location = new System.Drawing.Point(26, 242);
  165. this.uiCBpol.MinimumSize = new System.Drawing.Size(1, 1);
  166. this.uiCBpol.Name = "uiCBpol";
  167. this.uiCBpol.Padding = new System.Windows.Forms.Padding(22, 0, 0, 0);
  168. this.uiCBpol.Size = new System.Drawing.Size(178, 29);
  169. this.uiCBpol.Style = Sunny.UI.UIStyle.Gray;
  170. this.uiCBpol.TabIndex = 0;
  171. this.uiCBpol.Text = "限制线上点";
  172. //
  173. // uiCheckBox1
  174. //
  175. this.uiCheckBox1.CheckBoxColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  176. this.uiCheckBox1.Cursor = System.Windows.Forms.Cursors.Hand;
  177. this.uiCheckBox1.Font = new System.Drawing.Font("微软雅黑", 12F);
  178. this.uiCheckBox1.Location = new System.Drawing.Point(238, 242);
  179. this.uiCheckBox1.MinimumSize = new System.Drawing.Size(1, 1);
  180. this.uiCheckBox1.Name = "uiCheckBox1";
  181. this.uiCheckBox1.Padding = new System.Windows.Forms.Padding(22, 0, 0, 0);
  182. this.uiCheckBox1.Size = new System.Drawing.Size(178, 29);
  183. this.uiCheckBox1.Style = Sunny.UI.UIStyle.Gray;
  184. this.uiCheckBox1.TabIndex = 27;
  185. this.uiCheckBox1.Text = "限制与节点重合";
  186. //
  187. // GuanDianXinZeng
  188. //
  189. this.Controls.Add(this.uiCheckBox1);
  190. this.Controls.Add(this.uiCBpol);
  191. this.Controls.Add(this.groupBoxLayer);
  192. this.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(242)))), ((int)(((byte)(242)))), ((int)(((byte)(244)))));
  193. this.Name = "GuanDianXinZeng";
  194. this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(140)))), ((int)(((byte)(140)))));
  195. this.Size = new System.Drawing.Size(500, 315);
  196. this.Style = Sunny.UI.UIStyle.Gray;
  197. this.ResumeLayout(false);
  198. }
  199. }
  200. }