XiaoFangShuan.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Sunny.UI;
  14. using System.IO;
  15. namespace WWPipeLine.MapTools.Conditions.AnalystToolBar
  16. {
  17. public partial class XiaoFangShuan : ConditionPanel
  18. {
  19. private GeoPoint markPoint = null;
  20. public XiaoFangShuan()
  21. {
  22. this.ConditionPanelName = "消防栓搜索";
  23. InitializeComponent();
  24. this.IsShowPanelFooter = false;
  25. this.SetSize(700, 535);
  26. }
  27. protected override void OnLoad(EventArgs e)
  28. {
  29. Recordset rd = ComsStatic.dvJSLK_PZ.Query(" pzlx='事故点' ", CursorType.Static);
  30. ComsStatic.setUIDataGridView(uidgvshigudian, ComsStatic.RecordsetToDataTable(rd), "pzlx,pzkey");
  31. uidgvshigudian.ColumnHeadersVisible = false;
  32. }
  33. private void uitbBanjing_KeyPress(object sender, KeyPressEventArgs e)
  34. {
  35. if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8))
  36. e.Handled = true;
  37. }
  38. private void uiButton1_Click(object sender, EventArgs e)
  39. {
  40. ComsStatic.ShowOK("在地图中双击手动标注火灾事故位置");
  41. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  42. }
  43. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  44. {
  45. Point2D pClick = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  46. markPoint = new GeoPoint(pClick);
  47. MapControl.Map.TrackingLayer.Clear();
  48. string path = Commons.Paths.ApplicationResourcesDir + "\\huozai.gif";
  49. if (File.Exists(path))
  50. {
  51. GeoPicture geoPicture = new GeoPicture(path, pClick, 10, 10, 0);
  52. MapControl.Map.TrackingLayer.Add(geoPicture, "InterestPoint");
  53. }
  54. else
  55. {
  56. markPoint.Style = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red };
  57. MapControl.Map.TrackingLayer.Add(markPoint, "InterestPoint");
  58. }
  59. MapControl.Map.RefreshEx(MapControl.Map.ViewBounds);
  60. }
  61. private void uiButton2_Click(object sender, EventArgs e)
  62. {
  63. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  64. if (markPoint is null || string.IsNullOrEmpty(uitbBanjing.Text)) { ComsStatic.ShowOK("请先完成事故点的搜索和定位"); return; }
  65. DatasetVector dv = ComsStatic.Datasource.Datasets["JSXFSPT"] as DatasetVector;
  66. if (dv == null) { Sunny.UI.UIMessageTip.ShowError("当前数据源中不包含相应的矢量数据集"); return; }
  67. Recordset rd = dv.Query(markPoint, ComsStatic.StringToDouble(uitbBanjing.Text), "", CursorType.Static);
  68. DataTable dt = ComsStatic.RecordsetToDataTable(rd);
  69. dt.Columns.Add(new DataColumn { ColumnName = "cd", Caption = "距离(米)", DataType = Type.GetType("System.Double") });
  70. GeoPoint gp = null;
  71. foreach (DataRow dr in dt.Rows)
  72. {
  73. gp = new GeoPoint(ComsStatic.StringToDouble(dr["smx"]), ComsStatic.StringToDouble(dr["smy"]));
  74. dr["cd"] = Math.Round(Geometrist.Distance(gp, markPoint), 0);
  75. }
  76. DataView dataView = dt.DefaultView;
  77. dataView.Sort = "cd asc";
  78. ComsStatic.setUIDataGridView(uidgvxiaofangshuan, dataView.ToTable(), "cd,fsw,dzms,qsdw,");
  79. uidgvxiaofangshuan.Columns["cd"].DisplayIndex = 0;
  80. }
  81. public override void AfterClose()
  82. {
  83. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  84. base.AfterClose();
  85. }
  86. private void uidgvshigudian_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  87. {
  88. if (uidgvshigudian.SelectedRows == null || uidgvshigudian.SelectedRows.Count != 1) return;
  89. DataGridViewRow selectRow = uidgvshigudian.SelectedRows[0];
  90. new DoTrackingPoint().Doing(ComsStatic.StringToDouble(selectRow.Cells["smx"].Value), ComsStatic.StringToDouble(selectRow.Cells["smy"].Value));
  91. //Point2D p2d = new Point2D(ComsStatic.StringToDouble(selectRow.Cells["smx"].Value), ComsStatic.StringToDouble(selectRow.Cells["smy"].Value));
  92. //markPoint = new GeoPoint(p2d);
  93. //markPoint.Style = new GeoStyle() { MarkerSize = new Size2D(5, 5), LineColor = Color.Red };
  94. //MapControl.Map.Center = p2d;
  95. //MapControl.Map.TrackingLayer.Clear();
  96. //MapControl.Map.TrackingLayer.Add(markPoint, "InterestPoint");
  97. //MapControl.Map.Refresh();
  98. }
  99. private void uidgvxiaofangshuan_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  100. {
  101. if (uidgvxiaofangshuan.SelectedRows == null || uidgvxiaofangshuan.SelectedRows.Count != 1) return;
  102. DataGridViewRow selectRow = uidgvxiaofangshuan.SelectedRows[0];
  103. new DoTrackingPoint().Doing(ComsStatic.StringToDouble(selectRow.Cells["smx"].Value), ComsStatic.StringToDouble(selectRow.Cells["smy"].Value));
  104. }
  105. }
  106. }