using DevExpress.Xpf.Bars; 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 KUI.ComboBox; using KUI.Windows; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Xml; using System.Xml.Linq; namespace Kingo.Plugin.MapView.Views { public delegate void EditDicHandler(object sender); /// /// AttributeEdit.xaml 的交互逻辑 /// 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 Dics = null; public IHookHelper m_hookHelper; private IDataCatalogService catalogService = null; private List dLBMCompares = new List(); private List dLBM2017Compares = new List(); List kcxsList = new List(); List bhjclxList = new List(); private List gzflbzdm_nyd_bj = new List() { "0304", "0306", "0402", "0101", "0102", "0103", "0201", "0201A", "0204", "0204B", "0204C", "0204D", "0204F", "0204G", "0204H", "0301", "0301A", "0302", "0305", "0305A", "0307", "0307A", "0401", "0403", "0404", "0404A", "0404B", "1103", "1104", "1104A", "1107", "1107A", "1202", "1203" }; private NYYSInfo nYYSInfo = null; public AttributeEdit() { Platform.Instance.NotifyMsgEven2 += Instance_NotifyMsgEven2; 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 = "要素属性"; this.ID = Guid.NewGuid(); this.Loaded += (s, e) => { string cfgFilePath = System.IO.Path.Combine(SysAppPath.GetConfigPath(), "LayerFieldsCfg.xml"); if (!string.IsNullOrEmpty(cfgFilePath) && Cfg == null) Cfg = SerializeAPI.DeserializeToObject2(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 singledata = new List(); 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(); 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); } } /// /// 属性联动配置 /// public Linkage[] LinkageCfg { get; set; } //List singledata = null; #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; this.Data = obj; if (obj is IFeature feature) { if (feature.Class.AliasName == "地类图斑更新") isGetConfiguration = true; RefreshData(obj); } //MyPropertyGrid.ItemsSource = null; //if (singledata != null) //{ // if ((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE.StartsWith("51")) // { // singledata.ForEach(x => x.Visible = true); // } // 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; List singledata = null; try { ProjectInfo projectInfo = MapsManager.Instance.CurrProjectInfo as ProjectInfo; bool isBj = projectInfo.CODE.StartsWith("11"); if (catalogService == null) catalogService = Activator.BundleContext.GetFirstOrDefaultService(); singledata = new List(); 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++) { List removeLs = new List(); IField field = fe.Fields.get_Field(i); //if (SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43") && field.Name.Equals("BID"))//从BID字段开始,后面的字段都不显示了 //{ // break; //} 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 (!isBj) { 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" || currentDisplayType == "GZFLBZDM" || currentDisplayType == "DDTCBZ" || currentDisplayType == "SDXZ") && 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; } } else if (SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43") && fieldCfg.Fields.Count > 0) {//湖南配置子集通过sql隐藏某个属性 List sqlList = fieldCfg.Fields.Where(x => x.Sql != null).ToList(); foreach (FieldCfg item in sqlList) { if (GetAttrIsShow(fe, item, tempDisplayType, fieldCfg, ref p)) { removeLs.Add(item.Name); } } } 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 dataDicTionaries = new List(); 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 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; case enumPropertyType.MultiComboBox: if (!SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43")) { break; } p.PropertyType = enumPropertyType.MultiComboBox; #region 注释项 //if (fieldCfg.Fields.Count > 0) //{ // List dataDicTionaries = new List(); // 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 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); //} #endregion if (fieldCfg.Fields.Count > 0) { List dataDicTionaries = new List(); ProcessFieldCfg(fieldCfg, strDisplayType, tempDisplayType, Dics, ref dataDicTionaries, fe, ref p); } 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); } if (p.DicData != null) { p.DicData = p.DicData.Where(x => !string.IsNullOrWhiteSpace(x.CODE) && !string.IsNullOrWhiteSpace(x.NAME)).ToList(); } if (p.DicData == null || p.DicData.Count <= 0) { p.Visible = false; } break; 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 (p.DicData != null && p.DicData.Count > 0 && removeLs.Count > 0) { foreach (string item in removeLs) { if (item.Split(',').Length > 1) { string[] removes = item.Split(','); removes.ForEach(x => p.DicData.RemoveAll(y => y.CODE.Equals(x))); } else { p.DicData.RemoveAll(x => x.CODE.Equals(item)); } } } 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(); // } // p.MultiSelectDicData.Add(dicData.CODE); // } // } //} } if (isGetConfiguration && SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43") && fieldCfg.SetValueSql != null) { GetValueBySql(fe, fieldCfg.SetValueSql, fieldCfg.FieldName, ref p); } if (p.IsReadOnly == true) { p.FontColor = "#8E8E8E"; } else { p.FontColor = "#000000"; } if (fieldCfg != null) { if (fieldCfg.Name.Contains("_LSYD")) { if (SysConfigsOprator.GetAppsetingValueByKey("ArearName").Equals("43")) { p.Key = "附件"; string tcxx = singledata.FirstOrDefault(x => x.FieldName.ToUpper().Equals("DDTCBZ")).Value; if (!string.IsNullOrWhiteSpace(tcxx) && tcxx.Equals("1301")) { fieldCfg.AliasName = "批准文件名称"; p.Key = "批准文件名称"; } } else { p.FontColor = "#CC9933"; } } if (fieldCfg.Name.Contains("_GFBQ")) { p.FontColor = "#076DFD"; } } p.PropertyChanged += PropertyChangedEvent; if (p.FieldName.ToUpper() == "GZFLBZDM") { p.DicData = (p.DicData ?? new List()).Where(x => x.CODE.Length >= 4).ToList(); } if (Platform.Instance.SystemType == SystemTypeEnum.DTBJK) { p.IsReadOnly = true; } singledata.Add(p); } MyPropertyGrid.ItemsSource = null; if (singledata != null) { if ((MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo).CODE.StartsWith("51")) { singledata.ForEach(x => x.Visible = true); } MyPropertyGrid.ItemsSource = singledata.Where(x => x.Visible).OrderBy(x => x.Order).ToList(); } } catch (Exception ex) { if (ex.Message.Contains("种植作物“QT”时不可多选!") || ex.Message.Contains("地类编码非“01类”时不可多选!")) { MessageBox.Show(ex.Message); } else { LogAPI.Debug("属性表数据异常:" + ex.Message); LogAPI.Debug("属性表数据异常:" + ex.StackTrace); throw ex; } } } private void ReadBHJCLXConfig() { if (bhjclxList.Count > 0) { return; } string filePath = Path.Combine(Directory.GetCurrentDirectory(), "Configs", "DLBHAndGLBMConfig.xml"); XDocument doc = XDocument.Load(filePath); bhjclxList = doc.Descendants("Configuration") .Select(config => new BHJCLX { OldDLBM = config.Attribute("OldDLBM")?.Value, NewDLBM = config.Attribute("NewDLBM")?.Value, JCLX = config.Attribute("JCLX")?.Value, Priority = int.Parse(config.Attribute("Priority")?.Value), GLBM = config.Attribute("GLBM")?.Value, CheckDDTC = bool.TryParse(config.Attribute("CheckDDTC")?.Value, out bool checkDDTC) ? checkDDTC : false, DDTCDM = config.Attribute("DDTCDM")?.Value, }).ToList(); } private void ReadKCXSConfig() { if (kcxsList.Count > 0) { return; } string filePath = Path.Combine(Directory.GetCurrentDirectory(), "Configs", "BJKCXSConfig.xml"); XDocument doc = XDocument.Load(filePath); kcxsList = doc.Descendants("KCXSConfig") .Select(config => new BJKCXS { XZQDM = config.Attribute("XZQDM")?.Value, XZQMC = config.Attribute("XZQMC")?.Value, KCXSDatas = config.Elements("KCXSData") .Select(data => new KCXSData { GDLX = data.Attribute("GDLX")?.Value, PDJB = data.Attribute("PDJB")?.Value, KCXS = data.Attribute("KCXS")?.Value }).ToList() }).ToList(); } private void LoadDLBMConfigs() { if (dLBMCompares.Count > 0 && dLBM2017Compares.Count > 0) { return; } string filePath = Path.Combine(Directory.GetCurrentDirectory(), "Configs", "DLBMCompare.xml"); if (!File.Exists(filePath)) { throw new Exception($"配置文件未找到:{filePath}"); } XDocument doc = XDocument.Load(filePath); if (dLBMCompares.Count <= 0) { foreach (XElement element in doc.Descendants("DLBMConfig")) { DLBMCompare config = new DLBMCompare { SourceDlbm = element.Attribute("GZFLBZDM")?.Value, TargetDlbm = element.Attribute("DLBM")?.Value, TargetDlmc = element.Attribute("DLMC")?.Value }; dLBMCompares.Add(config); } } if (dLBM2017Compares.Count <= 0) { foreach (XElement element in doc.Descendants("DLBM2017Config")) { DLBMCompare config = new DLBMCompare { SourceDlbm = element.Attribute("GZFLBZDM")?.Value, TargetDlbm = element.Attribute("DLBM")?.Value, TargetDlmc = element.Attribute("DLMC")?.Value }; dLBM2017Compares.Add(config); } } } 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 /// /// 湖南地区需求 判定申诉说明字段 根据省级反馈意见为不通过的才能填写 /// /// 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 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(); } } /// /// 通过数据来源判断是否要显示一些属性--湖南 /// /// /// /// /// private bool IsShowAttrbute(IFeature feature, FieldCfg f) { if (string.IsNullOrEmpty(f.FieldName) || string.IsNullOrWhiteSpace(taskPackagePath) || !System.IO.File.Exists(taskPackagePath)) return true; List fieldNames = f.FieldName.Split(',').ToList(); string[] values = new string[fieldNames.Count]; IRDBHelper rdbHelper = null; try { string SqlField = f.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) { values[i] = feature.Value[ifield].ToString(); } else { values[i] = ""; } } string formattedSql = string.Format(f.Sql, values); if (f.JudgeVisibleValue.ToLower().Equals("notnull")) { var bsmObj = rdbHelper.ExecuteScalar(formattedSql, CommandType.Text); if (bsmObj != null && !string.IsNullOrEmpty(bsmObj.ToString())) { return false; } else { if (f.Fields.Count > 0) { return true; } else { return false; } } } else { DataTable dicDt = rdbHelper.ExecuteDatatable("Dic", formattedSql, true); if (dicDt != null) { if (dicDt.Rows.Count <= 0) { if (bool.Parse(f.JudgeVisibleValue)) { return true; } else { return false; } } foreach (DataRow dr in dicDt.Rows) { string zl = dr[SqlField].ToTrim(); if (zl == f.JudgeVisibleValue) { return false; } } } } return true; } catch (Exception ex) { LogAPI.Debug($"通过Sql控制隐藏属性异常:{ex.Message}"); LogAPI.Debug($"通过Sql控制隐藏属性异常:{ex.StackTrace}"); return true; } finally { rdbHelper?.DisConnect(); } } /// /// 获取配置属性是否展示--湖南 /// /// /// /// /// /// /// private bool GetAttrIsShow(IFeature feature, FieldCfg f, string tempDisplayType, FieldCfg fieldCfg, ref PropertyGridDataStruct p) { if (f.Sql != null) { if (IsShowAttrbute(feature, f)) { if (f.Fields.Count > 0) { foreach (FieldCfg item in f.Fields) { if (!string.IsNullOrWhiteSpace(tempDisplayType) && !string.IsNullOrWhiteSpace(item.DisplayWhere)) { string strChildDisplayType = string.Empty; int iDisplayType = feature.Fields.FindField(item.DisplayType != null ? item.DisplayType : tempDisplayType); if (iDisplayType > -1) strChildDisplayType = feature.Value[iDisplayType].ToString(); if (item.Name.Split(',').Contains(strChildDisplayType)) { return false; } else { p.Visible = false; return true; } } } } else { p.Visible = false; return true; } } else { return false; } } return false; } /// /// 通过Sql获取配置字段值--湖南 /// /// /// /// /// private void GetValueBySql(IFeature feature, string Sql, string FieldName, ref PropertyGridDataStruct p) { if (string.IsNullOrEmpty(FieldName) || string.IsNullOrWhiteSpace(taskPackagePath) || !System.IO.File.Exists(taskPackagePath)) return; List fieldNames = FieldName.Split(',').ToList(); IRDBHelper rdbHelper = null; try { string SqlField = Sql.ToLower().Split(new string[] { "select" }, StringSplitOptions.None)[1].Split(new string[] { "from" }, StringSplitOptions.None)[0].Trim(); string[] values = new string[fieldNames.Count]; 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) { values[i] = feature.Value[ifield].ToString(); } else { values[i] = ""; } } string formattedSql = string.Format(Sql, values); DataTable dicDt = rdbHelper.ExecuteDatatable("value", formattedSql, true); if (dicDt != null && dicDt.Rows.Count > 0) { string value = (dicDt.Rows[0][0] ?? "").ToString(); p.Value = value; } } catch (Exception ex) { LogAPI.Debug($"通过Sql获取值异常:{ex.Message}"); LogAPI.Debug($"通过Sql获取值异常:{ex.StackTrace}"); } finally { rdbHelper?.DisConnect(); } } //private void ChangeDicData(PropertyGridDataStruct item,) //{ //} /// /// 初始化属性联动配置 /// private void InitLinkageCfg() { if (LinkageCfg != null) LinkageCfg = null; #region 建库 //List list = new List //{ // 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 list = new List(); 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 = "ZZZWSM", TargetPropertyAliasName = "种植作物说明", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = true, IsSourceValue = true }); list.Add(new Linkage() { SourcePropertyName = "LYZTDM", SourcePropertyAliasName = "利用状态代码", TargetPropertyName = "LYZTMC", TargetPropertyAliasName = "利用状态名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false }); list.Add(new Linkage() { SourcePropertyName = "SSXTDM", SourcePropertyAliasName = "设施形态代码", TargetPropertyName = "SSXTMC", TargetPropertyAliasName = "设施形态名称", LinkageType = EnumLinkageType.KeyValueEqual, IsGroup = false }); list.Add(new Linkage() { SourcePropertyName = "DDTCBZ", SourcePropertyAliasName = "单独图层代码", TargetPropertyName = "DDTCMC", TargetPropertyAliasName = "单独图层名称", 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 Source = new List(); Source = MyPropertyGrid.ItemsSource as List; IEnumerable list = LinkageCfg.Where(w => w.SourcePropertyName == property.Key || w.SourcePropertyAliasName == property.Key); foreach (Linkage item in list) { IEnumerable 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 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 Source = new List(); // Source = singledata;//MyPropertyGrid.ItemsSource as List; // IEnumerable list = LinkageCfg.Where(w => w.SourcePropertyName == property.Key || w.SourcePropertyAliasName == property.Key).ToList(); // foreach (Linkage item in list) // { // IEnumerable 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 (item.IsSourceValue) // { // p.Value = property.Value; // } // #region 注释代码 // //if (!(Data is IFeature)) // // return; // //bool isFea = false; // //try // //{ // // isFea = Data is IFeature; // //} // //catch (Exception ex) // //{ // // System.Runtime.InteropServices.Marshal.ReleaseComObject(Data); // // Data = null; // // if (nYYSInfo == null) // // { // // throw; // // } // // if (nYYSInfo.DTBDLTBGX != null) // // { // // Data = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG").FeatureClass.GetFeature(nYYSInfo.DTBDLTBGX.ObjectID); // // } // // else if (nYYSInfo.WYRWTB != null) // // { // // Data = MapsManager.Instance.MapService.GetFeatureLayerByName("WYRW").FeatureClass.GetFeature(nYYSInfo.WYRWTB.ObjectID); // // } // // else // // { // // throw; // // } // // isFea = Data is IFeature; // //} // //if (!isFea) // // 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 // //{ // // if ((item.TargetPropertyName ?? "").Equals("DLMC")) // // { // // LogAPI.Debug($"dlmc:{p.Value}"); // // } // // //(Data as IFeature).set_Value(pindex, p.Value); // //} // //(Data as IFeature).Store(); // #endregion // break; // } // } // } // } #endregion bool isFe = false; isFe = Data is IFeature; if (!isFe) 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); } } //父级或关联字段属性修改,子级属性赋值为空 #region //string setNullFieldValue = string.Empty; //int setNullFieldIndex = (Data as IFeature).Fields.FindField(property.FieldName); //if (setNullFieldIndex > -1) // setNullFieldValue = (Data as IFeature).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)}"; //string cfgname = $"单图斑地类图斑更新_{(MapsManager.Instance.CurrProjectInfo as ProjectInfo).CODE.Substring(0, 2)}"; //if (!cfgname.StartsWith("单图斑地类图斑更新")) // cfgname = cfgname.Split('_')[0].ToSafeString(); //if (!cfgname.StartsWith("单图斑地类图斑更新")) //{ // return; //} //LayerInfo layer = Cfg.Layers.FirstOrDefault(f => f.CfgName == cfgname); //List 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 (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); //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).Count) //{ // MyPropertyGrid.ItemsSource = null; // MyPropertyGrid.ItemsSource = singledata.Where(x => x.Visible).OrderBy(x => x.Order).ToList(); //} //MyPropertyGrid.ItemsSource = null; //MyPropertyGrid.ItemsSource = singledata.Where(x => x.Visible).OrderBy(x => x.Order).ToList(); MyPropertyGrid.ItemsSource = MyPropertyGrid.ItemsSource; } 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; } } #region FieldCfg多子级情况使用递归避免重复写遍历--只适用于类似类举类型情况 private void ProcessFieldCfg(FieldCfg fieldCfg, string strDisplayType, string tempDisplayType, List Dics, ref List dataDicTionaries, IFeature fe, ref PropertyGridDataStruct p) { if (fieldCfg.Fields.Count > 0) { foreach (var iFields in fieldCfg.Fields) { if (iFields.Name.Split(',').Contains(strDisplayType)) { ProcessFieldCfgChild(iFields, strDisplayType, tempDisplayType, Dics, ref dataDicTionaries, fe, ref p); } } } else { var fieldCfg_child = fieldCfg.Fields.FirstOrDefault(x => x.Name.Split(',').Contains(strDisplayType)); if (fieldCfg_child != null) { ProcessFieldCfgChild(fieldCfg_child, strDisplayType, tempDisplayType, Dics, ref dataDicTionaries, fe, ref p); } } } private void ProcessFieldCfgChild(FieldCfg fieldCfg_child, string strDisplayType, string tempDisplayType, List Dics, ref List dataDicTionaries, IFeature fe, ref PropertyGridDataStruct p) { if (fieldCfg_child.Fields.Count > 0) { foreach (var item in fieldCfg_child.Fields) { if (!string.IsNullOrWhiteSpace(tempDisplayType) && (!string.IsNullOrWhiteSpace(item.DisplayWhere) || item.Fields.Count > 0)) { 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)) { ProcessFieldCfgChild(item, strChildDisplayType, tempDisplayType, Dics, ref dataDicTionaries, fe, ref p); } } } } ProcessDisplayConditions(fieldCfg_child, Dics, ref dataDicTionaries, ref p); } private void ProcessDisplayConditions(FieldCfg fieldCfg_child, List Dics, ref List dataDicTionaries, ref PropertyGridDataStruct p) { if (fieldCfg_child != null) { if (fieldCfg_child.DisplayWhere != null && !string.IsNullOrWhiteSpace(fieldCfg_child.DisplayWhere.Trim())) { var displaywhere = fieldCfg_child.DisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var dic = GetNoGroupDic(fieldCfg_child.DicName, Dics); if (dic != null && dic.Count > 0) { for (int j = 0; j < displaywhere.Length; j++) { var dataDicTionary = dic.FirstOrDefault(x => x.CODE.Trim().Equals(displaywhere[j])); if (dataDicTionary != null) dataDicTionaries.Add(dataDicTionary); } } p.DicData = dataDicTionaries; } if (!string.IsNullOrWhiteSpace((fieldCfg_child.DontDisplayWhere ?? "").Trim())) { var displaywhere = fieldCfg_child.DontDisplayWhere.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var dic = GetNoGroupDic(fieldCfg_child.DicName, Dics); foreach (var displayItem in displaywhere) { var dataDic = dic.FindAll(x => x.CODE.Equals(displayItem)); if (dataDic != null) { foreach (var data in dataDic) { dic.Remove(data); } } } p.DicData = dic; } } else { p.DicData = GetNoGroupDic(fieldCfg_child.DicName, Dics); } } #endregion private void IsShowAttrByRecursion(FieldCfg fieldCfg, IFeature fe, ref PropertyGridDataStruct p) { if (fieldCfg.Display != null) { var displayTypes = fieldCfg.DisplayType.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string strDisplayType = string.Empty; if (fieldCfg.Fields.Count > 0) { foreach (FieldCfg item in fieldCfg.Fields) { IsShowAttrByRecursion(item, fe, ref p); } } else { bool isVisible = false; foreach (var currentDisplayType in displayTypes) { int iDisplayType = fe.Fields.FindField(currentDisplayType); if (iDisplayType > -1) strDisplayType = fe.Value[iDisplayType].ToString(); if (string.IsNullOrWhiteSpace(strDisplayType)) { //地类编码为空 不加载其他信息 //if (!fieldCfg.StillShow) // p.Visible = false; isVisible = false; break; } else { isVisible = true; } } if (isVisible) { p.Visible = true; } } } } public Action DDTCBZChange; public Action 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 Listobjid_update = new List(); List Listobjid_insert = new List(); public void SaveEdit() { try { #region 数据检查调用_旧 //Dictionary> objids = GetAllEditOID() as Dictionary>; //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> objids = new Dictionary>(); objids.Add("修改", new List()); objids.Add("新增", new List()); objids.Add("删除", new List()); //获取当前要素类所有变化图形信息 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(); 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 lst = MyPropertyGrid.ItemsSource as List; //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; } this.ShowLoading("正在加载文档……", 0, 0); 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"); this.CloseLoading(); uCShowFile.ShowInMainWindow(true); } catch (Exception ex) { this.CloseLoading(); MessageHelper.ShowError("浏览批准文件异常:" + ex.Message); } finally { this.CloseLoading(); } } 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 GetNoGroupDic(string pDicType, List dicList = null) { List result = null; try { string s = GetDicTypeID(pDicType); if (string.IsNullOrWhiteSpace(s)) return result; List 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(); 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 static List result { get; set; } private List GetAllDic() { DataTable dt = null; //List result = new List(); IRDBHelper rdbHelper = null; try { //避免重复打开字典提示被占用 if (result != null && result.Count > 0) { return result; } result = new List(); 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(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 DicTypes = new Dictionary(); 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 (pDicType != null && 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; PropertyGridDataStruct property = (PropertyGridDataStruct)comboBoxEdit.DataContext; if (selectedItems == null || selectedItems.Count <= 0) { property.Value = ""; PropertyChangedEvent(property, null); //return; } else { string value = ""; foreach (DataDicTionary item in selectedItems) { value += item.CODE + ","; } property.Value = value.TrimEnd(','); PropertyChangedEvent(property, null); } } private void ComboBox_TextChanged(object sender, TextChangedEventArgs e) { AutoCompleteBox autoCompleteBox = sender as AutoCompleteBox; if (autoCompleteBox == null) return; PropertyGridDataStruct property = autoCompleteBox.DataContext as PropertyGridDataStruct; if (property == null) return; if (string.IsNullOrEmpty(autoCompleteBox.Text)) { property.Value = ""; } else { if (autoCompleteBox.SelectedValue != null) { property.Value = autoCompleteBox.SelectedValue.ToString(); } } PropertyChangedEvent(property, null); } } }