RWWithDataGridView.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using SuperMap.Analyst.NetworkAnalyst;
  2. using SuperMap.Data;
  3. using SuperMap.Mapping;
  4. using SuperMap.Plot;
  5. using System;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Windows.Forms;
  9. namespace WWPipeLine.MapBasic.Results
  10. {
  11. public class RWWithDataGridView : ResultWindow
  12. {
  13. private Sunny.UI.UIDataGridView m_DataGridView;
  14. private Layer m_LayerSelect = null;
  15. private GeoPoint markPoint = null;
  16. private int Timertag = 1;
  17. private Timer TimerM = new Timer();
  18. public RWWithDataGridView() : base()
  19. {
  20. m_DataGridView = new Sunny.UI.UIDataGridView();
  21. this.Controls.Add(m_DataGridView);
  22. m_DataGridView.CellMouseDoubleClick += DataGridView_CellMouseDoubleClick;
  23. CreateExportExcelButton();
  24. uiSymbolButtonExportToExcel.Click += UiSymbolButtonExportToExcel_Click;
  25. TimerM.Interval = 300;
  26. TimerM.Tick += TimerM_Tick;
  27. }
  28. private void TimerM_Tick(object sender, EventArgs e)
  29. {
  30. if (Timertag == 6)
  31. {
  32. TimerM.Stop();
  33. TimerM.Enabled = false;
  34. Timertag = 1;
  35. int index = ComsStatic.MapControl.Map.TrackingLayer.IndexOf("DoInterestPoint");
  36. if (index > -1) ComsStatic.MapControl.Map.TrackingLayer.Remove(index);
  37. ComsStatic.MapControl.Map.RefreshTrackingLayer();
  38. return;
  39. }
  40. else if (Timertag % 2 == 1 && markPoint != null)
  41. {
  42. ComsStatic.MapControl.Map.TrackingLayer.Add(markPoint, "DoInterestPoint");
  43. }
  44. else //if (Timertag % 2 == 0)
  45. {
  46. int index = ComsStatic.MapControl.Map.TrackingLayer.IndexOf("DoInterestPoint");
  47. if (index > -1) ComsStatic.MapControl.Map.TrackingLayer.Remove(index);
  48. }
  49. Timertag++;
  50. ComsStatic.MapControl.Map.RefreshTrackingLayer();
  51. }
  52. //导出
  53. private void UiSymbolButtonExportToExcel_Click(object sender, EventArgs e)
  54. {
  55. ExportToExcel(this.m_DataGridView);
  56. }
  57. /// <summary>
  58. /// 鼠标双击
  59. /// </summary>
  60. /// <param name="sender"></param>
  61. /// <param name="e"></param>
  62. protected void DataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  63. {
  64. if (m_LayerSelect is null) return;
  65. if (m_DataGridView.SelectedRows == null || m_DataGridView.SelectedRows.Count != 1) return;//选择不是一行
  66. int smid = ComsStatic.StringToInt(m_DataGridView.SelectedRows[0].Cells["smid"].Value);
  67. if (smid == 0) return;
  68. var fs = (m_LayerSelect.Dataset as DatasetVector).GetAllFeatures();
  69. if (!fs.ContainsKey(smid)) return;
  70. Geometry geoxy = fs[smid].GetGeometry();
  71. ComsStatic.MapControl.Map.Center = geoxy.InnerPoint;
  72. markPoint = new GeoPoint { X = geoxy.InnerPoint.X, Y = geoxy.InnerPoint.Y, Style = ComsStatic.geoStyle_Red_Mark5mm };
  73. TimerM.Enabled = true; TimerM.Start();
  74. ComsStatic.MapControl.Map.Refresh();
  75. }
  76. public override void ShowData(object data)
  77. {
  78. if (data == null)
  79. {
  80. DataTable dt = new DataTable();
  81. dt.Columns.Add("执行结果");
  82. DataRow dr = dt.NewRow();
  83. dr[0] = "查询无结果";
  84. dt.Rows.Add(dr);
  85. }
  86. else if (data is DataTable)
  87. {
  88. var dt = data as DataTable;
  89. foreach (Layer lyr in ComsStatic.MapLayers)
  90. {
  91. if (lyr.Name.Contains(dt.TableName) || lyr.Caption.Contains(dt.TableName))
  92. {
  93. m_LayerSelect = lyr; break;
  94. }
  95. }
  96. if (System.Text.RegularExpressions.Regex.IsMatch(dt.TableName?.ToString(), @"[\u4e00-\u9fa5]"))
  97. this.m_DataGridView.Tag = dt.TableName?.ToString();
  98. else
  99. this.m_DataGridView.Tag = base.Text;
  100. ComsStatic.setUIDataGridView(m_DataGridView, dt);
  101. }
  102. else
  103. {
  104. ComsStatic.ShowErrorLog("需要的参数为DataTable", string.Format("RWWithDataGridView中data的数据类型是{0}", data.GetType()));
  105. throw new ArgumentException("需要的参数为DataTable");
  106. }
  107. }
  108. private void InitializeComponent()
  109. {
  110. this.SuspendLayout();
  111. //
  112. // RWWithDataGridView
  113. //
  114. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  115. this.ClientSize = new System.Drawing.Size(800, 450);
  116. this.Name = "RWWithDataGridView";
  117. this.ResumeLayout(false);
  118. }
  119. }
  120. }