tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
using TProduct.Model;
 
namespace TProduct.WinFrmUI.Data4Factory
{
    public partial class SelProductValveContentListCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SelProductValveContentListCtrl()
        {
            InitializeComponent();
            this.treeList1.SetTreeListColor();
            this.layoutControl1.SetupLayoutControl();
            this.treeList1.InitialMultiColSettings();
        }
 
        public event Action<Model.ProductMainExValve> SelectProductValveEvent = null;
        public event Action<Model.ProductSeries> SelectProductSeriesEvent = null;
        private List<CurrentViewModel> _bindList = null;
        public class CurrentViewModel : Model.ProductMainExValve
        {
            public enum eObjectType
            {
                系列,
                设备
            }
 
            public CurrentViewModel() { }
            public CurrentViewModel(Model.ProductSeries rhs)
            {
                this.ParentID = -1;
                this.ID = rhs.ID;
                this.CreateUserID = rhs.CreateUserID;
                this.CreateTime = rhs.CreateTime;
                this.UpdateUserID = rhs.UpdateUserID;
                this.UpdateTime = rhs.UpdateTime;
                this.Code = rhs.Code;
                this.Name = rhs.Name;
                this.Model = rhs;
                this.ObjectType = eObjectType.系列;
            }
            public CurrentViewModel(Model.ProductMainExValve rhs) : base(rhs)
            {
                this.ParentID = SeriesID;
                this.ObjectType = eObjectType.设备;
                this.strDia = rhs.Dia.ToString();
                this.Model = rhs;
            }
            public CurrentViewModel(Model.ProductMainExValve rhs, RatedParas4Valve Valveparas) : base(rhs)
            {
                this.ParentID = SeriesID;
                this.Model = rhs;
                this.ObjectType = eObjectType.设备;
                if (Valveparas.Dia > 0)
                    this.strDia = Valveparas.Dia.ToString();
            }
            public string strDia { get; set; }
            public eObjectType ObjectType { get; set; }
            public long ParentID { get; set; }
            public object Model { get; set; }
            public bool Selected { get; set; }
        }
        public void SetBindingData()
        {
            _bindList = new List<CurrentViewModel>();
 
            var all = new Model.ProductSeries()
            {
                ID = -1,
                Name = "全部",
            };
            _bindList.Add(new CurrentViewModel(all));
            var seriesList = new BLL.ProductSeries().GetByProductType(Model.eProductType.Valve);
            if (seriesList == null)
                return;
            seriesList?.ForEach(x => _bindList.Add(new CurrentViewModel(x)));
            var productPumpList = new BLL.ProductValve().GetExAll();
            if (productPumpList == null || productPumpList.Count < 1)
            {
                return;
            }
            foreach (var item in productPumpList)
            {
                if (!string.IsNullOrEmpty(item.RatedParas))
                {
                    var paras = RatedParas4Valve.ToModel(item.RatedParas);
                    _bindList.Add(new CurrentViewModel(item, paras));
                }
                else
                {
                    _bindList.Add(new CurrentViewModel(item));
                }
            }
 
            this.bindingSource1.DataSource = _bindList;
            this.bindingSource1.ResetBindings(false);
            this.treeList1.ExpandAll();
 
        }
        public void SetFocused()
        {
            treeList1.FocusedNode = treeList1.Nodes.FirstNode;
        }
        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            if (_bindList == null)
                return;
            var vm = this.treeList1.GetCurrentViewModel(this._bindList) as CurrentViewModel;
            if (vm == null)
                return;
            if (vm.ObjectType == CurrentViewModel.eObjectType.系列)
                this.SelectProductSeriesEvent?.Invoke(vm.Model as Model.ProductSeries);
            if (vm.ObjectType == CurrentViewModel.eObjectType.设备)
                this.SelectProductValveEvent?.Invoke(vm as Model.ProductMainExValve);
        }
    }
}