duheng
2024-03-28 6c93aedfeeb66023f9506083517aee1a4e18e24d
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
using DevExpress.XtraGrid.Views.Grid;
using IStation.BLL;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Monitor
{
    public partial class ResultChartControl : DevExpress.XtraEditors.XtraUserControl
    {
        public ResultChartControl()
        {
            InitializeComponent();
        }
 
        private class CurrentModel  
        {
            /// <summary>
            /// 名称
            /// </summary>
            public string Name { get; set; }
            /// <summary>
            /// 泵台数
            /// </summary>
            public string PumpCount { get; set; }
            /// <summary>
            /// 开机时间段
            /// </summary>
            public string Time { get; set; }
            /// <summary>
            /// 电费 
            /// </summary>
            public double ElectricityPrice { get; set; }
            /// <summary>
            /// 用电量
            /// </summary>
            public double Electricity { get; set; }  
            /// <summary>
            /// 取水量
            /// </summary>
            public double Water { get; set;  }
            /// <summary>
            /// 持续时间
            /// </summary>
            public double TimeSpan { get; set; }
            /// <summary>
            /// 总取水量
            /// </summary>
            public double TotalWater { get; set; }
            /// <summary>
            /// 总电费
            /// </summary>
            public double TotalElePrice { get; set; }
            /// <summary>
            /// 总用电量
            /// </summary>
            public  double TotalEle { get;set; }    
         }
 
        DateTime DateTime;
        DateTime ListDayTime;
        List<CurrentModel> _currentModel = new List<CurrentModel>();
        CalcModel.AnaPrj _ana = null;
        Model.RunParasData _LastYeay = null;
 
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="datetime"></param>
        public void SetBindingData(DateTime datetime)
        {
            ListDayTime = datetime;
            if (checkEditCalendar.Checked == false)
            {
                DateTime= datetime.AddDays(-366);
            }
            else
            {
                DateTime = ConvertDateTime(datetime);
            }
             _currentModel.Clear();
            HistoryDataAPiHelper historyDataAPiHelper = new HistoryDataAPiHelper();
            PumpRunHelper pumpRunHelper = new PumpRunHelper();
              _ana = IStation.BLL.AnaPrj.GetPrj(datetime);
            _LastYeay = pumpRunHelper.GetByHistoryOneData(DateTime, out string error);
            var IsOpen = historyDataAPiHelper.MergeTimeSlots(MergeList(_LastYeay));
            if (IsOpen != null&& _ana!=null)
            {
                foreach (var model in IsOpen)
                {
                    var LastYear = new CurrentModel
                    {
                        Name = "去年同期",
                        PumpCount = string.Format("{0}台泵", model.Item3.ToString()),
                        Time = model.Item1.ToString("dd日HH:mm") + "-" + model.Item2.ToString("dd日HH:mm"),
                        ElectricityPrice = model.Item4,
                        Water = model.Item5,
                        Electricity = model.Item6,
                        TimeSpan= (model.Item2-model.Item1).TotalMinutes,
                         TotalEle= _LastYeay.Electric,
                         TotalElePrice= _LastYeay.Money,
                         TotalWater=_LastYeay.FlowIn
                    };
                      _currentModel.Add(LastYear);
                 }
            }
            if (_ana != null)
            {
                foreach (var item in _ana.BlockTimes)
                {
                    if (item.OpenPumpCount == 0)
                    {
                        continue;
                    }
                    var project = new CurrentModel
                    {
                        Name = "方案",
                        PumpCount = string.Format("{0}台泵", item.OpenPumpCount),
                       Time = item.StartTime.ToString("dd日HH:mm") + "-" + item.EndTime.ToString("dd日HH:mm"),
                       Electricity = item.SumPower,
                       ElectricityPrice=item.SumMoney,
                       Water = item.SumFlow,
                        TimeSpan= (item.EndTime-item.StartTime).TotalMinutes,
                        TotalEle= _ana.SumFlow4Disp,
                        TotalWater= _ana.SumPower4Disp, 
                        TotalElePrice= _ana.SumMoney,
                     };
                     _currentModel.Add(project);
                  }
            }
            this.bindingSource1.DataSource = _currentModel;
            this.bindingSource1.ResetBindings(false);
        } 
 
 
        //合并所有开始时间-结束时间
        private List<(DateTime, DateTime,double,double,double)> MergeList(Model.RunParasData   runParasData)
        {
            List<(DateTime, DateTime,double,double,double)> values = new List<(DateTime, DateTime, double, double, double)>();
            foreach (var item in runParasData.Pump1)
            {
                values.Add((item.StartTime, item.EndTime,item.Money, item.FlowIn,item.Electric));
            }
            foreach (var item in runParasData.Pump2)
            {
                values.Add((item.StartTime, item.EndTime, item.Money, item.FlowIn, item.Electric));
            }
            foreach (var item in runParasData.Pump3)
            {
                values.Add((item.StartTime, item.EndTime, item.Money, item.FlowIn, item.Electric));
            }
            foreach (var item in runParasData.Pump4)
            {
                values.Add((item.StartTime, item.EndTime, item.Money, item.FlowIn, item.Electric));
            }
            foreach (var item in runParasData.Pump5)
            {
                values.Add((item.StartTime, item.EndTime, item.Money, item.FlowIn, item.Electric));
            }
            return values;
        }
 
 
        //农历阴历日期转换
        private   DateTime ConvertDateTime(DateTime lastYearDay)
        {
 
            // 创建一个 ChineseLunisolarCalendar 实例
            ChineseLunisolarCalendar chineseCalendar = new ChineseLunisolarCalendar();
 
            // 获取今年的阴历日期
            int thisYear = chineseCalendar.GetYear(lastYearDay);
            int thisMonth = chineseCalendar.GetMonth(lastYearDay);
            int thisDay = chineseCalendar.GetDayOfMonth(lastYearDay);
 
  
            // 将阴历日期减去一年
            DateTime lastYearLunarDate = chineseCalendar.ToDateTime(thisYear, thisMonth, thisDay, 0, 0, 0, 0).AddYears(-1);
 
            // 将去年的阴历日期转换为阳历日期
            DateTime lastYearSolarDate = ConvertChineseToGregorian(lastYearLunarDate.Year, lastYearLunarDate.Month, lastYearLunarDate.Day);
            return lastYearSolarDate;
         }
 
        // 将农历日期转换为阳历日期的方法
        static DateTime ConvertChineseToGregorian(int year, int month, int day)
        {
            // 创建 ChineseLunisolarCalendar 实例
            ChineseLunisolarCalendar chineseCalendar = new ChineseLunisolarCalendar();
 
            // 将农历日期转换为阳历日期
            DateTime gregorianDate = chineseCalendar.ToDateTime(year, month, day, 0, 0, 0, 0);
 
            return gregorianDate;
        }
 
        //表格点击事件
        private void gridControl2_MouseDown(object sender, MouseEventArgs e)
        {
            GridView gridView = gridControl2.MainView as GridView;
            if (gridView != null)
            {
                // 获取鼠标所在的单元格
                DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo = gridView.CalcHitInfo(e.Location);
 
                // 如果点击到单元格上
                if (hitInfo.InRowCell)
                {
                    // 获取点击的单元格的行和列
                    int rowHandle = hitInfo.RowHandle;
                    int columnHandle = hitInfo.Column.VisibleIndex;
                    object cellValue = gridView.GetRowCellValue(rowHandle, gridView.Columns[columnHandle]);
 
                    // 处理获取到的单元格数据
                    if (cellValue != null)
                    {
 
                    }
                }
            }
        }
 
        private void checkEditCalendar_CheckedChanged(object sender, EventArgs e)
        {
            this.SetBindingData(ListDayTime);
        }
 
 
    }
}