From 47aa4ae2904b057c6ebadfe7f7bf801b9bb64fef Mon Sep 17 00:00:00 2001 From: lu <99954486@qq.com> Date: 星期四, 03 四月 2025 11:30:13 +0800 Subject: [PATCH] 选择字典 --- DevApp/Gs.DevApp/UserControl/UcDictionarySelect.cs | 70 +++++++++++++++++++++++++++++++---- 1 files changed, 62 insertions(+), 8 deletions(-) diff --git a/DevApp/Gs.DevApp/DevFrm/Work/SelectDictionary.cs b/DevApp/Gs.DevApp/UserControl/UcDictionarySelect.cs similarity index 61% rename from DevApp/Gs.DevApp/DevFrm/Work/SelectDictionary.cs rename to DevApp/Gs.DevApp/UserControl/UcDictionarySelect.cs index 29bf1f2..e0aefaa 100644 --- a/DevApp/Gs.DevApp/DevFrm/Work/SelectDictionary.cs +++ b/DevApp/Gs.DevApp/UserControl/UcDictionarySelect.cs @@ -1,19 +1,23 @@ -锘縰sing DevExpress.XtraEditors; -using DevExpress.XtraTreeList; +锘縰sing DevExpress.XtraTreeList; +using DevExpress.XtraTreeList.Nodes; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Data; +using System.Text; +using System.Windows.Forms; namespace Gs.DevApp.DevFrm.Work { - public partial class SelectDictionary : DevExpress.XtraEditors.XtraForm + public partial class UcDictionarySelect : DevExpress.XtraEditors.XtraForm { + private List<string> lstCheckedKeyID = new List<string>();//閫夋嫨灞�ID闆嗗悎 string strTitle = ""; string strWhere = ""; - public SelectDictionary(string _strTitle, string _strWhere) + public UcDictionarySelect(string _strTitle, string _strWhere) { InitializeComponent(); tlMenu.CustomDrawNodeCheckBox += TreeList1_CustomDrawNodeCheckBox; @@ -27,12 +31,16 @@ this.Text = _strTitle; btnIn.Click += (s, e) => { + findOrigin(tlMenu); var list = new List<dynamic>(); - list.Add(new + foreach (string key in lstCheckedKeyID) { - dicCode = "001", - dicTxt = "test1" - }); + list.Add(new + { + // dicCode = "001", + dicTxt = key + }); + }; UpdateParent?.Invoke(this, new UpdateParentEventArgs { DynamicList = list }); Close(); @@ -100,5 +108,51 @@ MsgHelper.Warning("鎻愮ず锛�" + ex.Message); } } + + + #region MyRegion + + /// <summary> + /// 鑾峰彇閫夋嫨鐘舵�佺殑鏁版嵁涓婚敭ID闆嗗悎 + /// </summary> + /// <param name="parentNode">鐖剁骇鑺傜偣</param> + private void GetCheckedKeyID(TreeListNode parentNode) + { + if (parentNode.Nodes.Count == 0) + { + return;//閫掑綊缁堟 + } + foreach (TreeListNode node in parentNode.Nodes) + { + if (node.CheckState == CheckState.Checked) + { + DataRowView drv = tlMenu.GetDataRecordByNode(node) as DataRowView;//鍏抽敭浠g爜锛屽氨鏄笉鐭ラ亾鏄繖鏍疯幏鍙栨暟鎹�岀籂缁撲簡寰堜箙(楝肩煡閬撳彲浠ヨ浆鎹负DataRowView鍟�) + if (drv != null) + { + string KeyFieldName = (string)drv["defectName"]; + lstCheckedKeyID.Add(KeyFieldName); + } + } + GetCheckedKeyID(node); + } + } + /// <summary> + /// 鑾峰彇閫変腑鐨勮妭鐐� + /// </summary> + /// <param name="tree"></param> + private void findOrigin(DevExpress.XtraTreeList.TreeList tree) + { + this.lstCheckedKeyID.Clear(); + + if (tree.Nodes.Count > 0) + { + foreach (TreeListNode root in tree.Nodes) + { + GetCheckedKeyID(root); + } + } + } + + #endregion } } \ No newline at end of file -- Gitblit v1.9.3