duheng
2024-03-25 de6cca765801bf519d72dc4271ee8ae81d1b4fec
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
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.XtraPrinting;
using IStation.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
 
namespace IStation.WinFrmUI.Monitor
{
    public partial class ResultChartControl : DevExpress.XtraEditors.XtraUserControl
    {
        public ResultChartControl()
        {
            InitializeComponent();
        }
 
        private class CurrentModel : HistoryDataHelper
        {
            /// <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 Electricity { get; set; }
        }
 
 
        List<CurrentModel> _currentModel = new List<CurrentModel>();
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="datetime"></param>
        public void SetBindingData(DateTime datetime)
        {
            _currentModel.Clear();
            HistoryDataAPiHelper historyDataHelper = new HistoryDataAPiHelper();
            var result = historyDataHelper.getPumpIsOpen();
            var time = new DateTime(2022, 11, 6);
            foreach (var item in result)
            {
                var currentmodel = new CurrentModel
                {
                    Name = "方案",
                    Time = item.Item1.ToString("HH:mm") + "----" + item.Item2.ToString("HH:mm"),
                    PumpCount = item.Item3.ToString() + "台",
                    water = Math.Round(GetWaterdata(item.Item1, item.Item2), 2),
                    electricity = GetElectrityData(item.Item1, item.Item2),
                    Electricity = electricityPirce(item.Item1, item.Item2, GetElectrityData(item.Item1, item.Item2))
                };
                _currentModel.Add(currentmodel);
            }
            this.bindingSource1.DataSource = _currentModel;
        }
 
 
 
        private double GetWaterdata(DateTime Str, DateTime end)
        {
            HistoryDataAPiHelper historyDataHelper = new HistoryDataAPiHelper();
            var waterData = historyDataHelper.GetWaterData();
            var pump1 = WaterData(waterData.Where(x => x.Tag == "二取水1号主水泵.日累计").ToList(), Str, end);
            var pump2 = WaterData(waterData.Where(x => x.Tag == "二取水2号主水泵.日累计").ToList(), Str, end);
            var pump3 = WaterData(waterData.Where(x => x.Tag == "二取水3号主水泵.日累计").ToList(), Str, end);
            var pump4 = WaterData(waterData.Where(x => x.Tag == "二取水4号主水泵.日累计").ToList(), Str, end);
            var pump5 = WaterData(waterData.Where(x => x.Tag == "二取水5号主水泵.日累计").ToList(), Str, end);
            return pump1 + pump2 + pump3 + pump4 + pump5;
        }
 
 
        private double WaterData(List<Model.PumpWater> waterData, DateTime Str, DateTime end)
        {
            double result = 0;
            for (int i = 0; i < waterData.Count; i++)
            {
                if (waterData[i].Values[0].DateTime == Str)
                {
                    double startValue;
                    double endValue;
                    startValue = waterData[i].Values[0].SingleWater;
                    for (int j = i + 1; j < waterData.Count; j++)
                    {
                        if (waterData[j].Values[0].DateTime == end)
                        {
                            endValue = waterData[j].Values[0].SingleWater;
                            result = endValue - startValue;
                            return result;
                        }
                    }
                }
            }
            return result;
        }
 
 
        //电费计算
        private double electricityPirce(DateTime startTime, DateTime endTime, double electricity)
        {
            var ElePriceSetting = new BLL.ElecPrice().GetAll().First();
            var MonthList = ElePriceSetting.Settings.MonthList;
            var FindMonth = MonthList.Find(x => x.StartMonth <= startTime.Month && x.EndMonth >= startTime.Month);
            foreach (var item in FindMonth.HourList)
            {
                if (startTime.Hour >= item.StartHour && endTime.Hour <= item.EndHour)
                {
                    return Math.Round(item.Price * electricity, 2);
                }
            }
            return 0;
        }
 
 
 
        private double GetElectrityData(DateTime Str, DateTime end)
        {
            HistoryDataAPiHelper historyDataHelper = new HistoryDataAPiHelper();
            var Ele = historyDataHelper.GetEleData();
            var pump1 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204040193046").ToList(), Str, end);
            var pump2 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204040193047").ToList(), Str, end);
            var pump3 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204012308007").ToList(), Str, end);
            var pump4 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204012408007").ToList(), Str, end);
            var pump5 = ElectricityData(Ele.Where(x => x.Tag == "_0402010204012508007").ToList(), Str, end);
            return Math.Round(pump1 + pump2 + pump3 + pump4 + pump5, 2);
        }
 
 
        private double ElectricityData(List<Model.electricity> EleData, DateTime Str, DateTime end)
        {
            double result = 0;
            for (int i = 0; i < EleData.Count; i++)
            {
                if (EleData[i].TotalEle[0].DateTime == Str)
                {
                    double startValue;
                    double endValue;
                    startValue = EleData[i].TotalEle[0].Value;
                    for (int j = i + 1; j < EleData.Count; j++)
                    {
                        if (EleData[j].TotalEle[0].DateTime == end)
                        {
                            endValue = EleData[j].TotalEle[0].Value;
                            result = endValue - startValue;
                            return result;
                        }
                    }
                }
            }
            return result;
        }
 
 
 
 
        //表格点击事件
        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)
                    {
 
                    }
                }
            }
        }
    }
}