You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							321 lines
						
					
					
						
							11 KiB
						
					
					
				
			
		
		
	
	
							321 lines
						
					
					
						
							11 KiB
						
					
					
				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 ESRI.ArcGIS.Geodatabase; | 
						|
using DevExpress.XtraEditors; | 
						|
using ESRI.ArcGIS.Carto; | 
						|
using KGIS.Plugin.LayerProperty.Model; | 
						|
using KGIS.Plugin.LayerProperty.Utils; | 
						|
using KGIS.Framework.Utils.Helper; | 
						|
 | 
						|
namespace KGIS.Plugin.LayerProperty.View.UC_Controls | 
						|
{ | 
						|
    public partial class UCSQLCreator : XtraUserControl | 
						|
    { | 
						|
        private KGIS.Framework.Utils.Dialog.OpenFileDialog openFileDialog1; | 
						|
        private SaveFileDialog saveFileDialog1; | 
						|
        private IFeatureClass m_FeatureClass; | 
						|
        private string sql; | 
						|
        public string SQL | 
						|
        { | 
						|
            get | 
						|
            { | 
						|
                this.sql = this.memoSQLInfo.Text; | 
						|
                return this.sql; | 
						|
            } | 
						|
            set | 
						|
            { | 
						|
                this.sql = value; | 
						|
                this.memoSQLInfo.Text = this.sql; | 
						|
            } | 
						|
        } | 
						|
        public UCSQLCreator() | 
						|
        { | 
						|
            InitializeComponent(); | 
						|
        } | 
						|
        public void InitUC(IFeatureLayer FeaLyr) | 
						|
        { | 
						|
            this.InitUC(FeaLyr.FeatureClass); | 
						|
        } | 
						|
        public void InitUC(IFeatureClass feacls) | 
						|
        { | 
						|
            if (feacls == null) | 
						|
            { | 
						|
                return; | 
						|
            } | 
						|
            this.m_FeatureClass = feacls; | 
						|
            SQLSearch.FeatureClass = feacls; | 
						|
            this.GetFields(feacls); | 
						|
            this.lstOnlyValue.Items.Clear(); | 
						|
        } | 
						|
        private void GetFields(IFeatureClass pLayer) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                this.lstField.Items.Clear(); | 
						|
                if (pLayer != null) | 
						|
                { | 
						|
                    int fieldCount = pLayer.Fields.FieldCount; | 
						|
                    for (int i = 0; i < fieldCount; i++) | 
						|
                    { | 
						|
                        IField field = pLayer.Fields.get_Field(i); | 
						|
                        if (field.Type != esriFieldType.esriFieldTypeGeometry && field.Type != esriFieldType.esriFieldTypeBlob && field.Type != esriFieldType.esriFieldTypeRaster) | 
						|
                        { | 
						|
                            ItemInfo<IField, string> item = new ItemInfo<IField, string>(field, field.Name); | 
						|
                            this.lstField.Items.Add(item); | 
						|
                        } | 
						|
                    } | 
						|
                    this.lstField.SelectedItem = this.lstField.Items[0]; | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                //RdbUtil.AddException(ex); | 
						|
            } | 
						|
        } | 
						|
        private void btnUnEqual_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("<>"); | 
						|
        } | 
						|
        private void btnEquals_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("="); | 
						|
        } | 
						|
        private void btnLike_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("LIKE"); | 
						|
        } | 
						|
        private void btnGreat_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString(">"); | 
						|
        } | 
						|
        private void btnGreatAndEqual_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString(">="); | 
						|
        } | 
						|
        private void btnAnd_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("AND"); | 
						|
        } | 
						|
        private void btnLess_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("<"); | 
						|
        } | 
						|
        private void btnLessAndEqual_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("<="); | 
						|
        } | 
						|
        private void btnOr_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("OR"); | 
						|
        } | 
						|
        private void btnQuest_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString(this.btnQuest.Text.Trim()); | 
						|
        } | 
						|
        private void btnAll_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertStringNospace(this.btnAll.Text.Trim()); | 
						|
        } | 
						|
        private void btnBracket_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("()"); | 
						|
        } | 
						|
        private void btnNot_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("NOT"); | 
						|
        } | 
						|
        private void btnIs_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.InsertString("IS"); | 
						|
        } | 
						|
        private void InsertString(string mStr) | 
						|
        { | 
						|
            mStr = " " + mStr.Trim() + " "; | 
						|
            int selectionStart = this.memoSQLInfo.SelectionStart; | 
						|
            if (this.memoSQLInfo != null && !string.IsNullOrWhiteSpace(this.memoSQLInfo.SelectedText)) | 
						|
            { | 
						|
                this.memoSQLInfo.SelectedText = mStr; | 
						|
            } | 
						|
            else | 
						|
            { | 
						|
                this.memoSQLInfo.Text = this.memoSQLInfo.Text.Insert(selectionStart, mStr).Trim(); | 
						|
            } | 
						|
            if (mStr.EndsWith("() ")) | 
						|
            { | 
						|
                this.memoSQLInfo.SelectionStart = mStr.Length + selectionStart - 2; | 
						|
                return; | 
						|
            } | 
						|
            this.memoSQLInfo.SelectionStart = mStr.Length + selectionStart; | 
						|
        } | 
						|
        private void InsertStringNospace(string mStr) | 
						|
        { | 
						|
            mStr = (mStr.Trim() ?? ""); | 
						|
            int selectionStart = this.memoSQLInfo.SelectionStart; | 
						|
            if (this.memoSQLInfo.SelectionLength > 0) | 
						|
            { | 
						|
                this.memoSQLInfo.SelectedText = mStr; | 
						|
            } | 
						|
            else | 
						|
            { | 
						|
                this.memoSQLInfo.Text = this.memoSQLInfo.Text.Insert(selectionStart, mStr).Trim(); | 
						|
            } | 
						|
            if (mStr.EndsWith("() ")) | 
						|
            { | 
						|
                this.memoSQLInfo.SelectionStart = mStr.Length + selectionStart - 2; | 
						|
                return; | 
						|
            } | 
						|
            this.memoSQLInfo.SelectionStart = mStr.Length + selectionStart; | 
						|
        } | 
						|
        private void lstField_DoubleClick(object sender, System.EventArgs e) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                this.Cursor = Cursors.AppStarting; | 
						|
                this.InsertString(this.lstField.SelectedItem.ToString().Trim()); | 
						|
                this.Cursor = Cursors.Default; | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                this.Cursor = Cursors.Default; | 
						|
                //RdbUtil.AddException(ex); | 
						|
            } | 
						|
        } | 
						|
        private void lstOnlyValue_DoubleClick(object sender, System.EventArgs e) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                this.Cursor = Cursors.AppStarting; | 
						|
                string text = this.lstOnlyValue.SelectedItem.ToString().Trim(); | 
						|
                if (!text.Equals("")) | 
						|
                { | 
						|
                    this.InsertString(text); | 
						|
                } | 
						|
                this.Cursor = Cursors.Default; | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                this.Cursor = Cursors.Default; | 
						|
                //RdbUtil.AddException(ex); | 
						|
            } | 
						|
        } | 
						|
        private void btnIsListFinish_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                if (this.m_FeatureClass == null) | 
						|
                { | 
						|
                    MessageHelper.ShowTips("请设置要查询的图层"); | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    this.Cursor = Cursors.WaitCursor; | 
						|
                    this.lstOnlyValue.Items.Clear(); | 
						|
                    object selectedValue = this.lstField.SelectedValue; | 
						|
                    ItemInfo<IField, string> itemInfo = selectedValue as ItemInfo<IField, string>; | 
						|
                    if (itemInfo != null) | 
						|
                    { | 
						|
                        SQLSearch.ShowUniqueValues(itemInfo.InnerValue, this.lstOnlyValue, -1); | 
						|
                    } | 
						|
                    this.Cursor = Cursors.Default; | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                //RdbUtil.AddException(ex); | 
						|
                this.Cursor = Cursors.Default; | 
						|
            } | 
						|
        } | 
						|
        private void btnClear_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            this.memoSQLInfo.Text = ""; | 
						|
        } | 
						|
        private void btnLoad_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                this.Cursor = Cursors.AppStarting; | 
						|
                string openFileName = this.GetOpenFileName(); | 
						|
                if (openFileName != "") | 
						|
                { | 
						|
                    this.memoSQLInfo.Text = SQLSearch.ReadFile(openFileName); | 
						|
                } | 
						|
                this.Cursor = Cursors.Default; | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                //RdbUtil.AddException(ex); | 
						|
                this.Cursor = Cursors.Default; | 
						|
            } | 
						|
        } | 
						|
        private void btnVerify_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            if (SQLSearch.VerifySql(this.m_FeatureClass, this.SQL)) | 
						|
            { | 
						|
                MessageHelper.ShowTips("验证成功!"); | 
						|
                return; | 
						|
            } | 
						|
            MessageHelper.ShowTips("验证失败,请检查语句!"); | 
						|
        } | 
						|
        private string GetOpenFileName() | 
						|
        { | 
						|
            string result; | 
						|
            try | 
						|
            { | 
						|
                if (this.openFileDialog1 == null) | 
						|
                { | 
						|
                    this.openFileDialog1 = new KGIS.Framework.Utils.Dialog.OpenFileDialog(); | 
						|
                } | 
						|
                this.openFileDialog1.InitialDirectory = Application.ExecutablePath; | 
						|
                this.openFileDialog1.Filter = "Exp Files(*.exp)|*.exp"; | 
						|
                if (this.openFileDialog1.ShowDialog()) | 
						|
                { | 
						|
                    result = this.openFileDialog1.FileName; | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    result = ""; | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                //RdbUtil.AddException(ex); | 
						|
                this.Cursor = Cursors.Default; | 
						|
                result = ""; | 
						|
            } | 
						|
            return result; | 
						|
        } | 
						|
        private void btnSaveAs_Click(object sender, System.EventArgs e) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                this.Cursor = Cursors.AppStarting; | 
						|
                string text = this.memoSQLInfo.Text; | 
						|
                SQLSearch.SaveFile(this.GetSaveFileName(), ref text); | 
						|
                this.Cursor = Cursors.Default; | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                //RdbUtil.AddException(ex); | 
						|
                this.Cursor = Cursors.Default; | 
						|
            } | 
						|
        } | 
						|
        private string GetSaveFileName() | 
						|
        { | 
						|
            if (this.saveFileDialog1 == null) | 
						|
            { | 
						|
                this.saveFileDialog1 = new SaveFileDialog(); | 
						|
            } | 
						|
            this.saveFileDialog1.InitialDirectory = Application.ExecutablePath; | 
						|
            this.saveFileDialog1.Filter = "Exp Files(*.exp)|*.exp"; | 
						|
            this.saveFileDialog1.ShowDialog(); | 
						|
            return this.saveFileDialog1.FileName; | 
						|
        } | 
						|
    } | 
						|
}
 | 
						|
 |