using JiangsuEarthquake.Common; using JiangsuEarthquake.DataAccess; using JiangsuEarthquake.Models; using JiangsuEarthquake.Views; using JiangsuEarthquake.Views.UserControls; using LiveCharts; using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Media; using static Org.BouncyCastle.Crypto.Engines.SM2Engine; using Brush = System.Windows.Media.Brush; namespace JiangsuEarthquake.ViewModels { public class RealTimeDataViewModel : NotifyBase { #region State Define private string mainSeisVol; public string MainSeisVol { get { return mainSeisVol; } set { mainSeisVol = value; this.DoNotify(); } } private string mainSeisCur; public string MainSeisCur { get { return mainSeisCur; } set { mainSeisCur = value; this.DoNotify(); } } private string backupSeisVol; public string BackupSeisVol { get { return backupSeisVol; } set { backupSeisVol = value; this.DoNotify(); } } private string backupSeisCur; public string BackupSeisCur { get { return backupSeisCur; } set { backupSeisCur = value; this.DoNotify(); } } private string boosterStationVol; public string BoosterStationVol { get { return boosterStationVol; } set { boosterStationVol = value; this.DoNotify(); } } private string boosterStationCur; public string BoosterStationCur { get { return boosterStationCur; } set { boosterStationCur = value; this.DoNotify(); } } private string juncBoxTem; public string JuncBoxTem { get { return juncBoxTem; } set { juncBoxTem = value; this.DoNotify(); } } private string juncBoxHum; public string JuncBoxHum { get { return juncBoxHum; } set { juncBoxHum = value; this.DoNotify(); } } private string juncBoxLeakage; public string JuncBoxLeakage { get { return juncBoxLeakage; } set { juncBoxLeakage = value; this.DoNotify(); } } private Brush juncBoxLeakageForeground; public Brush JuncBoxLeakageForeground { get { return juncBoxLeakageForeground; } set { juncBoxLeakageForeground = value; this.DoNotify(); } } private ImageSource juncBoxLeakageImage; public ImageSource JuncBoxLeakageImage { get { return juncBoxLeakageImage; } set { juncBoxLeakageImage = value; this.DoNotify(); } } #endregion public BaseStationModel baseStationModel { get; set; } = new BaseStationModel(); private BaseStationGestureModel baseStationGesture = new BaseStationGestureModel(); public BaseStationGestureModel BaseStationGesture { get { return baseStationGesture; } set { baseStationGesture = value; this.DoNotify(); } } #region SeriesCollection public SeriesCollection seriesCollectionConboxTem; public SeriesCollection SeriesCollectionConboxTem { get { return seriesCollectionConboxTem; } set { seriesCollectionConboxTem = value; this.DoNotify(); } } public SeriesCollection seriesCollectionConboxHum; public SeriesCollection SeriesCollectionConboxHum { get { return seriesCollectionConboxHum; } set { seriesCollectionConboxHum = value; this.DoNotify(); } } public SeriesCollection seriesCollectionMainSeis; public SeriesCollection SeriesCollectionMainSeis { get { return seriesCollectionMainSeis; } set { seriesCollectionMainSeis = value; this.DoNotify(); } } public SeriesCollection seriesCollectionBackupSeis; public SeriesCollection SeriesCollectionBackupSeis { get { return seriesCollectionBackupSeis; } set { seriesCollectionBackupSeis = value; this.DoNotify(); } } public SeriesCollection seriesCollectionBoosterStationVol; public SeriesCollection SeriesCollectionBoosterStationVol { get { return seriesCollectionBoosterStationVol; } set { seriesCollectionBoosterStationVol = value; this.DoNotify(); } } public SeriesCollection seriesCollectionBoosterStationCur; public SeriesCollection SeriesCollectionBoosterStationCur { get { return seriesCollectionBoosterStationCur; } set { seriesCollectionBoosterStationCur = value; this.DoNotify(); } } #endregion #region Formatter private Func _xFormatter; public Func XFormatter { get { return _xFormatter; } set { _xFormatter = value; this.DoNotify(); } } private Func _yFormatterVol; public Func YFormatterVol { get { return _yFormatterVol; } set { _yFormatterVol = value; this.DoNotify(); } } private Func _yFormatterCur; public Func YFormatterCur { get { return _yFormatterCur; } set { _yFormatterCur = value; this.DoNotify(); } } private Func _yFormatterTem; public Func YFormatterTem { get { return _yFormatterTem; } set { _yFormatterTem = value; this.DoNotify(); } } private Func _yFormatterHum; public Func YFormatterHum { get { return _yFormatterHum; } set { _yFormatterHum = value; this.DoNotify(); } } #endregion #region RecordTime public DateTime dataTimeConboxTem; public DateTime DataTimeConboxTem { get { return dataTimeConboxTem; } set { dataTimeConboxTem = value; this.DoNotify(); } } public DateTime dataTimeConboxHum; public DateTime DataTimeConboxHum { get { return dataTimeConboxHum; } set { dataTimeConboxHum = value; this.DoNotify(); } } public DateTime dataTimeMainSeis; public DateTime DataTimeMainSeis { get { return dataTimeMainSeis; } set { dataTimeMainSeis = value; this.DoNotify(); } } public DateTime dataTimeBackupSeis; public DateTime DataTimeBackupSeis { get { return dataTimeBackupSeis; } set { dataTimeBackupSeis = value; this.DoNotify(); } } public DateTime dataTimeBoosterStationVol; public DateTime DataTimeBoosterStationVol { get { return dataTimeBoosterStationVol; } set { dataTimeBoosterStationVol = value; this.DoNotify(); } } public DateTime dataTimeBoosterStationCur; public DateTime DataTimeBoosterStationCur { get { return dataTimeBoosterStationCur; } set { dataTimeBoosterStationCur = value; this.DoNotify(); } } #endregion #region AngleBackground public Brush angleBackgroundX; public Brush AngleBackgroundX { get { return angleBackgroundX; } set { angleBackgroundX = value; this.DoNotify(); } } public Brush angleBackgroundY; public Brush AngleBackgroundY { get { return angleBackgroundY; } set { angleBackgroundY = value; this.DoNotify(); } } public Brush angleBackgroundZ; public Brush AngleBackgroundZ { get { return angleBackgroundZ; } set { angleBackgroundZ = value; this.DoNotify(); } } #endregion /// /// 告警信息 /// private List alarmList = new List(); public List AlarmList { get { return alarmList; } set { alarmList = value; this.DoNotify(); } } public CommandBase ResetAngleCommand { get; set; } int station_id = 1; public RealTimeDataView realTimeDataView = new RealTimeDataView(); public BaseStationModelViewModel baseStationModelViewModel { get; set; } = new BaseStationModelViewModel(); public RealTimeDataViewModel(int id) { station_id = id; this.ResetAngleCommand = new CommandBase(); this.ResetAngleCommand.DoExcute = new Action(ResetAngle); this.ResetAngleCommand.DoCanExcute = new Func((o) => true); } public void ResetAngle(object o) { string sql = String.Format("select * from juncbox_env where StationID = {0} ORDER by id desc limit 1", station_id); MySqlDataReader dataReader = DBHelper.ExecuteReader(sql, 1); while (dataReader.Read()) { BaseStationGesture.RollAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["AttitudeX"].ToString()) ? "0.00" : dataReader["AttitudeX"].ToString()); BaseStationGesture.PitchAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["AttitudeY"].ToString()) ? "0.00" : dataReader["AttitudeY"].ToString()); BaseStationGesture.HeadingAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["AttitudeZ"].ToString()) ? "0.00" : dataReader["AttitudeZ"].ToString()); } dataReader.Dispose(); baseStationModelViewModel.BaseStationGesture.RollAngle = BaseStationGesture.RollAngle; baseStationModelViewModel.BaseStationGesture.PitchAngle = BaseStationGesture.PitchAngle; baseStationModelViewModel.BaseStationGesture.HeadingAngle = BaseStationGesture.HeadingAngle; baseStationModel.angleX.Content = BaseStationGesture.RollAngle; baseStationModel.angleY.Content = BaseStationGesture.PitchAngle; baseStationModel.angleZ.Content = BaseStationGesture.HeadingAngle; } } }