Shuxia Ning
2024-07-26 19db3c68c67e27531e716567cefaa266e71a2baf
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
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using System.Data;
 
namespace IStation.Win
{
    public partial class ModelValidView : XtraUserControl
    {
        public ModelValidView()
        {
            InitializeComponent();
            this.treeList1.InitialDefaultSettings();
            this.gridView1.SetNormalView();
            this.gridView2.SetNormalView();
            this.gridView2.OptionsView.ColumnAutoWidth = false; 
 
            this.dateEditStart.SetOnlyShowYearMonth();
            this.dateEditEnd.SetOnlyShowYearMonth();
 
            var year = 2024;
            var month = 1;
            this.dateEditStart.DateTime = new DateTime(year, month, 1);
            this.dateEditEnd.DateTime = new DateTime(year, month, DateTime.DaysInMonth(year, month));
        }
 
 
 
        private List<Model.HydraulicModelRecord> _hydraulic_model_record_list = null;
        private DataTable _data_table = null;
        private bool _init = false;
        private void Init()
        {
            if (_init)
                return;
            _data_table = new DataTable();
 
            var data_table_col_time = new DataColumn("Time");
            _data_table.Columns.Add(data_table_col_time);
            _data_table.PrimaryKey = new DataColumn[] { data_table_col_time };
 
            var col_time = new GridColumn();
            col_time.FieldName = "Time";
            col_time.Caption = "时间";
            this.gridView2.Columns.Add(col_time);
 
            var config = new IStation.Service.HydraulicModelValidationConfig().Get();
            foreach (var item in config.FlowIdMappingDict)
            {
                var col_key = new GridColumn();
                col_key.FieldName = item.Key;
                col_key.Caption = item.Key;
                col_key.Visible = true;
                this.gridView2.Columns.Add(col_key);
 
                var col_value = new GridColumn();
                col_value.FieldName = item.Value;
                col_value.Caption = item.Value;
                col_value.Visible = true;
                this.gridView2.Columns.Add(col_value);
 
                var col_key_value = new GridColumn();
                col_key_value.FieldName = GetTempId(item.Key, item.Value);
                col_key_value.Caption = GetTempId(item.Key, item.Value);
                col_key_value.Visible = true;
                this.gridView2.Columns.Add(col_key_value);
 
 
 
                _data_table.Columns.Add(item.Key, typeof(string));
                _data_table.Columns.Add(item.Value, typeof(string));
                _data_table.Columns.Add(GetTempId(item.Key, item.Value), typeof(string));
            }
 
            foreach (var item in config.PressureIdMappingDict)
            {
                var col_key = new GridColumn();
                col_key.FieldName = item.Key;
                col_key.Caption = item.Key;
                col_key.Visible = true;
                this.gridView2.Columns.Add(col_key);
 
                var col_value = new GridColumn();
                col_value.FieldName = item.Value;
                col_value.Caption = item.Value;
                col_value.Visible = true;
                this.gridView2.Columns.Add(col_value);
 
                var col_key_value = new GridColumn();
                col_key_value.FieldName = GetTempId(item.Key, item.Value);
                col_key_value.Caption = GetTempId(item.Key, item.Value);
                col_key_value.Visible = true;
                this.gridView2.Columns.Add(col_key_value);
 
                _data_table.Columns.Add(item.Key, typeof(string));
                _data_table.Columns.Add(item.Value, typeof(string));
                _data_table.Columns.Add(GetTempId(item.Key, item.Value), typeof(string));
            }
 
            _init = true;
        }
 
        private string GetTempId(string key,string value)
        {
            return $"{key}_{value}_diff";
        }
 
        //加载
        private void barBtnLoad_Click(object sender, EventArgs e)
        {
            WaitHelper.ShowWaitForm();
 
            Init();
 
            var start_time = this.dateEditStart.DateTime;
            var end_time = this.dateEditEnd.DateTime;
 
            _hydraulic_model_record_list = new IStation.Service.HydraulicModelRecord().GetByDate(start_time, end_time);
            if (_hydraulic_model_record_list == null || !_hydraulic_model_record_list.Any())
            {
                WaitHelper.HideWaitForm();
                XtraMessageBox.Show("无数据!");
                return;
            }
            SetGridView1(_hydraulic_model_record_list);
            SetGridView2(_hydraulic_model_record_list);
            WaitHelper.HideWaitForm();
        }
 
        
 
        private void SetGridView1(List<Model.HydraulicModelRecord> hydraulic_model_record_list)
        {
            var model_valid_vm_list = new List<ModelValidViewModel>();
            if (hydraulic_model_record_list != null && hydraulic_model_record_list.Any())
            {
                foreach (var hydraulic_model_record in hydraulic_model_record_list)
                {
                    var model_valid_vm = new ModelValidViewModel();
                    model_valid_vm.Time = hydraulic_model_record.Time;
                    model_valid_vm.ValueType = hydraulic_model_record.ValueType;
                    model_valid_vm.ModelId = hydraulic_model_record.ModelId;
                    model_valid_vm.ScadaId = hydraulic_model_record.ScadaId;
                    model_valid_vm.ModeValue = hydraulic_model_record.ModeValue;
                    model_valid_vm.ScadaValue = hydraulic_model_record.ScadaValue;
                    model_valid_vm.DifferenceValue = hydraulic_model_record.DifferenceValue;
                    model_valid_vm.Round();
                    model_valid_vm_list.Add(model_valid_vm);
                }
            }
            this.modelValidViewModelBindingSource.DataSource = model_valid_vm_list;
            this.modelValidViewModelBindingSource.ResetBindings(false);
        }
         
        private void SetGridView2(List<Model.HydraulicModelRecord> hydraulic_model_record_list)
        { 
            _data_table.Rows.Clear();
            if (hydraulic_model_record_list != null && hydraulic_model_record_list.Any())
            {
                foreach (var hydraulic_model_record in hydraulic_model_record_list)
                {
                    var time = hydraulic_model_record.Time.ToString("G");
                    var model_id = hydraulic_model_record.ModelId;
                    var scada_id = hydraulic_model_record.ScadaId;
                    var model_scada_id = GetTempId(model_id, scada_id);
 
                    DataRow dr = _data_table.Rows.Find(time);
                    if (dr == null)
                    {
                        dr = _data_table.NewRow();
                        dr["Time"] = time;
                        dr[model_id] = hydraulic_model_record.ModeValue;
                        dr[scada_id] = hydraulic_model_record.ScadaValue;
                        dr[model_scada_id] = hydraulic_model_record.DifferenceValue;
                        _data_table.Rows.Add(dr);  
                    }
                    else
                    {
                        dr[model_id] = hydraulic_model_record.ModeValue;
                        dr[scada_id] = hydraulic_model_record.ScadaValue;
                        dr[model_scada_id] = hydraulic_model_record.DifferenceValue;
                    }
                }
            }
            this.gridControl2.DataSource = _data_table;
            this.gridControl2.RefreshDataSource();
            this.gridView2.BestFitColumns();
        }
 
    }
}