//查询 private void buttonConditionSelect_Click(object sender, EventArgs e) { if (layer == null) { MessageBox.Show("请选择一个图层!"); return; } if (comboBoxConditionFieldName.Text == "" || comboBoxConditionFieldValue.Text == "" || comboBoxCondition.Text == "") { MessageBox.Show("请输入完整的查询条件!", "提示"); return; } GSOFeatureDataset featureDataset = layer.Dataset as GSOFeatureDataset; EnumFieldType currentFieldType = EnumFieldType.Text; if (featureDataset != null) { GSOFieldAttr field = featureDataset.GetField(comboBoxConditionFieldName.Text); if (field != null) { switch (field.Type) { case EnumFieldType.Double: case EnumFieldType.INT32: currentFieldType = EnumFieldType.Double; break; case EnumFieldType.Date: currentFieldType = EnumFieldType.Date; break; } } } try { switch (comboBoxCondition.Text) { case "=": for (int i = 0; i < layer.GetAllFeatures().Length; i++) { GSOFeature feature = layer.GetAt(i); if (feature != null && feature.GetValue(comboBoxConditionFieldName.Text).ToString() == comboBoxConditionFieldValue.Text) { features.Add(feature); } } break; case ">=": for (int i = 0; i < layer.GetAllFeatures().Length; i++) { GSOFeature feature = layer.GetAt(i); if (currentFieldType == EnumFieldType.Double) { if (feature != null && Double.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) >= Double.Parse(comboBoxConditionFieldValue.Text)) { features.Add(feature); } } else if (currentFieldType == EnumFieldType.Date) { if (feature != null && DateTime.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) >= DateTime.Parse(comboBoxConditionFieldValue.Text)) { features.Add(feature); } } } break; case "<=": for (int i = 0; i < layer.GetAllFeatures().Length; i++) { GSOFeature feature = layer.GetAt(i); if (currentFieldType == EnumFieldType.Double) { if (feature != null && Double.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) <= Double.Parse(comboBoxConditionFieldValue.Text)) { features.Add(feature); } } else if (currentFieldType == EnumFieldType.Date) { if (feature != null && DateTime.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) <= DateTime.Parse(comboBoxConditionFieldValue.Text)) { features.Add(feature); } } } break; case ">": for (int i = 0; i < layer.GetAllFeatures().Length; i++) { GSOFeature feature = layer.GetAt(i); if (currentFieldType == EnumFieldType.Double) { if (feature != null && Double.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) > Double.Parse(comboBoxConditionFieldValue.Text)) { features.Add(feature); } } else if (currentFieldType == EnumFieldType.Date) { if (feature != null && DateTime.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) > DateTime.Parse(comboBoxConditionFieldValue.Text)) { features.Add(feature); } } } break; case "<": for (int i = 0; i < layer.GetAllFeatures().Length; i++) { GSOFeature feature = layer.GetAt(i); if (currentFieldType == EnumFieldType.Double) { if (feature != null && Double.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) < Double.Parse(comboBoxConditionFieldValue.Text)) { features.Add(feature); } } else if (currentFieldType == EnumFieldType.Date) { if (feature != null && DateTime.Parse(feature.GetFieldAsDataTime(comboBoxConditionFieldName.Text).ToString()) < DateTime.Parse(comboBoxConditionFieldValue.Text)) { features.Add(feature); } } } break; } if (features == null) { MessageBox.Show("请重新输入查询条件!", "提示"); return; } if (features.Length == 0) { MessageBox.Show("没有找到符合查询条件的对象!", "提示"); return; } SetDataTable(features); } catch (Exception ex) { Log.PublishTxt(ex); MessageBox.Show(ex.Message, "提示"); return; } }