SercherTJ.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 Sunny.UI;
  14. using SuperMap.Data;
  15. namespace WWPipeLine.MapTools.Conditions.Sercher
  16. {
  17. public partial class SercherTJ : ConditionPanel
  18. {
  19. private DatasetVector dv;
  20. public bool isGeo = false;
  21. public SercherTJ()
  22. {
  23. this.ConditionPanelName = "条件查询";
  24. InitializeComponent();
  25. this.SetSize(500, 600);
  26. }
  27. protected override void OnLoad(EventArgs e)
  28. {
  29. if (isGeo)
  30. {
  31. MapControl.Tracked += ComsStatic.MapControl_Tracked_TrackingName;
  32. }
  33. uibtndengyu.Click += uibtnCaoZuoFu_Click;
  34. uibtnbudengyu.Click += uibtnCaoZuoFu_Click;
  35. uibtnLike.Click += uibtnCaoZuoFu_Click;
  36. uibtndayu.Click += uibtnCaoZuoFu_Click;
  37. uibtnxiaoyu.Click += uibtnCaoZuoFu_Click;
  38. uibtnAnd.Click += uibtnCaoZuoFu_Click;
  39. uibtndydy.Click += uibtnCaoZuoFu_Click;
  40. uibtnxydy.Click += uibtnCaoZuoFu_Click;
  41. uibtnOr.Click += uibtnCaoZuoFu_Click;
  42. uibtnzuokuohao.Click += uibtnCaoZuoFu_Click;
  43. uibtnyoukuohao.Click += uibtnCaoZuoFu_Click;
  44. uibtnIs.Click += uibtnCaoZuoFu_Click;
  45. uibtnbaifenhao.Click += uibtnCaoZuoFu_Click;
  46. uibtnNot.Click += uibtnCaoZuoFu_Click;
  47. uibtnNull.Click += uibtnCaoZuoFu_Click;
  48. ComsStatic.BindUICombox(uicbxLayer);
  49. }
  50. public override object Do(DockPanel dockPanel = null)
  51. {
  52. if (string.IsNullOrEmpty(uitbSql.Text))
  53. {
  54. UIMessageTip.ShowError("请先选择需要查询的图层,并设定查询条件"); return false;
  55. }
  56. Recordset rd = null;
  57. if (isGeo)
  58. {
  59. int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName);
  60. if (index == -1)
  61. {
  62. Sunny.UI.UIMessageTip.ShowError("请先绘制区域"); return false;
  63. }
  64. GeoRegion geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion;
  65. rd = dv.Query(geo, 0, uitbSql.Text, CursorType.Static);
  66. }
  67. else
  68. rd = dv.Query(uitbSql.Text, CursorType.Static);
  69. return ComsStatic.RecordsetToDataTable(rd);
  70. }
  71. private void uibtnSqltest_Click(object sender, EventArgs e)
  72. {
  73. if (string.IsNullOrEmpty(uitbSql.Text))
  74. {
  75. UIMessageTip.ShowError("请先选择需要查询的图层,并设定查询条件"); return;
  76. }
  77. Recordset rd = null;
  78. if (isGeo)
  79. {
  80. int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName);
  81. if (index == -1)
  82. {
  83. Sunny.UI.UIMessageTip.ShowError("请先绘制区域"); return;
  84. }
  85. GeoRegion geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion;
  86. rd = dv.Query(geo, 0, uitbSql.Text, CursorType.Static);
  87. }
  88. else
  89. rd = dv.Query(uitbSql.Text, CursorType.Static);
  90. if (rd.IsEmpty)
  91. {
  92. ComsStatic.ShowErrorLog("条件错误或者查询结果为空", uitbSql.Text);
  93. }
  94. else
  95. {
  96. ComsStatic.ShowOKLog("查询语句设置正确", uitbSql.Text);
  97. }
  98. ComsStatic.RecordsetDispose(rd);
  99. }
  100. private void uicbxLayer_SelectedIndexChanged(object sender, EventArgs e)
  101. {
  102. DoListItem item = (DoListItem)uicbxLayer.SelectedItem;
  103. dv = ComsStatic.Datasource.Datasets[item.Key] as DatasetVector;
  104. if (dv is null) { UIMessageTip.ShowError("当前选择的图层没有匹配的数据源"); return; }
  105. uicbxFields.Items.Clear();
  106. foreach (FieldInfo info in dv.FieldInfos)
  107. {
  108. if (ComsStatic.HideEnableTag.Contains("," + info.Name.ToLower() + ",") || info.IsSystemField) continue;
  109. uicbxFields.Items.Add(new DoListItem(info.Name, info.Caption));
  110. }
  111. uicbxFields.SelectedIndex = 0;
  112. }
  113. private void uicbxFields_SelectedIndexChanged(object sender, EventArgs e)
  114. {
  115. string fieldValue = (uicbxFields.SelectedItem as DoListItem).Key;
  116. Recordset rd = ComsStatic.QueryRecordset(dv, string.Format(" {0} is not null", fieldValue), new string[] { fieldValue }, new string[] { fieldValue }, new string[] { fieldValue });
  117. uilbValues.Items.Clear();
  118. rd.MoveFirst();
  119. while (!rd.IsEOF)
  120. {
  121. uilbValues.Items.Add(rd.GetFieldValue(fieldValue).ToString());
  122. rd.MoveNext();
  123. }
  124. ComsStatic.RecordsetDispose(rd);
  125. }
  126. private void uibtnCaoZuoFu_Click(object sender, EventArgs e)
  127. {
  128. UIButton uiBtn = sender as UIButton;
  129. if (uiBtn.Tag?.ToString() == "hasField")
  130. {
  131. string fieldValue = (uicbxFields.SelectedItem as DoListItem).Key;
  132. uitbSql.Text = string.Format(" {0} {1} {2} ", uitbSql.Text, fieldValue, uiBtn.Text);
  133. }
  134. else
  135. uitbSql.Text = string.Format(" {0} {1} ", uitbSql.Text, uiBtn.Text);
  136. }
  137. private void uibtnSqlClear_Click(object sender, EventArgs e)
  138. {
  139. uitbSql.Text = "";
  140. }
  141. private void uilbValues_ItemDoubleClick(object sender, EventArgs e)
  142. {
  143. uitbSql.Text += uilbValues.SelectedItem?.ToString();
  144. }
  145. }
  146. }