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
118
119
120
121
122
using System;
using System.Collections.Generic;
using TProduct.Model;
 
namespace TProduct.WinFrmUI.Data4Factory
{
    public partial class SelProductPumpContentListCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SelProductPumpContentListCtrl()
        {
            InitializeComponent();
            this.treeList1.SetTreeListColor();
            this.layoutControl1.SetupLayoutControl();
            this.treeList1.InitialMultiColSettings();
        }
 
        public event Action<Model.ProductMainExPump> SelectProductPumpChanedEvent = null;
        public event Action<Model.ProductSeries> SelectProductSeriesChanedEvent = null;
        private List<CurrentViewModel> _bindList = null;
        public class CurrentViewModel : Model.ProductMainExPump
        {
            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.ObjectType = eObjectType.系列;
                this.Model = rhs;
                this.ProductStyleID = rhs.ProductStyleID;
            }
            public CurrentViewModel(Model.ProductMainExPump rhs) : base(rhs)
            {
                this.ParentID = SeriesID;
            }
            public CurrentViewModel(Model.ProductMainExPump rhs, RatedParas4Pump pumpparas) : base(rhs)
            {
                this.ParentID = rhs.SeriesID;
                if (pumpparas.Q > 0)
                    this.Q = pumpparas.Q.ToString();
                if (pumpparas.Q < 0)
                    this.Q = "";
                if (pumpparas.H > 0)
                    this.H = pumpparas.H.ToString();
                if (pumpparas.H < 0)
                    this.H = "";
                if (rhs.Ratedn > 0)
                    this.N = rhs.Ratedn.ToString();
                if (rhs.Ratedn < 0)
                    this.N = "";
                this.Model = rhs;
                this.ObjectType = eObjectType.设备;
            }
            public long ParentID { get; set; }
            public string Q { get; set; }
            public string H { get; set; }
            public string N { get; set; }
            public eObjectType ObjectType { get; set; }
            public object Model { get; set; }
            public long ProductStyleID { get; set; }
        }
        public void SetBindingData()
        {
            _bindList = new List<CurrentViewModel>();
            var series = new BLL.ProductSeries().GetByProductType(Model.eProductType.Pump);
            series?.ForEach(x => _bindList.Add(new CurrentViewModel(x)));
            var productPumpList = new BLL.ProductPump().GetExAll();
            if (productPumpList == null || productPumpList.Count < 1)
            {
                return;
            }
            var all = new Model.ProductSeries()
            {
                ID = -1,
                Name = "全部",
            };
            _bindList.Add(new CurrentViewModel(all));
            foreach (var item in productPumpList)
            {
                if (!string.IsNullOrEmpty(item.RatedParas))
                {
                    var paras = RatedParas4Pump.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.SelectProductSeriesChanedEvent?.Invoke(vm.Model as Model.ProductSeries);
            if (vm.ObjectType == CurrentViewModel.eObjectType.设备)
                this.SelectProductPumpChanedEvent?.Invoke(vm.Model as Model.ProductMainExPump);
        }
    }
}