lixiaojun
2024-12-22 6551843c49431dacf67ea26e1ea21bf887a5246c
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
using DevExpress.Xpo.Helpers;
using Yw.Hydro;
 
namespace Yw.WinFrmUI
{
    public partial class SetHydroMonitorDockingListCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SetHydroMonitorDockingListCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalEditView(30);
            this.colRelation.OptionsColumn.AllowEdit = false;
            this.colPropName.OptionsColumn.AllowEdit = false;
            this.colUnitName.OptionsColumn.AllowEdit = false;
        }
 
        private Yw.Model.HydroModelInfo _hydroInfo = null;//水力信息    
        private Yw.Model.HydroVisualInfo _visual = null;//构件
        private List<HydroMonitorVmo> _allMonitorList = null;//所有监测列表
        private List<HydroMonitorValueViewModel> _allMonitorValueList = null;//所有监测值列表
        private HydroCalcuResult _calcuResult = null;//计算结果
        private BindingList<HydroMonitorDockingViewModel> _allBindingList = null;//所有绑定列表
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData
            (
                Yw.Model.HydroModelInfo hydroInfo,
                Yw.Model.HydroVisualInfo visual,
                List<HydroMonitorVmo> allMonitorList,
                List<HydroMonitorValueViewModel> allMonitorValueList,
                HydroCalcuResult calcuResult
            )
        {
            _hydroInfo = hydroInfo;
            _visual = visual;
            _allMonitorList = allMonitorList;
            _allMonitorValueList = allMonitorValueList;
            _calcuResult = calcuResult;
            _allBindingList = new BindingList<HydroMonitorDockingViewModel>();
            if (hydroInfo != null)
            {
                if (visual != null)
                {
                    var allCalcuResultDict = calcuResult?.GetVisualDict();
                    var propList = HydroMonitorPropHelper.GetPropList(visual.Catalog);
                    var sortCode = allMonitorList == null || allMonitorList.Count < 1 ? 0 : allMonitorList.Max(x => x.SortCode);
                    foreach (var prop in propList)
                    {
                        var vmo = allMonitorList?
                            .Find(x => x.ModelID == hydroInfo.ID && x.Relation == visual.Code
                            && x.SourceType == Yw.Hydro.eSourceType.Docking && x.PropName == prop);
                        if (vmo == null)
                        {
                            sortCode++;
                            vmo = new HydroMonitorVmo()
                            {
                                ID = 0,
                                ModelID = hydroInfo.ID,
                                Relation = visual.Code,
                                SourceType = Yw.Hydro.eSourceType.Docking,
                                PropName = prop,
                                Flags = new List<string>(),
                                SortCode = sortCode,
                                Description = string.Empty
                            };
                        }
                        double? propValue = null;
                        var monitorValue = allMonitorValueList?.Find(x => x.Vmo.Relation == vmo.Relation && x.Vmo.PropName == vmo.PropName);
                        if (monitorValue != null)
                        {
                            propValue = monitorValue.PropValue;
                        }
                        if (!propValue.HasValue)
                        {
                            var calcuVisualResult = allCalcuResultDict?.GetValue(visual.Code);
                            propValue = calcuVisualResult?.GetCalcuValue(vmo.PropName);
                        }
                        var vm = new HydroMonitorDockingViewModel(vmo, visual, propValue);
                        _allBindingList.Add(vm);
                    }
                }
            }
            InitialFlags();
            this.hydroMonitorDockingViewModelBindingSource.DataSource = _allBindingList;
            this.hydroMonitorDockingViewModelBindingSource.ResetBindings(false);
        }
 
 
        //初始化标签
        private async void InitialFlags()
        {
            var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(Yw.Hydro.DataType.HydroMonitor);
            this.repositoryItemCheckedComboBoxEdit1.Items.BeginUpdate();
            this.repositoryItemCheckedComboBoxEdit1.Items.Clear();
            if (flags != null && flags.Count > 0)
            {
                foreach (var flag in flags)
                {
                    this.repositoryItemCheckedComboBoxEdit1.Items.Add(flag.Name);
                }
            }
            this.repositoryItemCheckedComboBoxEdit1.Items.EndUpdate();
        }
 
        /// <summary>
        /// 获取值列表
        /// </summary>
        public async Task<List<HydroMonitorValueViewModel>> GetValueList()
        {
            if (_hydroInfo == null)
            {
                return default;
            }
            if (_visual == null)
            {
                return default;
            }
            var checkedList = _allBindingList?.Where(x => x.Checked).ToList();
            checkedList?.ForEach(x =>
            {
                x.Vmo.Flags = HydroFlagsHelper.ToList(x.Flags);
                x.Vmo.Description = x.Description;
            });
            var vmoList = checkedList?.Select(x => x.Vmo).ToList();
            var bol = await BLLFactory<Yw.BLL.HydroMonitor>.Instance.Save(_hydroInfo.ID, _visual.Code, eSourceType.Docking, vmoList);
            if (!bol)
            {
                TipFormHelper.ShowError("设置失败!");
                return default;
            }
            TipFormHelper.ShowSucceed("设置成功!");
            var monitorList = await BLLFactory<Yw.BLL.HydroMonitor>.Instance.GetBySourceType(_hydroInfo.ID, _visual.Code, eSourceType.Docking);
            var valueList = new List<HydroMonitorValueViewModel>();
            monitorList?.ForEach(x =>
            {
                double? propValue = null;
                var docking = checkedList.Find(t => t.Vmo.PropName == x.PropName);
                propValue = docking?.PropValue;
                var vm = new HydroMonitorValueViewModel(x, _visual, propValue);
                valueList.Add(vm);
            });
            return valueList;
        }
 
 
 
    }
}