




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、查询 public partial class SQLSelecFrm : Form private IMapControl2 pAxMapControl; public SQLSelecFrm(IMapControl2 lAxMapControl) InitializeComponent(); this.pAxMapControl = lAxMapControl; for (int i = 0; i < pAxMapControl.LayerCount; i+) comboBoxLayer.Items.Add(pAxMapControl.get_Layer(i).Name); comb
2、oBoxLayer.SelectedIndex = 0; /设置comboBoxMethod的选择项并置默认值为第台一项 comboBoxMethod.Items.Add("新建选择集"); comboBoxMethod.Items.Add("添加进已有的选择集"); comboBoxMethod.Items.Add("从当前选择集中清除"); comboBoxMethod.Items.Add("从当前选择集中再次筛选"); comboBoxMethod.SelectedIndex = 0; private voi
3、d button5_Click(object sender, EventArgs e) textBox_WhereClause.Text += " =" private void button6_Click(object sender, EventArgs e) textBox_WhereClause.Text += " <>" private void button8_Click(object sender, EventArgs e) textBox_WhereClause.Text += " >" private
4、 void button9_Click(object sender, EventArgs e) textBox_WhereClause.Text += " >=" private void button11_Click(object sender, EventArgs e) textBox_WhereClause.Text += " <" private void button12_Click(object sender, EventArgs e) textBox_WhereClause.Text += " <="
5、private void button15_Click(object sender, EventArgs e) textBox_WhereClause.Text += " ()" private void button7_Click(object sender, EventArgs e) textBox_WhereClause.Text += " LIKE" private void button10_Click(object sender, EventArgs e) textBox_WhereClause.Text += " AND"
6、; private void button13_Click(object sender, EventArgs e) textBox_WhereClause.Text += " OR" private void button16_Click(object sender, EventArgs e) textBox_WhereClause.Text += " NOT" private void button14_Click(object sender, EventArgs e) textBox_WhereClause.Text += " IS&quo
7、t; private void button2_Click(object sender, EventArgs e) textBox_WhereClause.Text = "" private void button17_Click(object sender, EventArgs e) textBox_WhereClause.Text += " ?" private void button18_Click(object sender, EventArgs e) textBox_WhereClause.Text += " *" priv
8、ate void comboBoxLayer_SelectedIndexChanged(object sender, EventArgs e) /如果没有图层被选择,将不能添加字段 if (comboBoxLayer.Text != null) /清listBox_Field listBox_Field.Items.Clear(); /获取要素 IFeatureLayer lFeatureLayer = (IFeatureLayer)pAxMapControl.Map.get_Layer(comboBoxLayer.SelectedIndex); IFeatureCursor lFeature
9、Cursor = lFeatureLayer.Search(null, true); IFeature lFeature = lFeatureCursor.NextFeature(); /循环添加所属图层的字段名进入listBox_Field中 /对于sriFieldTypeGeometry类型的自动则不予以添加 for (int i = 0; i < lFeature.Fields.FieldCount; i+) if (lFeature.Fields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry) listBox_F
10、ield.Items.Add(lFeature.Fields.get_Field(i).Name); /设置当前选择字段为第一个 listBox_Field.SelectedIndex = 0; /将描述信息修改 label_Description.Text = "SELECT * FROM " + comboBoxLayer.Text + " WHERE:" private void listBox_Field_DoubleClick(object sender, EventArgs e) IFeatureLayer lFeatureLayer = (
11、IFeatureLayer)pAxMapControl.Map.get_Layer(comboBoxLayer.SelectedIndex); if (lFeatureLayer.DataSourceType = "Shapefile Feature Class")/shapefile文 textBox_WhereClause.Text += """ + listBox_Field.Text + """ else textBox_WhereClause.Text += " " + listBox
12、_Field.Text + " " private void listBox_Value_DoubleClick(object sender, EventArgs e) textBox_WhereClause.Text += " " + listBox_Value.Text; private void listBox_Field_SelectedIndexChanged(object sender, EventArgs e) button_GetValue.Enabled = true; private void button_GetValue_Clic
13、k(object sender, EventArgs e) /获取要素图层与要素类将其作为参数传入GetUniqueValue()函数 IFeatureLayer lFeatureLayer = (IFeatureLayer)pAxMapControl.get_Layer(comboBoxLayer.SelectedIndex); IFeatureClass lFeatureClass = lFeatureLayer.FeatureClass; /将返回的所有值存入allValue数组中并进行排序 string allValue = GetUniqueValue(lFeatureClass,
14、listBox_Field.Text); Array.Sort(allValue); /获取字段对象用于在将其值添加进listbox_value中时判断字段类型 IFeatureCursor lFeatureCursor = lFeatureLayer.Search(null, true); IFeature lFeature = lFeatureCursor.NextFeature(); IField lField = new FieldClass(); for (int j = 0; j < lFeature.Fields.FieldCount; j+) if (listBox_Fi
15、eld.Text = lFeature.Fields.get_Field(j).Name) lField = lFeature.Fields.get_Field(j); /将之前listBox_Value中值清空然后加此次选中字段的所有数据 listBox_Value.Items.Clear(); for (int i = 0; i < allValue.Length; i+) if (lField.Type = esriFieldType.esriFieldTypeString) allValuei = "'" + allValuei + "
16、9;" listBox_Value.Items.Add(allValuei); else listBox_Value.Items.Add(allValuei); listBox_Value.Visible = true; button_GetValue.Enabled = false; / <summary> / 得到要素类某字段的唯一值 / </summary> / <param name="pFeatureClass">要素类</param> / <param name="strFld"
17、>指定要得到唯一值的字段</param> / <returns>唯一值字符数据</returns> public string GetUniqueValue(IFeatureClass pFeatureClass, string strFld) /得到IFeatureCursor括 IFeatureCursor pCursor = pFeatureClass.Search(null, false); /IDataStatistics对象实例 IDataStatistics pData = new DataStatisticsClass(); pData
18、.Field = strFld; pData.Cursor = pCursor as ICursor; /枚举唯一值 IEnumerator pEnumVar = pData.UniqueValues; /记录总数 int RecordCount = pData.UniqueValueCount; /字?符?数簓组哩7 string strValue = new stringRecordCount; pEnumVar.Reset(); int i = 0; while (pEnumVar.MoveNext() strValuei+ = pEnumVar.Current.ToString();
19、return strValue; public IFeatureSelection GetFeatureSelect(IFeatureLayer pFeatureLayer,string strQuery) IFeatureSelection lFeatureSelection = (IFeatureSelection)pFeatureLayer; IQueryFilter2 lQueryFilter = new QueryFilterClass(); lQueryFilter.WhereClause = strQuery; lFeatureSelection.SelectFeatures(l
20、QueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); pAxMapControl.ActiveView.Refresh(); return lFeatureSelection; private void button3_Click(object sender, EventArgs e) if (textBox_WhereClause.Text != "") try IFeatureLayer lFeatureLayer = (IFeatureLayer)pAxMapControl.get_L
21、ayer(comboBoxLayer.SelectedIndex); IFeatureSelection lFeatureSelection = (IFeatureSelection)lFeatureLayer; /判D断?选?择?的?SQL方?法8的?类8型í esriSelectionResultEnum lesriSREnum = esriSelectionResultEnum.esriSelectionResultNew; switch (comboBoxMethod.SelectedIndex) case 0: lesriSREnum = esriSelectionResu
22、ltEnum.esriSelectionResultNew; break; case 1: lesriSREnum = esriSelectionResultEnum.esriSelectionResultAdd; break; case 2: lesriSREnum = esriSelectionResultEnum.esriSelectionResultSubtract; break; case 3: lesriSREnum = esriSelectionResultEnum.esriSelectionResultAnd; break; default: MessageBox.Show(&
23、quot;请?选?择?一?种?查é询方?法?); break; /创洹9建¨查é询的?条?件t IQueryFilter2 lQueryFilter = new QueryFilterClass(); lQueryFilter.WhereClause = textBox_WhereClause.Text; /根ù据Y查é询添9加ó进?行D选?择?,?并刷新?屏á幕? lFeatureSelection.SelectFeatures(lQueryFilter, lesriSREnum, false); pAxMapControl.ActiveView.Refresh(); catch (Exception) MessageBox.Show
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 上海代课教师管理办法
- 仓储物流中心管理办法
- 财务决策保税管理办法
- 中国移动调账管理办法
- 业务指标预警管理办法
- iso热处理管理办法
- 上海联诚销售管理办法
- 规范报销费用管理办法
- 中央企业资金管理办法
- 中央投资补助管理办法
- 幼儿文学课件完整版
- DB6101T3128-2022养老服务规范 助餐服务
- 实验室常规玻璃仪器的操作及注意事项课件
- 临时用地复垦与方案
- 语言学纲要课件
- 地下室开槽引流方案
- 电子课件-《市场营销》-A45-2298完整版教学课件全书电子讲义(最新)
- 新苏教版科学六年级上册教学计划含进度表
- 2021年新苏教版科学六年级上册知识点整理
- 美的观念(玛丽艳)
- 农药学原理课件--作用机制研究的思路和方法
评论
0/150
提交评论