bug
lu
3 天以前 fa113f04a917e85af84813487f033fb6bc43a5d7
DevApp/Gs.DevApp/UserControl/UcDictionarySelect.cs
@@ -6,7 +6,8 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -14,36 +15,16 @@
{
    public partial class UcDictionarySelect : DevExpress.XtraEditors.XtraForm
    {
        private List<string> lstCheckedKeyID = new List<string>();//选择局ID集合
        private List<dynamic> lstCheckedKeyID = new List<dynamic>();//选择集合
        string strTitle = "";
        string strWhere = "";
        public UcDictionarySelect(string _strTitle, string _strWhere)
        public UcDictionarySelect(string _strTitle, string _strWhere, string _strMsg = "")
        {
            InitializeComponent();
            tlMenu.CustomDrawNodeCheckBox += TreeList1_CustomDrawNodeCheckBox;
            getTree();
            tlMenu.OptionsBehavior.Editable = true;
            tlMenu.OptionsSelection.EnableAppearanceFocusedCell = false;
            tlMenu.OptionsSelection.MultiSelect = true;
            tlMenu.OptionsSelection.MultiSelectMode = TreeListMultiSelectMode.CellSelect;
            lbMsg.Text = _strMsg;
            this.strTitle = _strTitle;
            this.strWhere = _strWhere;
            this.Text = _strTitle;
            btnIn.Click += (s, e) =>
            {
                findOrigin(tlMenu);
                var list = new List<dynamic>();
                foreach (string key in lstCheckedKeyID)
                {
                    list.Add(new
                    {
                        //  dicCode = "001",
                        dicTxt = key
                    });
                };
                UpdateParent?.Invoke(this, new UpdateParentEventArgs { DynamicList = list });
                Close();
            };
            tlMenu.IndicatorWidth = 50;
            tlMenu.CustomDrawNodeIndicator += (s, ee) =>
            {
@@ -51,6 +32,64 @@
                {
                    var index = ee.Node.TreeList.GetVisibleIndexByNode(ee.Node);
                    ee.Info.DisplayText = (index + 1).ToString();
                }
            };
            getTreeAsync();
            tlMenu.MouseDown += (s, e) =>
            {
                TreeListHitInfo hitInfo = tlMenu.CalcHitInfo(new Point(e.X, e.Y));
                if (hitInfo.HitInfoType == HitInfoType.Cell)
                {
                    TreeListNode node = hitInfo.Node;
                    if (node != null)
                    {
                        if (node.HasChildren) // 只有当节点有子节点时才考虑展开或折叠
                        {
                            if (node.Expanded)
                            {
                                node.Collapse();
                                btnOpen.Text = "全部展开";
                            }
                            else
                            {
                                node.Expand();
                                btnOpen.Text = "全部收拢";
                            }
                        }
                    }
                }
            };
            tlMenu.CustomDrawNodeCheckBox += TreeList1_CustomDrawNodeCheckBox;
            btnIn.Click += (s, e) =>
            {
                findOrigin(tlMenu);
                var list = new List<dynamic>();
                foreach (dynamic key in lstCheckedKeyID)
                {
                    list.Add(new
                    {
                        dicCode = key.dicCode,
                        dicTxt = key.dicTxt
                    });
                }
                ;
                UpdateParent?.Invoke(this, new UpdateParentEventArgs { DynamicList = list });
                Close();
            };
            btnOpen.Click += (s, e) => {
                if (btnOpen.Text == "全部展开")
                {
                    tlMenu.ExpandAll();
                    btnOpen.Text = "全部收拢";
                    return;
                }
                if (btnOpen.Text == "全部收拢")
                {
                    tlMenu.CollapseAll();
                    btnOpen.Text = "全部展开";
                    return;
                }
            };
        }
@@ -72,19 +111,13 @@
                e.Handled = true;
            }
        }
        // 可选:处理节点展开事件,确保动态加载的子节点生效
        private void treeList1_BeforeExpand(object sender, BeforeExpandEventArgs e)
        {
            // 若子节点是动态加载的,在此处加载数据
            // LoadChildNodes(e.Node);
        }
        /// <summary>
        ///     读取列表
        /// </summary>
        private void getTree()
        private async Task getTreeAsync()
        {
            var pgq = new PageQueryModel(1, 999999, "a.defect_name");
            string _where = " and 1=1 and a.type1=1 and " + this.strWhere;
            var pgq = new PageQueryModel(1, 999999, "a.defect_name", "asc", "", _where);
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
@@ -97,17 +130,17 @@
                tlMenu.ParentFieldName = "pid";
                tlMenu.Tag = "defectName";
                tlMenu.EndUpdate();
                this.tlMenu.CollapseAll();
                //  tlMenu.OptionsBehavior.Editable = true;
                tlMenu.OptionsBehavior.AllowRecursiveNodeChecking = false;
                tlMenu.BestFitColumns();
                tlMenu.CollapseAll();
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
            await Task.Delay(500); // 等待1000毫秒(1秒)
            tlMenu.CollapseAll();
        }
        #region MyRegion
@@ -125,20 +158,30 @@
                    if (drv != null)
                    {
                        string KeyFieldName = (string)drv["defectName"];
                        lstCheckedKeyID.Add(KeyFieldName);
                        string dicCode = (string)drv["defectCode"];
                        lstCheckedKeyID.Add(new
                        {
                            dicCode = dicCode,
                            dicTxt = KeyFieldName
                        });
                    }
                }
                return;//递归终止
            }
            foreach (TreeListNode node in parentNode.Nodes)
            {
                if (node.CheckState == CheckState.Checked)
                if (node.CheckState == CheckState.Checked && parentNode.Nodes.Count == 0)
                {
                    DataRowView drv = tlMenu.GetDataRecordByNode(node) as DataRowView;//关键代码,就是不知道是这样获取数据而纠结了很久(鬼知道可以转换为DataRowView啊)
                    if (drv != null)
                    {
                        string KeyFieldName = (string)drv["defectName"];
                        lstCheckedKeyID.Add(KeyFieldName);
                        string dicCode = (string)drv["defectCode"];
                        lstCheckedKeyID.Add(new
                        {
                            dicCode = dicCode,
                            dicTxt = KeyFieldName
                        });
                    }
                }
                GetCheckedKeyID(node);
@@ -160,5 +203,7 @@
            }
        }
        #endregion
    }
}