tangxu
2024-06-11 e08f18c84c96ca794407f4fcb737b26fa76c0a1f
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
using DevExpress.XtraBars.Docking2010;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using IStation.CalcModel;
using IStation.Model;
using IStation.WinFrmUI.CalcErQu.Wizard;
 
namespace IStation.WinFrmUI.CalcErQu
{
    public partial class pageCalcResult : XtraUserControl
    {
 
        private eAnaPrjType _anaPrjType = eAnaPrjType.Opt;
 
 
        private IStation.CalcModel.AnaRequest _anaRequest;
 
        /// <summary>
        /// 
        /// </summary>
        public pageCalcResult()
        {
            InitializeComponent();
 
 
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="anaPrjType"></param>
        internal void SetAnaType(eAnaPrjType anaPrjType)
        {
            this._anaPrjType = anaPrjType;
 
            RegistButtonClick();
        }
 
        #region 底部按钮
        /// <summary>
        /// 
        /// </summary>
        private void RegistButtonClick()
        {
            this.winBtnBottom.QueryPeekFormContent += windowsUIButtonPanel1_QueryPeekFormContent;
            foreach (var btn in winBtnBottom.Buttons)
            {
                if (btn is DevExpress.XtraBars.Docking2010.WindowsUIButton)
                {
                    var ui_btn = btn as DevExpress.XtraBars.Docking2010.WindowsUIButton;
                    if (ui_btn == null)
                        continue;
                    if (ui_btn.Tag == null)
                        continue;
                    switch (ui_btn.Tag.ToString())
                    {
                        case "导出":
                            {
                                // ExportRecursionCsv();
                                ui_btn.Click += (sender, e) => this.winBtnBottom.ShowPeekForm((DevExpress.XtraBars.Docking2010.WindowsUIButton)sender);
                                break;
                            }
                        case "Save":
                            ui_btn.Click += (sender, e) =>
                            {
                                if (_anaPrjType == eAnaPrjType.Opt)
                                {
                                    if (this._currentViewPrj == null)
                                        return;
                                    IStation.BLL.AnaPrj.SavePrj( this._anaRequest, IStation.AnaGlobalParas.Setting, _currentViewPrj, false);
                                      
                                    MessageBox.Show("保存成功");
                          
                                }
                                else
                                {
                                    ui_btn.Visible = false;
                                }
                            };
                            break;
                        case "Submit":
                            ui_btn.Click +=   (sender, e) =>
                            {
                                if (_anaPrjType != eAnaPrjType.Opt)
                                {
                                    return;
                                }
                                if (this._currentViewPrj == null)
                                    return;
                        
                                AlertTool.ShowInfo(this.ParentForm, "提示", "开始链接服务器");
                                IStation.BLL.AnaPrj.SavePrj(  this._anaRequest, IStation.AnaGlobalParas.Setting, _currentViewPrj,true );
                            };
                            break;
 
                        case "分析设置":
                            ui_btn.Click += (sender, e) =>
                            {
                                AnaSettingMgrDlg frm = new AnaSettingMgrDlg();
                                if (frm.ShowDialog() != DialogResult.OK)
                                    return;
                            };
                            break;
                        case "电价信息":
                            ui_btn.Click += (sender, e) =>
                            {
                                if (this._currentViewPrj == null)
                                    return;
 
                                ViewElecPriceByDay frm = new ViewElecPriceByDay();
                                frm.SetBindingData(this._currentViewPrj.StartTime);
                                frm.Show();
                            };
                            break;
                        case "上一步":
                            ui_btn.Click += (sender, e) =>
                            {
                                if (OnBeforePageEvent != null)
                                {
                                    OnBeforePageEvent.Invoke();
                                }
                            };
                            break;
 
 
                        case "重新分配":
                            ui_btn.Click += (sender, e) =>
                            {
                                RefreshPrjRangeTime();
                            };
                            break;
 
                        case "开始动画":
                            ui_btn.Click += (sender, e) =>
                            {
                                ShowChartTipWindow(true);
                            };
                            break;
                        case "暂停动画":
                            ui_btn.Click += (sender, e) =>
                            {
                                ShowChartTipWindow(false);
                            };
                            break;
                        default:
                            break;
                    }
                }
            }
 
 
 
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void windowsUIButtonPanel1_QueryPeekFormContent(object sender, QueryPeekFormContentEventArgs e)
        {
            if (e.Button is WindowsUIButton)
            {
                var tag = (e.Button as WindowsUIButton).Tag;
                if (tag == null)
                    return;
                if (tag.ToString() == "导出")
                {
                    #region 导出
 
                    var peekItems = new List<IStation.WinFrmUI.TilePeekItem>();
 
                    peekItems.Add(new IStation.WinFrmUI.TilePeekItem
                    {
                        Caption = "导出运行时间",
                        NormalImage = IStation.WinFrmUI.CalcErQu.Properties.Resources.Down32B,
                        Click = () =>
                        {
                            anaResultInfoDefaultCtrl.ExportSpanGrid();
                            this.winBtnBottom.HidePeekForm();
                        }
                    });
 
 
 
 
 
                    //peekItems.Add(new IStation.WinFrmUI.TilePeekItem
                    //{//加一个多余的, 保证下面不会被挡住
                    //    Caption = "",
                    //    Click = () =>
                    //    {
 
                    //    }
                    //});
 
                    var ctrl = new LayoutPeekCtrl();
                    ctrl.Padding = new System.Windows.Forms.Padding(0, 0, 0, 20);
                    //ctrl.Margin = new System.Windows.Forms.Padding(0, 0, 0, 40);
                    ctrl.SetBindingData(peekItems);
                    var peekCtrl = ctrl;// peekItems.CreatePeekCtrl();
                    e.Control = peekCtrl;
 
                    #endregion 风格
                }
            }
        }
 
 
        #endregion
 
 
 
        #region 动画
        //bool _isDispAnimationTip = false;
        //AnimationTipInfoDlg _tipDlg = null;
 
        private void ShowChartTipWindow(bool isShow)
        {
            //var realTimeDataList = anaResultInfoDefaultCtrl.GetRealTimeDataList();
            //if (_tipDlg != null)
            //{
            //    if (isShow)
            //    {
            //        if (_isDispAnimationTip)
            //            return;
            //        _isDispAnimationTip = true;
 
            //        _tipDlg.SetBindingData(this._currentViewPrj);
            //        _tipDlg.SetRealTimeDataList(realTimeDataList);
            //        _tipDlg.Show();
            //    }
            //    else
            //    {
            //        _isDispAnimationTip = false;
            //        _tipDlg.StopAnimation();
            //        _tipDlg.Hide();
            //    }
            //    return;
            //}
 
 
 
            //_tipDlg = new AnimationTipInfoDlg();
            //_tipDlg.TopMost = true;
            //_tipDlg.Name = "AnimationTipInfoDlg";
            //_tipDlg.WindowState = FormWindowState.Normal;
            //_tipDlg.SetPumpInfo(this._allCalcPumpInfos);
            //_tipDlg.OnStopAnimation += () =>
            //{
            //    this.anaResultInfoDefaultCtrl.SetTipLineVisible(false);
            //};
            //_tipDlg.OnStartAnimation += () =>
            //{
            //    this.anaResultInfoDefaultCtrl.SetTipLineVisible(true);
            //};
 
            //_tipDlg.OnRefreshAnimation += (t, d) =>
            //{
            //    anaResultInfoDefaultCtrl.SetTipLineValue(t);
            //};
 
            //_isDispAnimationTip = true;
            //anaResultInfoDefaultCtrl.SetTipLineValue(this._currentViewPrj.StartTime);
 
            //_tipDlg.OnHide = () =>
            //{
            //    _isDispAnimationTip = false;
            //    _tipDlg.Hide();
            //};
            //_tipDlg.SetRealTimeDataList(realTimeDataList);
            //_tipDlg.SetBindingData(this._currentViewPrj);
            //_tipDlg.Show();
        }
 
 
        #endregion
 
 
 
 
 
 
 
        /// <summary>
        /// 计算 手动
        /// </summary> 
        public void AnaManuResult(IStation.CalcModel.AnaRequest anaRequest, Action<bool> finish_cb)
        {
            this._anaRequest = anaRequest;
            if (anaRequest == null)
                return;
 
 
            if (anaRequest.WaterLevels长江 == null)
            {
                finish_cb.Invoke(false);
                MessageBox.Show("请输入长江水位信息");
                return;
            }
 
 
            //InitalPumpInfo();
 
            //InitialElePrice();
 
            //bool isLimitLevel = false;
            //if (anaRequest.MinLimitWaterBoxLevel != null && anaRequest.ReservoirMinLimitHours != null)
            //    isLimitLevel = true;
 
            //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(false, isLimitLevel);
 
            //string error_info;
            //AnaPrj anaPrj = new AnaPrj();
            //anaPrj.ID = Guid.NewGuid().ToString("N");
            //anaPrj.Type = 1;
            //anaPrj.Name = "手动";
            //anaPrj.CalcSpaceMinute = calcHelper.CalcSpaceMinute;
 
            //calcHelper.CalcManuPrj(ref anaPrj, anaRequest.ManuPrjTimeBlockList, out error_info);
            //if (!string.IsNullOrEmpty(error_info) || anaPrj == null)
            //{
            //    finish_cb.Invoke(false);
            //    MessageBox.Show(error_info);
            //    return;
            //}
 
 
 
            //this.ViewPrj(anaRequest, anaPrj, true);
 
            //finish_cb.Invoke(true);
        }
 
 
 
        /// <summary>
        /// 计算最优
        /// </summary> 
        public void AnaOptResult(IStation.CalcModel.AnaRequest anaRequest, Action<bool> finish_cb)
        {
            this._anaRequest = anaRequest;
            if (anaRequest == null)
                return;
 
 
 
            if (anaRequest.WaterLevels长江 == null)
            {
                finish_cb.Invoke(false);
                MessageBox.Show("请输入长江水位信息");
                return;
            }
 
 
            //InitalPumpInfo();
 
            //InitialElePrice();
 
            //bool isLimitLevel = false;
            //if (anaRequest.MinLimitWaterBoxLevel != null && anaRequest.ReservoirMinLimitHours != null)
            //    isLimitLevel = true;
            //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(true, isLimitLevel);
 
 
            var calcHelper = new IStation.CalcPrjHelper();
            AnaPrj defaultPrj = null;
            string error_info =  calcHelper.Calc(anaRequest, out defaultPrj);
 
            if (!string.IsNullOrEmpty(error_info) || defaultPrj == null  )
            {
                finish_cb.Invoke(false);
                MessageBox.Show(error_info);
                return;
            }
 
 
            // defaultPrj.Name = defaultPrj.Day.ToString();
 
            this.ViewPrj(anaRequest, defaultPrj, false);
 
            finish_cb.Invoke(true);
        }
 
 
 
        //
        AnaPrj _currentViewPrj;
        private void ViewPrj(IStation.CalcModel.AnaRequest anaRequest, AnaPrj current_prj, bool isManuPrj)
        {
            if (string.IsNullOrEmpty(current_prj.ID))
                current_prj.ID = Guid.NewGuid().ToString("N");
            this._currentViewPrj = current_prj;
            this._anaRequest = anaRequest;
            current_prj.SumMoney = Math.Round(current_prj.SumMoney, 0);
            current_prj.SumFlow = Math.Round(current_prj.SumFlow, 0);
            current_prj.SumPower = Math.Round(current_prj.SumPower, 0);
 
 
 
            //this.anaResultInfoDefaultCtrl.SetRiverWaterLevels(this._anaRequest.WaterLevels长江);
            //anaPrj.SumMoney = Math.Round(anaPrj.SumMoney, 0);
            //anaPrj.SumFlow = Math.Round(anaPrj.SumFlow, 0);
            //anaPrj.SumPower = Math.Round(anaPrj.SumPower, 0);
 
            var yester1_day_anaPrj = IStation.BLL.AnaPrj.GetPrj(current_prj.StartTime.AddDays(-1));
            //var yester2_day_anaPrj = HistoryAnaPrjFileHelper.GetAnaPrj(current_prj.StartTime.AddDays(-2));
 
            this.anaResultInfoDefaultCtrl.SetBindingData(current_prj, yester1_day_anaPrj);
 
 
            listBoxControl1.Items.Clear();
            listBoxControl1.Items.Add("----------目标参数---------");
            listBoxControl1.Items.Add(string.Format("取水总量 {0} 万方", anaRequest.TotalFlowIn / 10000));
            listBoxControl1.Items.Add(string.Format("优化目标 {0}  ", anaRequest.CalcOptType == eCalcOptType.功率 ? "用电量最优" : "电费最优"));
 
 
            listBoxControl1.Items.Add("----------开机方案---------");
            bool isFirstOpenPump = true;
            int last_open_num = 0;
            for (int i = 0; i < current_prj.BlockTimes.Count; i++)
            {
                var item = current_prj.BlockTimes[i];
 
 
                if (isFirstOpenPump)
                {
                    isFirstOpenPump = false;
                    last_open_num = item.OpenPumpCount;
                    listBoxControl1.Items.Add(string.Format("{0}  开机 {1}台 | 总台数{2}台", item.StartTime.ToString("HH:mm"), item.OpenPumpCount, item.OpenPumpCount));
                }
                else if (item.OpenPumpCount != last_open_num)
                {
                    isFirstOpenPump = false;
                    if (item.OpenPumpCount == 0)
                    {
                        listBoxControl1.Items.Add(string.Format("{0}  全部关机", item.StartTime.ToString("HH:mm"), item.OpenPumpCount));
                    }
                    else
                    {
                        if (item.OpenPumpCount > last_open_num)
                        {
                            if (last_open_num == 0)
                                listBoxControl1.Items.Add(string.Format("{0}  开启 {1}台 | 总台数{2}台", item.StartTime.ToString("HH:mm"), item.OpenPumpCount - last_open_num, item.OpenPumpCount));
                            else
                                listBoxControl1.Items.Add(string.Format("{0}  多开 {1}台 | 总台数{2}台", item.StartTime.ToString("HH:mm"), item.OpenPumpCount - last_open_num, item.OpenPumpCount));
                        }
                        else
                        {
                            listBoxControl1.Items.Add(string.Format("{0}  关掉 {1}台 | 总台数{2}台", item.StartTime.ToString("HH:mm"), last_open_num - item.OpenPumpCount, item.OpenPumpCount));
                        }
                    }
 
                    last_open_num = item.OpenPumpCount;
                }
            }
 
 
            //current_prj.Name = string.Format("当前水位:{0} ,最低水位:{1},最高水位:{2} ({3})",
            //        anaRequest.CurrentWaterBoxLevel,
            //        anaRequest.MinLimitWaterBoxLevel,
            //        anaRequest.MaxLimitWaterBoxLevel,
            //        anaRequest.CalcOptType);
 
            listBoxControl1.Items.Add("-----------水位参数--------");
 
            var allTime = current_prj.GetAllPointTimeList();
            DateTime max_wt_dt = allTime.First().Time;
            DateTime min_wt_dt = allTime.First().Time;
            double max_wt = double.MinValue;
            double min_wt = double.MaxValue;
            foreach (var pt in allTime)
            {
                if (max_wt < pt.WaterLevelH)
                {
                    max_wt_dt = pt.Time;
                    max_wt = pt.WaterLevelH;
                }
                if (min_wt > pt.WaterLevelH)
                {
                    min_wt_dt = pt.Time;
                    min_wt = pt.WaterLevelH;
                }
            }
 
            var wt_list = from x in allTime select x.WaterLevelH;
            var avr_wt = wt_list.Average();
            listBoxControl1.Items.Add(string.Format("最初水位: {0:N2} m (0时)", anaRequest.CurrentWaterBoxLevel));
            listBoxControl1.Items.Add(string.Format("最高水位: {1:N2} m ({0})", max_wt_dt.ToString("HH:mm"), Math.Round(max_wt, 2)));
            listBoxControl1.Items.Add(string.Format("最低水位: {1:N2} m ({0})", min_wt_dt.ToString("HH:mm"), Math.Round(min_wt, 2)));
            listBoxControl1.Items.Add(string.Format("平均水位: {0:N2} m", Math.Round(avr_wt, 2)));
 
            current_prj.WaterLevelInfo = string.Format("{0},{1},{2},{3},{4},{5}", anaRequest.CurrentWaterBoxLevel, max_wt_dt.ToString("HH:mm"), Math.Round(max_wt, 2),
                min_wt_dt.ToString("HH:mm"), Math.Round(min_wt, 2), Math.Round(avr_wt, 2));
        }
 
 
 
 
 
 
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="anaPrj"></param>
        /// <param name="ranges"></param>
        private void RereshPrjTimeSpan(IStation.CalcModel.AnaPrj anaPrj, List<CalcModel.PumpRunRange> ranges)
        {
            //IStation.WinFrmUI.WaitFrmHelper.ShowWaitForm(this);
 
            //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(false, false);
            //string error_info;
            //calcHelper.CalcManuPrj(ref anaPrj, ranges, out error_info);
            //IStation.WinFrmUI.WaitFrmHelper.HideWaitForm(this);
 
            //if (!string.IsNullOrEmpty(error_info) || anaPrj == null)
            //{
            //    MessageBox.Show(error_info);
            //    return;
            //}
 
 
            //this.ViewPrj(this._anaRequest, anaPrj, true);
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void layoutControlGroup7_CustomButtonClick(object sender,
            DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            var btn = e.Button as DevExpress.XtraEditors.ButtonsPanelControl.GroupBoxButton;
            if (btn == null || btn.Tag == null)
                return;
 
            if (btn.Tag.ToString() == "Export")
            {
 
            }
            if (btn.Tag.ToString() == "Empty")
            {
 
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="anaPrj"></param>
        private void RefreshPrjRangeTime()
        {
            var anaPrj = anaResultInfoDefaultCtrl.GetAnaPrj();
            if (anaPrj == null)
                return;
            //DateTime rangeStartTime, rangeEndTime;
            //GetAnaRangeTime(out rangeStartTime, out rangeEndTime);
            SetPrjItemSpanTimeInfoDlg frm = new SetPrjItemSpanTimeInfoDlg();
            frm.SetBindingData(anaPrj);
            frm.OnRefreshData += (prj, ranges) =>
            {
                anaPrj = prj;
                bindingSourcePrjList.ResetBindings(false);
 
                RereshPrjTimeSpan(anaPrj, ranges);
            };
            if (frm.ShowDialog() == DialogResult.OK)
            {
 
            }
        }
 
 
        // public event MethodInvoker OnNextPageEvent;//下一步委托事件
        public event MethodInvoker OnBeforePageEvent;//上一步委托事件
 
        /// <summary>
        /// 
        /// </summary>
        private void ExportRecursionCsv()
        {
            //if (string.IsNullOrEmpty(textEditTotalFlow水库放水量.Text))
            //{
            //    return;
            //}
 
            //if (!Initial长江水位())
            //{
            //    MessageBox.Show("请输入长江水位信息");
            //    return;
            //}
 
 
            //InitalPumpInfo();
 
            //InitialElePrice();
 
 
 
 
            //IStation.Calc.ErQuCalcBaseHelper calcHelper = GetCalcHelper(false );
 
 
 
            //SaveFileDialog saveFileDlg = new SaveFileDialog();
            //saveFileDlg.Filter = "csv 文件(*.csv)|*.csv";
            //if (saveFileDlg.ShowDialog() != DialogResult.OK)
            //    return;
 
            //string error_info;
            //calcHelper.ExportTimeData(saveFileDlg.FileName, out error_info);
            //if (!string.IsNullOrEmpty(error_info))
            //    MessageBox.Show(error_info);
        }
 
        private void anaResultInfoDefaultCtrl_Load(object sender, EventArgs e)
        {
 
        }
 
        private void groupControl1_CustomButtonClick(object sender, BaseButtonEventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            foreach(var item in listBoxControl1.Items)
            {
                sb.Append(item.ToString());sb.AppendLine();
            }
            Clipboard.SetDataObject(sb.ToString());
            MessageBox.Show("已把文字内容复制到黏贴板中");
        }
    }
}