cxDuoBianXing.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 cxDuoBianXing : ConditionPanel
  14. {
  15. private Sunny.UI.UILabel uilbMsg;
  16. private Sunny.UI.UIComboBox uiCBLayers;
  17. GeoRegion m_geo = null;
  18. public cxDuoBianXing() : base()
  19. {
  20. this.ConditionPanelName = "多边形查询";
  21. InitializeComponent();
  22. uilbMsg.Text = "鼠标右键开始绘制多边形,\n\r 依次点击鼠标左键,构建多边形断点,\n\r 再次点击右键结束绘制。";
  23. }
  24. protected override void OnLoad(EventArgs e)
  25. {
  26. MapControl.Action = SuperMap.UI.Action.CreatePolygon;
  27. MapControl.Tracked += new TrackedEventHandler(TrackedHandler);
  28. uiCBLayers.ValueMember = "LayerDatasetName";
  29. uiCBLayers.DisplayMember = "LayerCaption";
  30. uiCBLayers.DataSource = ComsStatic.getLayers();
  31. }
  32. private void TrackedHandler(object sender, TrackedEventArgs e)
  33. {
  34. if (e.Geometry is null) return;
  35. m_geo = e.Geometry.Clone() as GeoRegion;
  36. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("查询区域绘制失败"); return; }
  37. m_geo.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  38. MapControl.Map.TrackingLayer.Clear();
  39. MapControl.Map.TrackingLayer.Add(m_geo, "GeoRegion");
  40. MapControl.Map.Refresh();
  41. }
  42. public override object Do(DockPanel dockPanel = null)
  43. {
  44. IsConditionValid = false;
  45. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("请先绘制查询区域"); return false; }
  46. DatasetVector datasetVector = ComsStatic.Datasource.Datasets[uiCBLayers.SelectedValue.ToString()] as DatasetVector;
  47. if (datasetVector is null)
  48. {
  49. Sunny.UI.UIMessageTip.ShowError("当前选择的图层没有可用的数据"); return false;
  50. }
  51. Recordset recordset = datasetVector.Query(m_geo, 1, "1=1", CursorType.Static);
  52. if (recordset is null)
  53. {
  54. Sunny.UI.UIMessageTip.ShowError("当前图层没有查询到数据"); return false;
  55. }
  56. DataTable dt = ComsStatic.RecordsetToDataTable(recordset, uiCBLayers.SelectedText);
  57. recordset.Close(); recordset.Dispose();
  58. return dt;
  59. }
  60. public override void AfterClose()
  61. {
  62. MapControl.Tracked -= new TrackedEventHandler(TrackedHandler);
  63. base.AfterClose();
  64. }
  65. private void InitializeComponent()
  66. {
  67. this.uilbMsg = new Sunny.UI.UILabel();
  68. this.uiCBLayers = new Sunny.UI.UIComboBox();
  69. this.SuspendLayout();
  70. //
  71. // uilbMsg
  72. //
  73. this.uilbMsg.AutoSize = true;
  74. this.uilbMsg.Font = new System.Drawing.Font("微软雅黑", 12F);
  75. this.uilbMsg.Location = new System.Drawing.Point(3, 35);
  76. this.uilbMsg.Name = "uilbMsg";
  77. this.uilbMsg.Size = new System.Drawing.Size(74, 21);
  78. this.uilbMsg.TabIndex = 0;
  79. this.uilbMsg.Text = "操作说明";
  80. this.uilbMsg.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  81. //
  82. // uiCBLayers
  83. //
  84. this.uiCBLayers.DataSource = null;
  85. this.uiCBLayers.FillColor = System.Drawing.Color.White;
  86. this.uiCBLayers.Font = new System.Drawing.Font("微软雅黑", 12F);
  87. this.uiCBLayers.Location = new System.Drawing.Point(60, 5);
  88. this.uiCBLayers.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
  89. this.uiCBLayers.MinimumSize = new System.Drawing.Size(63, 0);
  90. this.uiCBLayers.Name = "uiCBLayers";
  91. this.uiCBLayers.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
  92. this.uiCBLayers.Size = new System.Drawing.Size(328, 29);
  93. this.uiCBLayers.TabIndex = 1;
  94. this.uiCBLayers.Text = "请选择需要查询的图层";
  95. this.uiCBLayers.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
  96. //
  97. // cxDuoBianXing
  98. //
  99. this.Controls.Add(this.uiCBLayers);
  100. this.Controls.Add(this.uilbMsg);
  101. this.Name = "cxDuoBianXing";
  102. this.Size = new System.Drawing.Size(392, 215);
  103. this.ResumeLayout(false);
  104. this.PerformLayout();
  105. }
  106. }
  107. }