GuanFa.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  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 SuperMap.Data;
  13. using WeifenLuo.WinFormsUI.Docking;
  14. using SuperMap.Mapping;
  15. using Sunny.UI;
  16. using SuperMap.Analyst.NetworkAnalyst;
  17. using System.IO;
  18. namespace WWPipeLine.MapTools.Conditions.AnalystToolBar
  19. {
  20. public partial class GuanFa : ConditionPanel
  21. {
  22. private int objectidJSLK = 0;
  23. DatasetVector dv = null;
  24. public GuanFa()
  25. {
  26. this.ConditionPanelName = "关阀分析";
  27. InitializeComponent();
  28. this.IsShowPanelFooter = false;
  29. this.SetSize(500, 600);
  30. }
  31. protected override void OnLoad(EventArgs e)
  32. {
  33. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  34. string dviName = ComsStatic.DatasourceMemory.Datasets.GetAvailableDatasetName("GuanFaNetwork");
  35. dv = NetworkBuilder.BuildNetwork(ComsStatic.gsGuanXian, ComsStatic.gsGuanDian, "objectid", "qsdh", "zddh", "bsm", ComsStatic.DatasourceMemory, dviName);
  36. }
  37. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  38. {
  39. Point2D pClick = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  40. GeoPoint pointClick = new GeoPoint(pClick);
  41. Recordset rdJSLK = ComsStatic.gsGuanXian.Query(pointClick, 10, " enabled=1 ", 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 line_temp;
  49. GeoLine line = null;
  50. int smidJSLK = 0;
  51. rdJSLK.MoveFirst();
  52. while (!rdJSLK.IsEOF)
  53. {
  54. line_temp = rdJSLK.GetGeometry() as GeoLine;
  55. distance_temp = Geometrist.Distance(pointClick, line_temp);
  56. if (distance_temp <= distance || distance == 0.0D)
  57. {
  58. distance = distance_temp;
  59. line = line_temp;
  60. smidJSLK = rdJSLK.GetID();
  61. }
  62. rdJSLK.MoveNext();
  63. }
  64. pClick = Geometrist.NearestPointToVertex(pClick, line);
  65. GeoPoint markPoint = new GeoPoint(pClick);
  66. MapControl.Map.TrackingLayer.Clear();
  67. string path = Commons.Paths.ApplicationResourcesDir + "\\baoguan.png";
  68. if (File.Exists(path))
  69. {
  70. GeoPicture geoPicture = new GeoPicture(path, pClick, 10, 10, 0);
  71. MapControl.Map.TrackingLayer.Add(geoPicture, "InterestPoint");
  72. }
  73. else
  74. {
  75. markPoint.Style = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red };
  76. MapControl.Map.TrackingLayer.Add(markPoint, "InterestPoint");
  77. }
  78. MapControl.Map.RefreshTrackingLayer();
  79. rdJSLK.SeekID(smidJSLK);
  80. uitb_bsm.Text = rdJSLK.GetFieldValue("bsm").ToString();
  81. uitb_zcbh.Text = rdJSLK.GetFieldValue("zcbh")?.ToString();
  82. uitbGdbh.Text = rdJSLK.GetFieldValue("gdbh")?.ToString();
  83. uitb_tz.Text = rdJSLK.GetFieldValue("tz")?.ToString();
  84. uitb_cz.Text = rdJSLK.GetFieldValue("cz")?.ToString();
  85. uitb_gj.Text = rdJSLK.GetFieldValue("gj").ToString();
  86. uitb_yl.Text = rdJSLK.GetFieldValue("yl")?.ToString();
  87. uitb_cd.Text = rdJSLK.GetFieldValue("cd").ToString();
  88. uitb_msfs.Text = rdJSLK.GetFieldValue("msfs")?.ToString();
  89. uidp_msrq.Text = rdJSLK.GetFieldValue("msrq")?.ToString();
  90. uitb_dzms.Text = rdJSLK.GetFieldValue("dzms")?.ToString();
  91. uitb_qsdw.Text = rdJSLK.GetFieldValue("qsdw")?.ToString();
  92. uitb_bz.Text = rdJSLK.GetFieldValue("bz")?.ToString();
  93. objectidJSLK = ComsStatic.StringToInt(rdJSLK.GetFieldValue("objectid"));
  94. ComsStatic.RecordsetDispose(rdJSLK);
  95. }
  96. public override void AfterClose()
  97. {
  98. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  99. base.AfterClose();
  100. }
  101. private void uiButton1_Click(object sender, EventArgs e)
  102. {
  103. if (objectidJSLK == 0) { UIMessageTip.ShowError("请选择爆管的管线"); return; }
  104. FacilityAnalystSetting analystSetting = new FacilityAnalystSetting();
  105. analystSetting.NetworkDataset = dv;
  106. analystSetting.NodeIDField = "SmNodeID";
  107. analystSetting.EdgeIDField = "objectid";
  108. analystSetting.FNodeIDField = "SmFNode";
  109. analystSetting.TNodeIDField = "SmTNode";
  110. analystSetting.DirectionField = "lx";
  111. analystSetting.Tolerance = 0.001;
  112. FacilityAnalyst m_facilityAnalyst = new FacilityAnalyst();
  113. m_facilityAnalyst.AnalystSetting = analystSetting;
  114. bool isLoad = m_facilityAnalyst.Load();
  115. Recordset rdChild = dv.ChildDataset.Query(" FLDM='供水阀门' ", CursorType.Static);
  116. if (rdChild.RecordCount == 0) { UIMessageTip.ShowError("无法查找到任何阀门信息"); return; }
  117. List<int> listNodeIDs = new List<int>();
  118. rdChild.MoveFirst();
  119. while (!rdChild.IsEOF)
  120. {
  121. listNodeIDs.Add(ComsStatic.StringToInt(rdChild.GetFieldValue("SmNodeID")));
  122. rdChild.MoveNext();
  123. }
  124. FacilityAnalystResult resultEdges = m_facilityAnalyst.FindCriticalFacilitiesUpFromEdge(listNodeIDs.ToArray(), objectidJSLK, true);
  125. if (resultEdges is null) { Sunny.UI.UIMessageTip.ShowWarning("未找到有效阀门"); return; }
  126. rdChild = dv.ChildDataset.Query(string.Format("SmNodeID in ({0})", string.Join(",", resultEdges.Nodes)), CursorType.Static);
  127. ComsStatic.setUIDataGridView(uidgv, ComsStatic.RecordsetToDataTable(rdChild), ",tz,fsw,xh,gg,cz,kj,dzms,bz,");
  128. m_facilityAnalyst.Dispose();
  129. }
  130. private void uidgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  131. {
  132. if (uidgv.SelectedRows == null || uidgv.SelectedRows.Count != 1) return;//选择不是一行
  133. DataGridViewRow selectRow = uidgv.SelectedRows[0];
  134. new DoTrackingPoint().Doing(ComsStatic.StringToDouble(selectRow.Cells["smx"].Value), ComsStatic.StringToDouble(selectRow.Cells["smy"].Value));
  135. }
  136. }
  137. }