SercherOnClick.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using SuperMap.Data;
  2. using SuperMap.Mapping;
  3. using SuperMap.UI;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Drawing;
  8. using WeifenLuo.WinFormsUI.Docking;
  9. using WWPipeLine.MapBasic;
  10. using WWPipeLine.MapBasic.Conditions;
  11. namespace WWPipeLine.MapTools.Conditions.Sercher
  12. {
  13. public class SercherOnClick : ConditionPanel
  14. {
  15. private LayerWithDataListPanel LayerPanel;
  16. public SercherOnClick() : base()
  17. {
  18. this.ConditionPanelName = "点击查询";
  19. InitializeComponent();
  20. }
  21. private Sunny.UI.UIGroupBox uigbLayer;
  22. private Sunny.UI.UITextBox uitbBanjing;
  23. private Sunny.UI.UILabel uiLabel1;
  24. private Selection[] _selection = null;
  25. protected override void OnLoad(EventArgs e)
  26. {
  27. LayerPanel = new LayerWithDataListPanel();
  28. LayerPanel.LoadToVector(true, true, true);
  29. uigbLayer.Controls.Add(LayerPanel);
  30. }
  31. public override object Do(DockPanel dockPanel = null)
  32. {
  33. if (LayerPanel.SelectLayers.Count == 0)
  34. {
  35. Sunny.UI.UIMessageTip.ShowError("请先选择需要查询的图层"); return false;
  36. }
  37. double banjing = ComsStatic.StringToDouble(uitbBanjing.Text);
  38. if (banjing == 0.0)
  39. {
  40. Sunny.UI.UIMessageTip.ShowError("请输入正确的查询半径"); return false;
  41. }
  42. _selection = MapControl.Map.FindSelection(true);
  43. if (_selection is null || _selection.Length != 1 || _selection[0].Count != 1)
  44. {
  45. Sunny.UI.UIMessageTip.ShowError("请先选择一个基础元素"); return false;
  46. }
  47. List<DataTable> dts = new List<DataTable>();
  48. Recordset _rd = null;
  49. DatasetVector dv = null;
  50. DataTable dt = null;
  51. Geometry m_geo = _selection[0].ToRecordset().GetGeometry();
  52. foreach (Layer lyr in LayerPanel.SelectLayers)
  53. {
  54. dv = lyr.Dataset as DatasetVector;
  55. if (dv is null || dv.RecordCount == 0) continue;
  56. _rd = dv.Query(m_geo, banjing, "", CursorType.Static);
  57. if (_rd is null || _rd.RecordCount == 0) continue;
  58. dt = ComsStatic.RecordsetToDataTable(_rd);
  59. dt.TableName = lyr.Caption;
  60. dts.Add(dt);
  61. }
  62. return dts;
  63. }
  64. private void InitializeComponent()
  65. {
  66. this.uigbLayer = new Sunny.UI.UIGroupBox();
  67. this.uitbBanjing = new Sunny.UI.UITextBox();
  68. this.uiLabel1 = new Sunny.UI.UILabel();
  69. this.SuspendLayout();
  70. //
  71. // uigbLayer
  72. //
  73. this.uigbLayer.Dock = System.Windows.Forms.DockStyle.Top;
  74. this.uigbLayer.Font = new System.Drawing.Font("微软雅黑", 12F);
  75. this.uigbLayer.Location = new System.Drawing.Point(0, 0);
  76. this.uigbLayer.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
  77. this.uigbLayer.MinimumSize = new System.Drawing.Size(1, 1);
  78. this.uigbLayer.Name = "uigbLayer";
  79. this.uigbLayer.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
  80. this.uigbLayer.Size = new System.Drawing.Size(500, 259);
  81. this.uigbLayer.TabIndex = 0;
  82. this.uigbLayer.Text = "查询图层选择";
  83. this.uigbLayer.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
  84. //
  85. // uitbBanjing
  86. //
  87. this.uitbBanjing.Cursor = System.Windows.Forms.Cursors.IBeam;
  88. this.uitbBanjing.DoubleValue = 10D;
  89. this.uitbBanjing.FillColor = System.Drawing.Color.White;
  90. this.uitbBanjing.Font = new System.Drawing.Font("微软雅黑", 12F);
  91. this.uitbBanjing.IntValue = 10;
  92. this.uitbBanjing.Location = new System.Drawing.Point(121, 269);
  93. this.uitbBanjing.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
  94. this.uitbBanjing.Maximum = 2147483647D;
  95. this.uitbBanjing.Minimum = -2147483648D;
  96. this.uitbBanjing.MinimumSize = new System.Drawing.Size(1, 1);
  97. this.uitbBanjing.Name = "uitbBanjing";
  98. this.uitbBanjing.Size = new System.Drawing.Size(76, 29);
  99. this.uitbBanjing.TabIndex = 3;
  100. this.uitbBanjing.Text = "10";
  101. this.uitbBanjing.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
  102. this.uitbBanjing.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.uitbBanjing_KeyPress);
  103. //
  104. // uiLabel1
  105. //
  106. this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
  107. this.uiLabel1.Location = new System.Drawing.Point(14, 273);
  108. this.uiLabel1.Name = "uiLabel1";
  109. this.uiLabel1.Size = new System.Drawing.Size(100, 23);
  110. this.uiLabel1.TabIndex = 2;
  111. this.uiLabel1.Text = "查询半径(M):";
  112. this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  113. //
  114. // SercherOnClick
  115. //
  116. this.Controls.Add(this.uitbBanjing);
  117. this.Controls.Add(this.uiLabel1);
  118. this.Controls.Add(this.uigbLayer);
  119. this.Name = "SercherOnClick";
  120. this.Size = new System.Drawing.Size(500, 315);
  121. this.ResumeLayout(false);
  122. }
  123. private void uitbBanjing_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  124. {
  125. if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8))
  126. e.Handled = true;
  127. }
  128. }
  129. }