ningshuxia
2025-03-24 7b8ae93d47186c442ff890a1a83d108f115924c7
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
namespace Yw.WinFrmUI
{
    public partial class SetHydroMonitorListCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SetHydroMonitorListCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalEditView(30);
            this.colParter.OptionsColumn.AllowEdit = false;
            this.colPropName.OptionsColumn.AllowEdit = false;
            this.colUnitName.OptionsColumn.AllowEdit = false;
        }
 
        private Yw.Model.HydroModelInfo _hydro = null;//水力信息    
        private Yw.Model.HydroVisualInfo _visual = null;//构件
        private List<HydroMonitorVmo> _allMonitorList = null;//所有监测列表
        private List<HydroMonitorValueViewModel> _allMonitorValueList = null;//所有监测值列表
        private BindingList<HydroMonitorViewModel> _allBindingList = null;//所有绑定列表
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData
            (
                Yw.Model.HydroModelInfo hydro,
                Yw.Model.HydroVisualInfo visual,
                List<HydroMonitorVmo> allMonitorList,
                List<HydroMonitorValueViewModel> allMonitorValueList
            )
        {
            _hydro = hydro;
            _visual = visual;
            _allMonitorList = allMonitorList;
            _allMonitorValueList = allMonitorValueList;
            _allBindingList = new BindingList<HydroMonitorViewModel>();
            if (hydro != null)
            {
                if (visual != null)
                {
                    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 == hydro.ID && x.Parter == visual.Code && x.PropName == prop);
                        if (vmo == null)
                        {
                            sortCode++;
                            vmo = new HydroMonitorVmo()
                            {
                                ID = 0,
                                ModelID = hydro.ID,
                                Parter = visual.Code,
                                SourceType = Yw.Hydro.eSourceType.None,
                                PropName = prop,
                                Flags = new List<string>(),
                                SortCode = sortCode,
                                Description = string.Empty
                            };
                        }
                        double? propValue = null;
                        var monitorValue = allMonitorValueList?.Find(x => x.Vmo.Parter == vmo.Parter && x.Vmo.PropName == vmo.PropName);
                        if (monitorValue != null)
                        {
                            propValue = monitorValue.PropValue;
                        }
                        var vm = new HydroMonitorViewModel(vmo, visual, propValue);
                        _allBindingList.Add(vm);
                    }
                }
            }
            InitialFlags();
            this.hydroMonitorViewModelBindingSource.DataSource = _allBindingList;
            this.hydroMonitorViewModelBindingSource.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 (_hydro == 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(_hydro.ID, _visual.Code, null, vmoList);
            if (!bol)
            {
                TipFormHelper.ShowError("设置失败!");
                return default;
            }
            TipFormHelper.ShowSucceed("设置成功!");
            var monitorList = await BLLFactory<Yw.BLL.HydroMonitor>.Instance.GetByParter(_hydro.ID, _visual.Code);
            var valueList = new List<HydroMonitorValueViewModel>();
            monitorList?.ForEach(x =>
            {
                double? propValue = null;
                var checkedItem = checkedList.Find(t => t.Vmo.PropName == x.PropName);
                propValue = checkedItem?.PropValue;
                var vm = new HydroMonitorValueViewModel(x, _visual, propValue);
                valueList.Add(vm);
            });
            return valueList;
        }
 
 
 
    }
}