754 lines
32 KiB
C#
754 lines
32 KiB
C#
using JiangsuEarthquake.Common;
|
||
using JiangsuEarthquake.DataAccess;
|
||
using JiangsuEarthquake.Models;
|
||
using JiangsuEarthquake.Views.UserControls;
|
||
using MySql.Data.MySqlClient;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Media;
|
||
using System.Windows.Threading;
|
||
using Brush = System.Windows.Media.Brush;
|
||
|
||
namespace JiangsuEarthquake.ViewModels
|
||
{
|
||
public class SeismometerStateDataViewModel : NotifyBase
|
||
{
|
||
|
||
#region Search Data
|
||
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 seismometerStateMsg;
|
||
|
||
public string SeismometerStateMsg
|
||
{
|
||
get { return seismometerStateMsg; }
|
||
set { seismometerStateMsg = value; this.DoNotify(); }
|
||
}
|
||
|
||
private ObservableCollection<EarthquakeSensorModel> seismometerStateDataList = new ObservableCollection<EarthquakeSensorModel>();
|
||
|
||
public ObservableCollection<EarthquakeSensorModel> SeismometerStateDataList
|
||
{
|
||
get { return seismometerStateDataList; }
|
||
set { seismometerStateDataList = value; this.DoNotify(); }
|
||
}
|
||
|
||
private ObservableCollection<EarthquakeSensorModel> totalSeismometerStateDataList = new ObservableCollection<EarthquakeSensorModel>();
|
||
|
||
public ObservableCollection<EarthquakeSensorModel> TotalSeismometerStateDataList
|
||
{
|
||
get { return totalSeismometerStateDataList; }
|
||
set { totalSeismometerStateDataList = value; this.DoNotify(); }
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region Command Define
|
||
public CommandBase ForwordSystemStateCommand { get; set; }
|
||
|
||
public CommandBase NextSystemStateCommand { get; set; }
|
||
|
||
public CommandBase AskDataBtnCommand { get; set; }
|
||
|
||
public CommandBase RefreshDataCommand { get; set; }
|
||
|
||
public CommandBase DownloadDataCommand { get; set; }
|
||
#endregion
|
||
|
||
|
||
#region Timer Define
|
||
public DispatcherTimer timerDownloadDataMsgHidden = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerAskData = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerAskDataMsgHidden = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerCycleAskData1 = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerCycleAskData2 = new DispatcherTimer();
|
||
#endregion
|
||
|
||
|
||
int station_id = 1;
|
||
|
||
|
||
#region Data Filtering
|
||
string timeSearch = "";
|
||
|
||
public static DialogViewModel vm;
|
||
|
||
private bool _isChecked;
|
||
|
||
public bool IsChecked
|
||
{
|
||
get { return _isChecked; }
|
||
set
|
||
{
|
||
_isChecked = value;
|
||
this.DoNotify();
|
||
|
||
if (IsChecked)
|
||
{
|
||
if (string.IsNullOrEmpty(EndDateTime.ToString()) || string.IsNullOrEmpty(StartDateTime.ToString()))
|
||
{
|
||
IsChecked = false;
|
||
return;
|
||
}
|
||
|
||
if (EndDateTime < StartDateTime)
|
||
{
|
||
HandyControl.Controls.Dialog.Show(new TextDialog("起始时间大于结束时间,\n请重新输入!"));
|
||
IsChecked = false;
|
||
//this.EndDateTime = DateTime.Now;
|
||
//this.StartDateTime = DateTime.Now.AddDays(-1);
|
||
return;
|
||
}
|
||
|
||
timeSearch = " and DataTime BETWEEN '" + StartDateTime + "' and '" + EndDateTime + "' ";
|
||
}
|
||
else
|
||
{
|
||
timeSearch = "";
|
||
}
|
||
|
||
//设置当前页为1
|
||
PageIndex = 1;
|
||
|
||
TotalSeismometerStateDataList.Clear();
|
||
SeismometerStateDataList.Clear();
|
||
|
||
string sql = String.Format("select * from seismograph_state 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())
|
||
{
|
||
EarthquakeSensorModel earthquakeSensorModel = new EarthquakeSensorModel();
|
||
earthquakeSensorModel.Index = index++;
|
||
earthquakeSensorModel.RecordTime = Convert.ToDateTime(dataReader["RecordTime"]);
|
||
earthquakeSensorModel.Out_Vol = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Out_Vol"].ToString()) ? "0" : dataReader["Out_Vol"]);
|
||
earthquakeSensorModel.Backup_Vol = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Backup_Vol"].ToString()) ? "0" : dataReader["Backup_Vol"]);
|
||
earthquakeSensorModel.Pre = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Pre"].ToString()) ? "0" : dataReader["Pre"]);
|
||
earthquakeSensorModel.Tem = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Tem"].ToString()) ? "0" : dataReader["Tem"]);
|
||
earthquakeSensorModel.Sei_Tilt_Angle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Sei_Tilt_Angle"].ToString()) ? "0" : dataReader["Sei_Tilt_Angle"]);
|
||
earthquakeSensorModel.OBS_Tilt_Angle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["OBS_Tilt_Angle"].ToString()) ? "0" : dataReader["OBS_Tilt_Angle"]);
|
||
earthquakeSensorModel.Species_Dif = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Species_Dif"].ToString()) ? "0" : dataReader["Species_Dif"]);
|
||
earthquakeSensorModel.Frequency_Dif = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Frequency_Dif"].ToString()) ? "0" : dataReader["Frequency_Dif"]);
|
||
earthquakeSensorModel.CF_Total_Cap = Convert.ToSingle(string.IsNullOrEmpty(dataReader["CF_Total_Cap"].ToString()) ? "0" : dataReader["CF_Total_Cap"]);
|
||
earthquakeSensorModel.CF_Usable_Cap = Convert.ToSingle(string.IsNullOrEmpty(dataReader["CF_Usable_Cap"].ToString()) ? "0" : dataReader["CF_Usable_Cap"]);
|
||
earthquakeSensorModel.SD_Total_Cap1 = Convert.ToSingle(string.IsNullOrEmpty(dataReader["SD_Total_Cap1"].ToString()) ? "0" : dataReader["SD_Total_Cap1"]);
|
||
earthquakeSensorModel.SD_Usable_Cap1 = Convert.ToSingle(string.IsNullOrEmpty(dataReader["SD_Usable_Cap1"].ToString()) ? "0" : dataReader["SD_Usable_Cap1"]);
|
||
earthquakeSensorModel.SD_Total_Cap2 = Convert.ToSingle(string.IsNullOrEmpty(dataReader["SD_Total_Cap2"].ToString()) ? "0" : dataReader["SD_Total_Cap2"]);
|
||
earthquakeSensorModel.SD_Usable_Cap2 = Convert.ToSingle(string.IsNullOrEmpty(dataReader["SD_Usable_Cap2"].ToString()) ? "0" : dataReader["SD_Usable_Cap2"]);
|
||
earthquakeSensorModel.Sei_U_Point = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Sei_U_Point"].ToString()) ? "0" : dataReader["Sei_U_Point"]);
|
||
earthquakeSensorModel.Sei_V_Point = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Sei_V_Point"].ToString()) ? "0" : dataReader["Sei_V_Point"]);
|
||
earthquakeSensorModel.Sei_W_Point = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Sei_W_Point"].ToString()) ? "0" : dataReader["Sei_W_Point"]);
|
||
earthquakeSensorModel.North_Angle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["North_Angle"].ToString()) ? "0" : dataReader["North_Angle"]);
|
||
TotalSeismometerStateDataList.Add(earthquakeSensorModel);
|
||
}
|
||
dataReader.Dispose();
|
||
RecordCount = index - 1;
|
||
if (RecordCount <= 10)
|
||
{
|
||
TotalPage = 1;
|
||
|
||
SeismometerStateDataList = TotalSeismometerStateDataList;
|
||
}
|
||
else
|
||
{
|
||
TotalPage = (int)Math.Ceiling((double)RecordCount / 10);
|
||
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
SeismometerStateDataList.Add(TotalSeismometerStateDataList[i]);
|
||
}
|
||
}
|
||
|
||
SeismometerStateMsg = string.Format("共计{0}页,当前第{1}页", TotalPage, PageIndex);
|
||
|
||
string record = "查询地震仪状态数据历史数据,查询时间范围为:" + StartDateTime + "至" + EndDateTime + ",共查询到" + RecordCount + "条历史数据";
|
||
|
||
sql = $"insert into log_record(StationID,RecordTime,Device_Name,Operation_Type,Record) values('{station_id}','{DateTime.Now}','海底地震监测基站-地震仪','数据查询','{record}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
public SeismometerStateDataViewModel(int id)
|
||
{
|
||
// 默认查询1天内的日志
|
||
this.EndDateTime = DateTime.Now;
|
||
this.StartDateTime = DateTime.Now.AddDays(-1);
|
||
|
||
PageIndex = 1;
|
||
station_id = id;
|
||
|
||
vm = new DialogViewModel
|
||
{
|
||
Content = ""
|
||
};
|
||
|
||
|
||
#region Command Set
|
||
this.ForwordSystemStateCommand = new CommandBase();
|
||
this.ForwordSystemStateCommand.DoExcute = new Action<object>(ForwordSystemState);
|
||
this.ForwordSystemStateCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.NextSystemStateCommand = new CommandBase();
|
||
this.NextSystemStateCommand.DoExcute = new Action<object>(NextSystemState);
|
||
this.NextSystemStateCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.AskDataBtnCommand = new CommandBase();
|
||
this.AskDataBtnCommand.DoExcute = new Action<object>(AskData);
|
||
this.AskDataBtnCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.RefreshDataCommand = new CommandBase();
|
||
this.RefreshDataCommand.DoExcute = new Action<object>(RefreshData);
|
||
this.RefreshDataCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.DownloadDataCommand = new CommandBase();
|
||
this.DownloadDataCommand.DoExcute = new Action<object>(DownloadData);
|
||
this.DownloadDataCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
#endregion
|
||
|
||
|
||
#region Timer Set
|
||
timerDownloadDataMsgHidden.Interval = TimeSpan.FromSeconds(2);
|
||
timerDownloadDataMsgHidden.Tick += TimerDownloadDataMsgHidden_Tick;
|
||
|
||
timerAskData.Interval = TimeSpan.FromSeconds(20);
|
||
timerAskData.Tick += TimerAskData_Tick;
|
||
|
||
timerAskDataMsgHidden.Interval = TimeSpan.FromSeconds(2);
|
||
timerAskDataMsgHidden.Tick += TimerAskDataMsgHidden_Tick;
|
||
#endregion
|
||
|
||
}
|
||
|
||
|
||
#region Ask Data
|
||
private void TimerAskData_Tick(object sender, EventArgs e)
|
||
{
|
||
if (!AskDataBtnIsReceived)
|
||
{
|
||
AskDataMsgVisibility = Visibility.Visible;
|
||
AskDataMsg = "请求数据发送成功,但未接收到数据!";
|
||
timerAskDataMsgHidden.Start();
|
||
AskDataMsgForeground = new SolidColorBrush(Colors.Red);
|
||
AskDataBtnIsEnabled = true;
|
||
}
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private void TimerAskDataMsgHidden_Tick(object sender, EventArgs e)
|
||
{
|
||
AskDataMsgVisibility = Visibility.Hidden;
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
//点击周期获取时,选中的是主地震仪还是备地震仪
|
||
private bool CheckIsMainSeis1 = false;
|
||
|
||
private bool CheckIsMainSeis2 = false;
|
||
|
||
private bool cycleRequestIsChecked;
|
||
|
||
public bool CycleRequestIsChecked
|
||
{
|
||
get { return cycleRequestIsChecked; }
|
||
set
|
||
{
|
||
cycleRequestIsChecked = value;
|
||
this.DoNotify();
|
||
|
||
if (CycleRequestIsChecked)
|
||
{
|
||
if (string.IsNullOrEmpty(CycleRequestCycle))
|
||
{
|
||
CycleRequestIsChecked = false;
|
||
return;
|
||
|
||
//可改为自动设定周期
|
||
}
|
||
|
||
//周期获取数据
|
||
if (station_id == 1)
|
||
{
|
||
CheckIsMainSeis1 = MainSeisIsChecked;
|
||
timerCycleAskData1.Interval = TimeSpan.FromSeconds(int.Parse(CycleRequestCycle));
|
||
timerCycleAskData1.Tick += TimerCycleAskData1_Tick;
|
||
timerCycleAskData1.Start();
|
||
}
|
||
else
|
||
{
|
||
CheckIsMainSeis2 = MainSeisIsChecked;
|
||
timerCycleAskData2.Interval = TimeSpan.FromSeconds(int.Parse(CycleRequestCycle));
|
||
timerCycleAskData2.Tick += TimerCycleAskData2_Tick;
|
||
timerCycleAskData2.Start();
|
||
}
|
||
|
||
string record = "周期请求地震仪状态数据已开启,请求周期为:" + CycleRequestCycle;
|
||
string seisDevice = MainSeisIsChecked == true ? "海底地震监测基站-主地震仪" : "海底地震监测基站-备地震仪";
|
||
|
||
string sql = $"insert into log_record(StationID,RecordTime,Device_Name,Operation_Type,Record) values('{station_id}','{DateTime.Now}','{seisDevice}','数据请求','{record}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
else
|
||
{
|
||
//停止定时器
|
||
if (station_id == 1)
|
||
{
|
||
timerCycleAskData1.Stop();
|
||
}
|
||
else
|
||
{
|
||
timerCycleAskData2.Stop();
|
||
}
|
||
|
||
string seisDevice = MainSeisIsChecked == true ? "海底地震监测基站-主地震仪" : "海底地震监测基站-备地震仪";
|
||
|
||
string sql = $"insert into log_record(StationID,RecordTime,Device_Name,Operation_Type,Record) values('{station_id}','{DateTime.Now}','{seisDevice}','数据请求','周期请求地震仪状态数据已关闭');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void TimerCycleAskData1_Tick(object sender, EventArgs e)
|
||
{
|
||
AskSeisData(1, CheckIsMainSeis1);
|
||
}
|
||
|
||
private void TimerCycleAskData2_Tick(object sender, EventArgs e)
|
||
{
|
||
AskSeisData(2, CheckIsMainSeis2);
|
||
}
|
||
|
||
private string cycleRequestCycle;
|
||
|
||
public string CycleRequestCycle
|
||
{
|
||
get { return cycleRequestCycle; }
|
||
set { cycleRequestCycle = value; this.DoNotify(); }
|
||
}
|
||
|
||
private string askDataMsg;
|
||
|
||
public string AskDataMsg
|
||
{
|
||
get { return askDataMsg; }
|
||
set { askDataMsg = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Brush askDataMsgForeground;
|
||
|
||
public Brush AskDataMsgForeground
|
||
{
|
||
get { return askDataMsgForeground; }
|
||
set { askDataMsgForeground = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool askDataBtnIsEnabled = true;
|
||
|
||
public bool AskDataBtnIsEnabled
|
||
{
|
||
get { return askDataBtnIsEnabled; }
|
||
set { askDataBtnIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool askDataBtnIsReceived = false;
|
||
|
||
public bool AskDataBtnIsReceived
|
||
{
|
||
get { return askDataBtnIsReceived; }
|
||
set { askDataBtnIsReceived = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Visibility askDataMsgVisibility = Visibility.Visible;
|
||
|
||
public Visibility AskDataMsgVisibility
|
||
{
|
||
get { return askDataMsgVisibility; }
|
||
set { askDataMsgVisibility = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool mainSeisIsChecked = true;
|
||
|
||
public bool MainSeisIsChecked
|
||
{
|
||
get { return mainSeisIsChecked; }
|
||
set { mainSeisIsChecked = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool backupSeisIsChecked = false;
|
||
|
||
public bool BackupSeisIsChecked
|
||
{
|
||
get { return backupSeisIsChecked; }
|
||
set { backupSeisIsChecked = value; this.DoNotify(); }
|
||
}
|
||
|
||
List<byte> sendDataSeis = new List<byte>();
|
||
|
||
private byte[] checkCode { get; set; } = new byte[2]; //从CMD到DATA结束的CRC16校验和
|
||
|
||
private List<byte> checkByte { get; set; } = new List<byte>(); //校验码Byte
|
||
|
||
public void AskData(object o)
|
||
{
|
||
AskSeisData(station_id, MainSeisIsChecked);
|
||
}
|
||
|
||
|
||
public void AskSeisData(int id, bool IsMainSeis)
|
||
{
|
||
AskDataBtnIsEnabled = false;
|
||
AskDataBtnIsReceived = false;
|
||
|
||
sendDataSeis.Clear();
|
||
sendDataSeis.AddRange(new byte[] { 0xBF, 0x13, 0x97, 0x74 }); //SYNC
|
||
sendDataSeis.AddRange(new byte[] { 0xA0, 0x50 }); //CMD
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
|
||
//地震计号
|
||
byte[] numDZJ = new byte[2];
|
||
if (id == 1)
|
||
{
|
||
if (IsMainSeis)
|
||
numDZJ = BitConverter.GetBytes(short.Parse(Tools.GetAppSetting("MainSeisNum1")));
|
||
else
|
||
numDZJ = BitConverter.GetBytes(short.Parse(Tools.GetAppSetting("BackupSeisNum1")));
|
||
}
|
||
else
|
||
{
|
||
if (IsMainSeis)
|
||
numDZJ = BitConverter.GetBytes(short.Parse(Tools.GetAppSetting("MainSeisNum2")));
|
||
else
|
||
numDZJ = BitConverter.GetBytes(short.Parse(Tools.GetAppSetting("BackupSeisNum2")));
|
||
}
|
||
numDZJ = Tools.PadArrayWithZeros(numDZJ, 2);
|
||
|
||
sendDataSeis.AddRange(numDZJ); //DATA
|
||
checkByte.Clear();
|
||
checkByte.AddRange(new byte[] { 0xA0, 0x50 }); //CMD
|
||
checkByte.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
checkByte.AddRange(numDZJ); //DATA
|
||
checkCode = Tools.ComputeChecksum(checkByte.ToArray()); //CHK_SUM
|
||
sendDataSeis.AddRange(checkCode);
|
||
|
||
bool result = false;
|
||
if (id == 1)
|
||
{
|
||
if (IsMainSeis) //主地震仪
|
||
{
|
||
if (MainWindow.mainViewModel.clientModelMainSeis1.IsConnected && MainWindow.mainViewModel.IsMainSeis1CertSucs)
|
||
{
|
||
result = MainWindow.mainViewModel.clientModelMainSeis1.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
AskDataMsgVisibility = Visibility.Visible;
|
||
AskDataMsg = "通信未连接!";
|
||
timerAskDataMsgHidden.Start();
|
||
AskDataMsgForeground = new SolidColorBrush(Colors.Red);
|
||
AskDataBtnIsEnabled = true;
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MainWindow.mainViewModel.clientModelBackupSeis1.IsConnected && MainWindow.mainViewModel.IsBackupSeis1CertSucs)
|
||
{
|
||
result = MainWindow.mainViewModel.clientModelBackupSeis1.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
AskDataMsgVisibility = Visibility.Visible;
|
||
AskDataMsg = "通信未连接!";
|
||
timerAskDataMsgHidden.Start();
|
||
AskDataMsgForeground = new SolidColorBrush(Colors.Red);
|
||
AskDataBtnIsEnabled = true;
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (IsMainSeis) //主地震仪
|
||
{
|
||
if (MainWindow.mainViewModel.clientModelMainSeis2.IsConnected && MainWindow.mainViewModel.IsMainSeis2CertSucs)
|
||
{
|
||
result = MainWindow.mainViewModel.clientModelMainSeis2.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
AskDataMsgVisibility = Visibility.Visible;
|
||
AskDataMsg = "通信未连接!";
|
||
timerAskDataMsgHidden.Start();
|
||
AskDataMsgForeground = new SolidColorBrush(Colors.Red);
|
||
AskDataBtnIsEnabled = true;
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MainWindow.mainViewModel.clientModelBackupSeis2.IsConnected && MainWindow.mainViewModel.IsBackupSeis2CertSucs)
|
||
{
|
||
result = MainWindow.mainViewModel.clientModelBackupSeis2.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
AskDataMsgVisibility = Visibility.Visible;
|
||
AskDataMsg = "通信未连接!";
|
||
timerAskDataMsgHidden.Start();
|
||
AskDataMsgForeground = new SolidColorBrush(Colors.Red);
|
||
AskDataBtnIsEnabled = true;
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (result)
|
||
{
|
||
AskDataMsgVisibility = Visibility.Visible;
|
||
AskDataMsg = "请求地震仪状态数据发送成功!";
|
||
timerAskDataMsgHidden.Start();
|
||
AskDataMsgForeground = new SolidColorBrush(Colors.Green);
|
||
timerAskData.Start();
|
||
}
|
||
else
|
||
{
|
||
AskDataMsgVisibility = Visibility.Visible;
|
||
AskDataMsg = "请求地震仪状态数据发送失败!";
|
||
timerAskDataMsgHidden.Start();
|
||
AskDataMsgForeground = new SolidColorBrush(Colors.Red);
|
||
AskDataBtnIsEnabled = true;
|
||
}
|
||
|
||
string seisDevice = IsMainSeis == true ? "海底地震监测基站-主地震仪" : "海底地震监测基站-备地震仪";
|
||
|
||
string sql = $"insert into log_record(StationID,RecordTime,Device_Name,Operation_Type,Record) values('{id}','{DateTime.Now}','{seisDevice}','数据请求','{AskDataMsg}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region Page Switching
|
||
public void ForwordSystemState(object o)
|
||
{
|
||
if (PageIndex == 1)
|
||
return;
|
||
PageIndex -= 1;
|
||
|
||
SeismometerStateDataList.Clear();
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
SeismometerStateDataList.Add(TotalSeismometerStateDataList[i + (PageIndex - 1) * 10]);
|
||
}
|
||
SeismometerStateMsg = string.Format("共计{0}页,当前第{1}页", TotalPage, PageIndex);
|
||
}
|
||
|
||
public void NextSystemState(object o)
|
||
{
|
||
if (PageIndex == TotalPage)
|
||
return;
|
||
PageIndex += 1;
|
||
|
||
SeismometerStateDataList.Clear();
|
||
for (int i = 0; i < (PageIndex == TotalPage ? (RecordCount - (PageIndex - 1) * 10) : 10); i++)
|
||
{
|
||
SeismometerStateDataList.Add(TotalSeismometerStateDataList[i + (PageIndex - 1) * 10]);
|
||
}
|
||
SeismometerStateMsg = string.Format("共计{0}页,当前第{1}页", TotalPage, PageIndex);
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region RefreshData
|
||
public void RefreshData(object o)
|
||
{
|
||
if (IsChecked)
|
||
{
|
||
timeSearch = " and DataTime BETWEEN '" + StartDateTime + "' and '" + EndDateTime + "' ";
|
||
}
|
||
else
|
||
{
|
||
timeSearch = "";
|
||
}
|
||
|
||
//设置当前页为1
|
||
PageIndex = 1;
|
||
|
||
TotalSeismometerStateDataList.Clear();
|
||
SeismometerStateDataList.Clear();
|
||
|
||
string sql = String.Format("select * from seismograph_state 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())
|
||
{
|
||
EarthquakeSensorModel earthquakeSensorModel = new EarthquakeSensorModel();
|
||
earthquakeSensorModel.Index = index++;
|
||
earthquakeSensorModel.RecordTime = Convert.ToDateTime(dataReader["RecordTime"]);
|
||
earthquakeSensorModel.Out_Vol = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Out_Vol"].ToString()) ? "0" : dataReader["Out_Vol"]);
|
||
earthquakeSensorModel.Backup_Vol = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Backup_Vol"].ToString()) ? "0" : dataReader["Backup_Vol"]);
|
||
earthquakeSensorModel.Pre = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Pre"].ToString()) ? "0" : dataReader["Pre"]);
|
||
earthquakeSensorModel.Tem = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Tem"].ToString()) ? "0" : dataReader["Tem"]);
|
||
earthquakeSensorModel.Sei_Tilt_Angle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Sei_Tilt_Angle"].ToString()) ? "0" : dataReader["Sei_Tilt_Angle"]);
|
||
earthquakeSensorModel.OBS_Tilt_Angle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["OBS_Tilt_Angle"].ToString()) ? "0" : dataReader["OBS_Tilt_Angle"]);
|
||
earthquakeSensorModel.Species_Dif = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Species_Dif"].ToString()) ? "0" : dataReader["Species_Dif"]);
|
||
earthquakeSensorModel.Frequency_Dif = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Frequency_Dif"].ToString()) ? "0" : dataReader["Frequency_Dif"]);
|
||
earthquakeSensorModel.CF_Total_Cap = Convert.ToSingle(string.IsNullOrEmpty(dataReader["CF_Total_Cap"].ToString()) ? "0" : dataReader["CF_Total_Cap"]);
|
||
earthquakeSensorModel.CF_Usable_Cap = Convert.ToSingle(string.IsNullOrEmpty(dataReader["CF_Usable_Cap"].ToString()) ? "0" : dataReader["CF_Usable_Cap"]);
|
||
earthquakeSensorModel.SD_Total_Cap1 = Convert.ToSingle(string.IsNullOrEmpty(dataReader["SD_Total_Cap1"].ToString()) ? "0" : dataReader["SD_Total_Cap1"]);
|
||
earthquakeSensorModel.SD_Usable_Cap1 = Convert.ToSingle(string.IsNullOrEmpty(dataReader["SD_Usable_Cap1"].ToString()) ? "0" : dataReader["SD_Usable_Cap1"]);
|
||
earthquakeSensorModel.SD_Total_Cap2 = Convert.ToSingle(string.IsNullOrEmpty(dataReader["SD_Total_Cap2"].ToString()) ? "0" : dataReader["SD_Total_Cap2"]);
|
||
earthquakeSensorModel.SD_Usable_Cap2 = Convert.ToSingle(string.IsNullOrEmpty(dataReader["SD_Usable_Cap2"].ToString()) ? "0" : dataReader["SD_Usable_Cap2"]);
|
||
earthquakeSensorModel.Sei_U_Point = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Sei_U_Point"].ToString()) ? "0" : dataReader["Sei_U_Point"]);
|
||
earthquakeSensorModel.Sei_V_Point = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Sei_V_Point"].ToString()) ? "0" : dataReader["Sei_V_Point"]);
|
||
earthquakeSensorModel.Sei_W_Point = Convert.ToSingle(string.IsNullOrEmpty(dataReader["Sei_W_Point"].ToString()) ? "0" : dataReader["Sei_W_Point"]);
|
||
earthquakeSensorModel.North_Angle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["North_Angle"].ToString()) ? "0" : dataReader["North_Angle"]);
|
||
TotalSeismometerStateDataList.Add(earthquakeSensorModel);
|
||
}
|
||
dataReader.Dispose();
|
||
RecordCount = index - 1;
|
||
if (RecordCount <= 10)
|
||
{
|
||
TotalPage = 1;
|
||
|
||
SeismometerStateDataList = TotalSeismometerStateDataList;
|
||
}
|
||
else
|
||
{
|
||
TotalPage = (int)Math.Ceiling((double)RecordCount / 10);
|
||
|
||
for (int i = 0; i < 10; i++)
|
||
{
|
||
SeismometerStateDataList.Add(TotalSeismometerStateDataList[i]);
|
||
}
|
||
}
|
||
|
||
SeismometerStateMsg = string.Format("共计{0}页,当前第{1}页", TotalPage, PageIndex);
|
||
|
||
sql = $"insert into log_record(StationID,RecordTime,Device_Name,Operation_Type,Record) values('{station_id}','{DateTime.Now}','海底地震监测基站-地震仪','数据刷新','刷新地震仪状态数据');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region DownloadData
|
||
private void TimerDownloadDataMsgHidden_Tick(object sender, EventArgs e)
|
||
{
|
||
DownloadDataMsgVisibility = Visibility.Hidden;
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private string downloadDataMsg;
|
||
|
||
public string DownloadDataMsg
|
||
{
|
||
get { return downloadDataMsg; }
|
||
set { downloadDataMsg = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Brush downloadDataMsgForeground;
|
||
|
||
public Brush DownloadDataMsgForeground
|
||
{
|
||
get { return downloadDataMsgForeground; }
|
||
set { downloadDataMsgForeground = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool downloadDataBtnIsEnabled = true;
|
||
|
||
public bool DownloadDataBtnIsEnabled
|
||
{
|
||
get { return downloadDataBtnIsEnabled; }
|
||
set { downloadDataBtnIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Visibility downloadDataMsgVisibility = Visibility.Visible;
|
||
|
||
public Visibility DownloadDataMsgVisibility
|
||
{
|
||
get { return downloadDataMsgVisibility; }
|
||
set { downloadDataMsgVisibility = value; this.DoNotify(); }
|
||
}
|
||
|
||
public void DownloadData(object o)
|
||
{
|
||
DownloadDataBtnIsEnabled = false;
|
||
|
||
string seismometerStateFolder = Tools.GetAppSetting("SeismometerStateFolder");
|
||
string savePath = CSVDownload.CreateFile(seismometerStateFolder, "SeismometerStateData_" + DateTime.Now.ToString("yyyyMMddhhMMss"), "csv");
|
||
|
||
bool result = CSVDownload.SaveSeismometerStateDataToCSVFile(TotalSeismometerStateDataList, savePath);
|
||
if (result)
|
||
{
|
||
DownloadDataMsg = "下载数据成功!";
|
||
DownloadDataMsgVisibility = Visibility.Visible;
|
||
DownloadDataMsgForeground = new SolidColorBrush(Colors.Green);
|
||
}
|
||
else
|
||
{
|
||
DownloadDataMsg = "下载数据失败!";
|
||
DownloadDataMsgVisibility = Visibility.Visible;
|
||
DownloadDataMsgForeground = new SolidColorBrush(Colors.Red);
|
||
}
|
||
|
||
timerDownloadDataMsgHidden.Start();
|
||
DownloadDataBtnIsEnabled = true;
|
||
|
||
string record = "下载地震仪状态数据," + DownloadDataMsg;
|
||
|
||
string sql = $"insert into log_record(StationID,RecordTime,Device_Name,Operation_Type,Record) values('{station_id}','{DateTime.Now}','海底地震监测基站-地震仪','数据下载','{record}');";
|
||
DBHelper.ExecuteNonQuery(sql, 1);
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|