tangxu
2024-03-26 edd23f115dba31d764fdaf75a6207d888d0419d3
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
using DevExpress.XtraEditors;
using DevExpress.XtraRichEdit.API.Native;
using IStation.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.CalcErQu
{
    public partial class AnaSettingMgrDlg : XtraForm
    {
        public AnaSettingMgrDlg()
        {
            InitializeComponent();
        }
 
        public class CurrentViewModel
        {
            public bool IsUse { get; set; } = true;
            public bool IsNexDay { get; set; }
            public int? StartH { get; set; }
            public int? StartM { get; set; } = 0;
            public int? EndH { get; set; }
            public int? EndM { get; set; } = 0;
        }
        private BindingList<CurrentViewModel> list不许换泵时间;
        private BindingList<CurrentViewModel> list允许开泵时间;
  
        private void AnaSettingMgrDlg_Load(object sender, EventArgs e)
        {
            var anaSetting = IStation.AnaGlobalParas.Setting;
            if (anaSetting == null)
                return;
            spinEditStartHour.EditValue = anaSetting.StartHourPerDay;
            spinEdit最少切换泵时间.EditValue = anaSetting.MinSwitchTimeMinute;
            spinEdit最少开泵时间.EditValue = anaSetting.MinOpenTimeMinute;
            spinEdit分析步长Q.EditValue = anaSetting.CalcSpaceMinuteQ;
            spinEdit切泵次数Q.EditValue = anaSetting.MaxPumpSwitchCountQ;
            spinEdit分析步长L.EditValue = anaSetting.CalcSpaceMinuteL;
            spinEdit切泵次数L.EditValue = anaSetting.MaxPumpSwitchCountL;
 
            spinEdit长江水位基准.EditValue = anaSetting.RiverWaterLevelBase;
 
            list不许换泵时间 = new BindingList<CurrentViewModel>();
            if ( anaSetting.SwitchPumpIgnoreTimes != null)
            { 
                foreach (var t in anaSetting.SwitchPumpIgnoreTimes)
                {
                    CurrentViewModel v = new CurrentViewModel();
                    v.IsUse = t.IsUse;
                    v.StartH = t.StartHour;
                    v.StartM = t.StartMinute;
                    v.EndH = t.EndHour;
                    v.EndM = t.EndMinute;
 
                    list不许换泵时间.Add(v);
                }
            }
            this.bindingSource1.DataSource = list不许换泵时间;
 
 
 
            list允许开泵时间 = new BindingList<CurrentViewModel>();
            if ( anaSetting.OpenPumpTimes != null)
            { 
                foreach (var t in anaSetting.OpenPumpTimes)
                { 
                    CurrentViewModel v = new CurrentViewModel();
                    v.IsUse = t.IsUse; 
                    v.StartH = t.StartHour;
                    v.StartM = t.StartMinute;
                    v.EndH = t.EndHour;
                    v.EndM = t.EndMinute;
 
                    list允许开泵时间.Add(v);
                }
            }
            this.bindingSource2.DataSource = list允许开泵时间;
 
 
            var list水库参数 = IStation.AnaGlobalParas.ReservoirParasList;
            if (list水库参数 != null && list水库参数.Count > 0)
            {
                List<Model.ReservoirParas> list水库参数New = new List<Model.ReservoirParas>();
                foreach (var item in list水库参数)
                {
                    list水库参数New.Add(new Model.ReservoirParas() { Level = Convert.ToDouble(item.Level), Area = Convert.ToDouble(item.Area), Volume = Convert.ToDouble(item.Volume) });
                }
                this.bindingSetting.DataSource = list水库参数New;
            }
 
 
 
            btnColor长江水位.BackColor = IStation.Settings.DispSetting.ChartColor长江水位;
            btnColor前池水位.BackColor = IStation.Settings.DispSetting.ChartColor前池水位;
            btnColor水库水位.BackColor = IStation.Settings.DispSetting.ChartColor水库水位;
            btnColor瞬时流量.BackColor = IStation.Settings.DispSetting.ChartColor瞬时流量;
            btnColor瞬时功率.BackColor = IStation.Settings.DispSetting.ChartColor瞬时功率;
        }
 
        private void btnOk_Click(object sender, EventArgs e)
        {
            var anaSetting = IStation.AnaGlobalParas.Setting;
            if (anaSetting == null)
                return;
            anaSetting.RiverWaterLevelBase = Convert.ToDouble(spinEdit长江水位基准.EditValue);
            anaSetting.MinSwitchTimeMinute = Convert.ToInt32(spinEdit最少切换泵时间.EditValue);
            anaSetting.StartHourPerDay = Convert.ToInt32(spinEditStartHour.EditValue);
            anaSetting.MinOpenTimeMinute = Convert.ToInt32(spinEdit最少开泵时间.EditValue);
            anaSetting.CalcSpaceMinuteQ = Convert.ToInt32(spinEdit分析步长Q.EditValue);
            anaSetting.MaxPumpSwitchCountQ = Convert.ToInt32(spinEdit切泵次数Q.EditValue);
            anaSetting.CalcSpaceMinuteL = Convert.ToInt32(spinEdit分析步长L.EditValue);
            anaSetting.MaxPumpSwitchCountL = Convert.ToInt32(spinEdit切泵次数L.EditValue);
 
            anaSetting.SwitchPumpIgnoreTimes = new List<CalcModel.AnaSetting.TimeRange>();
            foreach (var m in list不许换泵时间)
            { 
                if (m.StartH == null || m.EndH == null)
                {
                    continue;
                }
                 
                var v = new CalcModel.AnaSetting.TimeRange()
                {
                    IsUse = m.IsUse,
                    StartHour = m.StartH == null ? 0 : m.StartH.Value,
                    StartMinute = m.StartM == null ? 0 : m.StartM.Value,
                    EndHour = m.EndH == null ? 0 : m.EndH.Value,
                    EndMinute = m.EndM == null ? 0 : m.EndM.Value
                };
                if(v.StartHour *60+v.StartMinute >= v.EndHour * 60 + v.EndMinute)
                {
                    MessageBox.Show("切泵时间限制设置不合理");
                    return;
                }
                anaSetting.SwitchPumpIgnoreTimes.Add(v);
            }
 
            anaSetting.OpenPumpTimes = new List<CalcModel.AnaSetting.TimeRange>();
            foreach (var m in list允许开泵时间)
            {
                if (m.StartH == null || m.EndH == null)
                {
                    continue;
                }
 
                var v = new CalcModel.AnaSetting.TimeRange()
                {
                    IsUse = m.IsUse,
                    StartHour = m.StartH == null ? 0 : m.StartH.Value,
                    StartMinute = m.StartM == null ? 0 : m.StartM.Value,
                    EndHour = m.EndH == null ? 0 : m.EndH.Value,
                    EndMinute = m.EndM == null ? 0 : m.EndM.Value
                };
                if (v.StartHour * 60 + v.StartMinute >= v.EndHour * 60 + v.EndMinute)
                {
                    MessageBox.Show("开泵时间限制设置不合理");
                    return;
                }
                anaSetting.OpenPumpTimes.Add(v);
            }
 
 
 
 
            var list水库参数Old = IStation.AnaGlobalParas.ReservoirParasList;
            List<Model.ReservoirParas> list水库参数New = this.bindingSetting.DataSource as List<Model.ReservoirParas>;
            if(!Model.ReservoirParas.IsSample(list水库参数Old, list水库参数New))
            IStation.BLL.ReservoirParas.SaveList(list水库参数New);
 
 
            IStation.BLL.AnaSetting.SaveSetting(anaSetting);
 
            //
            this.Close();
        }
 
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void btnColor长江水位_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.ColorDialog colorDialog1 = new System.Windows.Forms.ColorDialog();
            colorDialog1.Color = IStation.Settings.DispSetting.ChartColor长江水位;
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IStation.Settings.DispSetting.ChartColor长江水位 = colorDialog1.Color;
                btnColor长江水位.BackColor = colorDialog1.Color;
                SettingsHelper.Save();
            }
        }
 
        private void btnColor前池水位_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.ColorDialog colorDialog1 = new System.Windows.Forms.ColorDialog();
            colorDialog1.Color = IStation.Settings.DispSetting.ChartColor前池水位;
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IStation.Settings.DispSetting.ChartColor前池水位 = colorDialog1.Color;
                btnColor前池水位.BackColor = colorDialog1.Color;
                SettingsHelper.Save();
            }
        }
 
        private void btnColor水库水位_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.ColorDialog colorDialog1 = new System.Windows.Forms.ColorDialog();
            colorDialog1.Color = IStation.Settings.DispSetting.ChartColor水库水位;
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IStation.Settings.DispSetting.ChartColor水库水位 = colorDialog1.Color;
                btnColor水库水位.BackColor = colorDialog1.Color;
                SettingsHelper.Save();
            }
        }
 
        private void btnColor瞬时流量_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.ColorDialog colorDialog1 = new System.Windows.Forms.ColorDialog();
            colorDialog1.Color = IStation.Settings.DispSetting.ChartColor瞬时流量;
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IStation.Settings.DispSetting.ChartColor瞬时流量 = colorDialog1.Color;
                btnColor瞬时流量.BackColor = colorDialog1.Color;
                SettingsHelper.Save();
            }
        }
 
        private void btnColor瞬时功率_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.ColorDialog colorDialog1 = new System.Windows.Forms.ColorDialog();
            colorDialog1.Color = IStation.Settings.DispSetting.ChartColor瞬时功率;
            if (colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IStation.Settings.DispSetting.ChartColor瞬时功率 = colorDialog1.Color;
                btnColor瞬时功率.BackColor = colorDialog1.Color;
                SettingsHelper.Save();
            }
        }
    }
}