| | |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraCharts; |
| | | using DevExpress.XtraGrid.Views.Grid; |
| | | using DevExpress.XtraGrid; |
| | | using DevExpress.XtraPrinting; |
| | | using IStation.Model; |
| | | using DevExpress.XtraRichEdit.Model; |
| | | using IStation.BLL; |
| | | using IStation.WinFrmUI.CalcErQu; |
| | | 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.Globalization; |
| | | using System.Windows.Forms; |
| | | using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; |
| | | using IStation.BLL; |
| | | |
| | | namespace IStation.WinFrmUI.Monitor |
| | | { |
| | |
| | | InitializeComponent(); |
| | | } |
| | | |
| | | private class CurrentModel : HistoryDataHelper |
| | | private class CurrentModel |
| | | { |
| | | /// <summary> |
| | | /// 名称 |
| | |
| | | /// <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; } |
| | | /// <summary> |
| | | /// 千吨水能耗 |
| | | /// </summary> |
| | | public double QDSLN { get; set; } |
| | | |
| | | } |
| | | |
| | | |
| | | DateTime DateTime; //api查询需要的日期 |
| | | DateTime ListDayTime; //listBox当前选择的日期 |
| | | List<CurrentModel> _currentModel = new List<CurrentModel>(); |
| | | CalcModel.AnaPrj _ana = null; |
| | | Model.RunParasData _LastYeay = null; |
| | | Model.RunParasData _currentData = null; |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | |
| | | /// <param name="datetime"></param> |
| | | public void SetBindingData(DateTime datetime) |
| | | { |
| | | PumpRunHelper pumpRunHelper = new PumpRunHelper(); |
| | | pumpRunHelper.GetPumpRunParasOneDay(datetime,out string error1); |
| | | pumpRunHelper.GetByHistoryOneData(new DateTime(2023,2,5),out string error); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | //电费计算 |
| | | 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) |
| | | ListDayTime = datetime; |
| | | if (checkEditCalendar.SelectedIndex == 1) |
| | | { |
| | | if (startTime.Hour >= item.StartHour && endTime.Hour <= item.EndHour) |
| | | 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); //去年同期 |
| | | _currentData = pumpRunHelper.GetPumpRunParasOneDay(DateTime, out string err); //实际数据 |
| | | var LastYearIsOpen = historyDataAPiHelper.MergeTimeSlots(MergeList(_LastYeay)); |
| | | var CurrentDateOpen = historyDataAPiHelper.MergeTimeSlots(MergeList(_currentData)); |
| | | if (LastYearIsOpen != null && _ana != null) |
| | | { |
| | | foreach (var model in LastYearIsOpen) |
| | | { |
| | | return Math.Round(item.Price * electricity, 2); |
| | | var LastYear = new CurrentModel |
| | | { |
| | | Name = "去年同期" + model.Item1.ToString("(yyyy-MM-dd)"), |
| | | PumpCount = string.Format("{0}台泵", model.Item3.ToString()), |
| | | Time = model.Item1.ToString("HH:mm") + "-" + model.Item2.ToString("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); |
| | | } |
| | | } |
| | | return 0; |
| | | if (_ana != null) |
| | | { |
| | | foreach (var item in _ana.BlockTimes) |
| | | { |
| | | if (item.OpenPumpCount == 0) |
| | | { |
| | | continue; |
| | | } |
| | | var project = new CurrentModel |
| | | { |
| | | Name = "方案" + item.StartTime.ToString("(yyyy-MM-dd)"), |
| | | PumpCount = string.Format("{0}台泵", item.OpenPumpCount), |
| | | Time = item.StartTime.ToString("HH:mm") + "-" + item.EndTime.ToString("HH:mm"), |
| | | Electricity = Math.Round(item.SumPower / 1000, 2), |
| | | ElectricityPrice = Math.Round(item.SumMoney / 1000, 2), |
| | | Water = Math.Round(item.SumFlow, 2), |
| | | TimeSpan = (item.EndTime - item.StartTime).TotalMinutes, |
| | | TotalEle = Math.Round(_ana.SumPower4Disp / 1000, 2), |
| | | TotalWater = _ana.SumFlow4Disp, |
| | | TotalElePrice = Math.Round(_ana.SumMoney / 1000, 2), |
| | | QDSLN = _ana.QDSLN |
| | | |
| | | }; |
| | | _currentModel.Add(project); |
| | | } |
| | | } |
| | | if (DateTime.Now.Date > datetime && CurrentDateOpen != null && LastYearIsOpen != null && _ana != null) |
| | | { |
| | | foreach (var model in CurrentDateOpen) |
| | | { |
| | | var CurrentDate = new CurrentModel |
| | | { |
| | | Name = "实际" + model.Item1.ToString("(yyyy-MM-dd)"), |
| | | PumpCount = string.Format("{0}台泵", model.Item3.ToString()), |
| | | Time = model.Item1.ToString("HH:mm") + "-" + model.Item2.ToString("HH:mm"), |
| | | ElectricityPrice = model.Item4, |
| | | Water = model.Item5, |
| | | Electricity = model.Item6, |
| | | TimeSpan = (model.Item2 - model.Item1).TotalMinutes, |
| | | TotalEle = _currentData.Electric, |
| | | TotalElePrice = _currentData.Money, |
| | | TotalWater = _currentData.FlowIn |
| | | }; |
| | | _currentModel.Add(CurrentDate); |
| | | } |
| | | } |
| | | GetTideData(Model.eTideSouce.Book, 5, datetime, new DateTime(datetime.Year, datetime.Month, datetime.Day, 23, 59, 59)); |
| | | GetTideData(Model.eTideSouce.Web, 6, datetime, new DateTime(datetime.Year, datetime.Month, datetime.Day, 23, 59, 59)); |
| | | this.bindingSource1.DataSource = _currentModel; |
| | | this.bindingSource1.ResetBindings(false); |
| | | } |
| | | |
| | | |
| | | |
| | | private double GetElectrityData(DateTime Str, DateTime end) |
| | | //合并所有开始时间-结束时间 |
| | | private List<(DateTime, DateTime, double, double, double)> MergeList(Model.RunParasData runParasData) |
| | | { |
| | | return 0; |
| | | 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 = new DateTime(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 chineseCalendar = new ChineseLunisolarCalendar(); |
| | | // 将农历日期转换为阳历日期 |
| | | DateTime gregorianDate = chineseCalendar.ToDateTime(year, month, day, 0, 0, 0, 0); |
| | | return gregorianDate; |
| | | } |
| | | |
| | | //表格点击事件 |
| | | private void gridControl2_MouseDown(object sender, MouseEventArgs e) |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //获取水位数据 |
| | | private void GetTideData(Model.eTideSouce eTideSouce, int sort, DateTime Startday, DateTime Endday) |
| | | { |
| | | XYDiagram main_diagram = chartControl实时数据.Diagram as XYDiagram; |
| | | var axisTime = main_diagram.AxisX; |
| | | axisTime.VisualRange.Auto = true; |
| | | axisTime.WholeRange.Auto = true; |
| | | axisTime.WholeRange.SideMarginsValue = 0; |
| | | axisTime.VisualRange.SideMarginsValue = 0; |
| | | axisTime.WholeRange.SetMinMaxValues(Startday, Startday.AddDays(1)); |
| | | axisTime.VisualRange.SetMinMaxValues(Startday, Startday.AddDays(1)); |
| | | var tidelist = BLL.TideHelper.GetByDayRange(eTideSouce, Startday, Endday, out string a); |
| | | var SeriseMonitor = this.chartControl实时数据.Series[sort]; |
| | | SeriseMonitor.Points.Clear(); |
| | | if (tidelist != null) |
| | | { |
| | | foreach (var item in tidelist) |
| | | { |
| | | SeriseMonitor.Points.Add(new SeriesPoint(item.Time, item.Level)); |
| | | } |
| | | } |
| | | if (SeriseMonitor.Points.Count == 0) |
| | | { |
| | | SeriseMonitor.ShowInLegend = false; |
| | | } |
| | | else SeriseMonitor.ShowInLegend = true; |
| | | } |
| | | |
| | | |
| | | //比较 |
| | | private void barBtnCompare_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | var dlg = new HistoryDlg(); |
| | | dlg.SetBindingData(_ana); |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | //日历check选择变换事件 |
| | | private void checkEditCalendar_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | this.SetBindingData(ListDayTime); |
| | | } |
| | | |
| | | |
| | | /* |
| | | private void gridView2_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) |
| | | { |
| | | GridView view = sender as GridView; |
| | | |
| | | // 指定需要合并的列 |
| | | if (e.Column.FieldName == "PumpCount") |
| | | { |
| | | // 获取当前单元格所在行的 Name 字段的值 |
| | | object currentNameValue = view.GetRowCellValue(e.ListSourceRowIndex, "Name"); |
| | | // int nRowIndex = e.ListSourceRowIndex + 1; |
| | | // 获取下一个单元格所在行的 Name 字段的值 |
| | | int nextRowIndex = e.ListSourceRowIndex + 1; |
| | | object nextNameValue = nextRowIndex < view.RowCount ? view.GetRowCellValue(nextRowIndex, "Name") : null; |
| | | |
| | | // 获取当前单元格的 PumpCount 字段的值 |
| | | object currentPumpCountValue = view.GetRowCellValue(e.ListSourceRowIndex, "PumpCount"); |
| | | |
| | | // 获取下一个单元格的 PumpCount 字段的值 |
| | | object nextPumpCountValue = nextRowIndex < view.RowCount ? view.GetRowCellValue(nextRowIndex, "PumpCount") : null; |
| | | |
| | | // 检查当前单元格的 Name 字段的值与下一个单元格的值是否相同,且当前单元格的 PumpCount 字段的值与下一个单元格的值是否相同,如果满足条件则进行合并 |
| | | if (currentNameValue != null && nextNameValue != null && currentPumpCountValue != null && nextPumpCountValue != null && |
| | | currentNameValue.Equals(nextNameValue) && currentPumpCountValue.Equals(nextPumpCountValue)) |
| | | { |
| | | // 将下一个单元格的 PumpCount 字段的值设为空字符串,以达到合并效果 |
| | | // view.SetRowCellValue(nextRowIndex, "PumpCount", nextPumpCountValue); |
| | | // view.DeleteRow(nextRowIndex); |
| | | view.SetRowCellValue(nextRowIndex, "PumpCount", $"{currentPumpCountValue}"); |
| | | |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | |
| | | private void gridView2_CellMerge(object sender, CellMergeEventArgs e) |
| | | { |
| | | foreach (DevExpress.XtraGrid.Columns.GridColumn column in gridView2.Columns) |
| | | { |
| | | if (column.FieldName == "PumpCount") |
| | | { |
| | | if (e.CellValue1 == e.CellValue2) |
| | | { |
| | | column.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True; |
| | | } |
| | | } |
| | | else |
| | | column.OptionsColumn.AllowMerge = DevExpress.Utils.DefaultBoolean.True; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |