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.
329 lines
13 KiB
329 lines
13 KiB
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Geodatabase; |
|
using KGIS.Framework.Maps; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Helper; |
|
using Kingo.PluginServiceInterface; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Text.RegularExpressions; |
|
using System.Windows; |
|
using System.Windows.Controls; |
|
|
|
namespace Kingo.Plugin.SystemSetting.View.ViewSystemSetting |
|
{ |
|
|
|
public partial class FrmWYInfoSetting : BaseWindow |
|
{ |
|
private bool isADD { get; set; } |
|
private List<WYZPCfg> wYZPCfgs = null; |
|
private WYZPCfg layerInfo = null; |
|
public Action Refresh; |
|
|
|
public FrmWYInfoSetting(bool isADD, WYZPCfg layerInfo, List<WYZPCfg> wYZPCfgs) |
|
{ |
|
InitializeComponent(); |
|
this.isADD = isADD; |
|
this.layerInfo = layerInfo; |
|
this.wYZPCfgs = wYZPCfgs; |
|
GetLayerInfo(); |
|
} |
|
|
|
private void GetLayerInfo() |
|
{ |
|
try |
|
{ |
|
List<LayerName> layerNameList = new List<LayerName>(); |
|
List<ILayer> pLayerList = MapsManager.Instance.MapService.GetAllLayerInMap<ILayer>(); |
|
if (pLayerList != null && pLayerList.Count != 0) |
|
{ |
|
foreach (var pLayer in pLayerList) |
|
{ |
|
if (pLayer is IGroupLayer || pLayer is IRasterLayer) |
|
continue; |
|
LayerName layer = new LayerName |
|
{ |
|
Name = (pLayer as IDataset).BrowseName, |
|
AliasName = pLayer.Name |
|
}; |
|
layerNameList.Add(layer); |
|
} |
|
} |
|
List<RelevantModel> modelList = new List<RelevantModel>(); |
|
string[] model = new string[] { "属性", "图形" }; |
|
|
|
for (int i = 0; i < model.Length; i++) |
|
{ |
|
string name = model[i]; |
|
RelevantModel modelInfo = new RelevantModel |
|
{ |
|
Name = name, |
|
Index = i |
|
}; |
|
modelList.Add(modelInfo); |
|
} |
|
this.cobLayerName.ItemsSource = layerNameList; |
|
this.cobModel.ItemsSource = modelList; |
|
if (this.isADD == false && this.layerInfo != null) |
|
{ |
|
List<LayerName> nameList = layerNameList.FindAll(x => x.Name == this.layerInfo.LayerName); |
|
if (nameList != null && nameList.Count != 0) |
|
{ |
|
LayerName layerName = nameList[0]; |
|
this.cobLayerName.SelectedItem = layerName; |
|
} |
|
|
|
List<RelevantModel> list = modelList.FindAll(x => x.Name == this.layerInfo.RelevantModel); |
|
if (list != null && list.Count != 0) |
|
{ |
|
RelevantModel relevantModel = list[0]; |
|
this.cobModel.SelectedItem = relevantModel; |
|
} |
|
|
|
if (this.layerInfo.RelevantModel == "属性") |
|
{ |
|
BindCobFields(this.layerInfo.LayerName); |
|
|
|
this.cobFields.IsEditable = false; |
|
} |
|
else |
|
{ |
|
this.cobFields.ItemsSource = null; |
|
this.cobFields.IsEditable = true; |
|
this.cobFields.Text = this.layerInfo.AreaScale; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取外业信息图层配置失败:" + ex); |
|
} |
|
} |
|
|
|
private void btnOK_Click(object sender, RoutedEventArgs e) |
|
{ |
|
try |
|
{ |
|
if (this.cobLayerName.SelectedItem == null) |
|
{ |
|
MessageHelper.Show(string.Format("未选择图层名称!")); |
|
return; |
|
} |
|
if (this.cobModel.SelectedItem == null) |
|
{ |
|
MessageHelper.Show(string.Format("未选择关联方式!")); |
|
return; |
|
} |
|
RelevantModel model = this.cobModel.SelectedItem as RelevantModel; |
|
if (model.Name == "属性") |
|
{ |
|
if (this.cobFields.SelectedItem == null) |
|
{ |
|
MessageHelper.Show(string.Format("未选择属性字段!")); |
|
return; |
|
} |
|
} |
|
else |
|
{ |
|
if (string.IsNullOrWhiteSpace(this.cobFields.Text)) |
|
{ |
|
MessageHelper.Show(string.Format("未输入面积占比!")); |
|
return; |
|
} |
|
|
|
Regex rx = new Regex("^[0-9]*$"); |
|
if (rx.IsMatch(this.cobFields.Text) == false) |
|
{ |
|
MessageHelper.Show(string.Format("面积占比输入不正确,请输入正整数!")); |
|
return; |
|
} |
|
|
|
double areaScale = Convert.ToDouble(this.cobFields.Text); |
|
if (areaScale > 100) |
|
{ |
|
MessageHelper.Show(string.Format("面积占比输入不正确,不可超出100!")); |
|
return; |
|
} |
|
} |
|
|
|
if (this.isADD == true) |
|
{ |
|
WYZPCfg layerInfo = new WYZPCfg(); |
|
layerInfo.IsCheck = true; |
|
LayerName layer = this.cobLayerName.SelectedItem as LayerName; |
|
List<WYZPCfg> WyInfoList = wYZPCfgs.FindAll(x => x.LayerName == layer.Name); |
|
if (WyInfoList != null && WyInfoList.Count != 0) |
|
{ |
|
MessageHelper.Show(string.Format("{0}图层在配置文件中已存在,不在进行添加,请选择其他图层!", layer.AliasName)); |
|
return; |
|
} |
|
layerInfo.LayerName = layer.Name; |
|
layerInfo.LayerAliasName = layer.AliasName; |
|
layerInfo.RelevantModel = model.Name; |
|
if (layerInfo.RelevantModel == "属性") |
|
{ |
|
LayerField field = this.cobFields.SelectedItem as LayerField; |
|
layerInfo.AttributeField = field.Name; |
|
layerInfo.AreaScale = null; |
|
} |
|
else |
|
{ |
|
layerInfo.AreaScale = this.cobFields.Text; |
|
layerInfo.AttributeField = null; |
|
} |
|
wYZPCfgs.Add(layerInfo); |
|
MessageHelper.Show("外业信息图层添加成功!"); |
|
Refresh?.Invoke(); |
|
this.Close(); |
|
} |
|
else |
|
{ |
|
if (this.layerInfo != null) |
|
{ |
|
LayerName layer = this.cobLayerName.SelectedItem as LayerName; |
|
foreach (WYZPCfg item in wYZPCfgs) |
|
{ |
|
if (item.LayerName == this.layerInfo.LayerName) |
|
{ |
|
item.LayerName = layer.Name; |
|
item.LayerAliasName = layer.AliasName; |
|
item.RelevantModel = model.Name; |
|
if (item.RelevantModel == "属性") |
|
{ |
|
LayerField field = this.cobFields.SelectedItem as LayerField; |
|
item.AttributeField = field.Name; |
|
item.AreaScale = string.Empty; |
|
} |
|
else |
|
{ |
|
item.AreaScale = this.cobFields.Text; |
|
item.AttributeField = string.Empty; |
|
} |
|
} |
|
} |
|
} |
|
MessageHelper.Show("外业信息图层修改成功!"); |
|
Refresh?.Invoke(); |
|
this.Close(); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
if (this.isADD) |
|
{ |
|
LogAPI.Debug("外业信息图层添加失败:" + ex); |
|
MessageHelper.Show("外业信息图层添加失败:" + ex); |
|
} |
|
else |
|
{ |
|
LogAPI.Debug("外业信息图层修改失败:" + ex); |
|
MessageHelper.Show("外业信息图层修改失败:" + ex); |
|
} |
|
} |
|
} |
|
|
|
private void CobLayerName_SelectionChanged(object sender, SelectionChangedEventArgs e) |
|
{ |
|
if (e.AddedItems != null && e.AddedItems.Count != 0) |
|
{ |
|
LayerName layerName = e.AddedItems[0] as LayerName; |
|
|
|
if (this.cobModel.SelectedItem != null) |
|
{ |
|
RelevantModel model = this.cobModel.SelectedItem as RelevantModel; |
|
if (model.Name == "属性") |
|
{ |
|
BindCobFields(layerName.Name); |
|
} |
|
} |
|
} |
|
} |
|
|
|
private void CobModel_SelectionChanged(object sender, SelectionChangedEventArgs e) |
|
{ |
|
if (e.AddedItems != null && e.AddedItems.Count != 0) |
|
{ |
|
RelevantModel model = e.AddedItems[0] as RelevantModel; |
|
if (model.Name == "属性") |
|
{ |
|
if (this.cobLayerName.SelectedItem == null) |
|
{ |
|
MessageHelper.Show(string.Format("请先选择图层名称,才能获取属性字段!")); |
|
return; |
|
} |
|
LayerName layerName = this.cobLayerName.SelectedItem as LayerName; |
|
BindCobFields(layerName.Name); |
|
this.cobFields.IsEditable = false; |
|
} |
|
else |
|
{ |
|
this.cobFields.ItemsSource = null; |
|
this.cobFields.IsEditable = true; |
|
} |
|
} |
|
} |
|
|
|
private void BindCobFields(string layerName) |
|
{ |
|
try |
|
{ |
|
List<LayerField> fieldList = new List<LayerField>(); |
|
IFeatureLayer layer = MapsManager.Instance.MapService.GetFeatureLayerByName(layerName); |
|
IFields fields = layer.FeatureClass.Fields; |
|
for (int i = 0; i < fields.FieldCount; i++) |
|
{ |
|
IField field = fields.Field[i]; |
|
string fieldName = field.Name; |
|
if (field.Name.ToUpper().Contains("SHAPE")) |
|
continue; |
|
|
|
LayerField fieldInfo = new LayerField(); |
|
fieldInfo.Name = fieldName; |
|
fieldInfo.AliasName = field.AliasName; |
|
fieldInfo.Index = i; |
|
fieldList.Add(fieldInfo); |
|
} |
|
this.cobFields.ItemsSource = fieldList; |
|
|
|
if (this.isADD == false && this.layerInfo != null) |
|
{ |
|
List<LayerField> list = fieldList.FindAll(x => x.Name == this.layerInfo.AttributeField); |
|
if (list != null && list.Count != 0) |
|
{ |
|
LayerField layerField = list[0]; |
|
this.cobFields.SelectedItem = layerField; |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("获取属性字段失败:" + ex); |
|
} |
|
} |
|
|
|
private void btnCancel_Click(object sender, RoutedEventArgs e) |
|
{ |
|
this.Close(); |
|
} |
|
|
|
public class LayerName |
|
{ |
|
public int Index { get; set; } |
|
public string Name { get; set; } |
|
public string AliasName { get; set; } |
|
} |
|
|
|
public class RelevantModel |
|
{ |
|
public int Index { get; set; } |
|
public string Name { get; set; } |
|
} |
|
|
|
public class LayerField |
|
{ |
|
public int Index { get; set; } |
|
public string Name { get; set; } |
|
public string AliasName { get; set; } |
|
} |
|
} |
|
}
|
|
|