DWbount.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 WeifenLuo.WinFormsUI.Docking;
  12. using WWPipeLine.MapBasic;
  13. using SuperMap.Data;
  14. using Sunny.UI;
  15. namespace WWPipeLine.MapTools.Conditions.Locations
  16. {
  17. public partial class DWbount : ConditionPanel
  18. {
  19. private DatasetVector _dv;
  20. public DWbount()
  21. {
  22. this.ConditionPanelName = "按照行政区域定位";
  23. InitializeComponent();
  24. this.IsShowPanelFooter = false;
  25. }
  26. protected override void OnLoad(EventArgs e)
  27. {
  28. _dv = ComsStatic.Datasource.Datasets["BOUNTPY"] as DatasetVector;
  29. if (_dv == null)
  30. {
  31. Sunny.UI.UIMessageTip.ShowError("当前数据源中不包含相应的矢量数据集"); return;
  32. }
  33. ComsStatic.setUIDataGridView(uiDataGridViewDW, ComsStatic.RecordsetToDataTable(_dv.GetRecordset(false, CursorType.Static)));
  34. uiDataGridViewDW.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  35. }
  36. private void uiDataGridViewDW_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  37. {
  38. DataGridView dataGridView = (sender as DataGridView);
  39. var selectRows = dataGridView.SelectedRows;
  40. if (selectRows == null || selectRows.Count != 1) return;//选择不是一行
  41. DataGridViewRow selectRow = selectRows[0];
  42. var index = -1;
  43. foreach (DataGridViewColumn c in selectRow.DataGridView.Columns)
  44. {
  45. if (c.Name.ToUpper() == "SMID")
  46. {
  47. index = selectRow.DataGridView.Columns.IndexOf(c); break;
  48. }
  49. }
  50. if (index == -1) return;//列数据中不包含SMID列
  51. int smid = ComsStatic.StringToInt(selectRow.Cells[index].Value);
  52. if (smid == 0) return;//SMID的值为null
  53. Geometry geoxy = null;
  54. var fs = _dv.GetAllFeatures();
  55. if (fs.ContainsKey(smid))
  56. {
  57. geoxy = fs[smid].GetGeometry();
  58. }
  59. if (geoxy == null) return;//当前数据集没有找到SMID对应的数据
  60. MapControl.Map.ViewBounds = geoxy.Bounds;
  61. MapControl.Map.Refresh();
  62. }
  63. }
  64. }