lu
2025-04-03 9607b0b7ecb0f621e9e00c376063342c467788e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using DevExpress.XtraEditors;
using DevExpress.XtraTreeList;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
 
 
namespace Gs.DevApp.DevFrm.Work
{
    public partial class SelectDictionary : DevExpress.XtraEditors.XtraForm
    {
        string strTitle = "";
        string strWhere = "";
        public SelectDictionary(string _strTitle, string _strWhere)
        {
            InitializeComponent();
            tlMenu.CustomDrawNodeCheckBox += TreeList1_CustomDrawNodeCheckBox;
            getTree();
            tlMenu.OptionsBehavior.Editable = true;
            tlMenu.OptionsSelection.EnableAppearanceFocusedCell = false;
            tlMenu.OptionsSelection.MultiSelect = true;
            tlMenu.OptionsSelection.MultiSelectMode = TreeListMultiSelectMode.CellSelect;
            this.strTitle = _strTitle;
            this.strWhere = _strWhere;
            this.Text = _strTitle;
            btnIn.Click += (s, e) =>
            {
                var list = new List<dynamic>();
                list.Add(new
                {
                    dicCode = "001",
                    dicTxt = "test1"
                });
                UpdateParent?.Invoke(this,
                    new UpdateParentEventArgs { DynamicList = list });
                Close();
            };
            tlMenu.IndicatorWidth = 50;
            tlMenu.CustomDrawNodeIndicator += (s, ee) =>
            {
                if (ee.IsNodeIndicator)
                {
                    var index = ee.Node.TreeList.GetVisibleIndexByNode(ee.Node);
                    ee.Info.DisplayText = (index + 1).ToString();
                }
            };
        }
 
        /// <summary>
        ///     选择后的回调事件
        /// </summary>
        public event EventHandler<UpdateParentEventArgs> UpdateParent;
        private void TreeList1_CustomDrawNodeCheckBox(object sender, DevExpress.XtraTreeList.CustomDrawNodeCheckBoxEventArgs e)
        {
            // 判断当前节点是否为叶子节点(无子节点)
            if (e.Node.Nodes.Count == 0)
            {
                // 允许绘制复选框(默认行为)
            }
            else
            {
                // 取消绘制复选框
                e.Handled = true;
            }
        }
 
        // 可选:处理节点展开事件,确保动态加载的子节点生效
        private void treeList1_BeforeExpand(object sender, BeforeExpandEventArgs e)
        {
            // 若子节点是动态加载的,在此处加载数据
            // LoadChildNodes(e.Node);
        }
        /// <summary>
        ///     读取列表
        /// </summary>
        private void getTree()
        {
            var pgq = new PageQueryModel(1, 999999, "a.defect_name");
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
                var strReturn =
                    UtilityHelper.HttpPost("", "MesDefectCodeManager/GetListPage", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                var dt = dd.rtnData.list;
                tlMenu.DataSource = dt;
                tlMenu.KeyFieldName = "guid";
                tlMenu.ParentFieldName = "pid";
                tlMenu.Tag = "defectName";
                tlMenu.EndUpdate();
                this.tlMenu.CollapseAll();
                //  tlMenu.OptionsBehavior.Editable = true;
                tlMenu.OptionsBehavior.AllowRecursiveNodeChecking = false;
                tlMenu.BestFitColumns();
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}