ShiGuDian.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 bool isClick = false;
  23. private GeoPoint markPoint = null;
  24. public ShiGuDian()
  25. {
  26. this.ConditionPanelName = "事故点定位";
  27. this.IsShowPanelFooter = false;
  28. InitializeComponent();
  29. this.SetSize(500, 500);
  30. }
  31. protected override void OnLoad(EventArgs e)
  32. {
  33. dv = ComsStatic.Datasource.Datasets["pyroad"] 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. ComsStatic.RecordsetDispose(rd);
  44. uilbRoad.SelectedIndex = 0;
  45. foreach (Layer lyr in ComsStatic.MapLayersUsed)
  46. {
  47. uicbxLayers.Items.Add(new DoListItem(lyr.Dataset.Name, lyr.Caption));
  48. }
  49. uicbxLayers.SelectedIndex = 0;
  50. }
  51. private void uiButton2_Click(object sender, EventArgs e)
  52. {
  53. int RoadSmID = ComsStatic.StringToInt((uilbRoad.SelectedItem as DoListItem).Key);
  54. Geometry geo = dv.GetAllFeatures()[RoadSmID].GetGeometry();
  55. if (geo is null) { UIMessageTip.ShowError("未查询到当前道路信息,无法完成事故点定位"); return; }
  56. DatasetVector dvLayer = ComsStatic.Datasource.Datasets[(uicbxLayers.SelectedItem as DoListItem).Key] as DatasetVector;
  57. if (dvLayer is null) { UIMessageTip.ShowError("未查询到当前选择图层的数据集信息"); return; }
  58. Recordset rdd = dvLayer.Query(geo, ComsStatic.StringToDouble(uitbBanjing.Text), CursorType.Static);
  59. ComsStatic.setUIDataGridView(uidgv, ComsStatic.RecordsetToDataTable(rdd), ",fsw,cd,dzms,qsdw,name,address,");
  60. }
  61. private void uidgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  62. {
  63. isClick = false;
  64. if (uidgv.SelectedRows == null || uidgv.SelectedRows.Count != 1) return;
  65. DataGridViewRow selectRow = uidgv.SelectedRows[0];
  66. markPoint = new GeoPoint(ComsStatic.GetPoint2D(selectRow.Cells["smx"].Value, selectRow.Cells["smy"].Value));
  67. new DoTrackingPoint().Doing(ComsStatic.StringToDouble(selectRow.Cells["smx"].Value), ComsStatic.StringToDouble(selectRow.Cells["smy"].Value));
  68. }
  69. private void uiButton1_Click(object sender, EventArgs e)
  70. {
  71. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  72. if (markPoint is null) { ComsStatic.ShowOK("请先完成事故点的搜索和定位"); return; }
  73. Recordset rd = ComsStatic.dvConfig.GetRecordset(true, CursorType.Dynamic);
  74. rd.AddNew(markPoint);
  75. if (isClick)
  76. {
  77. rd.SetFieldValue("pzlx", "事故点");
  78. rd.SetFieldValue("pzKey", "手动添加");
  79. }
  80. else
  81. {
  82. rd.SetFieldValue("pzlx", "事故点");
  83. rd.SetFieldValue("pzKey", uicbxLayers.SelectedItem.ToString());
  84. }
  85. ComsStatic.ShowUIMessageTipOKorError(rd.Update(), "标记事故点");
  86. markPoint = null; isClick = false;
  87. }
  88. private void uiButton3_Click(object sender, EventArgs e)
  89. {
  90. MapControl.MouseDoubleClick += MapControl_MouseDoubleClick;
  91. }
  92. private void MapControl_MouseDoubleClick(object sender, MouseEventArgs e)
  93. {
  94. isClick = true;
  95. Point2D pClick = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  96. markPoint = new GeoPoint(pClick);
  97. MapControl.Map.TrackingLayer.Clear();
  98. string path = Commons.Paths.ApplicationResourcesDir + "\\shigudian.png";
  99. if (File.Exists(path))
  100. {
  101. GeoPicture geoPicture = new GeoPicture(path, pClick, 10, 10, 0);
  102. MapControl.Map.TrackingLayer.Add(geoPicture, "InterestPoint");
  103. }
  104. else
  105. {
  106. markPoint.Style = new GeoStyle { MarkerSize = new Size2D(5, 5), LineColor = Color.Red };
  107. MapControl.Map.TrackingLayer.Add(markPoint, "InterestPoint");
  108. }
  109. MapControl.Map.RefreshTrackingLayer();
  110. }
  111. public override void AfterClose()
  112. {
  113. MapControl.MouseDoubleClick -= MapControl_MouseDoubleClick;
  114. base.AfterClose();
  115. }
  116. }
  117. }