private void button1_Click(object sender, EventArgs e) { GSOLayer l1 = ctl.Globe.Layers[comboBoxLayerSource.SelectedIndex]; GSOFeatureDataset flayer1 = l1.Dataset as GSOFeatureDataset; GSOLayer l2 = ctl.Globe.Layers[comboBoxLayerTarget.SelectedIndex]; GSOFeatureDataset flayer2 = l2.Dataset as GSOFeatureDataset; string sourceIDFieldName = comboBoxFieldSource.SelectedItem.ToString().Trim(); string targetIDFieldName = comboBoxFiledTarget.SelectedItem.ToString().Trim(); if (sourceIDFieldName == null || targetIDFieldName == null) { MessageBox.Show("请选择唯一标识字段!", "提示"); return; } if (isSameType(flayer1, sourceIDFieldName, flayer2, targetIDFieldName) == false) { MessageBox.Show("请选择类型相同的唯一标识字段!", "提示"); return; } //for (int i = 1; i <= changeCount; i++) { string sourceChangeFieldName = comboBoxChangeSource1.SelectedItem == null ? "" : comboBoxChangeSource1.SelectedItem.ToString().Trim(); string targetChangeFieldName = comboBoxChangeTarget1.SelectedItem == null ? "" : comboBoxChangeTarget1.SelectedItem.ToString().Trim(); if (sourceChangeFieldName == "" || targetChangeFieldName == "") { MessageBox.Show("请选择要修改的字段!", "提示"); return; } if (isSameType(flayer1, sourceChangeFieldName, flayer2, targetChangeFieldName) == false) { MessageBox.Show("请选择类型相同的要修改的字段!", "提示"); return; } for (int j = 0; j < flayer1.GetAllFeatures().Length; j++) { if (flayer1.GetFeatureAt(j) == null) { continue; } object fieldValue = flayer1.GetFeatureAt(j).GetValue(sourceIDFieldName); GSOFeatures targetLayerFeatures = flayer2.GetFeatureByFieldValue(targetIDFieldName, fieldValue.ToString().Trim(), true); if (targetLayerFeatures != null) { for (int m = 0; m < targetLayerFeatures.Length; m++) { GSOFeature targetLayerFeature = targetLayerFeatures[m]; if (targetLayerFeature != null) { fieldValue = flayer1.GetFeatureAt(j).GetValue(sourceChangeFieldName); if (flayer1.GetField(sourceChangeFieldName) != null) { switch (flayer1.GetField(sourceChangeFieldName).Type) { case EnumFieldType.Double: double dFieldValue = 0.0; if (double.TryParse(fieldValue.ToString(), out dFieldValue) == true) { targetLayerFeature.SetFieldValue(targetChangeFieldName, dFieldValue); } break; case EnumFieldType.INT32: int intFieldValue = 0; if (int.TryParse(fieldValue.ToString(), out intFieldValue) == true) { targetLayerFeature.SetFieldValue(targetChangeFieldName, intFieldValue); } break; case EnumFieldType.DateTime: DateTime datatimeFieldValue = DateTime.Now; if (DateTime.TryParse(fieldValue.ToString(), out datatimeFieldValue) == true) { targetLayerFeature.SetFieldValue(targetChangeFieldName, datatimeFieldValue); } break; case EnumFieldType.Text: targetLayerFeature.SetFieldValue(targetChangeFieldName, fieldValue.ToString()); break; } } } } } } } MessageBox.Show("修改成功!", "提示"); }