123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WWPipeLine.MapBasic.Conditions;
- using WeifenLuo.WinFormsUI.Docking;
- using WWPipeLine.MapBasic;
- using Sunny.UI;
- using SuperMap.Data;
- namespace WWPipeLine.MapTools.Conditions.Sercher
- {
- public partial class SercherTJ : ConditionPanel
- {
- private DatasetVector dv;
- public bool isGeo = false;
- public SercherTJ()
- {
- this.ConditionPanelName = "条件查询";
- InitializeComponent();
- this.SetSize(500, 600);
- }
- protected override void OnLoad(EventArgs e)
- {
- if (isGeo)
- {
- MapControl.Tracked += ComsStatic.MapControl_Tracked_TrackingName;
- }
- uibtndengyu.Click += uibtnCaoZuoFu_Click;
- uibtnbudengyu.Click += uibtnCaoZuoFu_Click;
- uibtnLike.Click += uibtnCaoZuoFu_Click;
- uibtndayu.Click += uibtnCaoZuoFu_Click;
- uibtnxiaoyu.Click += uibtnCaoZuoFu_Click;
- uibtnAnd.Click += uibtnCaoZuoFu_Click;
- uibtndydy.Click += uibtnCaoZuoFu_Click;
- uibtnxydy.Click += uibtnCaoZuoFu_Click;
- uibtnOr.Click += uibtnCaoZuoFu_Click;
- uibtnzuokuohao.Click += uibtnCaoZuoFu_Click;
- uibtnyoukuohao.Click += uibtnCaoZuoFu_Click;
- uibtnIs.Click += uibtnCaoZuoFu_Click;
- uibtnbaifenhao.Click += uibtnCaoZuoFu_Click;
- uibtnNot.Click += uibtnCaoZuoFu_Click;
- uibtnNull.Click += uibtnCaoZuoFu_Click;
- ComsStatic.BindUICombox(uicbxLayer);
- }
- public override object Do(DockPanel dockPanel = null)
- {
- if (string.IsNullOrEmpty(uitbSql.Text))
- {
- UIMessageTip.ShowError("请先选择需要查询的图层,并设定查询条件"); return false;
- }
- Recordset rd = null;
- if (isGeo)
- {
- int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName);
- if (index == -1)
- {
- Sunny.UI.UIMessageTip.ShowError("请先绘制区域"); return false;
- }
- GeoRegion geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion;
- rd = dv.Query(geo, 0, uitbSql.Text, CursorType.Static);
- }
- else
- rd = dv.Query(uitbSql.Text, CursorType.Static);
- return ComsStatic.RecordsetToDataTable(rd);
- }
- private void uibtnSqltest_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(uitbSql.Text))
- {
- UIMessageTip.ShowError("请先选择需要查询的图层,并设定查询条件"); return;
- }
- Recordset rd = null;
- if (isGeo)
- {
- int index = MapControl.Map.TrackingLayer.IndexOf(ComsStatic.ControlToolsTrackingName);
- if (index == -1)
- {
- Sunny.UI.UIMessageTip.ShowError("请先绘制区域"); return;
- }
- GeoRegion geo = MapControl.Map.TrackingLayer.Get(index) as GeoRegion;
- rd = dv.Query(geo, 0, uitbSql.Text, CursorType.Static);
- }
- else
- rd = dv.Query(uitbSql.Text, CursorType.Static);
- if (rd.IsEmpty)
- {
- ComsStatic.ShowErrorLog("条件错误或者查询结果为空", uitbSql.Text);
- }
- else
- {
- ComsStatic.ShowOKLog("查询语句设置正确", uitbSql.Text);
- }
- ComsStatic.RecordsetDispose(rd);
- }
- private void uicbxLayer_SelectedIndexChanged(object sender, EventArgs e)
- {
- DoListItem item = (DoListItem)uicbxLayer.SelectedItem;
- dv = ComsStatic.Datasource.Datasets[item.Key] as DatasetVector;
- if (dv is null) { UIMessageTip.ShowError("当前选择的图层没有匹配的数据源"); return; }
- uicbxFields.Items.Clear();
- foreach (FieldInfo info in dv.FieldInfos)
- {
- if (ComsStatic.HideEnableTag.Contains("," + info.Name.ToLower() + ",") || info.IsSystemField) continue;
- uicbxFields.Items.Add(new DoListItem(info.Name, info.Caption));
- }
- uicbxFields.SelectedIndex = 0;
- }
- private void uicbxFields_SelectedIndexChanged(object sender, EventArgs e)
- {
- string fieldValue = (uicbxFields.SelectedItem as DoListItem).Key;
- Recordset rd = ComsStatic.QueryRecordset(dv, string.Format(" {0} is not null", fieldValue), new string[] { fieldValue }, new string[] { fieldValue }, new string[] { fieldValue });
- uilbValues.Items.Clear();
- rd.MoveFirst();
- while (!rd.IsEOF)
- {
- uilbValues.Items.Add(rd.GetFieldValue(fieldValue).ToString());
- rd.MoveNext();
- }
- ComsStatic.RecordsetDispose(rd);
- }
- private void uibtnCaoZuoFu_Click(object sender, EventArgs e)
- {
- UIButton uiBtn = sender as UIButton;
- if (uiBtn.Tag?.ToString() == "hasField")
- {
- string fieldValue = (uicbxFields.SelectedItem as DoListItem).Key;
- uitbSql.Text = string.Format(" {0} {1} {2} ", uitbSql.Text, fieldValue, uiBtn.Text);
- }
- else
- uitbSql.Text = string.Format(" {0} {1} ", uitbSql.Text, uiBtn.Text);
- }
- private void uibtnSqlClear_Click(object sender, EventArgs e)
- {
- uitbSql.Text = "";
- }
- private void uilbValues_ItemDoubleClick(object sender, EventArgs e)
- {
- uitbSql.Text += uilbValues.SelectedItem?.ToString();
- }
- }
- }
|