duheng
2024-09-25 d7c384ceea90e2adeedcd8199fa651392ab655de
WinFrmUI/HStation.WinFrmUI.Basic/01-SysCatalogManage/SetSysPropForCatalogDlg.cs
@@ -1,5 +1,7 @@
using DevExpress.DataAccess.Wizard.Model;
using DevExpress.CodeParser;
using DevExpress.DataAccess.Wizard.Model;
using DevExpress.XtraEditors;
using System;
using Yw.Dto;
namespace HStation.WinFrmUI.Basic
@@ -9,7 +11,10 @@
        public SetSysPropForCatalogDlg()
        {
            InitializeComponent();
            this.gridView1.Columns["GroupName"].Group();
            // this.treeList1.Columns["GroupName"].;
            /*            this.gridView1.Columns["GroupName"].Group();
            */
            repositoryItemCheckedComboBoxEdit1.DisplayMember = "Name";
            repositoryItemCheckedComboBoxEdit1.ValueMember = "ID";
        }
@@ -28,7 +33,11 @@
            foreach (var item in PropTreeList)
            {
                repositoryItemCheckedComboBoxEdit1.Items.Clear();
                var parent = new SysPropMappingViewModel();
                parent.ID = item.ID;
                parent.IsGroup = true;
                parent.Name = item.Name;
                _allBindingList.Add(parent);
                if (item.PropList.Count > 0)
                {
                    foreach (var child in item.PropList)
@@ -36,6 +45,7 @@
                        var model = new SysPropMappingViewModel();
                        model.GroupName = item.Name;
                        model.ID = child.ID;
                        model.ParentID = item.ID;
                        model.Name = child.Name;
                        model.IsHave = child.Have;
                        model.IsNull = child.IsNull;
@@ -43,6 +53,7 @@
                        model.UnitName = child.UnitName;
                        model.Inherit = child.Inherit;
                        model.ChoiceList = child.ChoiceList;
                        model.ChoiceIds = child.ChoiceList.Where(x => x.Have).Select(x => x.ID).ToList();
                        var stringList = child.ChoiceList.Where(x => x.Have == true).ToList().Select(x => x.ID.ToString()).ToList();
                        string result = string.Join(", ", stringList);
                        model.DisplayChoice = result;
@@ -51,7 +62,7 @@
                }
            }
            this.sysCatalogPropViewModelBindingSource.DataSource = _allBindingList;
            this.gridView1.ExpandAllGroups();
            this.treeList1.ExpandAll();
        }
        // 完成
@@ -84,9 +95,47 @@
            this.Close();
        }
        private void gridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        private void repositoryItemCheckedComboBoxEdit1_EditValueChanged(object sender, EventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            try
            {
                var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
                if (vm == null)
                    return;
                var allselectList = repositoryItemCheckedComboBoxEdit1.GetCheckedItems();
                var strList = Convert.ToString(allselectList);
                if (strList != null && strList != string.Empty)
                {
                    if (strList.Contains(','))
                    {
                        string[] parts = strList.Split(',');
                        List<long> longs = parts.Select(part => long.Parse(part.Trim())).ToList();
                        vm.ChoiceIds = longs;
                    }
                    else
                    {
                        if (long.TryParse(strList, out long Id))
                        {
                            List<long> choiceId = new List<long>();
                            choiceId.Add(Id);
                            vm.ChoiceIds = choiceId;
                        }
                    }
                }
                else
                {
                    vm.ChoiceIds = new List<long>();
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void treeList1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
            var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                return;
@@ -95,49 +144,79 @@
            {
                e.Cancel = true;
            }
            if (gridView1.FocusedColumn.Name == "colPropChoice")
            if (vm.IsGroup)
            {
                e.Cancel = true;
            }
            if (treeList1.FocusedColumn.Name == "colPropChoice")
            {
                repositoryItemCheckedComboBoxEdit1.Items.Clear();
                repositoryItemCheckedComboBoxEdit1.DataSource = vm.ChoiceList;
            }
        }
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        private void treeList1_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e)
        {
            var gridView = sender as DevExpress.XtraGrid.Views.Grid.GridView;
            if (gridView != null)
            if (e.Node != null)
            {
                foreach (var item in _allBindingList)
                string Inherit = e.Node.GetValue("Inherit").ToString();
                string isGroup = e.Node.GetValue("IsGroup").ToString();
                if (Inherit == "True")
                {
                    int index = _allBindingList.IndexOf(item);
                    if (gridView.GetRowHandle(index) == e.RowHandle)
                    {
                        if (item.Inherit)
                        {
                            e.Appearance.BackColor = Color.Gray;
                        }
                        break;
                    }
                    e.Appearance.BackColor = Color.DarkGray;
                }
                if (isGroup == "True")
                {
                    e.Appearance.BackColor = Color.Gainsboro;
                }
            }
        }
        private void repositoryItemCheckedComboBoxEdit1_EditValueChanged(object sender, EventArgs e)
        private void treeList1_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e)
        {
            try
            string isGroup = e.Node.GetValue("Inherit").ToString();
            if (isGroup == "True")
            {
                var allselectList = repositoryItemCheckedComboBoxEdit1.GetCheckedItems();
                string[] parts = Convert.ToString(allselectList).Split(',');
                List<long> longs = parts.Select(part => long.Parse(part.Trim())).ToList();
                var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
                if (vm != null)
                e.State = CheckState.Unchecked;
            }
            else
            {
                if (e.PrevState == CheckState.Checked)
                {
                    vm.ChoiceIds = longs;
                    e.State = CheckState.Unchecked;
                }
                else
                {
                    e.State = CheckState.Checked;
                }
            }
            catch (Exception ex)
        }
        private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
        {
            SetCheckedChildNodes(e.Node, e.Node.CheckState, e);
         }
        #region 设置子节点状态
        private void SetCheckedChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check, DevExpress.XtraTreeList.NodeEventArgs e)
        {
            for (int i = 0; i < node.Nodes.Count; i++)
            {
                string Inherit = node.Nodes[i].GetValue("Inherit").ToString();
                if (Inherit == "False")
                {
                    node.Nodes[i].CheckState = check;
                    SetCheckedChildNodes(node.Nodes[i], check, e);
                }
                else if (Inherit == "True")
                {
                    node.Nodes[i].CheckState = CheckState.Checked;
                    SetCheckedChildNodes(node.Nodes[i], check, e);
                 }
            }
        }
    }
        #endregion 设置子节点状态
      }
}