duheng
2024-04-12 e6ff36d8a3edb397ffe176c187b0fee815d615f7
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
 
namespace IStation.WinFrmUI.River
{
    public partial class ReservoirParaRequestCtrl : XtraUserControl
    {
        public ReservoirParaRequestCtrl()
        {
            InitializeComponent();
 
            rowDropFlow.Visible = false;
            checkBox总量.Checked = true;
            vGridControl1.Visible = false;
            layoutControlItem3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            btn保存为模板.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            layoutControlItem4.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
            //rowNeedHeightMin.Visible = false;
            //rowNeedHeightMax.Visible = false; 
 
            //hourBlockRangePanel.OnFreshTotalHour += (h) =>
            //{
            //    barStaticItem总时间.Text = string.Format("总时间: {0} H", h);
            //};
 
        }
        public class CurrentViewModel
        {
            public int Hour { get; set; }
 
            public string DropFlow { get; set; }
            public string NeedMinHeight { get; set; }
            public string NeedMaxHeight { get; set; }
        }
        List<CurrentViewModel> _bindDataList;
 
        private void ReservoirParaRequestCtrl_Load(object sender, EventArgs e)
        {
            vGridControl1.RecordWidth = 50;
    
  
            // vGridControl1.RowHeaderWidth = 30;
            //  vGridControl1.RecordHeaderHeight = 300;
 
            //hourBlockRangePanel.InitialTimeBlock();
            _bindDataList = new List<CurrentViewModel>();
            for(int i = 1; i < 25; i++)
            {
                _bindDataList.Add(new CurrentViewModel() { Hour = i });
            }
          
            //barEditItem用水总量.EditValue =
            //    Settings.AnaSetting.LastReservoirDropFlow;
            this.bindingSource1.DataSource = _bindDataList;
 
 
            Task.Run(() =>
            {
                var last3 = BLL.TotalWaterOut.GetLastDay3( );
                if (last3 != null && last3.Count == 3)
                {
                    this.Invoke(new Action(() =>
                    {
                        bci前一日记录.Checked = true;
                        bci前一日记录.Tag = Math.Round(last3[0], 1);
                        barEditItem用水总量.Text = Math.Round(last3[0], 1).ToString();
 
                        bci前三日记录.Checked = false ;
                        bci前三日记录.Tag = Math.Round((last3[0] + last3[1]+ last3[2])/3, 1);
                    }));
                }
            });
        }
 
 
        public List<double> GetFlowHourValues()
        {
            List<double> list = new List<double>();
            if (checkBox总量.Checked)
            {
                if (barEditItem用水总量.EditValue == null)
                    return null;
 
                var total = Convert.ToDouble(barEditItem用水总量.EditValue);
 
               // Settings.AnaSetting.LastReservoirDropFlow = total;
              //  IStation.SettingsHelper.Save();
 
                for (int i = 0; i < 24; i++)
                {
                    list.Add(total / 24);
                }
            }
            else
            {
                double total = 0;
                for (int i = 0; i < 24; i++)
                {
                    if (!string.IsNullOrEmpty(_bindDataList[i].DropFlow))
                    {
                        var flow = Convert.ToDouble(_bindDataList[i].DropFlow);
                        total = total + flow;
                        list.Add(flow);
                    }
 
                }
                if (total < 10)
                {
                    return null;
                }
            }
 
 
            return list;
        }
 
        public List<double?> GetMinLevelHourValues()
        {
            List<double?> list = new List<double?>(); 
 
            for (int i = 0; i < 24; i++)
            {
                if (!string.IsNullOrEmpty(_bindDataList[i].NeedMinHeight))
                {
                    var levl = Convert.ToDouble(_bindDataList[i].NeedMinHeight);
 
                    list.Add(levl);
                }
                else
                {
                    list.Add(null);
                }
            } 
            return list;
        }
 
        public List<double?> GetMaxLevelHourValues()
        {
            List<double?> list = new List<double?>();
 
            for (int i = 0; i < 24; i++)
            {
                if (!string.IsNullOrEmpty(_bindDataList[i].NeedMaxHeight))
                {
                    var levl = Convert.ToDouble(_bindDataList[i].NeedMaxHeight);
 
                    list.Add(levl);
                }
                else
                {
                    list.Add(null);
                }
            }
            return list;
        }
 
 
 
