123
tangxu
2024-07-25 65e211e44704a9ca155cbd31d990c2ad62b34e93
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using DevExpress.Utils.About;
using DevExpress.XtraEditors;
using Eventech.Common;
using IStation.Unit;
using IStation.Untity;
using IStation.WinFrmUI.Basic.basic;
using System;
using System.ComponentModel;
using System.Linq;
 
namespace IStation.WinFrmUI.Basic
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MonitorPointGridMgrCtrl : XtraUserControl
    {
        public MonitorPointGridMgrCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView();
            this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
            this.gridView1.OptionsView.AllowCellMerge = true;
            this.gridView1.ActiveFilterEnabled = false;
            this.layoutControl1.SetupLayoutControl();
        }
 
        public class CurrentViewModel : Model.MonitorPointExSignalExSignalType
        {
            public CurrentViewModel() { }
 
            public CurrentViewModel(Model.MonitorPointExSignalExSignalType rhs, string belongName) : base(rhs)
            {
                if (int.TryParse(this.UnitValue, out int value))
                {
                    var dict = UnitHelper.GetEnUnitDict(this.UnitType);
                    if (dict != null)
                        this.Unit = dict[value];
                }
                else
                {
                    this.Unit = this.UnitValue;
                    
                }
 
                this.BelongName = belongName;
                this.FlagsList = FlagsHelper.ToString(rhs.Flags);
 
            }
 
            public string Unit { get; set; }
            public string BelongName { get; set; }
            public string FlagsList { get; set; }
        }
 
        /// <summary>
        /// 聚焦改变事件
        /// </summary> 
        public event Action<Model.MonitorPointExSignalExSignalType> FocusedChangedEvent;
 
        private BindingList<CurrentViewModel> _allBindingList = null;//所有绑定列表
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void Clear()
        {
            _allBindingList = new BindingList<CurrentViewModel>();
            this.currentViewModelBindingSource.DataSource = _allBindingList;
            this.FocusedChangedEvent?.Invoke(null);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
            WaitFrmHelper.ShowWaitForm("正在加载数据...");
            _allBindingList = new BindingList<CurrentViewModel>();
 
            var bll = new BLL.MonitorPoint();
            var stations = new BLL.Station().GetAll();
            if (stations != null && stations.Any())
            {
                foreach (var station in stations)
                {
                    var stationMappings = bll.GetExSignalExSignalTypeByMappingTypeAndMappingID(IStation.ObjectType.Station, station.ID);
                    if (stationMappings != null && stationMappings.Any())
                    {
                        foreach (var mapping in stationMappings)
                        {
                            var vm = new CurrentViewModel(mapping, station.Name);
                            _allBindingList.Add(vm);
                        }
                    }
 
                    var pumps = new BLL.Product().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID);
                    if (pumps != null || pumps.Any())
                    {
                        foreach (var pump in pumps)
                        {
                            var enginePumpId = pump.ParentIds.FirstOrDefault();
                            var pumpMappings = bll.GetExSignalExSignalTypeByMappingTypeAndMappingID(IStation.ObjectType.Product, enginePumpId);
                            if (pumpMappings != null && pumpMappings.Any())
                            {
                                foreach (var mapping in pumpMappings)
                                {
                                    var vm = new CurrentViewModel(mapping, pump.Name);
                                    _allBindingList.Add(vm);
                                }
                            }
                        }
                    }
                }
            }
 
 
 
            this.currentViewModelBindingSource.DataSource = _allBindingList;
            this.gridView1.BestFitColumns();
            WaitFrmHelper.HideWaitForm();
        }
 
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(string mappingName, string mappingType, long mappingId)
        {
            WaitFrmHelper.ShowWaitForm("正在加载数据...");
            _allBindingList = new BindingList<CurrentViewModel>();
 
            var monitorPointExSignalExSignalTypes = new BLL.MonitorPoint().GetExSignalExSignalTypeByMappingTypeAndMappingID(mappingType, mappingId);
            if (monitorPointExSignalExSignalTypes != null && monitorPointExSignalExSignalTypes.Any())
            {
                foreach (var item in monitorPointExSignalExSignalTypes)
                {
                    var vm = new CurrentViewModel(item, mappingName);
                    _allBindingList.Add(vm);
                }
            }
 
            this.currentViewModelBindingSource.DataSource = _allBindingList;
            this.gridView1.BestFitColumns();
            WaitFrmHelper.HideWaitForm();
        }
 
 
        //聚焦改变
        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
                return;
 
            this.FocusedChangedEvent?.Invoke(vm);
 
        }
 
       
        //private Model.MonitorPoint monitorPoint= null;
        //private Model.Signal Signal= null;
        //编辑监测信息
        public void EditMonitor()
        {
            var row = gridView1.GetCurrentViewModel(_allBindingList);
            if (row == null) 
                return;       
            var dlg = new EditMonitorDlg();
            dlg.SetBindingData(row,row.Name);
            dlg.ReloadDataEvent += (Info) =>
            {
                var monitor=Info.GetMonitorPoint();
               
                var bll = new BLL.MonitorPoint();
                var isok = bll.Update(monitor);
                if (isok)
                {
                    this.currentViewModelBindingSource.ResetBindings(false);
                    this.SetBindingData();
                }
                var bl = new BLL.Signal();
                var signal = Info.GetSignal();
                var isokk = bl.Update(signal);
                if (isokk)
                {
                    this.currentViewModelBindingSource.ResetBindings(false);
                    this.SetBindingData();
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
    }
 
}