ShiGuDian.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 System.IO;
  17. namespace WWPipeLine.MapTools.Conditions.AnalystToolBar
  18. {
  19. public partial class ShiGuDian : ConditionPanel
  20. {
  21. DatasetVector dv = null;
  22. private int smid = 0;
  23. private GeoPoint markPoint = null;
  24. public ShiGuDian()
  25. {
  26. this.ConditionPanelName = "事故点定位";
  27. InitializeComponent();
  28. this.IsShowPanelFooter = false;
  29. this.SetSize(630, 635);
  30. }
  31. protected override void OnLoad(EventArgs e)
  32. {
  33. dv = ComsStatic.Datasource.Datasets["ROADPY"] as DatasetVector;
  34. if (dv is null) { UIMessageTip.ShowError("当前系统未配置道路数据集"); this.ParentForm.Close(); return; }
  35. //Recordset rd = ComsStatic.QueryRecordset(dv, "", new string[] { "name" }, new string[] { "name" }, new string[] { "name" });
  36. Recordset rd = dv.GetRecordset(false, CursorType.Static);
  37. rd.MoveFirst();
  38. while (!rd.IsEOF)
  39. {
  40. uilbRoad.Items.Add(new DoListItem(rd.GetFieldValue("smid").ToString(), rd.GetFieldValue("name").ToString()));
  41. rd.MoveNext();
  42. }
  43. uilbRoad.SelectedIndex = 0;
  44. foreach (Layer lyr in ComsStatic.MapLayersUsed)
  45. {
  46. uicbxLayers.Items.Add(new DoListItem(lyr.Dataset.Name, lyr.Caption));
  47. }
  48. uicbxLayers.SelectedIndex = 0;
  49. }
  50. private void uitbBanjing_KeyPress(object sender, KeyPressEventArgs e)
  51. {
  52. if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8))
  53. e.Handled = true;
  54. }
  55. private void uiButton2_Click(object sender, EventArgs e)
  56. {
  57. int RoadSmID = ComsStatic.StringToInt((uilbRoad.SelectedItem as DoListItem).Key);
  58. Geometry geo = dv.GetAllFeatures()[RoadSmID].GetGeometry();
  59. if (geo is null) { UIMessageTip.ShowError("未查询到当前道路信息,无法完成事故点定位"); return; }
  60. DatasetVector dvLayer = ComsStatic.Datasource.Datasets[(uicbxLayers.SelectedItem as DoListItem).Key] as DatasetVector;
  61. if (dvLayer is null) { UIMessageTip.ShowError("未查询到当前选择图层的数据集信息"); return; }
  62. Recordset rdd = dvLayer.Query(geo, ComsStatic.StringToDouble(uitbBanjing.Text), CursorType.Static);
  63. ComsStatic.setUIDataGridView(uidgv, ComsStatic.RecordsetToDataTable(rdd), ",fsw,cd,dzms,qsdw,name,address");
  64. }
  65. private void uidgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  66. {
  67. if (uidgv.SelectedRows == null || uidgv.SelectedRows.Count != 1) return;
  68. DataGridViewRow selectRow = uidgv.SelectedRows[0];
  69. new DoTrackingPoint().Doing(ComsStatic.StringToDouble(selectRow.Cells["smx"].Value), ComsStatic.StringToDouble(selectRow.Cells["smy"].Value));
  70. }
  71. private void uiButton1_Click(object sender, EventArgs e)
  72. {
  73. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  74. if (markPoint is null) { ComsStatic.ShowOK("请先完成事故点的搜索和定位"); return; }
  75. Recordset rd = ComsStatic.dvJSLK_PZ.GetRecordset(true, CursorType.Dynamic);
  76. rd.AddNew(markPoint);
  77. if (smid != 0)
  78. {
  79. rd.SetFieldValue("pzlx", "事故点");
  80. rd.SetFieldValue("pzKey", uicbxLayers.SelectedItem.ToString());// rdd.Dataset.Name
  81. rd.SetFieldValue("pzValue", smid.ToString());
  82. }
  83. else
  84. {
  85. rd.SetFieldValue("pzlx", "事故点");
  86. rd.SetFieldValue("pzKey", "手动添加");
  87. }
  88. ComsStatic.ShowUIMessageTipOKorError(rd.Update(), "标记事故点");
  89. markPoint = null; smid = 0;
  90. }
  91. private void uiButton3_Click(object sender, EventArgs e)
  92. {
  93. ComsStatic.ShowOK("在地图中双击手动标注事故点位置");
  94. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  95. }
  96. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  97. {
  98. Point2D pClick = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  99. markPoint = new GeoPoint(pClick);
  100. MapControl.Map.TrackingLayer.Clear();
  101. string path = Commons.Paths.ApplicationResourcesDir + "\\shigudian.png";
  102. if (File.Exists(path))
  103. {
  104. GeoPicture geoPicture = new GeoPicture(path, pClick, 10, 10, 0);
  105. MapControl.Map.TrackingLayer.Add(geoPicture, "InterestPoint");
  106. }
  107. else
  108. {
  109. markPoint.Style = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red };
  110. MapControl.Map.TrackingLayer.Add(markPoint, "InterestPoint");
  111. }
  112. MapControl.Map.RefreshEx(MapControl.Map.ViewBounds);
  113. }
  114. public override void AfterClose()
  115. {
  116. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  117. base.AfterClose();
  118. }
  119. }
  120. }