        private void btn保存为模板_Click(object sender, EventArgs e)
        {
            SaveAsTemplate();
        }
 
 
        private bool _isInitialTemplateList = false;
        private void popupContainerEdit1_QueryPopUp(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (!SettingsHelper.IsDesingMode())
            {
                if (_isInitialTemplateList)
                    return;
                _isInitialTemplateList = true;
                InitialTemplateList();
            } 
        }
 
        private void listBoxControl1_DoubleClick(object sender, EventArgs e)
        {
            //if (listBoxControl1.SelectedValue == null) return;
            //var fileName = listBoxControl1.SelectedValue.ToString();
         
            //var folderPath = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(), "ReservoirDropTemplate");
            //if (!System.IO.Directory.Exists(folderPath))
            //{
            //    return;
            //}
            //LoadTemplate(System.IO.Path.Combine(folderPath, fileName));
        }
 
        private void InitialTemplateList()
        {
            //var folderPath = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(), "ReservoirDropTemplate");
            //if (!System.IO.Directory.Exists(folderPath))
            //{
            //    return;
            //}
 
            //DirectoryInfo folder = new DirectoryInfo(folderPath);
            //listBoxControl1.Items.Clear();
 
            //foreach (FileInfo file in folder.GetFiles("*.json",
            //    SearchOption.AllDirectories))
            //{
            //    // 处理每个文件 
            //    this.listBoxControl1.Items.Add(file.Name);
            //}
        }
 
        private void LoadTemplate(string filePath)
        {
            if (!System.IO.File.Exists(filePath))
            {
                return;
            }
 
            //文件流读取
            System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
            System.IO.StreamReader sr = new System.IO.StreamReader(fs, Encoding.GetEncoding("gb2312"));
            var contents = sr.ReadToEnd();
            sr.Close(); fs.Close();
 
            var templates = JsonHelper.Json2Object<List<HourValue>>(contents);
            if (templates == null) { return; }
 
 
            //var def = _bindList.First();
            //def.ClearHourValues();
            //foreach (var item in templates)
            //{
            //     def.HourValues[item.Hour]  = item.Value;
            //}
            //this.bindingSource1.DataSource = _bindList;
            //this.bindingSource1.ResetBindings(false);
        }
        private void SaveAsTemplate()
        {
            var rootFolder = System.IO.Path.Combine(IStation.DataFolderHelper.GetRootPath(),
                "ReservoirDropTemplate");
            if (!System.IO.Directory.Exists(rootFolder))
            {
                System.IO.Directory.CreateDirectory(rootFolder);
            }
            InputTemplateNameDlg frm = new InputTemplateNameDlg();
            if (frm.ShowDialog() != DialogResult.OK)
                return;
            var name = frm.TemplateName;
 
 
            //var values = GetUseHourValues();
            //if (values == null || values.Count == 0)
            //    return;
 
            //var fileContents = JsonHelper.Object2Json(values);
 
            //var fileName = System.IO.Path.Combine(rootFolder, name.Trim() + ".json");
            //if (System.IO.File.Exists(fileName))
            //{
            //    System.IO.File.Delete(fileName);
            //}
            //StreamWriter streamWriter = new StreamWriter(fileName, false, System.Text.Encoding.GetEncoding("gb2312"));
 
            //streamWriter.Write(fileContents);
 
            //streamWriter.Flush();
            //streamWriter.Close();
 
            //MessageBox.Show("保存成功");
        }
 
        private void checkBox总量_CheckedChanged(object sender, EventArgs e)
        {
            barEditItem用水总量.Enabled = checkBox总量.Checked;
            vGridControl1.Visible = !checkBox总量.Checked;
            rowDropFlow.Visible = !checkBox总量.Checked;
        }
 
        private void bci前一日记录_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            bci前一日记录.Checked = true; 
            barEditItem用水总量.Text = Convert.ToDouble(bci前一日记录.Tag).ToString();
 
            bci前三日记录.Checked = false; 
        }
 
        private void bci前三日记录_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            bci前一日记录.Checked =  false;
            barEditItem用水总量.Text = Convert.ToDouble(bci前三日记录.Tag).ToString();
 
            bci前三日记录.Checked = true;
        }
    }
}