using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geodatabase; using KGIS.Framework.DBOperator; using KGIS.Framework.Maps; using KGIS.Framework.Platform; using KGIS.Framework.Utils; using KGIS.Framework.Utils.Helper; using Kingo.Plugin.General.Model; using Kingo.PluginServiceInterface; using Kingo.PluginServiceInterface.Model; using KUI.Windows; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using static Kingo.PluginServiceInterface.Model.BatchAttribute; namespace Kingo.Plugin.General.ViewDTBJK { /// /// UCSetBatchAttribute.xaml 的交互逻辑 /// public partial class UCSetBatchAttribute : BaseWindow { private ProjectInfo ProjectInfo { get; set; } private TaskPackage _taskPackage { get; set; } List Dics = null; private Dictionary AttributeBMAndName { get; set; } List listTBBSM { get; set; } public UCSetBatchAttribute() { InitializeComponent(); SetFieldsPage.Visibility = Visibility.Collapsed; SetTBPage.Visibility = Visibility.Collapsed; listTBBSM = new List(); AttributeBMAndName = new Dictionary() { { "DDTCBZ", "DDTCMC" }, { "DLBM", "DLMC" }, { "TBXHDM", "TBXHMC" }, { "ZZSXDM", "ZZSXMC" } }; } public void BindData(TaskPackage taskPackage) { try { _taskPackage = taskPackage; ProjectInfo = KGIS.Framework.Maps.MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; if (Platform.Instance.DicHelper != null && (Dics == null || Dics.Count == 0)) { Dics = Platform.Instance.DicHelper.GetAllDic(); } gridPackage.ItemsSource = null; gridPackage.ItemsSource = InitListBatchAttributes(taskPackage); dgSetTBTableMapping.ItemsSource = null; listTBBSM = GetAllTBBSM(); dgSetTBTableMapping.ItemsSource = listTBBSM; } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.BindData 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.BindData 异常:" + ex.StackTrace); } } private List InitListBatchAttributes(TaskPackage taskPackage) { IRDBHelper rDBHelper = null; try { string packagePath = taskPackage.PackagePath; if (ProjectInfo == null) return null; if (ProjectInfo.ListBatchAttributes == null || ProjectInfo.ListBatchAttributes.Count == 0) { if (taskPackage.PackageTempPath != null && File.Exists(taskPackage.PackageTempPath)) packagePath = taskPackage.PackageTempPath; rDBHelper = RDBFactory.CreateDbHelper($"{packagePath}{ProjectInfo.Pathpassword}", DatabaseType.SQLite); DataTable dataTable = rDBHelper.ExecuteDatatable("data", "SELECT * FROM DTBDLTBGX;", true); if (dataTable == null) { LogAPI.Debug("未找到DTBDLTBGX文件中存在表或者DTBDLTBGX文件数据为空!"); return null; } LayerFieldCfg Cfg = null; string cfgFilePath = System.IO.Path.Combine(SysAppPath.GetConfigPath(), "LayerFieldsCfg.xml"); if (!string.IsNullOrEmpty(cfgFilePath) && Cfg == null) Cfg = SerializeAPI.DeserializeToObject2(cfgFilePath); string cfgname = $"{"单图斑地类图斑更新"}_{ProjectInfo.CODE.Substring(0, 2)}"; LayerInfo layer = Cfg.Layers.FirstOrDefault(f => f.CfgName == cfgname); //LayerInfo layer = Cfg.Layers[0]; string fieldValue = ""; foreach (FieldCfg Fielditem in layer.Fields) { if (Fielditem.IsReadOnly == true) continue; if (AttributeBMAndName.ContainsValue(Fielditem.Name.ToUpper()) || (Fielditem.DicName != null && AttributeBMAndName.ContainsValue(Fielditem.DicName.ToUpper()))) continue; fieldValue = ""; BatchAttribute tempBatchAttribute = new BatchAttribute(); enumPropertyType PropertyType = Fielditem.EnumPropertyType == null ? enumPropertyType.TextBox : (enumPropertyType)System.Enum.Parse(typeof(enumPropertyType), Fielditem.EnumPropertyType); tempBatchAttribute.PropertyType = PropertyType; if (PropertyType == enumPropertyType.ComboBox) { var dic = GetNoGroupDic(Fielditem.DicName, Dics); tempBatchAttribute.DicData = dic; } if (Fielditem.DicName != null && dataTable.Columns.Contains(Fielditem.DicName)) { fieldValue = dataTable.Rows[0][Fielditem.DicName].ToString(); tempBatchAttribute.AttributeName = Fielditem.DicName; tempBatchAttribute.AttributeAliasName = Fielditem.AliasName; tempBatchAttribute.AttributeValue = fieldValue; ProjectInfo.ListBatchAttributes.Add(tempBatchAttribute); } else if (Fielditem.Name != null && dataTable.Columns.Contains(Fielditem.Name)) { fieldValue = dataTable.Rows[0][Fielditem.Name].ToString(); tempBatchAttribute.AttributeName = Fielditem.Name; tempBatchAttribute.AttributeAliasName = Fielditem.AliasName; tempBatchAttribute.AttributeValue = fieldValue; ProjectInfo.ListBatchAttributes.Add(tempBatchAttribute); } } ProjectInfo.Save(); } return ProjectInfo.ListBatchAttributes; } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute InitListBatchAttributes 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute InitListBatchAttributes 异常:" + ex.StackTrace); return ProjectInfo.ListBatchAttributes; } finally { if (rDBHelper != null) rDBHelper.DisConnect(); } } 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 List GetAllDic() { DataTable dt = null; List result = new List(); 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(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 (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 BtnSetFieldsTable_Click(object sender, RoutedEventArgs e) { try { SetFieldsPage.Visibility = Visibility.Visible; dgTableMapping.ItemsSource = null; dgTableMapping.ItemsSource = GetAllBatchAttributes(); } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.BtnSetFieldsTable_Click 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.BtnSetFieldsTable_Click 异常:" + ex.StackTrace); } } private List GetAllBatchAttributes() { List batchAttributes = new List(); IRDBHelper rDBHelper = null; if (ProjectInfo == null) return null; try { string packagePath = _taskPackage.PackagePath; if (_taskPackage.PackageTempPath != null && File.Exists(_taskPackage.PackageTempPath)) packagePath = _taskPackage.PackageTempPath; rDBHelper = RDBFactory.CreateDbHelper($"{packagePath}{ProjectInfo.Pathpassword}", DatabaseType.SQLite); DataTable dataTable = rDBHelper.ExecuteDatatable("data", "SELECT * FROM DTBDLTBGX;", true); if (dataTable == null) { LogAPI.Debug("未找到DTBDLTBGX文件中存在表或者DTBDLTBGX文件数据为空!"); return null; } LayerFieldCfg Cfg = null; string cfgFilePath = System.IO.Path.Combine(SysAppPath.GetConfigPath(), "LayerFieldsCfg.xml"); if (!string.IsNullOrEmpty(cfgFilePath) && Cfg == null) Cfg = SerializeAPI.DeserializeToObject2(cfgFilePath); string cfgname = $"{"单图斑地类图斑更新"}_{ProjectInfo.CODE.Substring(0, 2)}"; LayerInfo layer = Cfg.Layers.FirstOrDefault(f => f.CfgName == cfgname); //LayerInfo layer = Cfg.Layers[0]; string fieldValue = ""; foreach (FieldCfg Fielditem in layer.Fields) { if (Fielditem.IsReadOnly == true) continue; if (AttributeBMAndName.ContainsValue(Fielditem.Name.ToUpper()) || (Fielditem.DicName != null && AttributeBMAndName.ContainsValue(Fielditem.DicName.ToUpper()))) continue; fieldValue = ""; BatchAttribute tempBatchAttribute = new BatchAttribute(); enumPropertyType PropertyType = Fielditem.EnumPropertyType == null ? enumPropertyType.TextBox : (enumPropertyType)System.Enum.Parse(typeof(enumPropertyType), Fielditem.EnumPropertyType); tempBatchAttribute.PropertyType = PropertyType; if (PropertyType == enumPropertyType.ComboBox) { var dic = GetNoGroupDic(Fielditem.DicName, Dics); tempBatchAttribute.DicData = dic; } if (Fielditem.DicName != null && dataTable.Columns.Contains(Fielditem.DicName)) { fieldValue = dataTable.Rows[0][Fielditem.DicName].ToString(); tempBatchAttribute.AttributeName = Fielditem.DicName; tempBatchAttribute.AttributeAliasName = Fielditem.AliasName; tempBatchAttribute.AttributeValue = fieldValue; batchAttributes.Add(tempBatchAttribute); } else if (Fielditem.Name != null && dataTable.Columns.Contains(Fielditem.Name)) { fieldValue = dataTable.Rows[0][Fielditem.Name].ToString(); tempBatchAttribute.AttributeName = Fielditem.Name; tempBatchAttribute.AttributeAliasName = Fielditem.AliasName; tempBatchAttribute.AttributeValue = fieldValue; batchAttributes.Add(tempBatchAttribute); } } return batchAttributes; } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute InitListBatchAttributes 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute InitListBatchAttributes 异常:" + ex.StackTrace); return batchAttributes; } finally { if (rDBHelper != null) rDBHelper.DisConnect(); } } /// /// 刷新列表 /// /// /// private void BtnRefresh_Click(object sender, RoutedEventArgs e) { gridPackage.ItemsSource = InitListBatchAttributes(_taskPackage); } private void BtnSaveBatchAttribute_Click(object sender, RoutedEventArgs e) { IRDBHelper rDBHelper = null; IFeatureCursor _cursor = null; try { string packagePath = _taskPackage.PackagePath; if (ProjectInfo == null) return; ProjectInfo.ListBatchAttributes = gridPackage.ItemsSource as List; if (ProjectInfo.ListBatchAttributes == null || ProjectInfo.ListBatchAttributes.Count == 0) return; if (this.dgSetTBTableMapping == null || (dgSetTBTableMapping.ItemsSource as List) == null || (dgSetTBTableMapping.ItemsSource as List).Count == 0) { MessageHelper.ShowTips("未设置图斑列表或需要修改的图斑列表是空"); LogAPI.Debug("未设置图斑列表或需要修改的图斑列表是空"); return; } //listTBBSM = dgSetTBTableMapping.ItemsSource as List; if (listTBBSM == null || listTBBSM.Count == 0) { MessageHelper.ShowTips("未设置图斑列表或需要修改的图斑列表是空"); LogAPI.Debug("未设置图斑列表或需要修改的图斑列表是空"); return; } string btbsms = string.Join("','", listTBBSM.FindAll(a => a.IsCheck).Select(x => x.tbbsm)); IFeatureLayer DtbFeatureLayer = MapsManager.Instance.MapService.GetFeatureLayerByName("DLTBBG"); if (_taskPackage.PackageTempPath != null && File.Exists(_taskPackage.PackageTempPath)) packagePath = _taskPackage.PackageTempPath; rDBHelper = RDBFactory.CreateDbHelper($"{packagePath}{ProjectInfo.Pathpassword}", DatabaseType.SQLite); DataTable dataTable = rDBHelper.ExecuteDatatable("data", $"SELECT * FROM DTBDLTBGX;", true); if (dataTable == null || dataTable.Rows.Count <= 0) return; this.ShowLoading("正在批量赋属性值,请稍后......", 0, 0); string nameForValue = ""; foreach (BatchAttribute currentBatchAttribute in ProjectInfo.ListBatchAttributes) { if (!dataTable.Columns.Contains(currentBatchAttribute.AttributeName)) continue; if (currentBatchAttribute.DicData != null && AttributeBMAndName.ContainsKey(currentBatchAttribute.AttributeName.ToUpper())) { AttributeBMAndName.TryGetValue(currentBatchAttribute.AttributeName.ToUpper(), out string name); if (dataTable.Columns.Contains(name)) { nameForValue = currentBatchAttribute.DicData.FirstOrDefault(a => a.CODE == currentBatchAttribute.AttributeValue).NAME; rDBHelper.ExecuteNonQueryWithException(string.Format("update dtbdltbgx set {0}='{1}' WHERE BSM in ('{2}') ", name, nameForValue, btbsms), CommandType.Text); if (DtbFeatureLayer != null && DtbFeatureLayer as FeatureClass != null) (DtbFeatureLayer as FeatureClass).Workspace.ExecuteSQL(string.Format("update DLTBBG set {0}='{1}' WHERE BSM in ('{2}') ", name, nameForValue, btbsms)); } } if ("TBMJ,KCXS,KCMJ,TBDLMJ,XZDWKD,GDDB,SJNF".Contains(currentBatchAttribute.AttributeName)) { if (string.IsNullOrEmpty(currentBatchAttribute.AttributeValue)) rDBHelper.ExecuteNonQueryWithException(string.Format("update dtbdltbgx set {0}={1} WHERE BSM in ('{2}') ", currentBatchAttribute.AttributeName, 0, btbsms), CommandType.Text); else rDBHelper.ExecuteNonQueryWithException(string.Format("update dtbdltbgx set {0}={1} WHERE BSM in ('{2}') ", currentBatchAttribute.AttributeName, currentBatchAttribute.AttributeValue, btbsms), CommandType.Text); } else rDBHelper.ExecuteNonQueryWithException(string.Format("update dtbdltbgx set {0}='{1}' WHERE BSM in ('{2}') ", currentBatchAttribute.AttributeName, currentBatchAttribute.AttributeValue, btbsms), CommandType.Text); //更新矢量图层 if (DtbFeatureLayer != null && DtbFeatureLayer as FeatureClass != null && DtbFeatureLayer.FeatureClass != null) { int fieldIndex = DtbFeatureLayer.FeatureClass.Fields.FindField(currentBatchAttribute.AttributeName); if (fieldIndex > -1) { esriFieldType fieldType = DtbFeatureLayer.FeatureClass.Fields.Field[fieldIndex].Type; if (fieldType == esriFieldType.esriFieldTypeDouble) { if (string.IsNullOrEmpty(currentBatchAttribute.AttributeValue)) (DtbFeatureLayer as FeatureClass).Workspace.ExecuteSQL(string.Format("update DLTBBG set {0}={1} WHERE BSM in ('{2}') ", currentBatchAttribute.AttributeName, 0, btbsms)); else (DtbFeatureLayer as FeatureClass).Workspace.ExecuteSQL(string.Format("update DLTBBG set {0}={1} WHERE BSM in ('{2}') ", currentBatchAttribute.AttributeName, currentBatchAttribute.AttributeValue, btbsms)); } else if (fieldType == esriFieldType.esriFieldTypeString) { (DtbFeatureLayer as FeatureClass).Workspace.ExecuteSQL(string.Format("update DLTBBG set {0}='{1}' WHERE BSM in ('{2}') ", currentBatchAttribute.AttributeName, currentBatchAttribute.AttributeValue, btbsms)); } } } } //继承属性 _cursor = DtbFeatureLayer.FeatureClass.Update(new QueryFilterClass() { WhereClause = $"BSM in ('{btbsms}')" }, false); IFeature f = null; int idx = DtbFeatureLayer.FeatureClass.FindField("BSM"); if (idx > -1) { while ((f = _cursor.NextFeature()) != null) { UpdateAttributeEntity updateAttributeEntity = new UpdateAttributeEntity() { feature = f, rdbHelper = rDBHelper }; Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "UpdateAttribute", Content = updateAttributeEntity }); _cursor.UpdateFeature(f); } } this.CloseLoading(); MessageHelper.ShowTips("批量保存完成"); this.Close(); } catch (Exception ex) { this.CloseLoading(); LogAPI.Debug("UCSetBatchAttribute.批量保存属性值异常 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.批量保存属性值异常 异常:" + ex.StackTrace); MessageHelper.ShowTips("批量保存属性值异常:" + ex.Message); } finally { this.CloseLoading(); if (rDBHelper != null) rDBHelper.DisConnect(); } } #region 字段显示设置页面 /// /// 保存显示的字段 /// /// /// private void BtnSave_Click(object sender, RoutedEventArgs e) { try { List batchAttributes = dgTableMapping.ItemsSource as List; if (batchAttributes == null || batchAttributes.Count == 0) return; List tempBatchAttributes = batchAttributes.FindAll(a => a.IsCheck == true); ProjectInfo.ListBatchAttributes = tempBatchAttributes; ProjectInfo.Save(); SetFieldsPage.Visibility = Visibility.Collapsed; gridPackage.ItemsSource = null; gridPackage.ItemsSource = InitListBatchAttributes(_taskPackage); } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.BtnSave_Click 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.BtnSave_Click 异常:" + ex.StackTrace); } } private void BtnClose_Click(object sender, RoutedEventArgs e) { SetFieldsPage.Visibility = Visibility.Collapsed; } private void checkBox_Click(object sender, RoutedEventArgs e) { try { BatchAttribute value = dgTableMapping.SelectedItem as BatchAttribute; if (value != null) { value.IsCheck = (bool)(sender as CheckBox).IsChecked; } } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.checkBox_Click 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.checkBox_Click 异常:" + ex.StackTrace); } } private void AllCheckEidt_Click(object sender, RoutedEventArgs e) { try { if (this.dgTableMapping == null || (dgTableMapping.ItemsSource as List) == null) { return; } List listTableMapping = dgTableMapping.ItemsSource as List; bool check = (sender as CheckBox).IsChecked == null ? false : bool.Parse((sender as CheckBox).IsChecked.Value.ToString()); if (check) { listTableMapping.ForEach(a => a.IsCheck = true); } else { listTableMapping.ForEach(a => a.IsCheck = false); } dgTableMapping.ItemsSource = null; dgTableMapping.ItemsSource = listTableMapping; } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.AllCheckEidt_Click 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.AllCheckEidt_Click 异常:" + ex.StackTrace); MessageHelper.ShowTips("全选发生异常:" + ex.Message); } } #endregion #region 设置图斑列表页面 /// /// 设置图斑列表 /// /// /// private void BtnSetTB_Click(object sender, RoutedEventArgs e) { try { SetTBPage.Visibility = Visibility.Visible; dgSetTBTableMapping.ItemsSource = null; dgSetTBTableMapping.ItemsSource = listTBBSM; } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.BtnSetTB_Click 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.BtnSetTB_Click 异常:" + ex.StackTrace); } } private List GetAllTBBSM() { List selectTBBSM = new List(); IRDBHelper rDBHelper = null; try { string packagePath = _taskPackage.PackagePath; if (ProjectInfo == null) return selectTBBSM; if (_taskPackage.PackageTempPath != null && File.Exists(_taskPackage.PackageTempPath)) packagePath = _taskPackage.PackageTempPath; rDBHelper = RDBFactory.CreateDbHelper($"{packagePath}{ProjectInfo.Pathpassword}", DatabaseType.SQLite); DataTable dataTable = rDBHelper.ExecuteDatatable("data", "SELECT BSM, TBBSM FROM DTBDLTBGX;", true); if (dataTable == null || dataTable.Rows.Count <= 0) return selectTBBSM; foreach (DataRow dataRow in dataTable.Rows) { selectTBBSM.Add(new ListTbbsm() { IsCheck = true, bsm = dataRow["TBBSM"].ToSafeString(), tbbsm = dataRow["BSM"].ToSafeString() }); } return selectTBBSM; } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.GetAllTBBSM 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.GetAllTBBSM 异常:" + ex.StackTrace); return selectTBBSM; } finally { if (rDBHelper != null) rDBHelper.DisConnect(); } } private void BtnSetTBOK_Click(object sender, RoutedEventArgs e) { SetTBPage.Visibility = Visibility.Collapsed; } private void setTBAllCheckEidt_Click(object sender, RoutedEventArgs e) { try { if (this.dgSetTBTableMapping == null || (dgSetTBTableMapping.ItemsSource as List) == null) { return; } //List listTBBSM = dgSetTBTableMapping.ItemsSource as List; listTBBSM = dgSetTBTableMapping.ItemsSource as List; bool check = (sender as CheckBox).IsChecked == null ? false : bool.Parse((sender as CheckBox).IsChecked.Value.ToString()); if (check) { listTBBSM.ForEach(a => a.IsCheck = true); } else { listTBBSM.ForEach(a => a.IsCheck = false); } dgSetTBTableMapping.ItemsSource = null; dgSetTBTableMapping.ItemsSource = listTBBSM; } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.setTBAllCheckEidt_Click 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.setTBAllCheckEidt_Click 异常:" + ex.StackTrace); MessageHelper.ShowTips("全选发生异常:" + ex.Message); } } private void setTBCheckBox_Click(object sender, RoutedEventArgs e) { try { ListTbbsm value = dgSetTBTableMapping.SelectedItem as ListTbbsm; if (value != null) { value.IsCheck = (bool)(sender as CheckBox).IsChecked; } } catch (Exception ex) { LogAPI.Debug("UCSetBatchAttribute.setTBCheckBox_Click 异常:" + ex.Message); LogAPI.Debug("UCSetBatchAttribute.setTBCheckBox_Click 异常:" + ex.StackTrace); } } #endregion } public class ListTbbsm { public string bsm { get; set; } public string tbbsm { get; set; } public bool IsCheck { get; set; } } }