年度变更建库软件5.0版本
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.
 
 

2020 lines
106 KiB

using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using KGIS.Framework.DBOperator;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Utils.Interface;
using KGIS.Framework.Views;
using Kingo.Plugin.MapView.Enum;
using Kingo.Plugin.MapView.Model;
using Kingo.Plugin.MapView.Views.FeatureAttribute;
using Kingo.PluginServiceInterface;
using Kingo.PluginServiceInterface.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Xml;
namespace Kingo.Plugin.MapView.Views
{
public delegate void EditDicHandler(object sender);
/// <summary>
/// AttributeEdit.xaml 的交互逻辑
/// </summary>
public partial class AttributeEdit : UserControl, IElementInfo, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public FrmDataCheck frmdatachck = null;
private object Data { get; set; }
private DataRow BGTBData { get; set; }
EngineEditor editor = new EngineEditorClass();
List<DataDicTionary> Dics = null;
public IHookHelper m_hookHelper;
private IDataCatalogService catalogService = null;
public AttributeEdit()
{
InitializeComponent();
this.DockAreas = DockStyle.DockRight | DockStyle.Float;//Common.Interface.DockStyle.DockRight | Common.Interface.DockStyle.Float;
this.FloatSize = new System.Drawing.Size(400, 500);
this.DefaultArea = DockStyle.Float;// Common.Interface.DockStyle.DockRight;
this.ShowCloseButton = false;
this.ShowAutoHideButton = true;
this.Title = "要素属性";
Platform.Instance.NotifyMsgEven2 += Instance_NotifyMsgEven2;
this.Loaded += (s, e) =>
{
string cfgFilePath = System.IO.Path.Combine(SysAppPath.GetConfigPath(), "LayerFieldsCfg.xml");
if (!string.IsNullOrEmpty(cfgFilePath) && Cfg == null)
Cfg = SerializeAPI.DeserializeToObject2<LayerFieldCfg>(cfgFilePath);
};
}
private void Instance_NotifyMsgEven2(NotifyMsgPackage msg)
{
if (msg.MsgType == "RefreshFeatureProperty")
{
if (msg.Content is DataRow)
{
DataRow row = msg.Content as DataRow;
this.BGTBData = row;
BindBGTB(row);
}
}
}
private void BindBGTB(DataRow row)
{
try
{
int obj = Convert.ToInt32(row["OBJECTID"]);
IFeatureClass bgtbFC = KGIS.Framework.Maps.MapsManager.Instance.MapService.GetFeatureClassByName("DLTBBG");
IFeature pFeature = bgtbFC.GetFeature(obj);
List<PropertyGridDataStruct> singledata = new List<PropertyGridDataStruct>();
for (int i = 0; i < row.Table.Columns.Count; i++)
{
string colName = row.Table.Columns[i].ColumnName;
if (colName.ToUpper() == "OBJECTID" || colName.ToUpper().Contains("SHAPE"))
continue;
IFeature fe = this.Data as IFeature;
int fieldindex = fe.Fields.FindField(colName);
if (fieldindex > -1)
{
IField field = fe.Fields.Field[fieldindex];
if (field.Name.ToUpper() == "SHAPE" || field.Name.ToUpper().Contains("_EXTRA"))
continue;
IDomain domain = field.Domain;
//矢量化工程没有模板,无法解决问题
PropertyGridDataStruct p = new PropertyGridDataStruct();
p.DisplayMemberPath = "NAME";
p.ValuePath = "CODE";
if (!field.Editable)
{
p.IsReadOnly = !field.Editable;
}
else
{
p.IsReadOnly = editor.EditState == esriEngineEditState.esriEngineStateNotEditing || (editor.EditWorkspace != null && editor.EditWorkspace.PathName != (fe.Class as FeatureClass).Workspace.PathName);
}
//是否可以编辑
//p.IsReadOnly = !field.Editable;
//是否可以为空
p.AllowNull = field.IsNullable;
if (string.IsNullOrWhiteSpace(field.AliasName))
{
p.Key = field.Name;
}
else
{
p.Key = field.AliasName;
}
if (row[colName] == null)
{
p.Value = null;
}
else
{
p.Value = row[colName].ToString().Trim();
}
if (domain != null && (domain as ICodedValueDomain) != null)
{
p.PropertyType = enumPropertyType.ComboBox;
if (LinkageCfg != null)
{
foreach (var item in LinkageCfg)
{
if (field.Name == item.TargetPropertyName || field.Name == item.SourcePropertyName)
{
p.IsGroup = item.IsGroup;
break;
}
}
Linkage cfg = LinkageCfg.FirstOrDefault(w => w.SourcePropertyName == field.Name && w.LinkageType == EnumLinkageType.None && (!string.IsNullOrWhiteSpace(w.DisplayMemberPath) || !string.IsNullOrWhiteSpace(w.ValuePath)));
if (cfg != null)
{
p.DisplayMemberPath = cfg.DisplayMemberPath;
p.ValuePath = cfg.ValuePath;
}
}
ICodedValueDomain codeValue = domain as ICodedValueDomain;
p.DicData = new List<DataDicTionary>();
if (codeValue.CodeCount == 0)
{
try
{
//矢量化工程TBXHDM需要转换为获取TBXHLX字段值,对应bug11118
if (domain.Name == "TBXHDM")
{
domain.Name = "TBXHLX";
}
DicTypeEnum dicType = (DicTypeEnum)System.Enum.Parse(typeof(DicTypeEnum), domain.Name);
if (Platform.Instance.DicHelper != null && Dics != null)
{
p.DicData = Platform.Instance.DicHelper.GetNoGroupDic(dicType, Dics);
}
}
catch (Exception ex)
{
LogAPI.Debug("属性联动 绑定数据期间 转化域名及获取域枚举类型 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("属性联动 绑定数据期间 转化域名及获取域枚举类型 时异常信息结束");
}
}
else
{
for (int codeIndex = 0; codeIndex < codeValue.CodeCount; codeIndex++)
{
p.DicData.Add(new DataDicTionary() { NAME = codeValue.get_Name(codeIndex), CODE = codeValue.get_Value(codeIndex).ToString() });
}
}
}
else
{
p.PropertyType = enumPropertyType.TextBox;
}
p.PropertyChanged += PropertyChangedEvent;
singledata.Add(p);
}
}
MyPropertyGrid.ItemsSource = singledata;
}
catch (Exception ex)
{
LogAPI.Debug("变更图斑信息绑定失败:" + ex.Message);
}
}
/// <summary>
/// 属性联动配置
/// </summary>
public Linkage[] LinkageCfg { get; set; }
List<PropertyGridDataStruct> singledata = null;
public void BindData1(object obj)
{
if (obj == null)
{
InitLinkageCfg();
MyPropertyGrid.ItemsSource = null;
return;
}
if (LinkageCfg == null)
InitLinkageCfg();
if (Platform.Instance.DicHelper != null && (Dics == null || Dics.Count == 0))
{
Dics = Platform.Instance.DicHelper.GetAllDic();
}
#region 根据地类显示不同的属性及属性值
//不显示
//List<string> ALLContinueList = new List<string>() { "标识码", "要素代码", "图斑面积", "扣除地类面积", "图斑地类面积", "数据年份", "耕地坡度级别" };
Dictionary<List<string>, List<string>> keyValuePairs = new Dictionary<List<string>, List<string>>();
List<string> ContinueList = null;
//道路不显示
keyValuePairs.Add(
new List<string>() { "1004", "1006", "1101", "1107", "1107A", "1203" },
new List<string>() { "图斑细化代码", "图斑细化名称", "种植属性名称", "种植属性代码", "扣除地类面积", "扣除地类编码", "扣除地类系数", "图斑细化名称", "图斑细化代码", "耕地类型", "耕地等别", "耕地坡度级别" }
);
//不显示城镇村属性码的非耕地
keyValuePairs.Add(
new List<string>() { "1001", "1002", "1003", "1007", "1009", "1109" },
new List<string>() { "图斑细化代码", "图斑细化名称", "种植属性名称", "种植属性代码", "扣除地类面积", "扣除地类编码", "扣除地类系数", "图斑细化名称", "图斑细化代码", "耕地类型", "耕地等别", "城镇村属性码", "耕地坡度级别" }
);
//耕地不显示
keyValuePairs.Add(
new List<string>() { "0101", "0102", "0103" },
new List<string>() { "线状地物宽度" }
);
//非耕地,非道路 不显示
keyValuePairs.Add(
new List<string>() { "0201", "0201K", "0202", "0202K", "0203", "0203K", "0204", "0204K", "0301", "0301K", "0302", "0302K", "0303", "0304", "0305", "0306", "0307", "0307K", "0401", "0402", "0403", "0403K", "0404", "0508", "05H1", "0601", "0602", "0603", "0701", "0702", "0809", "0810", "0810A", "08H1", "08H2", "08H2A", "09", "1005", "1008", "1102", "1103", "1104", "1104A", "1104K", "1105", "1106", "1108", "1110", "1201", "1202", "1204", "1205", "1206", "1207", },
new List<string>() { "扣除地类面积", "扣除地类编码", "扣除地类系数", "耕地类型", "耕地等别", "耕地坡度级别", "线状地物宽度" }
);
#endregion
//List<DataDicTionary> tempDic = Platform.Instance.DicHelper.GetAllDic();
this.Data = obj;
singledata = new List<PropertyGridDataStruct>();
if (obj is IFeature)
{
IFeature fe = obj as IFeature;
//ExecuteDataCheck(fe);
IFeatureClass pFeatureClass = fe.Class as IFeatureClass;
IDataset dataset = pFeatureClass as IDataset;
int objIndex = fe.Fields.FindField("OBJECTID");
//if (dataset != null && dataset.Name == "DLTBBG" && Platform.Instance.SystemType == SystemTypeEnum.TBBG)
//{
// if (this.BGTBData == null)
// {
// Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = "GetTBBGDetail", MsgType = "GetTBBGDetail" });
// return;
// }
// else
// {
// int objectid = Convert.ToInt32(fe.Value[objIndex]);
// int objid = Convert.ToInt32(this.BGTBData["OBJECTID"]);
// if (objectid == objid)
// {
// BindBGTB(this.BGTBData);
// return;
// }
// }
//}
int iDLBM = fe.Fields.FindField("DLBM");
if (iDLBM != -1)
{
string strDLBM = fe.Value[iDLBM].ToString();
ContinueList = keyValuePairs.FirstOrDefault(x => x.Key.Contains(strDLBM)).Value;
}
for (int i = 0; i < fe.Fields.FieldCount; i++)
{
IField field = fe.Fields.get_Field(i);
if (field.Name.ToUpper() == "SHAPE" || field.Name.ToUpper().Contains("_EXTRA") || field.Name == "ErrorMessage" || field.Name == "ErrorShape")
continue;
//if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK && field.Name.ToUpper() == "OBJECTID")
// break;
IDomain domain = field.Domain;
//矢量化工程没有模板,无法解决问题
//IDomain domain = null;
//if (ruleTable != null)
//{
// KGIS.Config.RuleColumnEntity ruleColumn = ruleTable.Columns.FirstOrDefault(x => x.ColumnName == field.Name);
// if (ruleColumn != null && !string.IsNullOrWhiteSpace(ruleColumn.DIC))
// {
// domain = new CodedValueDomainClass();
// domain.Name = ruleColumn.DIC;
// }
//}
//else
//{
// domain = field.Domain;
//}
PropertyGridDataStruct p = new PropertyGridDataStruct();
p.DisplayMemberPath = "NAME";
p.ValuePath = "CODE";
if (!field.Editable)
{
p.IsReadOnly = !field.Editable;
}
else
{
p.IsReadOnly = editor.EditState == esriEngineEditState.esriEngineStateNotEditing || (editor.EditWorkspace != null && editor.EditWorkspace.PathName != (fe.Class as FeatureClass).Workspace.PathName);
}
//是否可以编辑
//p.IsReadOnly = !field.Editable;
//是否可以为空
p.AllowNull = field.IsNullable;
if (string.IsNullOrWhiteSpace(field.AliasName))
{
p.Key = field.Name;
}
else
{
//var alltable = Config.DataCheckTableMappingConfig.GetRuleTableEntityByTableName((fe.Class as IFeatureClass).AliasName);
//if (Config.DataCheckTableMappingConfig.GetTableName((fe.Class as FeatureClass).Name) == true)
//{
p.Key = field.AliasName;
//p.Text = field.AliasName;
//}
//else
//{
// Config.RuleTableEntity ruleTable = Config.DataCheckTableMappingConfig.GetRuleTableEntityByTableName((fe.Class as FeatureClass).Name);
// var aToolTip = ruleTable.Columns.SingleOrDefault(x => x.AliasName == field.AliasName);
// var PicTool = aToolTip == null ? "" : aToolTip.Pic;
// if (field.AliasName == "OBJECTID" || field.AliasName == "SHAPE_Length" || field.AliasName == "SHAPE_Area" || field.AliasName == "PointCount")
// {
// //p.Text = field.AliasName;
// p.Key = field.AliasName;
// }
// else
// {
// p.Key = field.AliasName;
// if (PicTool == "M") { p.FontColor = "#FFFF0000"; }
// else if (PicTool == "C") { p.FontColor = "#FF0000FF"; }
// else { p.FontColor = "#FF000000"; }
// p.Text = "(" + PicTool + ")";
// }
// //p.HeaderToolTip = aToolTip == null ? "" : aToolTip.ToolTip;
// if (aToolTip != null && !string.IsNullOrWhiteSpace(aToolTip.ToolTip))
// {
// //p.HeaderToolTip = ViewControls.Helper.ShowToolTipHelper.BreakLongString(aToolTip.ToolTip, 30);
// }
//}
}
p.FieldName = field.Name;
if (ContinueList != null && ContinueList.Contains(p.Key))//根据地类排除显示
continue;
if (fe.get_Value(i) is DBNull || fe.get_Value(i) == null)
{
p.Value = null;
}
else
{
p.Value = fe.get_Value(i).ToString().Trim();
}
if (domain != null && (domain as ICodedValueDomain) != null)
{
p.PropertyType = enumPropertyType.ComboBox;
if (LinkageCfg != null)
{
foreach (var item in LinkageCfg)
{
if (field.Name == item.TargetPropertyName || field.Name == item.SourcePropertyName)
{
p.IsGroup = item.IsGroup;
break;
}
}
Linkage cfg = LinkageCfg.FirstOrDefault(w => w.SourcePropertyName == field.Name && w.LinkageType == EnumLinkageType.None && (!string.IsNullOrWhiteSpace(w.DisplayMemberPath) || !string.IsNullOrWhiteSpace(w.ValuePath)));
if (cfg != null)
{
p.DisplayMemberPath = cfg.DisplayMemberPath;
p.ValuePath = cfg.ValuePath;
}
}
ICodedValueDomain codeValue = domain as ICodedValueDomain;
p.DicData = new List<DataDicTionary>();
if (codeValue.CodeCount == 0)
{
try
{
//矢量化工程TBXHDM需要转换为获取TBXHLX字段值,对应bug11118
if (domain.Name == "TBXHDM")
{
domain.Name = "TBXHLX";
}
if (Platform.Instance.SystemType != SystemTypeEnum.DTBJK && Platform.Instance.SystemType != SystemTypeEnum.YCLJK)
{
DicTypeEnum dicType = (DicTypeEnum)System.Enum.Parse(typeof(DicTypeEnum), domain.Name);
if (Platform.Instance.DicHelper != null && Dics != null)
{
if (dicType == DicTypeEnum.QSDM)
{
p.DicData = p.DicData = Dics.Where(x => (x.OWNERDIC == "1" || Convert.ToInt32(x.OWNERDIC) >= 50) && x.CODE.Length >= 19).ToLookup(x => x.CODE).ToDictionary(x => x.Key, x => x.First()).Values.ToList();
}
}
}
else
{
//p.DicData = Platform.Instance.DicHelper.GetNoGroupDic(dicType, Dics);
//20230630修改 根据domain.Name 直接查询字典项
//单图斑建库中的很多分类在枚举中没有
p.DicData = GetNoGroupDic(domain.Name, Dics);
}
}
catch (Exception ex)
{
LogAPI.Debug("属性联动 绑定数据期间 转化域名及获取域枚举类型 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("属性联动 绑定数据期间 转化域名及获取域枚举类型 时异常信息结束");
}
}
else
{
for (int codeIndex = 0; codeIndex < codeValue.CodeCount; codeIndex++)
{
p.DicData.Add(new DataDicTionary() { NAME = codeValue.get_Name(codeIndex), CODE = codeValue.get_Value(codeIndex).ToString() });
}
}
}
else if (p.Key == "图斑细化代码")
{
p.PropertyType = enumPropertyType.ComboBox;
p.DicData = Dics.Where(x => x.OWNERDIC == "31").ToLookup(x => x.CODE).ToDictionary(x => x.Key, x => x.First()).Values.ToList();
}
else if (p.Key == "种植属性代码")
{
p.PropertyType = enumPropertyType.ComboBox;
p.DicData = Dics.Where(x => x.OWNERDIC == "32").ToLookup(x => x.CODE).ToDictionary(x => x.Key, x => x.First()).Values.ToList();
}
else if (p.Key == "权属单位代码" || p.Key == "坐落单位代码")
{
p.PropertyType = enumPropertyType.ComboBox;
p.DicData = Dics.Where(x => (x.OWNERDIC == "1" || Convert.ToInt32(x.OWNERDIC) >= 50) && x.CODE.Length >= 19).ToLookup(x => x.CODE).ToDictionary(x => x.Key, x => x.First()).Values.ToList();
}
else if (p.Key == "城镇村属性码")
{
p.PropertyType = enumPropertyType.ComboBox;
p.DicData = Dics.Where(x => x.OWNERDIC == "41" || x.OWNERDIC == "42" || x.OWNERDIC == "43").ToLookup(x => x.CODE).ToDictionary(x => x.Key, x => x.First()).Values.ToList();
}
else if (field.Name.Equals("PZWJMC") || field.AliasName.Equals("批准文件名称"))
{
p.PropertyType = enumPropertyType.ButtonEdit;
}
else
{
p.PropertyType = enumPropertyType.TextBox;
}
p.PropertyChanged += PropertyChangedEvent;
singledata.Add(p);
}
}
MyPropertyGrid.ItemsSource = singledata;
}
#region 配置版本
LayerFieldCfg Cfg = null;
string taskPackagePath = null;
public void BindData(object obj)
{
try
{
if (obj == null)
{
MyPropertyGrid.ItemsSource = null;
return;
}
if (singledata != null)
singledata.Clear();
if (LinkageCfg == null)
InitLinkageCfg();
if (Platform.Instance.DicHelper != null && (Dics == null || Dics.Count == 0))
{
Dics = Platform.Instance.DicHelper.GetAllDic();
}
isGetConfiguration = false;
if (obj is NYYSInfo)
{
NYYSInfo nYYSInfo = obj as NYYSInfo;
if (nYYSInfo != null && nYYSInfo.TaskPackages != null)
taskPackagePath = nYYSInfo.TaskPackages.PackageTempPath;
try
{
this.Data = obj = nYYSInfo.DTBDLTBGX != null ? MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG").FeatureClass.GetFeature(nYYSInfo.DTBDLTBGX.ObjectID) : null;
isGetConfiguration = true;
}
catch (Exception)
{ }
}
else
{
this.Data = obj;
}
if (obj is IFeature feature)
{
if (feature.Class.AliasName == "地类图斑更新")
isGetConfiguration = true;
RefreshData(obj);
}
MyPropertyGrid.ItemsSource = null;
if (singledata != null)
MyPropertyGrid.ItemsSource = singledata.Where(x => x.Visible).OrderBy(x => x.Order).ToList();
}
catch (Exception ex)
{
LogAPI.Debug($"AttributeEdit绑定错误: {ex.Message}");
LogAPI.Debug($"AttributeEdit绑定错误: {ex.StackTrace}");
MessageHelper.ShowError("AttributeEdit绑定错误:" + ex.Message);
}
}
private bool isGetConfiguration = false;
private void RefreshData(object obj)
{
DataDicTionary dataDicTionary = null;
try
{
if (catalogService == null)
catalogService = Activator.BundleContext.GetFirstOrDefaultService<IDataCatalogService>();
singledata = null;
singledata = new List<PropertyGridDataStruct>();
IFeature fe = obj as IFeature;
if (Cfg == null) return;
string DDTCBZValue = string.Empty;
int iddtc = fe.Fields.FindField("DDTCBZ");
if (iddtc > -1)
DDTCBZValue = fe.Value[iddtc].ToString();
string dlbmValue = string.Empty;
int iDLBM = fe.Fields.FindField("DLBM");
if (iDLBM > -1)
dlbmValue = fe.Value[iDLBM].ToString();
string tempDisplayType = string.Empty;
for (int i = 0; i < fe.Fields.FieldCount; i++)
{
IField field = fe.Fields.get_Field(i);
if (field.Name.ToUpper().Equals("OBJECTID") || field.Name.ToUpper().Contains("SHAPE_AREA") || field.Name.ToUpper().Contains("SHAPE_LENGTH") || field.Name.ToUpper() == "SHAPE" || field.Name.ToUpper().Contains("_EXTRA") || field.Name == "ErrorMessage" || field.Name == "ErrorShape") continue;
if (field.Name.ToUpper().Contains("YSDM") || field.Name.ToUpper().Contains("TBYBH") || field.Name.ToUpper() == "TBBH") continue;
PropertyGridDataStruct p = new PropertyGridDataStruct();
FieldCfg fieldCfg = null;
if (isGetConfiguration)
{
string cfgname = $"{GetFieldEditCfg(fe)}_{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).CODE.Substring(0, 2)}";
if (!cfgname.StartsWith("单图斑地类图斑更新"))
cfgname = cfgname.Split('_')[0].ToSafeString();
LayerInfo layer = Cfg.Layers.FirstOrDefault(f => f.CfgName == cfgname);
fieldCfg = layer?.Fields.FirstOrDefault(x => x.Name == field.Name);
if (fieldCfg == null) continue;
p.Visible = fieldCfg.Display;
p.Order = fieldCfg.Order;
string strDisplayType = string.Empty;
// DisplayType 根据其他属性判断是否需要显示
if (fieldCfg.DisplayType != null && !string.IsNullOrWhiteSpace(fieldCfg.DisplayType.ToTrim()))
{
tempDisplayType = fieldCfg.DisplayType;
var displayTypes = fieldCfg.DisplayType.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var currentDisplayType in displayTypes)
{
int iDisplayType = fe.Fields.FindField(currentDisplayType);
if (iDisplayType > -1)
strDisplayType = fe.Value[iDisplayType].ToString();
if ((currentDisplayType == "DLBM" && string.IsNullOrWhiteSpace(strDisplayType)))
{
//地类编码为空 不加载其他信息
if (!fieldCfg.StillShow)
p.Visible = false;
}
}
if (displayTypes.Length > 1)
{
tempDisplayType = displayTypes.ToList().Find(a => a != "DLBM");
int iDisplayType = fe.Fields.FindField(tempDisplayType);
if (iDisplayType > -1)
strDisplayType = fe.Value[iDisplayType].ToString();
}
}
#region 属性信息显示条件
if (fieldCfg.Sql != null && fieldCfg.FieldName != null)
{
if (!JudgeSSSMVisible(fe, fieldCfg.Sql, fieldCfg.FieldName, fieldCfg.JudgeVisibleValue))
p.Visible = false;
}
else if (fieldCfg.DisplayWhere != null && !string.IsNullOrWhiteSpace(fieldCfg.DisplayWhere.ToTrim()))
{
var displaywhere = fieldCfg.DisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (fieldCfg.ShowTips != null)
{
if (displaywhere.Where(x => strDisplayType.Contains(x)).FirstOrDefault() != null)
MessageHelper.ShowTips(fieldCfg.ShowTips);
}
else
{
if (!displaywhere.Contains(strDisplayType))
{
p.Visible = false;
}
}
}
else if (fieldCfg.Fields.Count > 0 && fieldCfg.Fields.Where(x => x.DontDisplayWhere is null).ToList().Count == 0)
{
bool isContinue = false;
foreach (var item in fieldCfg.Fields)
{
var displaywhere = item.DontDisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string strChildDisplayType = string.Empty;
int iDisplayType = fe.Fields.FindField(item.DisplayType != null ? item.DisplayType : tempDisplayType);
if (iDisplayType > -1)
strChildDisplayType = fe.Value[iDisplayType].ToString();
if (displaywhere.Contains(strChildDisplayType))
{
isContinue = true;
break;
}
}
if (isContinue)
{
p.Visible = false;
}
}
if (fieldCfg.DontDisplayWhere != null && !string.IsNullOrWhiteSpace(fieldCfg.DontDisplayWhere.ToTrim()))
{
var displaywhere = fieldCfg.DontDisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (displaywhere.Contains(strDisplayType))
{
continue;
}
}
#endregion
//以配置文件中的为准,默认为TextBox
enumPropertyType PropertyType = fieldCfg.EnumPropertyType == null ? enumPropertyType.TextBox : (enumPropertyType)System.Enum.Parse(typeof(enumPropertyType), fieldCfg.EnumPropertyType);
switch (PropertyType)
{
case enumPropertyType.TextBox:
p.PropertyType = enumPropertyType.TextBox;
break;
case enumPropertyType.ComboBox:
p.PropertyType = enumPropertyType.ComboBox;
if (fieldCfg.Fields.Count > 0)
{
List<DataDicTionary> dataDicTionaries = new List<DataDicTionary>();
FieldCfg fieldCfg_child = null;
if (fieldCfg.Fields.Where(x => x.Fields.Count > 0).ToList().Count > 0)
{
foreach (var iFields in fieldCfg.Fields)
{
if (iFields.Name.Split(',').Contains(strDisplayType))
{
if (iFields.Fields.Count > 0)
{
foreach (var item in iFields.Fields)
{
if (!string.IsNullOrWhiteSpace(tempDisplayType) && !string.IsNullOrWhiteSpace(item.DisplayWhere))
{
string strChildDisplayType = string.Empty;
int iDisplayType = fe.Fields.FindField(item.DisplayType != null ? item.DisplayType : tempDisplayType);
if (iDisplayType > -1)
strChildDisplayType = fe.Value[iDisplayType].ToString();
if (item.Name.Split(',').Contains(strChildDisplayType))
{
fieldCfg_child = item;
}
}
}
}
else
{
fieldCfg_child = iFields;
}
}
}
}
else
{
fieldCfg_child = fieldCfg.Fields.FirstOrDefault(x => x.Name.Split(',').Contains(strDisplayType));
}
if (fieldCfg_child != null)
{
if (fieldCfg_child.DisplayWhere != null && !string.IsNullOrWhiteSpace(fieldCfg_child.DisplayWhere.ToTrim()))
{
var displaywhere = fieldCfg_child.DisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var dic = GetNoGroupDic(fieldCfg.DicName, Dics);
if (dic != null && dic.Count > 0)
{
for (int j = 0; j < displaywhere.Length; j++)
{
dataDicTionary = dic.FirstOrDefault(x => x.CODE.ToTrim().Equals(displaywhere[j]));
if (dataDicTionary != null)
dataDicTionaries.Add(dataDicTionary);
}
}
p.DicData = dataDicTionaries;
}
if (!string.IsNullOrWhiteSpace(fieldCfg_child.DontDisplayWhere.ToTrim()))
{
var displaywhere = fieldCfg_child.DontDisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var dic = GetNoGroupDic(fieldCfg.DicName, Dics);
for (int j = 0; j < displaywhere.Length; j++)
{
List<DataDicTionary> dataDic = Dics.FindAll(x => x.CODE.Equals(displaywhere[j]));
if (dataDic != null)
{
foreach (DataDicTionary data in dataDic)
{
dic.Remove(data);
}
}
}
p.DicData = dic;
}
}
else
{
p.DicData = GetNoGroupDic(fieldCfg.DicName, Dics);
}
}
else
{
if (fieldCfg.ComboBoxItems != null)
p.DicData = GetNoGroupDic(fieldCfg.DicName, Dics).FindAll(a => fieldCfg.ComboBoxItems.Contains(a.CODE));
else
p.DicData = GetNoGroupDic(fieldCfg.DicName, Dics);
}
break;
#region 注释项
//case enumPropertyType.MultiComboBox:
// p.PropertyType = enumPropertyType.MultiComboBox;
// if (fieldCfg.Fields.Count > 0)
// {
// List<DataDicTionary> dataDicTionaries = new List<DataDicTionary>();
// FieldCfg fieldCfg_child = null;
// if (fieldCfg.Fields.Where(x => x.Fields.Count > 0).ToList().Count > 0)
// {
// foreach (var iFields in fieldCfg.Fields)
// {
// if (iFields.Name.Split(',').Contains(strDisplayType))
// {
// if (iFields.Fields.Count > 0)
// {
// foreach (var item in iFields.Fields)
// {
// if (!string.IsNullOrWhiteSpace(tempDisplayType) && !string.IsNullOrWhiteSpace(item.DisplayWhere))
// {
// string strChildDisplayType = string.Empty;
// int iDisplayType = fe.Fields.FindField(item.DisplayType != null ? item.DisplayType : tempDisplayType);
// if (iDisplayType > -1)
// strChildDisplayType = fe.Value[iDisplayType].ToString();
// if (item.Name.Split(',').Contains(strChildDisplayType))
// {
// fieldCfg_child = item;
// }
// }
// }
// }
// else
// {
// fieldCfg_child = iFields;
// }
// }
// }
// }
// else
// {
// fieldCfg_child = fieldCfg.Fields.FirstOrDefault(x => x.Name.Split(',').Contains(strDisplayType));
// }
// if (fieldCfg_child != null)
// {
// if (fieldCfg_child.DisplayWhere != null && !string.IsNullOrWhiteSpace(fieldCfg_child.DisplayWhere.ToTrim()))
// {
// var displaywhere = fieldCfg_child.DisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// var dic = GetNoGroupDic(fieldCfg.DicName, Dics);
// if (dic != null && dic.Count > 0)
// {
// for (int j = 0; j < displaywhere.Length; j++)
// {
// dataDicTionary = dic.FirstOrDefault(x => x.CODE.ToTrim().Equals(displaywhere[j]));
// if (dataDicTionary != null)
// dataDicTionaries.Add(dataDicTionary);
// }
// }
// p.DicData = dataDicTionaries;
// }
// if (!string.IsNullOrWhiteSpace(fieldCfg_child.DontDisplayWhere.ToTrim()))
// {
// var displaywhere = fieldCfg_child.DontDisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// var dic = GetNoGroupDic(fieldCfg.DicName, Dics);
// for (int j = 0; j < displaywhere.Length; j++)
// {
// List<DataDicTionary> dataDic = Dics.FindAll(x => x.CODE.Equals(displaywhere[j]));
// if (dataDic != null)
// {
// foreach (DataDicTionary data in dataDic)
// {
// dic.Remove(data);
// }
// }
// }
// p.DicData = dic;
// }
// }
// else
// {
// p.DicData = GetNoGroupDic(fieldCfg.DicName, Dics);
// }
// }
// else
// {
// if (fieldCfg.ComboBoxItems != null)
// p.DicData = GetNoGroupDic(fieldCfg.DicName, Dics).FindAll(a => fieldCfg.ComboBoxItems.Contains(a.CODE));
// else
// p.DicData = GetNoGroupDic(fieldCfg.DicName, Dics);
// }
// break;
#endregion
case enumPropertyType.ButtonEdit:
p.PropertyType = enumPropertyType.ButtonEdit;
break;
case enumPropertyType.ButtonEditFJ:
p.PropertyType = enumPropertyType.ButtonEditFJ;
break;
default:
break;
}
}
else
{
p.PropertyType = enumPropertyType.TextBox;
p.Visible = true;
}
p.DisplayMemberPath = "NAME";
p.ValuePath = "CODE";
if (fieldCfg != null)
{
if (fieldCfg.NotEdit != null && dlbmValue != null)
{
var norEdit = fieldCfg.NotEdit.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (norEdit.Contains(dlbmValue) || fieldCfg.IsReadOnly == true)
{
p.IsReadOnly = true;
}
}
else if (fieldCfg.CanEdit != null && dlbmValue != null)
{
var canEdit = fieldCfg.CanEdit.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (canEdit.Contains(dlbmValue))
{
p.IsReadOnly = false;
}
else if (fieldCfg.IsReadOnly == true)
{
p.IsReadOnly = true;
}
}
else if (fieldCfg.IsReadOnly == true)
{
p.IsReadOnly = true;
}
}
else if (!field.Editable)
{
p.IsReadOnly = !field.Editable;
}
else
{
p.IsReadOnly = editor.EditState == esriEngineEditState.esriEngineStateNotEditing || (editor.EditWorkspace != null && editor.EditWorkspace.PathName != (fe.Class as FeatureClass).Workspace.PathName);
}
p.AllowNull = field.IsNullable;
p.FieldName = field.Name;
if (string.IsNullOrWhiteSpace(field.AliasName))
{
p.Key = field.Name;
}
else
{
p.Key = field.AliasName;
}
if (fe.get_Value(i) is DBNull || fe.get_Value(i) == null)
{
p.Value = null;
}
else
{
p.Value = fe.get_Value(i).ToString();
//if (p.PropertyType == enumPropertyType.MultiComboBox && p.DicData != null)
//{
// foreach (DataDicTionary dicData in p.DicData)
// {
// if (!string.IsNullOrEmpty(dicData.CODE) && p.Value.Contains(dicData.CODE))
// {
// dicData.IsChecked = true;
// if (p.MultiSelectDicData == null)
// {
// p.MultiSelectDicData = new List<string>();
// }
// p.MultiSelectDicData.Add(dicData.CODE);
// }
// }
//}
}
if (p.IsReadOnly == true)
{
p.FontColor = "#8E8E8E";
}
else
{
p.FontColor = "#000000";
}
if (fieldCfg != null)
{
if (fieldCfg.Name.Contains("_LSYD"))
{
p.FontColor = "#CC9933";
}
if (fieldCfg.Name.Contains("_GFBQ"))
{
p.FontColor = "#076DFD";
}
}
p.PropertyChanged += PropertyChangedEvent;
singledata.Add(p);
}
}
catch (Exception ex)
{
LogAPI.Debug("属性表数据异常:" + ex.Message);
LogAPI.Debug("属性表数据异常:" + ex.StackTrace);
throw ex;
}
}
private string GetFieldEditCfg(IFeature feature)
{
string FieldEditCfg = string.Empty;
try
{
IFeatureClass pFeatureClass = feature.Class as IFeatureClass;
IDataset dataset = pFeatureClass as IDataset;
var editLayer = MapsManager.Instance.MapService.GetFeatureLayerByName(dataset.Name);
LayerCfg s = catalogService.CurrentLayers as LayerCfg;
LayerCfg layCfg = s?.GetAllItem().FirstOrDefault(f => f.Data == editLayer);
if (layCfg != null)
FieldEditCfg = layCfg.FieldEditCfg;
}
catch (Exception ex)
{
LogAPI.Debug("GetFieldEditCfg异常:" + ex.Message);
LogAPI.Debug("GetFieldEditCfg异常:" + ex.StackTrace);
throw ex;
}
return FieldEditCfg;
}
#endregion
/// <summary>
/// 湖南地区需求 判定申诉说明字段 根据省级反馈意见为不通过的才能填写
/// </summary>
/// <returns></returns>
private bool JudgeSSSMVisible(IFeature feature, string Sql, string FieldName, string JudgeVisibleValue)
{
if (string.IsNullOrEmpty(FieldName) || string.IsNullOrWhiteSpace(taskPackagePath) || !System.IO.File.Exists(taskPackagePath)) return false;
List<string> fieldNames = FieldName.Split(',').ToList();
IRDBHelper rdbHelper = null;
string sqlValue = "";
try
{
string SqlField = Sql.ToLower().Split(new string[] { "select" }, StringSplitOptions.None)[1].Split(new string[] { "from" }, StringSplitOptions.None)[0].Trim();
rdbHelper = RDBFactory.CreateDbHelper($"{taskPackagePath}{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).Pathpassword}", DatabaseType.SQLite);
for (int i = 0; i < fieldNames.Count; i++)
{
string fieldValue = string.Empty;
int ifield = feature.Fields.FindField(fieldNames[i]);
if (ifield > -1)
fieldValue = feature.Value[ifield].ToString();
if (i == 0)
sqlValue = FieldName + $" = '{fieldValue}' ";
else
sqlValue += " and " + FieldName + $" = '{fieldValue}' ";
}
if (string.IsNullOrEmpty(sqlValue)) return false;
string sqlStr = string.Format(Sql + " " + sqlValue);
DataTable dicDt = rdbHelper.ExecuteDatatable("Dic", sqlStr, true);
if (dicDt != null)
{
if (dicDt.Rows.Count == 0) return false;
foreach (System.Data.DataRow dr in dicDt.Rows)
{
string zl = dr[SqlField].ToTrim();
if (zl == JudgeVisibleValue)
{
return true;
}
}
}
return false;
}
catch
{
return false;
}
finally
{
if (rdbHelper != null)
rdbHelper.DisConnect();
}
}
/// <summary>
/// 初始化属性联动配置
/// </summary>
private void InitLinkageCfg()
{
if (LinkageCfg != null) LinkageCfg = null;
#region 建库
//List<Linkage> list = new List<Linkage>
//{
// new Linkage() { SourcePropertyName = "ZLDWDM", SourcePropertyAliasName = "坐落单位代码", TargetPropertyName = "ZLDWMC", TargetPropertyAliasName = "坐落单位名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true },
// new Linkage() { SourcePropertyName = "ZLDWDM", SourcePropertyAliasName = "坐落单位名称", DisplayMemberPath = "DisplayName", ValuePath = "CODE" },
// new Linkage() { SourcePropertyName = "QSDWDM", SourcePropertyAliasName = "权属单位代码", TargetPropertyName = "QSDWMC", TargetPropertyAliasName = "权属单位名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true },
// new Linkage() { SourcePropertyName = "QSDWDM", SourcePropertyAliasName = "权属单位名称", DisplayMemberPath = "DisplayName", ValuePath = "CODE" },
// new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", TargetPropertyName = "DLMC", TargetPropertyAliasName = "地类名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true },
// new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" },
// new Linkage() { SourcePropertyName = "TBXHDM", SourcePropertyAliasName = "图斑细化代码", TargetPropertyName = "TBXHMC", TargetPropertyAliasName = "图斑细化名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false },
// new Linkage() { SourcePropertyName = "TBXHDM", SourcePropertyAliasName = "图斑细化代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" },
// new Linkage() { SourcePropertyName = "LYXZFLBM", SourcePropertyAliasName = "利用现状分类编码", TargetPropertyName = "LYXZFLMC", TargetPropertyAliasName = "利用现状分类名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false },
// new Linkage() { SourcePropertyName = "LYXZFLBM", SourcePropertyAliasName = "利用现状分类编码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" },
// new Linkage() { SourcePropertyName = "ZZSXDM", SourcePropertyAliasName = "种植属性代码", TargetPropertyName = "ZZSXMC", TargetPropertyAliasName = "种植属性名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false },
// new Linkage() { SourcePropertyName = "ZZSXDM", SourcePropertyAliasName = "种植属性代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" },
// new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDLX", TargetPropertyAliasName = "耕地类型", TargetPropertyValue = "Auto", IsReadOnly = false },
// new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDPDJB", TargetPropertyAliasName = "耕地坡度级别", TargetPropertyValue = "Auto", IsReadOnly = false },
// new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "GDDB", TargetPropertyAliasName = "耕地等别", TargetPropertyValue = "Auto", IsReadOnly = false },
// new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCDLBM", TargetPropertyAliasName = "扣除地类编码", TargetPropertyValue = "Auto", IsReadOnly = false },
// new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCXS", TargetPropertyAliasName = "扣除系数", TargetPropertyValue = "Auto", IsReadOnly = false },
// new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", SourcePropertyValue = "01", TargetPropertyName = "KCMJ", TargetPropertyAliasName = "扣除面积", TargetPropertyValue = "Auto", IsReadOnly = false }
//};
//LinkageCfg = list.ToArray();
#endregion
#region 单图斑
List<Linkage> list = new List<Linkage>();
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "DLBM", SourcePropertyAliasName = "地类编码", TargetPropertyName = "DLMC", TargetPropertyAliasName = "地类名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "TBXHDM", SourcePropertyAliasName = "图斑细化代码", TargetPropertyName = "TBXHMC", TargetPropertyAliasName = "图斑细化名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "TBXHDM", SourcePropertyAliasName = "图斑细化代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "ZZSXDM", SourcePropertyAliasName = "种植属性代码", TargetPropertyName = "ZZSXMC", TargetPropertyAliasName = "种植属性名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "ZZSXDM", SourcePropertyAliasName = "种植属性代码", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "DDTCDM", SourcePropertyAliasName = "图层信息", TargetPropertyName = "DDTCMC", TargetPropertyAliasName = "单独图层名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
list.Add(new Linkage() { SourcePropertyName = "DDTCDM", SourcePropertyAliasName = "图层信息", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "LJLX", SourcePropertyAliasName = "类举类型", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "XMLX", SourcePropertyAliasName = "项目类型", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "ZLDWDM", SourcePropertyAliasName = "坐落单位代码", TargetPropertyName = "ZLDWMC", TargetPropertyAliasName = "坐落单位名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "ZLDWDM", SourcePropertyAliasName = "坐落单位名称", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
list.Add(new Linkage() { SourcePropertyName = "QSDWDM", SourcePropertyAliasName = "权属单位代码", TargetPropertyName = "QSDWMC", TargetPropertyAliasName = "权属单位名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true });
list.Add(new Linkage() { SourcePropertyName = "QSDWDM", SourcePropertyAliasName = "权属单位名称", DisplayMemberPath = "DisplayName", ValuePath = "CODE" });
//list.Add(new Linkage() { SourcePropertyName = "ZZZW", SourcePropertyAliasName = "种植作物", TargetPropertyName = "ZZZW", TargetPropertyAliasName = "种植作物", DisplayMemberPath = "DisplayName", ValuePath = "CODE", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false });
LinkageCfg = list.ToArray();
#endregion
}
public static string GetDBConnectionByName(string pName)
{
try
{
XmlDocument doc = new XmlDocument();
string strPath = SysAppPath.GetConfigPath() + SysAppPath.SystemConfigName;
doc.Load(strPath);
XmlNode xmlSysNode = doc.SelectSingleNode("configuration/ConnectionStrings");
if (xmlSysNode.ChildNodes != null && xmlSysNode.ChildNodes.Count > 0)
{
foreach (XmlNode node in xmlSysNode.ChildNodes)
{
if (node.Attributes["Name"].Value == pName)
{
string connstr = node.Attributes["ConnectionString"].Value;
if (!string.IsNullOrWhiteSpace(connstr))
{
return connstr;
}
}
}
}
}
catch
{ }
return "";
}
public void ClearData()
{
MyPropertyGrid.ItemsSource = null;
}
void PropertyChangedEvent_OLD(object sender, PropertyChangedEventArgs e)
{
try
{
if (MyPropertyGrid.ItemsSource == null)
return;
PropertyGridDataStruct property = (PropertyGridDataStruct)sender;
if (property != null)
{
//修改新添加图层改变字段值,下拉框的就进入一下方法 2018/4/28
if (property.PropertyType != enumPropertyType.TextBox)
{
#region 属性联动
if (LinkageCfg != null && LinkageCfg.Length > 0)
{
List<PropertyGridDataStruct> Source = new List<PropertyGridDataStruct>();
Source = MyPropertyGrid.ItemsSource as List<PropertyGridDataStruct>;
IEnumerable<Linkage> list = LinkageCfg.Where(w => w.SourcePropertyName == property.Key || w.SourcePropertyAliasName == property.Key);
foreach (Linkage item in list)
{
IEnumerable<PropertyGridDataStruct> T_Property = Source.Where(w => w.Key == item.TargetPropertyName || w.Key == item.TargetPropertyAliasName);
foreach (var p in T_Property)
{
switch (item.LinkageType)
{
case EnumLinkageType.Equal:
p.Value = property.Value;
break;
case EnumLinkageType.KeyValueEqual:
if (property.DicData == null)
return;
DataDicTionary dic = property.DicData.FirstOrDefault(f => f.NAME == property.Value);
if (dic != null && !string.IsNullOrEmpty(dic.CODE))
{
p.Value = dic.CODE;
}
dic = property.DicData.FirstOrDefault(f => f.CODE == property.Value);
if (dic != null && !string.IsNullOrEmpty(dic.NAME))
{
p.Value = dic.NAME;
}
break;
case EnumLinkageType.SubItem:
if (p.PropertyType == enumPropertyType.ComboBox/* || p.PropertyType == enumPropertyType.MultiComboBox*/)
{
DataDicTionary d = property.DicData.FirstOrDefault(f => f.NAME.Equals(property.Value) || f.CODE.Equals(property.Value));
if (d != null)
{
if (!string.IsNullOrWhiteSpace(p.Value) && !p.Value.StartsWith(d.CODE))
{
p.Value = "";
}
IEnumerable<DataDicTionary> dicArr = property.DicData.Where(w => w.CODE.StartsWith(d.CODE) && w.CODE != d.CODE);
if (dicArr != null)
p.DicData = dicArr.ToList();
}
}
break;
default:
if (property.Value.StartsWith(item.SourcePropertyValue))
{
if (item.TargetPropertyValue != "Auto")
{
p.Value = item.TargetPropertyValue;
}
if (editor.EditState == esriEngineEditState.esriEngineStateEditing)
{
p.IsReadOnly = item.IsReadOnly;
}
}
else
{
p.Value = "";
p.IsReadOnly = !item.IsReadOnly;
}
break;
}
if (p.Key == "种植属性代码" || p.Key == "种植属性名称")
{
p.IsReadOnly = false;
}
}
}
}
#endregion
}
if (Data is IFeature)
{
ESRI.ArcGIS.Carto.IFeatureLayer player = MapsManager.Instance.MapService.GetFeatureLayerByName(((Data as IFeature).Class as FeatureClass).BrowseName);
if (player != null)
Data = player.FeatureClass.GetFeature((Data as IFeature).OID);
int index = (Data as IFeature).Fields.FindField(property.Key);
if (index == -1)
index = (Data as IFeature).Fields.FindFieldByAliasName(property.Key);
if (index != -1)
{
var val = (Data as IFeature).get_Value(index);
if (!val.Equals(property.Value))
{
if (val is DBNull && string.IsNullOrWhiteSpace(property.Value))
{
}
else
{
if (editor.EditState == esriEngineEditState.esriEngineStateEditing)
{
editor.StartOperation();
try
{
if (property.Key == "耕地等别" && string.IsNullOrEmpty(property.Value))
{
(Data as IFeature).set_Value(index, DBNull.Value);
}
else
{
if (property.Value != null && (Data as IFeature).Fields.get_Field(index).Length < property.Value.Length)
{
MessageHelper.ShowError(property.Key + ":填写值长度过长!");
editor.AbortOperation();
return;
}
(Data as IFeature).set_Value(index, property.Value);
}
(Data as IFeature).Store();
if (editor.EditState == esriEngineEditState.esriEngineStateEditing)
{
editor.StopOperation("Attribute update");
//ExecuteDataCheck(Data as IFeature);
//SaveEdit();
//通知属性表 即时刷新 edit by cmj 2018/5/9
//var platfrom = Env.Instance.Platfrom;
//platfrom.RefreshPanel(new NotifyMsgPackage()
//{
// MsgType = "RefreshAttr",
// Content = new AttrNotifyMsgModel()
// {
// Key = property.Key,
// Oid = (Data as IFeature).OID,
// Value = property.Value,
// Index = index
// }
//});
}
}
catch (Exception ex2)
{
LogAPI.Debug("属性改变事件中 结束编辑操作期间 时异常,异常信息如下:");
LogAPI.Debug(ex2);
LogAPI.Debug("属性改变事件中 结束编辑操作期间 时异常信息结束");
editor.AbortOperation();
}
}
}
}
}
}
MyPropertyGrid.ItemsSource = MyPropertyGrid.ItemsSource;
}
RefreshData(Data);
IFeature feature = Data as IFeature;
Platform.Instance.SendMsg(new NotifyMsgPackage() { Content = feature, MsgType = "RefreshViewAttrTable" });
}
catch (Exception ex)
{
//LogAPI.Debug("属性联动异常:" + ex);
LogAPI.Debug("属性改变事件期间 属性联动异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("属性改变事件期间 属性联动异常信息结束");
}
}
private void PropertyChangedEvent(object sender, PropertyChangedEventArgs e)
{
try
{
if (MyPropertyGrid.ItemsSource == null)
return;
PropertyGridDataStruct property = (PropertyGridDataStruct)sender;
if (property == null)
return;
#region 属性联动
if (LinkageCfg != null && LinkageCfg.Length > 0)
{
List<PropertyGridDataStruct> Source = new List<PropertyGridDataStruct>();
Source = singledata;//MyPropertyGrid.ItemsSource as List<PropertyGridDataStruct>;
IEnumerable<Linkage> list = LinkageCfg.Where(w => w.SourcePropertyName == property.Key || w.SourcePropertyAliasName == property.Key).ToList();
foreach (Linkage item in list)
{
IEnumerable<PropertyGridDataStruct> T_Property = Source.Where(w => w.Key == item.TargetPropertyName || w.Key == item.TargetPropertyAliasName).ToList();
foreach (var p in T_Property)
{
switch (item.LinkageType)
{
case EnumLinkageType.KeyValueEqual:
if (property.DicData == null)
break;
DataDicTionary dic = property.DicData.FirstOrDefault(f => f.NAME == property.Value);
if (dic != null)
{
p.Value = dic.CODE;
}
dic = property.DicData.FirstOrDefault(f => f.CODE == property.Value);
if (dic != null)
{
p.Value = dic.NAME;
}
if (!(Data is IFeature))
return;
IFeature pfeature = Data as IFeature;
int pindex = pfeature.Fields.FindField(p.Key);
if (pindex == -1)
{
pindex = pfeature.Fields.FindFieldByAliasName(p.Key);
}
if (pindex < 0) return;
if (string.IsNullOrWhiteSpace(p.Value))
{
(Data as IFeature).set_Value(pindex, DBNull.Value);
}
else
{
(Data as IFeature).set_Value(pindex, p.Value);
}
(Data as IFeature).Store();
break;
}
}
}
}
#endregion
if (!(Data is IFeature))
return;
IFeature feature = Data as IFeature;
int index = feature.Fields.FindField(property.Key);
if (index == -1)
{
index = feature.Fields.FindFieldByAliasName(property.Key);
}
if (index < 0) return;
var val = (Data as IFeature).get_Value(index);
if (val.Equals(property.Value))
{
MyPropertyGrid.ItemsSource = MyPropertyGrid.ItemsSource;
return;
}
if (val is DBNull && string.IsNullOrWhiteSpace(property.Value))
{
MyPropertyGrid.ItemsSource = MyPropertyGrid.ItemsSource;
return;
}
if (property.Key == "图层信息" && DDTCBZChange != null)
{
DDTCBZChange(property.Value);
}
if (property.Key == "城镇村属性码" && CZCSXMChange != null)
{
CZCSXMChange(property.Value);
}
try
{
if (editor.EditState == esriEngineEditState.esriEngineStateEditing)
{
editor.StartOperation();
}
if (property.Key == "耕地等别" && string.IsNullOrEmpty(property.Value))
{
(Data as IFeature).set_Value(index, DBNull.Value);
}
else if (property.Key == "标识码" || property.Key == "BSM" || property.Key == "图斑标识码"
|| property.Key == "TBBSM" || property.Key == "图斑唯一标识码" || property.Key == "TBWYBSM")
{
//此处标识码是统一赋值guid,不让修改
}
else
{
if (string.IsNullOrWhiteSpace(property.Value))
{
(Data as IFeature).set_Value(index, DBNull.Value);
}
else
{
(Data as IFeature).set_Value(index, property.Value);
}
}
(Data as IFeature).Store();
if (editor.EditState == esriEngineEditState.esriEngineStateEditing)
{
editor.StopOperation("Attribute update");
}
}
catch (Exception ex2)
{
if (editor.EditState == esriEngineEditState.esriEngineStateEditing)
{
editor.AbortOperation();
}
throw ex2;
}
RefreshData(Data);
//父级或关联字段属性修改,子级属性赋值为空
#region
string setNullFieldValue = string.Empty;
int setNullFieldIndex = feature.Fields.FindField(property.FieldName);
if (setNullFieldIndex > -1)
setNullFieldValue = feature.get_Value(setNullFieldIndex).ToString();
PropertyGridDataStruct tempPropertyGridData = null;
//LayerInfo layer = Cfg.Layers.FirstOrDefault(f => f.CfgName == GetFieldEditCfg(feature));
string cfgname = $"{GetFieldEditCfg(feature)}_{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).CODE.Substring(0, 2)}";
if (!cfgname.StartsWith("单图斑地类图斑更新"))
cfgname = cfgname.Split('_')[0].ToSafeString();
LayerInfo layer = Cfg.Layers.FirstOrDefault(f => f.CfgName == cfgname);
List<FieldCfg> fieldCfgs = layer.Fields.FindAll(x => x.SetNullField == property.FieldName);
foreach (FieldCfg fieldCfg in fieldCfgs)
{
if (fieldCfg.LengthWhere != null && !string.IsNullOrWhiteSpace(fieldCfg.LengthWhere.ToTrim()) && fieldCfg.NotSetNullValue != null && !string.IsNullOrWhiteSpace(fieldCfg.NotSetNullValue.ToTrim()))
{
int.TryParse(fieldCfg.LengthWhere, out int length);
if (setNullFieldValue == null || setNullFieldValue.Length < length)
{
SetNull(fieldCfg, feature, tempPropertyGridData);
continue;
}
var setnullvalue = fieldCfg.NotSetNullValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (setnullvalue == null || !setnullvalue.Contains(setNullFieldValue.Substring(0, length)))
{
SetNull(fieldCfg, feature, tempPropertyGridData);
}
}
else if (fieldCfg.SetNullValue != null)
{
if (string.IsNullOrWhiteSpace(fieldCfg.SetNullValue.ToTrim()))
{
SetNull(fieldCfg, feature, tempPropertyGridData);
continue;
}
var setnullvalue = fieldCfg.SetNullValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if ((string.IsNullOrEmpty(setNullFieldValue) && setnullvalue == null) || setnullvalue.Contains(setNullFieldValue))
{
SetNull(fieldCfg, feature, tempPropertyGridData);
}
}
else if (fieldCfg.NotSetNullValue != null && !string.IsNullOrWhiteSpace(fieldCfg.NotSetNullValue.ToTrim()))
{
var setnullvalue = fieldCfg.NotSetNullValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if ((string.IsNullOrEmpty(setNullFieldValue) && setnullvalue == null) || !setnullvalue.Contains(setNullFieldValue))
{
SetNull(fieldCfg, feature, tempPropertyGridData);
}
}
}
#endregion
if (property.PropertyType == enumPropertyType.ComboBox/* || property.PropertyType == enumPropertyType.MultiComboBox*/)
{
MyPropertyGrid.ItemsSource = null;
MyPropertyGrid.ItemsSource = singledata.Where(x => x.Visible).OrderBy(x => x.Order).ToList();
}
else if (singledata.Where(x => x.Visible).OrderBy(x => x.Order).ToList().Count != (MyPropertyGrid.ItemsSource as List<PropertyGridDataStruct>).Count)
{
MyPropertyGrid.ItemsSource = null;
MyPropertyGrid.ItemsSource = singledata.Where(x => x.Visible).OrderBy(x => x.Order).ToList();
}
}
catch (Exception ex)
{
LogAPI.Debug("属性改变事件期间 属性联动异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("属性改变事件期间 属性联动异常信息结束");
}
}
private void SetNull(FieldCfg fieldCfg, IFeature feature, PropertyGridDataStruct tempPropertyGridData)
{
try
{
if (fieldCfg.Name != null)
{
tempPropertyGridData = singledata.FirstOrDefault(a => a.FieldName == fieldCfg.Name);
if (tempPropertyGridData != null)
{
if (feature.Fields.FindField(fieldCfg.Name) > -1)
feature.set_Value(feature.Fields.FindField(fieldCfg.Name), DBNull.Value);
tempPropertyGridData.Value = null;
}
}
else if (fieldCfg.AliasName != null)
{
tempPropertyGridData = singledata.FirstOrDefault(a => a.Key == fieldCfg.AliasName);
if (tempPropertyGridData != null)
{
if (feature.Fields.FindFieldByAliasName(fieldCfg.AliasName) > -1)
feature.set_Value(feature.Fields.FindFieldByAliasName(fieldCfg.AliasName), DBNull.Value);
tempPropertyGridData.Value = null;
}
}
feature.Store();
}
catch (Exception ex)
{
LogAPI.Debug("设置属性为空异常:" + ex);
return;
}
}
public Action<string> DDTCBZChange;
public Action<string> CZCSXMChange;
#region IDockPanel接口
public Guid ID
{
get;
set;
}
public DockStyle _DockAreas;
public DockStyle DockAreas
{
get;
set;
}
public System.Drawing.Size FloatSize
{
get;
set;
}
public int DockWidth
{
get;
set;
}
public int DockHeight
{
get;
set;
}
public DockStyle DefaultArea
{
get;
set;
}
public bool ShowCloseButton
{
get;
set;
}
public bool ShowAutoHideButton
{
get;
set;
}
public string Title
{
get;
set;
}
public int ShowIndex { get; set; }
public bool ResetSize { get; set; }
public bool AllowEdit { get; set; }
public bool IsShow { get; set; }
#endregion
List<int> Listobjid_update = new List<int>();
List<int> Listobjid_insert = new List<int>();
public void SaveEdit()
{
try
{
#region 数据检查调用_旧
//Dictionary<string, List<int>> objids = GetAllEditOID() as Dictionary<string, List<int>>;
//if (objids != null)
//{
// IFeatureClass m_Fc = MapsManager.Instance.MapService.GetFeatureClassByName("DLTBBG");
// ProjectInfo projectInfo = (MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo);
// string dbPath = System.IO.Path.Combine(projectInfo.ProjDir, "DataCheckrResult.db");
// foreach (int oid in objids["修改"])
// {
// if (!Listobjid_update.Contains(oid))
// Listobjid_update.Add(oid);
// ExecuteDataCheck(m_Fc.GetFeature(oid));
// }
// foreach (int oid in objids["新增"])
// {
// if (!Listobjid_insert.Contains(oid))
// Listobjid_insert.Add(oid);
// ExecuteDataCheck(m_Fc.GetFeature(oid));
// }
// foreach (int oid in objids["删除"])
// {
// SQLiteDBOperate.Instance.ExecuteNonQuery(dbPath, $"delete from DataCheckResults WHERE OBJECTID='{oid}';", null);
// }
// if (objids["修改"].Count == 0)
// {
// foreach (var item in Listobjid_update)
// {
// ExecuteDataCheck(m_Fc.GetFeature(item));
// }
// }
// if (objids["新增"].Count == 0)
// {
// foreach (var item in Listobjid_insert)
// {
// ExecuteDataCheck(m_Fc.GetFeature(item));
// }
// }
//}
#endregion
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
public object GetAllEditOID()
{
IWorkspaceEdit2 workspaceEdit2 = (IWorkspaceEdit2)editor.EditWorkspace;
IDataChangesEx dataChangesEx = workspaceEdit2.get_EditDataChanges(esriEditDataChangesType.esriEditDataChangesWithinSession);
Dictionary<string, List<int>> objids = new Dictionary<string, List<int>>();
objids.Add("修改", new List<int>());
objids.Add("新增", new List<int>());
objids.Add("删除", new List<int>());
//获取当前要素类所有变化图形信息
IFIDSet fids = dataChangesEx.ChangedIDs["DLTBBG", esriDifferenceType.esriDifferenceTypeUpdateNoChange];
#region 参数
//准备输入参数
int featureOID = -1;
#endregion
fids.Next(out featureOID);
while (featureOID != -1)
{
if (!objids["修改"].Contains(featureOID))
objids["修改"].Add(featureOID);
fids.Next(out featureOID);
}
//获取删除图形信息
fids = dataChangesEx.ChangedIDs["DLTBBG", esriDifferenceType.esriDifferenceTypeDeleteNoChange];
fids.Next(out featureOID);
while (featureOID != -1)
{
if (!objids["删除"].Contains(featureOID))
objids["删除"].Add(featureOID);
fids.Next(out featureOID);
}
//获取插入图形信息
fids = dataChangesEx.ChangedIDs["DLTBBG", esriDifferenceType.esriDifferenceTypeInsert];
fids.Next(out featureOID);
while (featureOID != -1)
{
if (!objids["新增"].Contains(featureOID))
objids["新增"].Add(featureOID);
fids.Next(out featureOID);
}
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(fids);
return objids;
}
public void ExecuteDataCheck(IFeature feature)
{
IDataCheckHelper dataCheckHelper = UIShell.OSGi.BundleRuntime.Instance.GetFirstOrDefaultService<IDataCheckHelper>();
if (dataCheckHelper == null) return;
dataCheckHelper.DataCheckByThread(new CheckParametr()
{
CheckType = enumCheckType.Attribute | enumCheckType.Graphic,
DataSource = feature,
IDataCheckName = "BGQDataCheck"
});
}
private void SelectPZWJ_Click(object sender, System.Windows.RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog openFileDialog = null;
try
{
DevExpress.Xpf.Editors.ButtonInfo buttonInfo = (DevExpress.Xpf.Editors.ButtonInfo)((Button)sender).DataContext;
DevExpress.Xpf.Editors.ButtonEdit buttonEdit = (DevExpress.Xpf.Editors.ButtonEdit)buttonInfo.Parent;
object tag = buttonEdit.Tag;
List<PropertyGridDataStruct> lst = MyPropertyGrid.ItemsSource as List<PropertyGridDataStruct>;
//PropertyGridDataStruct p = lst.FirstOrDefault(x => x.Key.Equals("批准文件名称") || x.Key.Equals("附件"));
PropertyGridDataStruct p = lst.FirstOrDefault(x => x.Key.Equals(tag.ToString()));
int index = -1;
openFileDialog = new System.Windows.Forms.OpenFileDialog();
if (p.Key == "附件")
{
index = (this.Data as IFeature).Fields.FindField("XZGDFJ");
openFileDialog.Title = "选择新增耕地附件";
openFileDialog.Filter = "新增耕地附件(*.pdf)|*.pdf";
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = true;
}
else
{
index = (this.Data as IFeature).Fields.FindField("PZWJ_LSYD");
openFileDialog.Title = "选择临时用地批准文件";
openFileDialog.Filter = "临时用地批准文件(*.pdf)|*.pdf";
//openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
openFileDialog.RestoreDirectory = true;
}
//打开文件对话框选择的文件
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
if (editor == null)
{
editor = new EngineEditorClass();
}
editor.StartOperation();
(this.Data as IFeature).set_Value(index, DBNull.Value);
//editor.StopOperation("批准文件");
editor.StopOperation(p.Key);
p.Value = string.Empty;
return;
}
if (openFileDialog.FileName == null)
{
MessageHelper.ShowError("请选择文件!");
return;
}
if (editor == null)
{
editor = new EngineEditorClass();
}
editor.StartOperation();
if (p.Key == "附件")
{
p.Value = string.Join(";", openFileDialog.FileNames);
//int indexFj = (this.Data as IFeature).Fields.FindField("XZGDFJ");
(this.Data as IFeature).set_Value(index, string.Join(";", openFileDialog.FileNames));
//(this.Data as IFeature).Store();
}
else
{
p.Value = System.IO.Path.GetFileName(openFileDialog.FileName);
using (System.IO.FileStream fs = new System.IO.FileStream(openFileDialog.FileName, System.IO.FileMode.Open))
{
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
IMemoryBlobStream pMBS = new MemoryBlobStreamClass();
IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)pMBS;
object objValue = br.ReadBytes((int)fs.Length);
varBlobStream.ImportFromVariant(objValue);
(this.Data as IFeature).set_Value(index, varBlobStream);
fs.Close();
}
}
editor.StopOperation(p.Key);
}
catch (Exception ex)
{
MessageHelper.ShowError("选择文件异常:" + ex.Message);
}
finally
{
if (openFileDialog != null)
{
openFileDialog.Dispose();
}
}
}
UCShowFile uCShowFile = null;
private void BtnBrowse_Click(object sender, System.Windows.RoutedEventArgs e)
{
try
{
object obj = (this.Data as IFeature).get_Value((this.Data as IFeature).Fields.FindField("PZWJ_LSYD"));
if (obj == null || string.IsNullOrEmpty(obj.ToString()))
{
MessageHelper.ShowTips("浏览批准文件为空");
return;
}
KGIS.Framework.Platform.Helper.ProgressHelper.ShowProcessBar("正在加载文档......");
try
{
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(KGIS.Framework.Utils.SysAppPath.GetTempPath());
System.IO.FileInfo[] files = directory.GetFiles();
foreach (var item in files)
{
try
{
item.Delete();
}
catch { }
}
}
catch { }
object pzwjmc = (this.Data as IFeature).get_Value((this.Data as IFeature).Fields.FindField("PZWJMC_LSYD"));
if (pzwjmc == null)
pzwjmc = Guid.NewGuid() + ".pdf";
string tempPath = System.IO.Path.Combine(KGIS.Framework.Utils.SysAppPath.GetTempPath(), pzwjmc.ToString());
if (!System.IO.File.Exists(tempPath))
{
IMemoryBlobStream pMBS = new MemoryBlobStreamClass();
IMemoryBlobStreamVariant varBlobStream = (IMemoryBlobStreamVariant)obj;
object obj1 = null;
varBlobStream.ExportToVariant(out obj1);
using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Open(tempPath, System.IO.FileMode.OpenOrCreate)))
{
bw.Write(obj1 as byte[]);
bw.Close();
}
}
if (uCShowFile == null)
{
uCShowFile = new UCShowFile();
uCShowFile.Title = pzwjmc.ToString();
uCShowFile.Closed += UCShowFile_Closed;
uCShowFile.WindowState = WindowState.Maximized;
}
uCShowFile.BindData(tempPath, ".pdf");
uCShowFile.ShowInMainWindow(true);
}
catch (Exception ex)
{
KGIS.Framework.Platform.Helper.ProgressHelper.CloseProcessBar();
MessageHelper.ShowError("浏览批准文件异常:" + ex.Message);
}
finally
{
}
}
private void UCShowFile_Closed(object sender, EventArgs e)
{
if (uCShowFile != null)
uCShowFile = null;
}
//private void UIElement_OnGotFocus(object sender, RoutedEventArgs e)
//{
// (sender as ViewControls.ComboBox.AutoComboTextBox).ShowAllSuggestions();
//}
//private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
//{
// // PropertyChangedEvent();
//}
private List<DataDicTionary> GetNoGroupDic(string pDicType, List<DataDicTionary> dicList = null)
{
List<DataDicTionary> result = null;
try
{
string s = GetDicTypeID(pDicType);
if (string.IsNullOrWhiteSpace(s))
return result;
List<DataDicTionary> tempDic = dicList;
if (dicList == null || dicList.Count == 0)
tempDic = GetAllDic();
if (tempDic == null)
return result;
foreach (DataDicTionary item in tempDic)
{
if (item.OWNERDIC == s)
{
if (result == null)
{
result = new List<DataDicTionary>();
result.Add(new DataDicTionary() { CODE = "", NAME = "", DisplayName = "" });
}
if (result.FirstOrDefault(x => x.NAME == item.NAME && x.CODE == item.CODE) != null)
{
continue;//去重
}
result.Add(item);
}
}
}
catch (Exception ex)
{
throw ex;
}
return result;
}
private List<DataDicTionary> GetAllDic()
{
DataTable dt = null;
List<DataDicTionary> result = new List<DataDicTionary>();
IRDBHelper rdbHelper = null;
try
{
if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) != null)
{
string dbPath = ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) as ProjectInfo).GetDicDataPath();
if (!string.IsNullOrWhiteSpace(dbPath))
{
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
string strSQL = "select * from Sys_DicDetail";
dt = rdbHelper.ExecuteDatatable("Dic", strSQL, true);
if (dt != null)
{
result = KGIS.Framework.Utils.Utility.TBToList.ToList<DataDicTionary>(dt).OrderBy(x => x.CODE).ToList();
result.ForEach(x => x.DisplayName = x.CODE + "-" + x.NAME);
}
}
}
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
if (dt != null)
{
dt.Clear();
dt.Dispose();
}
}
return result;
}
private Dictionary<string, string> DicTypes = new Dictionary<string, string>();
public string GetDicTypeID(string pDicType, bool GetNewDic = false)
{
string result = string.Empty;
DataTable dtDicTypeID = null;
try
{
if (dtDicTypeID == null || GetNewDic)
{
IRDBHelper rdbHelper = null;
try
{
string dbPath = ((MapsManager.Instance.CurrProjectInfo as ProjectInfo) as ProjectInfo).GetDicDataPath();
if (string.IsNullOrWhiteSpace(dbPath))
{
LogAPI.Debug("GetDicDataPath 获取失败");
}
rdbHelper = RDBFactory.CreateDbHelper("Data Source=" + dbPath, DatabaseType.SQLite);
string strSQL = "select ID,ALIASNAME from Sys_DicManage ";
dtDicTypeID = rdbHelper.ExecuteDatatable("DicType", strSQL, true);
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
finally
{
if (rdbHelper != null)
{
rdbHelper.DisConnect();
}
}
}
if (dtDicTypeID != null && dtDicTypeID.Rows.Count > 0)
{
foreach (DataRow item in dtDicTypeID.Rows)
{
if (item[0] != null && !(item[0] is DBNull))
{
if (item[1].ToString() == pDicType.ToString())
result = item[0].ToString();
if (DicTypes.ContainsKey(item[0].ToString()))
continue;
DicTypes.Add(item[0].ToString(), item[1].ToString());
}
}
}
return result;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (dtDicTypeID != null)
{
dtDicTypeID.Clear();
dtDicTypeID.Dispose();
}
}
return string.Empty;
}
//private void MultiComboBox_PopupClosed(object sender, DevExpress.Xpf.Editors.ClosePopupEventArgs e)
//{
// DevExpress.Xpf.Editors.ComboBoxEdit comboBoxEdit = sender as DevExpress.Xpf.Editors.ComboBoxEdit;
// if (comboBoxEdit == null) return;
// var selectedItems = comboBoxEdit.SelectedItems;
// if (selectedItems == null || selectedItems.Count <= 0) return;
// PropertyGridDataStruct property = (PropertyGridDataStruct)comboBoxEdit.DataContext;
// string value = "";
// foreach (DataDicTionary item in selectedItems)
// {
// value += item.CODE + ",";
// }
// property.Value = value.TrimEnd(',');
// PropertyChangedEvent(property, null);
//}
}
}