1 完成升压站单路直流电压电流组合采集器报警设置功能指令、通信编写,并进行串口通信测试; 新增bug: 1 串口通信内部存在bug,导致两个串口内部有关联,从而导致两个串口无法同时通信;
326 lines
11 KiB
C#
326 lines
11 KiB
C#
using JiangsuEarthquake.Common;
|
||
using JiangsuEarthquake.DataAccess;
|
||
using JiangsuEarthquake.Models;
|
||
using JiangsuEarthquake.Views;
|
||
using JiangsuEarthquake.Views.UserControls;
|
||
using LiveCharts;
|
||
using LiveCharts.Defaults;
|
||
using LiveCharts.Wpf;
|
||
using MySql.Data.MySqlClient;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Media;
|
||
|
||
namespace JiangsuEarthquake.ViewModels
|
||
{
|
||
public class BoosterStationStateDataViewModel : NotifyBase
|
||
{
|
||
public BoosterStationStateDataModel boosterStationStateDataModel { get; set; } = new BoosterStationStateDataModel();
|
||
|
||
public BoosterStationStateDataView boosterStationStateDataView { get; set; } = new BoosterStationStateDataView();
|
||
|
||
|
||
#region SearchData
|
||
|
||
private DateTime _startDateTime;
|
||
|
||
public DateTime StartDateTime
|
||
{
|
||
get { return _startDateTime; }
|
||
set { Set(ref _startDateTime, value); }
|
||
}
|
||
|
||
private DateTime _endDateTime;
|
||
|
||
public DateTime EndDateTime
|
||
{
|
||
get { return _endDateTime; }
|
||
set { Set(ref _endDateTime, value); }
|
||
}
|
||
|
||
int PageIndex = 0;
|
||
|
||
private int recordCount;
|
||
|
||
public int RecordCount
|
||
{
|
||
get { return recordCount; }
|
||
set { recordCount = value; this.DoNotify(); }
|
||
}
|
||
|
||
private int totalPage;
|
||
|
||
public int TotalPage
|
||
{
|
||
get { return totalPage; }
|
||
set { totalPage = value; this.DoNotify(); }
|
||
}
|
||
|
||
private string boosterStationStateMsg;
|
||
|
||
public string BoosterStationStateMsg
|
||
{
|
||
get { return boosterStationStateMsg; }
|
||
set { boosterStationStateMsg = value; this.DoNotify(); }
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region Coordinate Axis
|
||
public SeriesCollection seriesCollection;
|
||
|
||
public SeriesCollection SeriesCollection
|
||
{
|
||
get { return seriesCollection; }
|
||
set
|
||
{
|
||
seriesCollection = value;
|
||
this.DoNotify();
|
||
}
|
||
}
|
||
|
||
private Func<double, string> _xFormatter;
|
||
|
||
public Func<double, string> XFormatter
|
||
{
|
||
get { return _xFormatter; }
|
||
set
|
||
{
|
||
_xFormatter = value;
|
||
this.DoNotify();
|
||
}
|
||
}
|
||
|
||
private Func<double, string> _yFormatter1;
|
||
|
||
public Func<double, string> YFormatter1
|
||
{
|
||
get { return _yFormatter1; }
|
||
set
|
||
{
|
||
_yFormatter1 = value;
|
||
this.DoNotify();
|
||
}
|
||
}
|
||
|
||
private Func<double, string> _yFormatter2;
|
||
|
||
public Func<double, string> YFormatter2
|
||
{
|
||
get { return _yFormatter2; }
|
||
set
|
||
{
|
||
_yFormatter2 = value;
|
||
this.DoNotify();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
private ObservableCollection<BoosterStationStateDataModel> boosterStationStateDataList = new ObservableCollection<BoosterStationStateDataModel>();
|
||
|
||
public ObservableCollection<BoosterStationStateDataModel> BoosterStationStateDataList
|
||
{
|
||
get { return boosterStationStateDataList; }
|
||
set { boosterStationStateDataList = value; this.DoNotify(); }
|
||
}
|
||
|
||
private ObservableCollection<BoosterStationStateDataModel> totalBoosterStationStateDataList = new ObservableCollection<BoosterStationStateDataModel>();
|
||
|
||
public ObservableCollection<BoosterStationStateDataModel> TotalBoosterStationStateDataList
|
||
{
|
||
get { return totalBoosterStationStateDataList; }
|
||
set { totalBoosterStationStateDataList = value; this.DoNotify(); }
|
||
}
|
||
|
||
public CommandBase ForwordBoosterStationStateCommand { get; set; } //读取日志信息
|
||
|
||
public CommandBase NextBoosterStationStateCommand { get; set; } //读取日志信息
|
||
|
||
int station_id = 1;
|
||
|
||
|
||
#region Data Filtering
|
||
public static DialogViewModel vm;
|
||
|
||
private bool _isChecked;
|
||
|
||
public bool IsChecked
|
||
{
|
||
get { return _isChecked; }
|
||
set
|
||
{
|
||
_isChecked = value;
|
||
this.DoNotify();
|
||
|
||
string timeSearch = "";
|
||
if (IsChecked)
|
||
{
|
||
if (string.IsNullOrEmpty(EndDateTime.ToString()) || string.IsNullOrEmpty(StartDateTime.ToString()))
|
||
{
|
||
IsChecked = false;
|
||
return;
|
||
}
|
||
|
||
if (EndDateTime < StartDateTime)
|
||
{
|
||
HandyControl.Controls.Dialog.Show(new TextDialog("起始时间大于结束时间,\n请重新输入!"));
|
||
//this.EndDateTime = DateTime.Now;
|
||
//this.StartDateTime = DateTime.Now.AddDays(-1);
|
||
IsChecked = false;
|
||
return;
|
||
}
|
||
|
||
timeSearch = " and DataTime BETWEEN '" + StartDateTime + "' and '" + EndDateTime + "' ";
|
||
}
|
||
else
|
||
{
|
||
timeSearch = "";
|
||
}
|
||
|
||
//设置当前页为1
|
||
PageIndex = 1;
|
||
|
||
TotalBoosterStationStateDataList.Clear();
|
||
BoosterStationStateDataList.Clear();
|
||
|
||
var chartValuesTeam1 = new ChartValues<DateTimePoint>();
|
||
var chartValuesTeam2 = new ChartValues<DateTimePoint>();
|
||
string sql = String.Format("select RecordTime,In_Vol,In_Cur from boosterstationstate where StationID = {0} {1} ORDER by id desc limit 100", station_id, timeSearch);
|
||
MySqlDataReader dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
int index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
BoosterStationStateDataModel boosterStationStateDataModel = new BoosterStationStateDataModel();
|
||
boosterStationStateDataModel.Index = index++;
|
||
boosterStationStateDataModel.DataTime = Convert.ToDateTime(dataReader["RecordTime"]);
|
||
boosterStationStateDataModel.In_Vol = Convert.ToSingle(string.IsNullOrEmpty(dataReader["In_Vol"].ToString()) ? "0" : dataReader["In_Vol"]);
|
||
boosterStationStateDataModel.In_Cur = Convert.ToSingle(string.IsNullOrEmpty(dataReader["In_Cur"].ToString()) ? "0" : dataReader["In_Cur"]);
|
||
TotalBoosterStationStateDataList.Add(boosterStationStateDataModel);
|
||
|
||
if (!Convert.IsDBNull(dataReader["In_Vol"]) && !Convert.IsDBNull(dataReader["In_Cur"]))
|
||
{
|
||
chartValuesTeam1.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Vol"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
chartValuesTeam2.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Cur"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
}
|
||
}
|
||
dataReader.Dispose();
|
||
|
||
RecordCount = index - 1;
|
||
if (RecordCount <= 10)
|
||
{
|
||
TotalPage = 1;
|
||
|
||
BoosterStationStateDataList = TotalBoosterStationStateDataList;
|
||
}
|
||
else
|
||
{
|
||
TotalPage = (int)Math.Ceiling((double)RecordCount / 10);
|
||
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
BoosterStationStateDataList.Add(TotalBoosterStationStateDataList[i]);
|
||
}
|
||
}
|
||
|
||
BoosterStationStateMsg = string.Format("共计{0}页,当前第{1}页", TotalPage, PageIndex);
|
||
|
||
SeriesCollection = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电压",
|
||
Values =chartValuesTeam1,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
new LineSeries
|
||
{
|
||
Title = "输入电流",
|
||
Values = chartValuesTeam2,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 1,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 255, 165, 0)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
XFormatter = val => new DateTime((long)val).ToString("MM/dd HH:mm");
|
||
YFormatter1 = val => val.ToString("F2") + " V";
|
||
YFormatter2 = val => val.ToString("F2") + " A";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
public BoosterStationStateDataViewModel(int id)
|
||
{
|
||
// 默认查询1天内的日志
|
||
this.EndDateTime = DateTime.Now;
|
||
this.StartDateTime = DateTime.Now.AddDays(-1);
|
||
|
||
PageIndex = 1;
|
||
station_id = id;
|
||
|
||
vm = new DialogViewModel
|
||
{
|
||
Content = ""
|
||
};
|
||
|
||
this.ForwordBoosterStationStateCommand = new CommandBase();
|
||
this.ForwordBoosterStationStateCommand.DoExcute = new Action<object>(ForwordBoosterStationState);
|
||
this.ForwordBoosterStationStateCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.NextBoosterStationStateCommand = new CommandBase();
|
||
this.NextBoosterStationStateCommand.DoExcute = new Action<object>(NextBoosterStationState);
|
||
this.NextBoosterStationStateCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
}
|
||
|
||
|
||
#region Page Switching
|
||
public void ForwordBoosterStationState(object o)
|
||
{
|
||
if (PageIndex == 1)
|
||
return;
|
||
PageIndex -= 1;
|
||
|
||
BoosterStationStateDataList.Clear();
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
BoosterStationStateDataList.Add(TotalBoosterStationStateDataList[i + (PageIndex - 1) * 10]);
|
||
}
|
||
BoosterStationStateMsg = string.Format("共计{0}页,当前第{1}页", TotalPage, PageIndex);
|
||
}
|
||
|
||
public void NextBoosterStationState(object o)
|
||
{
|
||
if (PageIndex == TotalPage)
|
||
return;
|
||
PageIndex += 1;
|
||
|
||
BoosterStationStateDataList.Clear();
|
||
for (int i = 0; i < (PageIndex == TotalPage ? (RecordCount - (PageIndex - 1) * 10) : 10); i++)
|
||
{
|
||
BoosterStationStateDataList.Add(TotalBoosterStationStateDataList[i + (PageIndex - 1) * 10]);
|
||
}
|
||
BoosterStationStateMsg = string.Format("共计{0}页,当前第{1}页", TotalPage, PageIndex);
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|