2366 lines
112 KiB
C#
2366 lines
112 KiB
C#
using JiangsuEarthquake.Base;
|
||
using JiangsuEarthquake.Common;
|
||
using JiangsuEarthquake.DataAccess;
|
||
using JiangsuEarthquake.Models;
|
||
using LiveCharts.Defaults;
|
||
using LiveCharts.Wpf;
|
||
using LiveCharts;
|
||
using MySql.Data.MySqlClient;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using System.Runtime.Intrinsics.X86;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Media;
|
||
using System.Windows.Threading;
|
||
using System.IO.Ports;
|
||
using JiangsuEarthquake.Views.UserControls;
|
||
using HandyControl.Tools.Extension;
|
||
using K4os.Compression.LZ4.Streams.Frames;
|
||
using Org.BouncyCastle.Crypto.Paddings;
|
||
|
||
namespace JiangsuEarthquake.ViewModels
|
||
{
|
||
public class MainViewModel : NotifyBase
|
||
{
|
||
#region ViewModel Define
|
||
//页面
|
||
public static RealTimeDataViewModel realTimeDataViewModel1 = new RealTimeDataViewModel(1);
|
||
public static RealTimeDataViewModel realTimeDataViewModel2 = new RealTimeDataViewModel(2);
|
||
public static AlarmRecordViewModel alarmRecordViewModel1 = new AlarmRecordViewModel(1);
|
||
public static AlarmRecordViewModel alarmRecordViewModel2 = new AlarmRecordViewModel(2);
|
||
public static BoosterStationStateDataViewModel boosterStationStateDataViewModel1 = new BoosterStationStateDataViewModel(1);
|
||
public static BoosterStationStateDataViewModel boosterStationStateDataViewModel2 = new BoosterStationStateDataViewModel(2);
|
||
public static LogRecordViewModel logRecordViewModel1 = new LogRecordViewModel(1);
|
||
public static LogRecordViewModel logRecordViewModel2 = new LogRecordViewModel(2);
|
||
public static SystemControlViewModel systemControlViewModel1 = new SystemControlViewModel();
|
||
public static SystemControlViewModel systemControlViewModel2 = new SystemControlViewModel();
|
||
public static SystemStateDataViewModel systemStateDataViewModel1 = new SystemStateDataViewModel(1);
|
||
public static SystemStateDataViewModel systemStateDataViewModel2 = new SystemStateDataViewModel(2);
|
||
public static BaseStationModelViewModel baseStationModelViewModel1 = new BaseStationModelViewModel();
|
||
public static BaseStationModelViewModel baseStationModelViewModel2 = new BaseStationModelViewModel();
|
||
|
||
//控制
|
||
public static SwitchStateModel switchStateModel1 = new SwitchStateModel();
|
||
public static SwitchStateModel switchStateModel2 = new SwitchStateModel();
|
||
public static StateFeedBackModel stateFeedBackModel1 = new StateFeedBackModel();
|
||
public static StateFeedBackModel stateFeedBackModel2 = new StateFeedBackModel();
|
||
public static SwitchInfoModel switchInfoModel1 = new SwitchInfoModel();
|
||
public static SwitchInfoModel switchInfoModel2 = new SwitchInfoModel();
|
||
public static EarthQuakeParaSetModel earthQuakeParaSetModel1 = new EarthQuakeParaSetModel();
|
||
public static EarthQuakeParaSetModel earthQuakeParaSetModel2 = new EarthQuakeParaSetModel();
|
||
public static EarthquakeSensorModel earthquakeSensorModel1 = new EarthquakeSensorModel();
|
||
public static EarthquakeSensorModel earthquakeSensorModel2 = new EarthquakeSensorModel();
|
||
|
||
private SwitchStateModel ss;
|
||
|
||
public SwitchStateModel SS
|
||
{
|
||
get { return ss; }
|
||
set { ss = value; this.DoNotify(); }
|
||
}
|
||
|
||
private EarthQuakeParaSetModel eqps;
|
||
|
||
public EarthQuakeParaSetModel EQPS
|
||
{
|
||
get { return eqps; }
|
||
set { eqps = value; }
|
||
}
|
||
|
||
private EarthquakeSensorModel eqsm;
|
||
|
||
public EarthquakeSensorModel EQSM
|
||
{
|
||
get { return eqsm; }
|
||
set { eqsm = value; }
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region Something Define
|
||
/// <summary>
|
||
/// 刷新下控制域的DataContext
|
||
/// </summary>
|
||
public void FlashControlPageDataContext()
|
||
{
|
||
if (station_id == 1)
|
||
{
|
||
SS = switchStateModel1;
|
||
EQPS = earthQuakeParaSetModel1;
|
||
EQSM = earthquakeSensorModel1;
|
||
}
|
||
else if (station_id == 2)
|
||
{
|
||
SS = switchStateModel2;
|
||
EQPS = earthQuakeParaSetModel2;
|
||
EQSM = earthquakeSensorModel2;
|
||
}
|
||
}
|
||
|
||
private FrameworkElement _pageContent;
|
||
|
||
public FrameworkElement PageContent
|
||
{
|
||
get { return _pageContent; }
|
||
set { _pageContent = value; this.DoNotify(); }
|
||
}
|
||
|
||
public int station_id { get; set; } = 1;
|
||
|
||
int ChartPointNum = 15;
|
||
|
||
|
||
|
||
string Title_Name = ""; //设置当前显示的标题 1 浮标 2 接驳盒 3 系统控制 4 日志记录
|
||
|
||
private string bDCountDown = "";
|
||
|
||
public string BDCountDown
|
||
{
|
||
get { return bDCountDown; }
|
||
set { bDCountDown = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool gridIsEnabled = true;
|
||
|
||
public bool GridIsEnabled
|
||
{
|
||
get { return gridIsEnabled; }
|
||
set { gridIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Visibility vis = Visibility.Hidden;
|
||
/// <summary>
|
||
/// 按钮是否可见
|
||
/// </summary>
|
||
public Visibility DetailButtonVisibility
|
||
{
|
||
get { return vis; }
|
||
set { vis = value; this.DoNotify(); }
|
||
}
|
||
|
||
public static ErrorMessageModel EM { get; set; } = new ErrorMessageModel();
|
||
#endregion
|
||
|
||
|
||
#region CommandBase Define
|
||
public CommandBase NavChangedCommand { get; set; }
|
||
|
||
public CommandBase CommunicationChangedCommand { get; set; }//切换控制器的通信路径
|
||
|
||
public CommandBase Switch { set; get; }
|
||
public CommandBase ParaSetSwitch { set; get; } //系统参数设置按钮
|
||
#endregion
|
||
|
||
|
||
#region Timer Define
|
||
public DispatcherTimer timerOpenSetMsgHidden = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerCloseSetMsgHidden = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerSeisZeroSetStart = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerSeisZeroSetStop = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerSeisLevelSetStart = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerSeisLevelSetStop = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerSeisParaMsgHidden = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerEarthQuakeParaSet = new DispatcherTimer();
|
||
|
||
public DispatcherTimer timerEarthQuakeParaRead = new DispatcherTimer();
|
||
#endregion
|
||
|
||
|
||
#region Communication
|
||
//下位机
|
||
public CommandBase Socket1DoOpenCommand { get; set; }
|
||
|
||
public CommandBase Socket2DoOpenCommand { get; set; }
|
||
|
||
public ServerModel serverModel1 { get; set; } = new ServerModel();
|
||
|
||
public ServerModel serverModel2 { get; set; } = new ServerModel();
|
||
|
||
public static SocketInfo SocketServerInfo1 { get; set; } = new SocketInfo() //PLC1连接信息
|
||
{
|
||
IP = Tools.GetAppSetting("XWJ_Service_IP1"),
|
||
Port = Convert.ToInt32(Tools.GetAppSetting("XWJ_Service_Port1"))
|
||
};
|
||
|
||
public static SocketInfo SocketServerInfo2 { get; set; } = new SocketInfo() //PLC2连接信息
|
||
{
|
||
IP = Tools.GetAppSetting("XWJ_Service_IP2"),
|
||
Port = Convert.ToInt32(Tools.GetAppSetting("XWJ_Service_Port2"))
|
||
};
|
||
|
||
|
||
//升压站
|
||
public CommandBase Socket1DoConnectCommand { get; set; } //客户端连接/断开操作
|
||
|
||
public CommandBase Socket2DoConnectCommand { get; set; } //客户端连接/断开操作
|
||
|
||
public ClientModel clientModel1 { get; set; } = new ClientModel();
|
||
|
||
public ClientModel clientModel2 { get; set; } = new ClientModel();
|
||
|
||
public static SocketInfo SocketInfo1 { get; set; } = new SocketInfo() //PLC1连接信息
|
||
{
|
||
IP = Tools.GetAppSetting("SYZ_Client_IP1"),
|
||
Port = Convert.ToInt32(Tools.GetAppSetting("SYZ_Client_Port1"))
|
||
};
|
||
|
||
public static SocketInfo SocketInfo2 { get; set; } = new SocketInfo() //PLC2连接信息
|
||
{
|
||
IP = Tools.GetAppSetting("SYZ_Client_IP2"),
|
||
Port = Convert.ToInt32(Tools.GetAppSetting("SYZ_Client_Port2"))
|
||
};
|
||
|
||
|
||
//地震仪
|
||
public CommandBase SocketDZY1DoConnectCommand { get; set; } //客户端连接/断开操作
|
||
|
||
public CommandBase SocketDZY2DoConnectCommand { get; set; } //客户端连接/断开操作
|
||
|
||
public ClientModel clientModelDZY1 { get; set; } = new ClientModel();
|
||
|
||
public ClientModel clientModelDZY2 { get; set; } = new ClientModel();
|
||
|
||
public static SocketInfo SocketInfoDZY1 { get; set; } = new SocketInfo() //PLC1连接信息
|
||
{
|
||
IP = Tools.GetAppSetting("DZY_Client_IP1"),
|
||
Port = Convert.ToInt32(Tools.GetAppSetting("DZY_Client_Port1"))
|
||
};
|
||
|
||
public static SocketInfo SocketInfoDZY2 { get; set; } = new SocketInfo() //PLC2连接信息
|
||
{
|
||
IP = Tools.GetAppSetting("DZY_Client_IP2"),
|
||
Port = Convert.ToInt32(Tools.GetAppSetting("DZY_Client_Port2"))
|
||
};
|
||
|
||
|
||
#region Useless
|
||
//public CommandBase Com1DoConnectCommand { get; set; } //串口连接/断开操作
|
||
//public CommandBase Com2DoConnectCommand { get; set; } //串口连接/断开操作
|
||
|
||
//public ComModel comModel1 { get; set; } = new ComModel();
|
||
|
||
//public ComModel2 comModel2 { get; set; } = new ComModel2();
|
||
|
||
//public static SerialInfo SerialInfo1 { get; set; } = new SerialInfo() //初始化串口连接信息
|
||
//{
|
||
// PortName = Tools.GetAppSetting("PortName1"),
|
||
// BaudRate = Convert.ToInt32(Tools.GetAppSetting("BaudRate1")),
|
||
// DataBit = 8,
|
||
// Parity = Parity.None,
|
||
// StopBits = StopBits.One
|
||
//};
|
||
|
||
//public static SerialInfo SerialInfo2 { get; set; } = new SerialInfo() //初始化串口连接信息
|
||
//{
|
||
// PortName = Tools.GetAppSetting("PortName2"),
|
||
// BaudRate = Convert.ToInt32(Tools.GetAppSetting("BaudRate2")),
|
||
// DataBit = 8,
|
||
// Parity = Parity.None,
|
||
// StopBits = StopBits.One
|
||
//};
|
||
#endregion
|
||
#endregion
|
||
|
||
|
||
public static DialogViewModel vm;
|
||
|
||
|
||
public MainViewModel()
|
||
{
|
||
vm = new DialogViewModel
|
||
{
|
||
Content = ""
|
||
};
|
||
|
||
|
||
#region Command Define
|
||
this.NavChangedCommand = new CommandBase();
|
||
this.NavChangedCommand.DoExcute = new Action<object>(DoNavChanged);
|
||
this.NavChangedCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.Switch = new CommandBase();
|
||
this.Switch.DoExcute = new Action<object>(Btn_Switch);
|
||
this.Switch.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.ParaSetSwitch = new CommandBase();
|
||
this.ParaSetSwitch.DoExcute = new Action<object>(Btn_ParaSet);
|
||
this.ParaSetSwitch.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.Socket1DoOpenCommand = new CommandBase();
|
||
this.Socket1DoOpenCommand.DoExcute = new Action<object>(Socket1DoOpen);
|
||
this.Socket1DoOpenCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.Socket2DoOpenCommand = new CommandBase();
|
||
this.Socket2DoOpenCommand.DoExcute = new Action<object>(Socket2DoOpen);
|
||
this.Socket2DoOpenCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.Socket1DoConnectCommand = new CommandBase();
|
||
this.Socket1DoConnectCommand.DoExcute = new Action<object>(DoSocket1Connect);
|
||
this.Socket1DoConnectCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.Socket2DoConnectCommand = new CommandBase();
|
||
this.Socket2DoConnectCommand.DoExcute = new Action<object>(DoSocket2Connect);
|
||
this.Socket2DoConnectCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.SocketDZY1DoConnectCommand = new CommandBase();
|
||
this.SocketDZY1DoConnectCommand.DoExcute = new Action<object>(DoSocketDZY1Connect);
|
||
this.SocketDZY1DoConnectCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
|
||
this.SocketDZY2DoConnectCommand = new CommandBase();
|
||
this.SocketDZY2DoConnectCommand.DoExcute = new Action<object>(DoSocketDZY2Connect);
|
||
this.SocketDZY2DoConnectCommand.DoCanExcute = new Func<object, bool>((o) => true);
|
||
#endregion
|
||
|
||
|
||
#region Timer Set
|
||
timerOpenSetMsgHidden.Interval = TimeSpan.FromSeconds(2);
|
||
timerOpenSetMsgHidden.Tick += TimerOpenSetMsgHidden_Tick;
|
||
|
||
timerCloseSetMsgHidden.Interval = TimeSpan.FromSeconds(2);
|
||
timerCloseSetMsgHidden.Tick += TimerCloseSetMsgHidden_Tick;
|
||
|
||
timerSeisZeroSetStart.Interval = TimeSpan.FromSeconds(20);
|
||
timerSeisZeroSetStart.Tick += TimerSeisZeroSetStart_Tick;
|
||
|
||
timerSeisZeroSetStop.Interval = TimeSpan.FromSeconds(20);
|
||
timerSeisZeroSetStop.Tick += TimerSeisZeroSetStop_Tick;
|
||
|
||
timerSeisLevelSetStart.Interval = TimeSpan.FromSeconds(20);
|
||
timerSeisLevelSetStart.Tick += TimerSeisLevelSetStart_Tick;
|
||
|
||
timerSeisLevelSetStop.Interval = TimeSpan.FromSeconds(20);
|
||
timerSeisLevelSetStop.Tick += TimerSeisLevelSetStop_Tick;
|
||
|
||
timerSeisParaMsgHidden.Interval = TimeSpan.FromSeconds(2);
|
||
timerSeisParaMsgHidden.Tick += TimerSeisParaMsgHidden_Tick;
|
||
|
||
timerEarthQuakeParaSet.Interval = TimeSpan.FromSeconds(20);
|
||
timerEarthQuakeParaSet.Tick += TimerEarthQuakeParaSet_Tick;
|
||
|
||
timerEarthQuakeParaRead.Interval = TimeSpan.FromSeconds(20);
|
||
timerEarthQuakeParaRead.Tick += TimerEarthQuakeParaRead_Tick;
|
||
#endregion
|
||
|
||
|
||
#region 日志页面初始化
|
||
string sql = String.Format("select * from logrecordhis where StationID = {0} ORDER by id desc limit 100", 1);
|
||
MySqlDataReader dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
int index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
LogRecordModel logRecord = new LogRecordModel();
|
||
logRecord.Index = index++;
|
||
logRecord.DataTime = Convert.ToDateTime(dataReader["DataTime"]);
|
||
logRecord.Remark = dataReader["Record"].ToString();
|
||
logRecordViewModel1.TotalLogRecordList.Add(logRecord);
|
||
}
|
||
dataReader.Dispose();
|
||
logRecordViewModel1.RecordCount = index - 1;
|
||
logRecordViewModel1.TotalPage = index <= 10 ? 1 : (int)Math.Ceiling((double)index / 10);
|
||
|
||
for (int i = 0; i < (logRecordViewModel1.RecordCount < 10 ? logRecordViewModel1.RecordCount : 10); i++)
|
||
{
|
||
logRecordViewModel1.LogRecordList.Add(logRecordViewModel1.TotalLogRecordList[i]);
|
||
}
|
||
logRecordViewModel1.LogMsg = string.Format("共计{0}页,当前第{1}页", logRecordViewModel1.TotalPage, 1);
|
||
|
||
sql = String.Format("select * from logrecordhis where StationID = {0} ORDER by id desc limit 100", 2);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
LogRecordModel logRecord = new LogRecordModel();
|
||
logRecord.Index = index++;
|
||
logRecord.DataTime = Convert.ToDateTime(dataReader["DataTime"]);
|
||
logRecord.Remark = dataReader["Record"].ToString();
|
||
logRecordViewModel2.TotalLogRecordList.Add(logRecord);
|
||
}
|
||
dataReader.Dispose();
|
||
logRecordViewModel2.RecordCount = index - 1;
|
||
logRecordViewModel2.TotalPage = index <= 10 ? 1 : (int)Math.Ceiling((double)index / 10);
|
||
for (int i = 0; i < (logRecordViewModel2.RecordCount < 10 ? logRecordViewModel2.RecordCount : 10); i++)
|
||
{
|
||
logRecordViewModel2.LogRecordList.Add(logRecordViewModel2.TotalLogRecordList[i]);
|
||
}
|
||
logRecordViewModel2.LogMsg = string.Format("共计{0}页,当前第{1}页", logRecordViewModel2.TotalPage, 1);
|
||
#endregion
|
||
|
||
|
||
#region 告警页面初始化
|
||
sql = String.Format("select * from alarminfohis where StationID = {0} ORDER by id desc limit 100", 1);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
AlarmRecordModel alarmRecordModel = new AlarmRecordModel();
|
||
alarmRecordModel.Index = index++;
|
||
alarmRecordModel.DataTime = Convert.ToDateTime(dataReader["DataTime"]);
|
||
alarmRecordModel.ParaName = dataReader["ParaName"].ToString();
|
||
alarmRecordModel.ParaState = dataReader["ParaState"].ToString();
|
||
alarmRecordModel.ProcessingMethod = dataReader["ProcessingMethod"].ToString();
|
||
if (Convert.ToInt32(dataReader["UrgencyLevel"]) == 1)
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleRed");
|
||
}
|
||
else if (Convert.ToInt32(dataReader["UrgencyLevel"]) == 2)
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleOrange");
|
||
}
|
||
else
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleYellow");
|
||
}
|
||
alarmRecordViewModel1.TotalAlarmRecordList.Add(alarmRecordModel);
|
||
}
|
||
dataReader.Dispose();
|
||
alarmRecordViewModel1.RecordCount = index - 1;
|
||
alarmRecordViewModel1.TotalPage = (index - 1) <= 10 ? 1 : (int)Math.Ceiling((double)(index - 1) / 10);
|
||
for (int i = 0; i < (alarmRecordViewModel1.RecordCount < 10 ? alarmRecordViewModel1.RecordCount : 10); i++)
|
||
{
|
||
alarmRecordViewModel1.AlarmRecordList.Add(alarmRecordViewModel1.TotalAlarmRecordList[i]);
|
||
}
|
||
alarmRecordViewModel1.AlarmMsg = string.Format("共计{0}页,当前第{1}页", alarmRecordViewModel1.TotalPage, 1);
|
||
|
||
sql = String.Format("select * from alarminfohis where StationID = {0} ORDER by id desc limit 100", 2);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
AlarmRecordModel alarmRecordModel = new AlarmRecordModel();
|
||
alarmRecordModel.Index = index++;
|
||
alarmRecordModel.DataTime = Convert.ToDateTime(dataReader["DataTime"]);
|
||
alarmRecordModel.ParaName = dataReader["ParaName"].ToString();
|
||
alarmRecordModel.ParaState = dataReader["ParaState"].ToString();
|
||
alarmRecordModel.ProcessingMethod = dataReader["ProcessingMethod"].ToString();
|
||
if (Convert.ToInt32(dataReader["UrgencyLevel"]) == 1)
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleRed");
|
||
}
|
||
else if (Convert.ToInt32(dataReader["UrgencyLevel"]) == 2)
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleOrange");
|
||
}
|
||
else
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleYellow");
|
||
}
|
||
alarmRecordViewModel2.TotalAlarmRecordList.Add(alarmRecordModel);
|
||
}
|
||
dataReader.Dispose();
|
||
alarmRecordViewModel2.RecordCount = index - 1;
|
||
alarmRecordViewModel2.TotalPage = (index - 1) <= 10 ? 1 : (int)Math.Ceiling((double)(index - 1) / 10);
|
||
for (int i = 0; i < (alarmRecordViewModel2.RecordCount < 10 ? alarmRecordViewModel2.RecordCount : 10); i++)
|
||
{
|
||
alarmRecordViewModel2.AlarmRecordList.Add(alarmRecordViewModel2.TotalAlarmRecordList[i]);
|
||
}
|
||
alarmRecordViewModel2.AlarmMsg = string.Format("共计{0}页,当前第{1}页", alarmRecordViewModel2.TotalPage, 1);
|
||
#endregion
|
||
|
||
|
||
#region 系统状态页面初始化
|
||
sql = String.Format("select * from conboxenvpara where StationID = {0} ORDER by id desc limit 100", 1);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
BaseStationStatusModel baseStationStatusModel = new BaseStationStatusModel();
|
||
baseStationStatusModel.Index = index++;
|
||
baseStationStatusModel.DataTime = Convert.ToDateTime(dataReader["DataTime"]);
|
||
baseStationStatusModel.In_Vol = Convert.ToSingle(string.IsNullOrEmpty(dataReader["In_Vol"].ToString()) ? "0" : dataReader["In_Vol"]);
|
||
baseStationStatusModel.In_Cur = Convert.ToSingle(string.IsNullOrEmpty(dataReader["In_Cur"].ToString()) ? "0" : dataReader["In_Cur"]);
|
||
baseStationStatusModel.JBH_Tem = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Tem"].ToString()) ? "0" : dataReader["JBH_Tem"]);
|
||
baseStationStatusModel.JBH_Hum = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Hum"].ToString()) ? "0" : dataReader["JBH_Hum"]);
|
||
int leakState = Convert.ToInt32(string.IsNullOrEmpty(dataReader["JBH_Leak"].ToString()) ? "1" : dataReader["JBH_Leak"]);
|
||
if (leakState == 1)
|
||
{
|
||
baseStationStatusModel.JBH_Leak = (ImageSource)Application.Current.FindResource("CycleRed");
|
||
}
|
||
else
|
||
{
|
||
baseStationStatusModel.JBH_Leak = (ImageSource)Application.Current.FindResource("CycleGreen");
|
||
}
|
||
baseStationStatusModel.JBH_Attitude_x = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_x"].ToString()) ? "0" : dataReader["JBH_Attitude_x"]);
|
||
baseStationStatusModel.JBH_Attitude_y = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_y"].ToString()) ? "0" : dataReader["JBH_Attitude_y"]);
|
||
baseStationStatusModel.JBH_Attitude_z = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_z"].ToString()) ? "0" : dataReader["JBH_Attitude_z"]);
|
||
systemStateDataViewModel1.TotalSystemStateDataList.Add(baseStationStatusModel);
|
||
}
|
||
dataReader.Dispose();
|
||
systemStateDataViewModel1.RecordCount = index - 1;
|
||
systemStateDataViewModel1.TotalPage = (index - 1) <= 10 ? 1 : (int)Math.Ceiling((double)(index - 1) / 10);
|
||
for (int i = 0; i < (systemStateDataViewModel1.RecordCount < 10 ? systemStateDataViewModel1.RecordCount : 10); i++)
|
||
{
|
||
systemStateDataViewModel1.SystemStateDataList.Add(systemStateDataViewModel1.TotalSystemStateDataList[i]);
|
||
}
|
||
systemStateDataViewModel1.SystemStateMsg = string.Format("共计{0}页,当前第{1}页", systemStateDataViewModel1.TotalPage, 1);
|
||
|
||
sql = String.Format("select * from conboxenvpara where StationID = {0} ORDER by id desc limit 100", 2);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
BaseStationStatusModel baseStationStatusModel = new BaseStationStatusModel();
|
||
baseStationStatusModel.Index = index++;
|
||
baseStationStatusModel.DataTime = Convert.ToDateTime(dataReader["DataTime"]);
|
||
baseStationStatusModel.In_Vol = Convert.ToSingle(string.IsNullOrEmpty(dataReader["In_Vol"].ToString()) ? "0" : dataReader["In_Vol"]);
|
||
baseStationStatusModel.In_Cur = Convert.ToSingle(string.IsNullOrEmpty(dataReader["In_Cur"].ToString()) ? "0" : dataReader["In_Cur"]);
|
||
baseStationStatusModel.JBH_Tem = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Tem"].ToString()) ? "0" : dataReader["JBH_Tem"]);
|
||
baseStationStatusModel.JBH_Hum = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Hum"].ToString()) ? "0" : dataReader["JBH_Hum"]);
|
||
int leakState = Convert.ToInt32(string.IsNullOrEmpty(dataReader["JBH_Leak"].ToString()) ? "1" : dataReader["JBH_Leak"]);
|
||
if (leakState == 1)
|
||
{
|
||
baseStationStatusModel.JBH_Leak = (ImageSource)Application.Current.FindResource("CycleRed");
|
||
}
|
||
else
|
||
{
|
||
baseStationStatusModel.JBH_Leak = (ImageSource)Application.Current.FindResource("CycleGreen");
|
||
}
|
||
baseStationStatusModel.JBH_Attitude_x = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_x"].ToString()) ? "0" : dataReader["JBH_Attitude_x"]);
|
||
baseStationStatusModel.JBH_Attitude_y = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_y"].ToString()) ? "0" : dataReader["JBH_Attitude_y"]);
|
||
baseStationStatusModel.JBH_Attitude_z = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_z"].ToString()) ? "0" : dataReader["JBH_Attitude_z"]);
|
||
systemStateDataViewModel2.TotalSystemStateDataList.Add(baseStationStatusModel);
|
||
}
|
||
dataReader.Dispose();
|
||
systemStateDataViewModel2.RecordCount = index - 1;
|
||
systemStateDataViewModel2.TotalPage = (index - 1) <= 10 ? 1 : (int)Math.Ceiling((double)(index - 1) / 10);
|
||
for (int i = 0; i < (systemStateDataViewModel2.RecordCount < 10 ? systemStateDataViewModel2.RecordCount : 10); i++)
|
||
{
|
||
systemStateDataViewModel2.SystemStateDataList.Add(systemStateDataViewModel2.TotalSystemStateDataList[i]);
|
||
}
|
||
systemStateDataViewModel2.SystemStateMsg = string.Format("共计{0}页,当前第{1}页", systemStateDataViewModel2.TotalPage, 1);
|
||
#endregion
|
||
|
||
|
||
#region 升压站状态数据界面初始化
|
||
sql = String.Format("select RecordTime,In_Vol,In_Cur from boosterstationstate where StationID = {0} ORDER by id desc limit 100", 1);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
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"]);
|
||
boosterStationStateDataViewModel1.TotalBoosterStationStateDataList.Add(boosterStationStateDataModel);
|
||
}
|
||
dataReader.Dispose();
|
||
boosterStationStateDataViewModel1.RecordCount = index - 1;
|
||
boosterStationStateDataViewModel1.TotalPage = (index - 1) <= 10 ? 1 : (int)Math.Ceiling((double)(index - 1) / 10);
|
||
for (int i = 0; i < (boosterStationStateDataViewModel1.RecordCount < 10 ? boosterStationStateDataViewModel1.RecordCount : 10); i++)
|
||
{
|
||
boosterStationStateDataViewModel1.BoosterStationStateDataList.Add(boosterStationStateDataViewModel1.TotalBoosterStationStateDataList[i]);
|
||
}
|
||
boosterStationStateDataViewModel1.BoosterStationStateMsg = string.Format("共计{0}页,当前第{1}页", boosterStationStateDataViewModel1.TotalPage, 1);
|
||
|
||
sql = String.Format("select RecordTime,In_Vol,In_Cur from boosterstationstate where StationID = {0} ORDER by id desc limit 100", 2);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
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"]);
|
||
boosterStationStateDataViewModel2.TotalBoosterStationStateDataList.Add(boosterStationStateDataModel);
|
||
}
|
||
dataReader.Dispose();
|
||
boosterStationStateDataViewModel2.RecordCount = index - 1;
|
||
boosterStationStateDataViewModel2.TotalPage = (index - 1) <= 10 ? 1 : (int)Math.Ceiling((double)(index - 1) / 10);
|
||
for (int i = 0; i < (boosterStationStateDataViewModel2.RecordCount < 10 ? boosterStationStateDataViewModel2.RecordCount : 10); i++)
|
||
{
|
||
boosterStationStateDataViewModel2.BoosterStationStateDataList.Add(boosterStationStateDataViewModel2.TotalBoosterStationStateDataList[i]);
|
||
}
|
||
boosterStationStateDataViewModel2.BoosterStationStateMsg = string.Format("共计{0}页,当前第{1}页", boosterStationStateDataViewModel2.TotalPage, 1);
|
||
#endregion
|
||
|
||
|
||
#region 升压站状态页面折线图初始化
|
||
var chartValuesTeam1 = new ChartValues<DateTimePoint>();
|
||
var chartValuesTeam2 = new ChartValues<DateTimePoint>();
|
||
sql = String.Format("select RecordTime,In_Vol,In_Cur from boosterstationstate where StationID = {0} ORDER by id desc limit {1}", 1, ChartPointNum);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
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();
|
||
boosterStationStateDataViewModel1.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)
|
||
},
|
||
};
|
||
boosterStationStateDataViewModel1.XFormatter = val => new DateTime((long)val).ToString("MM/dd HH:mm");
|
||
boosterStationStateDataViewModel1.YFormatter1 = val => val.ToString("F2") + " V";
|
||
boosterStationStateDataViewModel1.YFormatter2 = val => val.ToString("F2") + " A";
|
||
|
||
var chartValuesTeam3 = new ChartValues<DateTimePoint>();
|
||
var chartValuesTeam4 = new ChartValues<DateTimePoint>();
|
||
sql = String.Format("select RecordTime,In_Vol,In_Cur from boosterstationstate where StationID = {0} ORDER by id desc limit {1}", 2, ChartPointNum);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
if (!Convert.IsDBNull(dataReader["In_Vol"]) && !Convert.IsDBNull(dataReader["In_Cur"]))
|
||
{
|
||
chartValuesTeam3.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Vol"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
chartValuesTeam4.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Cur"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
}
|
||
}
|
||
dataReader.Dispose();
|
||
boosterStationStateDataViewModel2.SeriesCollection = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电压",
|
||
Values = chartValuesTeam3,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
new LineSeries
|
||
{
|
||
Title = "输入电流",
|
||
Values = chartValuesTeam4,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 1,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 255, 165, 0)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
boosterStationStateDataViewModel2.XFormatter = val => new DateTime((long)val).ToString("MM/dd HH:mm");
|
||
boosterStationStateDataViewModel2.YFormatter1 = val => val.ToString("F2") + " V";
|
||
boosterStationStateDataViewModel2.YFormatter2 = val => val.ToString("F2") + " A";
|
||
#endregion
|
||
|
||
|
||
#region 实时数据显示页面折线图初始化
|
||
var chartValuesConboxTem = new ChartValues<DateTimePoint>();
|
||
var chartValuesConboxHum = new ChartValues<DateTimePoint>();
|
||
var chartValuesConboxVol = new ChartValues<DateTimePoint>();
|
||
var chartValuesConboxCur = new ChartValues<DateTimePoint>();
|
||
sql = String.Format("select * from conboxenvpara where StationID = {0} ORDER by id desc limit {1}", 1, ChartPointNum);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
if (!Convert.IsDBNull(dataReader["In_Vol"]) && !Convert.IsDBNull(dataReader["In_Cur"]))
|
||
{
|
||
chartValuesConboxVol.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Vol"]),
|
||
DateTime = Convert.ToDateTime(dataReader["DataTime"]),
|
||
});
|
||
chartValuesConboxCur.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Cur"]),
|
||
DateTime = Convert.ToDateTime(dataReader["DataTime"]),
|
||
});
|
||
}
|
||
if (!Convert.IsDBNull(dataReader["JBH_Tem"]) && !Convert.IsDBNull(dataReader["JBH_Hum"]))
|
||
{
|
||
chartValuesConboxTem.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["JBH_Tem"]),
|
||
DateTime = Convert.ToDateTime(dataReader["DataTime"]),
|
||
});
|
||
chartValuesConboxHum.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["JBH_Hum"]),
|
||
DateTime = Convert.ToDateTime(dataReader["DataTime"]),
|
||
});
|
||
}
|
||
}
|
||
dataReader.Dispose();
|
||
realTimeDataViewModel1.SeriesCollectionConboxVol = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电压",
|
||
Values = chartValuesConboxVol,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
realTimeDataViewModel1.SeriesCollectionConboxCur = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电流",
|
||
Values = chartValuesConboxCur,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
realTimeDataViewModel1.SeriesCollectionConboxTem = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "温度",
|
||
Values = chartValuesConboxTem,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
realTimeDataViewModel1.SeriesCollectionConboxHum = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "湿度",
|
||
Values = chartValuesConboxHum,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
|
||
var chartValuesBoosterStationVol = new ChartValues<DateTimePoint>();
|
||
var chartValuesBoosterStationCur = new ChartValues<DateTimePoint>();
|
||
sql = String.Format("select RecordTime,In_Vol,In_Cur from boosterstationstate where StationID = {0} ORDER by id desc limit {1}", 1, ChartPointNum);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
if (!Convert.IsDBNull(dataReader["In_Vol"]) && !Convert.IsDBNull(dataReader["In_Cur"]))
|
||
{
|
||
chartValuesBoosterStationVol.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Vol"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
chartValuesBoosterStationCur.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Cur"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
}
|
||
}
|
||
dataReader.Dispose();
|
||
realTimeDataViewModel1.SeriesCollectionBoosterStationVol = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电压",
|
||
Values = chartValuesBoosterStationVol,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
realTimeDataViewModel1.SeriesCollectionBoosterStationCur = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电流",
|
||
Values = chartValuesBoosterStationCur,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
|
||
realTimeDataViewModel1.XFormatter = val => new DateTime((long)val).ToString("MM/dd HH:mm");
|
||
realTimeDataViewModel1.YFormatterVol = val => val.ToString("F2") + " V";
|
||
realTimeDataViewModel1.YFormatterCur = val => val.ToString("F2") + " A";
|
||
realTimeDataViewModel1.YFormatterTem = val => val.ToString("F2") + " ℃";
|
||
realTimeDataViewModel1.YFormatterHum = val => val.ToString("F2") + " %";
|
||
|
||
chartValuesConboxTem = new ChartValues<DateTimePoint>();
|
||
chartValuesConboxHum = new ChartValues<DateTimePoint>();
|
||
chartValuesConboxVol = new ChartValues<DateTimePoint>();
|
||
chartValuesConboxCur = new ChartValues<DateTimePoint>();
|
||
sql = String.Format("select * from conboxenvpara where StationID = {0} ORDER by id desc limit {1}", 2, ChartPointNum);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
if (!Convert.IsDBNull(dataReader["In_Vol"]) && !Convert.IsDBNull(dataReader["In_Cur"]))
|
||
{
|
||
chartValuesConboxVol.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Vol"]),
|
||
DateTime = Convert.ToDateTime(dataReader["DataTime"]),
|
||
});
|
||
chartValuesConboxCur.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Cur"]),
|
||
DateTime = Convert.ToDateTime(dataReader["DataTime"]),
|
||
});
|
||
}
|
||
if (!Convert.IsDBNull(dataReader["JBH_Tem"]) && !Convert.IsDBNull(dataReader["JBH_Hum"]))
|
||
{
|
||
chartValuesConboxTem.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["JBH_Tem"]),
|
||
DateTime = Convert.ToDateTime(dataReader["DataTime"]),
|
||
});
|
||
chartValuesConboxHum.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["JBH_Hum"]),
|
||
DateTime = Convert.ToDateTime(dataReader["DataTime"]),
|
||
});
|
||
}
|
||
}
|
||
dataReader.Dispose();
|
||
realTimeDataViewModel2.SeriesCollectionConboxVol = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电压",
|
||
Values = chartValuesConboxVol,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
realTimeDataViewModel2.SeriesCollectionConboxCur = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电流",
|
||
Values = chartValuesConboxCur,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
realTimeDataViewModel2.SeriesCollectionConboxTem = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "温度",
|
||
Values = chartValuesConboxTem,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
realTimeDataViewModel2.SeriesCollectionConboxHum = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "湿度",
|
||
Values = chartValuesConboxHum,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
|
||
chartValuesBoosterStationVol = new ChartValues<DateTimePoint>();
|
||
chartValuesBoosterStationCur = new ChartValues<DateTimePoint>();
|
||
sql = String.Format("select RecordTime,In_Vol,In_Cur from boosterstationstate where StationID = {0} ORDER by id desc limit {1}", 2, ChartPointNum);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
if (!Convert.IsDBNull(dataReader["In_Vol"]) && !Convert.IsDBNull(dataReader["In_Cur"]))
|
||
{
|
||
chartValuesBoosterStationVol.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Vol"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
chartValuesBoosterStationCur.Add(new DateTimePoint
|
||
{
|
||
Value = Convert.ToSingle(dataReader["In_Cur"]),
|
||
DateTime = Convert.ToDateTime(dataReader["RecordTime"]),
|
||
});
|
||
}
|
||
}
|
||
dataReader.Dispose();
|
||
realTimeDataViewModel2.SeriesCollectionBoosterStationVol = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电压",
|
||
Values = chartValuesBoosterStationVol,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
realTimeDataViewModel2.SeriesCollectionBoosterStationCur = new SeriesCollection
|
||
{
|
||
new LineSeries
|
||
{
|
||
Title = "输入电流",
|
||
Values = chartValuesBoosterStationCur,
|
||
LineSmoothness = 0,
|
||
ScalesYAt = 0,
|
||
Stroke = new SolidColorBrush(Color.FromArgb(255, 43, 237, 241)),
|
||
Fill = new SolidColorBrush(Colors.Transparent)
|
||
},
|
||
};
|
||
|
||
realTimeDataViewModel2.XFormatter = val => new DateTime((long)val).ToString("MM/dd HH:mm");
|
||
realTimeDataViewModel2.YFormatterVol = val => val.ToString("F2") + " V";
|
||
realTimeDataViewModel2.YFormatterCur = val => val.ToString("F2") + " A";
|
||
realTimeDataViewModel2.YFormatterTem = val => val.ToString("F2") + " ℃";
|
||
realTimeDataViewModel2.YFormatterHum = val => val.ToString("F2") + " %";
|
||
#endregion
|
||
|
||
|
||
#region 实时数据显示页面数据初始化
|
||
sql = String.Format("select * from conboxenvpara where StationID = {0} ORDER by id desc limit 1", 1);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
realTimeDataViewModel1.BaseStationStatus[0].Value = string.IsNullOrEmpty(dataReader["In_Vol"].ToString()) ? "0.00" : dataReader["In_Vol"].ToString();
|
||
realTimeDataViewModel1.BaseStationStatus[3].Value = string.IsNullOrEmpty(dataReader["In_Cur"].ToString()) ? "0.00" : dataReader["In_Cur"].ToString();
|
||
realTimeDataViewModel1.BaseStationStatus[1].Value = string.IsNullOrEmpty(dataReader["JBH_Tem"].ToString()) ? "0.00" : dataReader["JBH_Tem"].ToString();
|
||
realTimeDataViewModel1.BaseStationStatus[4].Value = string.IsNullOrEmpty(dataReader["JBH_Hum"].ToString()) ? "0.00" : dataReader["JBH_Hum"].ToString();
|
||
//realTimeDataViewModel1.BaseStationStatus[4].Value = string.IsNullOrEmpty(dataReader["JBH_Attitude_x"].ToString()) ? "0.00" : dataReader["JBH_Attitude_x"].ToString();
|
||
//realTimeDataViewModel1.BaseStationStatus[5].Value = string.IsNullOrEmpty(dataReader["JBH_Attitude_y"].ToString()) ? "0.00" : dataReader["JBH_Attitude_y"].ToString();
|
||
//realTimeDataViewModel1.BaseStationStatus[6].Value = string.IsNullOrEmpty(dataReader["JBH_Attitude_z"].ToString()) ? "0.00" : dataReader["JBH_Attitude_z"].ToString();
|
||
int leakState = Convert.ToInt32(string.IsNullOrEmpty(dataReader["JBH_Leak"].ToString()) ? "1" : dataReader["JBH_Leak"]);
|
||
if (leakState == 1)
|
||
{
|
||
realTimeDataViewModel1.LeakageImage = (ImageSource)Application.Current.FindResource("CycleRed");
|
||
}
|
||
else
|
||
{
|
||
realTimeDataViewModel1.LeakageImage = (ImageSource)Application.Current.FindResource("CycleGreen");
|
||
}
|
||
|
||
realTimeDataViewModel1.DataTimeConboxTem = Convert.ToDateTime(dataReader["DataTime"]);
|
||
realTimeDataViewModel1.DataTimeConboxHum = Convert.ToDateTime(dataReader["DataTime"]);
|
||
realTimeDataViewModel1.DataTimeConboxVol = Convert.ToDateTime(dataReader["DataTime"]);
|
||
realTimeDataViewModel1.DataTimeConboxCur = Convert.ToDateTime(dataReader["DataTime"]);
|
||
}
|
||
dataReader.Dispose();
|
||
|
||
sql = String.Format("select * from boosterstationstate where StationID = {0} ORDER by id desc limit 1", 1);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
realTimeDataViewModel1.BaseStationStatus[2].Value = string.IsNullOrEmpty(dataReader["In_Vol"].ToString()) ? "0.00" : dataReader["In_Vol"].ToString();
|
||
realTimeDataViewModel1.BaseStationStatus[5].Value = string.IsNullOrEmpty(dataReader["In_Cur"].ToString()) ? "0.00" : dataReader["In_Cur"].ToString();
|
||
realTimeDataViewModel1.DataTimeBoosterStationVol = Convert.ToDateTime(dataReader["RecordTime"]);
|
||
realTimeDataViewModel1.DataTimeBoosterStationCur = Convert.ToDateTime(dataReader["RecordTime"]);
|
||
}
|
||
dataReader.Dispose();
|
||
|
||
sql = String.Format("select * from conboxenvpara where StationID = {0} ORDER by id desc limit 1", 2);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
realTimeDataViewModel2.BaseStationStatus[0].Value = string.IsNullOrEmpty(dataReader["In_Vol"].ToString()) ? "0.00" : dataReader["In_Vol"].ToString();
|
||
realTimeDataViewModel2.BaseStationStatus[3].Value = string.IsNullOrEmpty(dataReader["In_Cur"].ToString()) ? "0.00" : dataReader["In_Cur"].ToString();
|
||
realTimeDataViewModel2.BaseStationStatus[1].Value = string.IsNullOrEmpty(dataReader["JBH_Tem"].ToString()) ? "0.00" : dataReader["JBH_Tem"].ToString();
|
||
realTimeDataViewModel2.BaseStationStatus[4].Value = string.IsNullOrEmpty(dataReader["JBH_Hum"].ToString()) ? "0.00" : dataReader["JBH_Hum"].ToString();
|
||
//realTimeDataViewModel2.BaseStationStatus[4].Value = string.IsNullOrEmpty(dataReader["JBH_Attitude_x"].ToString()) ? "0.00" : dataReader["JBH_Attitude_x"].ToString();
|
||
//realTimeDataViewModel2.BaseStationStatus[5].Value = string.IsNullOrEmpty(dataReader["JBH_Attitude_y"].ToString()) ? "0.00" : dataReader["JBH_Attitude_y"].ToString();
|
||
//realTimeDataViewModel2.BaseStationStatus[6].Value = string.IsNullOrEmpty(dataReader["JBH_Attitude_z"].ToString()) ? "0.00" : dataReader["JBH_Attitude_z"].ToString();
|
||
int leakState = Convert.ToInt32(string.IsNullOrEmpty(dataReader["JBH_Leak"].ToString()) ? "1" : dataReader["JBH_Leak"]);
|
||
if (leakState == 1)
|
||
{
|
||
realTimeDataViewModel2.LeakageImage = (ImageSource)Application.Current.FindResource("CycleRed");
|
||
}
|
||
else
|
||
{
|
||
realTimeDataViewModel2.LeakageImage = (ImageSource)Application.Current.FindResource("CycleGreen");
|
||
}
|
||
|
||
realTimeDataViewModel2.DataTimeConboxTem = Convert.ToDateTime(dataReader["DataTime"]);
|
||
realTimeDataViewModel2.DataTimeConboxHum = Convert.ToDateTime(dataReader["DataTime"]);
|
||
realTimeDataViewModel2.DataTimeConboxVol = Convert.ToDateTime(dataReader["DataTime"]);
|
||
realTimeDataViewModel2.DataTimeConboxCur = Convert.ToDateTime(dataReader["DataTime"]);
|
||
}
|
||
dataReader.Dispose();
|
||
|
||
sql = String.Format("select * from boosterstationstate where StationID = {0} ORDER by id desc limit 1", 2);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
realTimeDataViewModel2.BaseStationStatus[2].Value = string.IsNullOrEmpty(dataReader["In_Vol"].ToString()) ? "0.00" : dataReader["In_Vol"].ToString();
|
||
realTimeDataViewModel2.BaseStationStatus[5].Value = string.IsNullOrEmpty(dataReader["In_Cur"].ToString()) ? "0.00" : dataReader["In_Cur"].ToString();
|
||
realTimeDataViewModel2.DataTimeBoosterStationVol = Convert.ToDateTime(dataReader["RecordTime"]);
|
||
realTimeDataViewModel2.DataTimeBoosterStationCur = Convert.ToDateTime(dataReader["RecordTime"]);
|
||
}
|
||
dataReader.Dispose();
|
||
#endregion
|
||
|
||
|
||
#region 实时数据显示页面告警数据初始化
|
||
sql = String.Format("select * from alarminfohis where StationID = {0} ORDER by id desc limit 7", 1);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
AlarmRecordModel alarmRecordModel = new AlarmRecordModel();
|
||
alarmRecordModel.Index = index++;
|
||
alarmRecordModel.DataTime = Convert.ToDateTime(dataReader["DataTime"]);
|
||
alarmRecordModel.ParaName = dataReader["ParaName"].ToString();
|
||
alarmRecordModel.ParaState = dataReader["ParaState"].ToString();
|
||
alarmRecordModel.ProcessingMethod = dataReader["ProcessingMethod"].ToString();
|
||
if (Convert.ToInt32(dataReader["UrgencyLevel"]) == 1)
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleYellow");
|
||
}
|
||
else if (Convert.ToInt32(dataReader["UrgencyLevel"]) == 2)
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleOrange");
|
||
}
|
||
else
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleRed");
|
||
}
|
||
realTimeDataViewModel1.AlarmList.Add(alarmRecordModel);
|
||
}
|
||
dataReader.Dispose();
|
||
|
||
sql = String.Format("select * from alarminfohis where StationID = {0} ORDER by id desc limit 7", 2);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
index = 1;
|
||
while (dataReader.Read())
|
||
{
|
||
AlarmRecordModel alarmRecordModel = new AlarmRecordModel();
|
||
alarmRecordModel.Index = index++;
|
||
alarmRecordModel.DataTime = Convert.ToDateTime(dataReader["DataTime"]);
|
||
alarmRecordModel.ParaName = dataReader["ParaName"].ToString();
|
||
alarmRecordModel.ParaState = dataReader["ParaState"].ToString();
|
||
alarmRecordModel.ProcessingMethod = dataReader["ProcessingMethod"].ToString();
|
||
if (Convert.ToInt32(dataReader["UrgencyLevel"]) == 1)
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleYellow");
|
||
}
|
||
else if (Convert.ToInt32(dataReader["UrgencyLevel"]) == 2)
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleOrange");
|
||
}
|
||
else
|
||
{
|
||
alarmRecordModel.UrgencyLevel = (ImageSource)Application.Current.FindResource("CycleRed");
|
||
}
|
||
realTimeDataViewModel2.AlarmList.Add(alarmRecordModel);
|
||
}
|
||
dataReader.Dispose();
|
||
#endregion
|
||
|
||
|
||
#region 实时数据显示页面三维模型姿态数据初始化
|
||
sql = String.Format("select * from conboxenvpara where StationID = {0} ORDER by id desc limit 1", 1);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
realTimeDataViewModel1.BaseStationGesture.RollAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_x"].ToString()) ? "0.00" : dataReader["JBH_Attitude_x"].ToString());
|
||
realTimeDataViewModel1.BaseStationGesture.PitchAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_y"].ToString()) ? "0.00" : dataReader["JBH_Attitude_y"].ToString());
|
||
realTimeDataViewModel1.BaseStationGesture.HeadingAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_z"].ToString()) ? "0.00" : dataReader["JBH_Attitude_z"].ToString());
|
||
}
|
||
dataReader.Dispose();
|
||
|
||
baseStationModelViewModel1.BaseStationGesture.RollAngle = realTimeDataViewModel1.BaseStationGesture.RollAngle;
|
||
baseStationModelViewModel1.BaseStationGesture.PitchAngle = realTimeDataViewModel1.BaseStationGesture.PitchAngle;
|
||
baseStationModelViewModel1.BaseStationGesture.HeadingAngle = realTimeDataViewModel1.BaseStationGesture.HeadingAngle;
|
||
|
||
float CalibrationHG = Convert.ToSingle(Tools.GetAppSetting("CalibrationHG"));
|
||
float CalibrationFY = Convert.ToSingle(Tools.GetAppSetting("CalibrationFY"));
|
||
float CalibrationPH = Convert.ToSingle(Tools.GetAppSetting("CalibrationPH"));
|
||
realTimeDataViewModel1.BaseStationGesture.PY_HG = realTimeDataViewModel1.BaseStationGesture.RollAngle - CalibrationHG;
|
||
realTimeDataViewModel1.BaseStationGesture.PY_FY = realTimeDataViewModel1.BaseStationGesture.PitchAngle - CalibrationFY;
|
||
realTimeDataViewModel1.BaseStationGesture.PY_PH = realTimeDataViewModel1.BaseStationGesture.HeadingAngle - CalibrationPH;
|
||
if (Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_HG) <= 0.75)
|
||
realTimeDataViewModel1.AngleBackgroundX = new SolidColorBrush(Colors.Green);
|
||
else if (Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_HG) > 0.75 && Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_HG) <= 1)
|
||
realTimeDataViewModel1.AngleBackgroundX = new SolidColorBrush(Colors.Yellow);
|
||
else
|
||
realTimeDataViewModel1.AngleBackgroundX = new SolidColorBrush(Colors.Red);
|
||
if (Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_FY) <= 0.75)
|
||
realTimeDataViewModel1.AngleBackgroundY = new SolidColorBrush(Colors.Green);
|
||
else if (Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_FY) > 0.75 && Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_FY) <= 1)
|
||
realTimeDataViewModel1.AngleBackgroundY = new SolidColorBrush(Colors.Yellow);
|
||
else
|
||
realTimeDataViewModel1.AngleBackgroundY = new SolidColorBrush(Colors.Red);
|
||
if (Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_PH) <= 0.75)
|
||
realTimeDataViewModel1.AngleBackgroundZ = new SolidColorBrush(Colors.Green);
|
||
else if (Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_PH) > 0.75 && Math.Abs(realTimeDataViewModel1.BaseStationGesture.PY_PH) <= 1)
|
||
realTimeDataViewModel1.AngleBackgroundZ = new SolidColorBrush(Colors.Yellow);
|
||
else
|
||
realTimeDataViewModel1.AngleBackgroundZ = new SolidColorBrush(Colors.Red);
|
||
|
||
|
||
sql = String.Format("select * from conboxenvpara where StationID = {0} ORDER by id desc limit 1", 2);
|
||
dataReader = DBHelper.ExecuteReader(sql, 1);
|
||
while (dataReader.Read())
|
||
{
|
||
realTimeDataViewModel2.BaseStationGesture.RollAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_x"].ToString()) ? "0.00" : dataReader["JBH_Attitude_x"].ToString());
|
||
realTimeDataViewModel2.BaseStationGesture.PitchAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_y"].ToString()) ? "0.00" : dataReader["JBH_Attitude_y"].ToString());
|
||
realTimeDataViewModel2.BaseStationGesture.HeadingAngle = Convert.ToSingle(string.IsNullOrEmpty(dataReader["JBH_Attitude_z"].ToString()) ? "0.00" : dataReader["JBH_Attitude_z"].ToString());
|
||
}
|
||
dataReader.Dispose();
|
||
|
||
baseStationModelViewModel2.BaseStationGesture.RollAngle = realTimeDataViewModel2.BaseStationGesture.RollAngle;
|
||
baseStationModelViewModel2.BaseStationGesture.PitchAngle = realTimeDataViewModel2.BaseStationGesture.PitchAngle;
|
||
baseStationModelViewModel2.BaseStationGesture.HeadingAngle = realTimeDataViewModel2.BaseStationGesture.HeadingAngle;
|
||
|
||
realTimeDataViewModel2.BaseStationGesture.PY_HG = realTimeDataViewModel2.BaseStationGesture.RollAngle - CalibrationHG;
|
||
realTimeDataViewModel2.BaseStationGesture.PY_FY = realTimeDataViewModel2.BaseStationGesture.PitchAngle - CalibrationFY;
|
||
realTimeDataViewModel2.BaseStationGesture.PY_PH = realTimeDataViewModel2.BaseStationGesture.HeadingAngle - CalibrationPH;
|
||
if (Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_HG) <= 0.75)
|
||
realTimeDataViewModel2.AngleBackgroundX = new SolidColorBrush(Colors.Green);
|
||
else if (Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_HG) > 0.75 && Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_HG) <= 1)
|
||
realTimeDataViewModel2.AngleBackgroundX = new SolidColorBrush(Colors.Yellow);
|
||
else
|
||
realTimeDataViewModel2.AngleBackgroundX = new SolidColorBrush(Colors.Red);
|
||
if (Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_FY) <= 0.75)
|
||
realTimeDataViewModel2.AngleBackgroundY = new SolidColorBrush(Colors.Green);
|
||
else if (Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_FY) > 0.75 && Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_FY) <= 1)
|
||
realTimeDataViewModel2.AngleBackgroundY = new SolidColorBrush(Colors.Yellow);
|
||
else
|
||
realTimeDataViewModel2.AngleBackgroundY = new SolidColorBrush(Colors.Red);
|
||
if (Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_PH) <= 0.75)
|
||
realTimeDataViewModel2.AngleBackgroundZ = new SolidColorBrush(Colors.Green);
|
||
else if (Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_PH) > 0.75 && Math.Abs(realTimeDataViewModel2.BaseStationGesture.PY_PH) <= 1)
|
||
realTimeDataViewModel2.AngleBackgroundZ = new SolidColorBrush(Colors.Yellow);
|
||
else
|
||
realTimeDataViewModel2.AngleBackgroundZ = new SolidColorBrush(Colors.Red);
|
||
#endregion
|
||
|
||
//默认打开第一个界面
|
||
DoNavChanged("RealTimeDataView");
|
||
}
|
||
|
||
|
||
#region Communication Command
|
||
/// <summary>
|
||
/// SocketServer1连接
|
||
/// </summary>
|
||
/// <param name="o"></param>
|
||
public void Socket1DoOpen(object o)
|
||
{
|
||
if(serverModel1.IsOpened) //服务器已开启
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(100);
|
||
serverModel1.DoStop();
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(150);
|
||
|
||
if (serverModel1.DoStart(SocketServerInfo1))
|
||
{
|
||
//EM.Socket1ConMessage = string.Format("IP:{0} \r\n端口号:{1}", SocketInfo1.IP, SocketInfo1.Port.ToString());
|
||
//更新下App.config中的配置信息
|
||
Tools.UpdateAppSettings("XWJ_Service_IP1", SocketServerInfo1.IP);
|
||
Tools.UpdateAppSettings("XWJ_Service_Port1", SocketServerInfo1.Port.ToString());
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// SocketServer2连接
|
||
/// </summary>
|
||
/// <param name="o"></param>
|
||
public void Socket2DoOpen(object o)
|
||
{
|
||
if (serverModel2.IsOpened) //服务器已开启
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(100);
|
||
serverModel2.DoStop();
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(150);
|
||
|
||
if (serverModel2.DoStart(SocketServerInfo2))
|
||
{
|
||
//EM.Socket1ConMessage = string.Format("IP:{0} \r\n端口号:{1}", SocketInfo1.IP, SocketInfo1.Port.ToString());
|
||
//更新下App.config中的配置信息
|
||
Tools.UpdateAppSettings("XWJ_Service_IP2", SocketServerInfo2.IP);
|
||
Tools.UpdateAppSettings("XWJ_Service_Port2", SocketServerInfo2.Port.ToString());
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// SocketClient1连接
|
||
/// </summary>
|
||
/// <param name="o"></param>
|
||
public void DoSocket1Connect(object o)
|
||
{
|
||
if (clientModel1.IsConnected)
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(100);
|
||
clientModel1.DisConnect();
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(150);
|
||
|
||
if (clientModel1.DoConnect(SocketInfo1))
|
||
{
|
||
//EM.Socket1ConMessage = string.Format("IP:{0} \r\n端口号:{1}", SocketInfo1.IP, SocketInfo1.Port.ToString());
|
||
//更新下App.config中的配置信息
|
||
Tools.UpdateAppSettings("SYZ_Client_IP1", SocketInfo1.IP);
|
||
Tools.UpdateAppSettings("SYZ_Client_Port1", SocketInfo1.Port.ToString());
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// SocketClient2连接
|
||
/// </summary>
|
||
/// <param name="o"></param>
|
||
public void DoSocket2Connect(object o)
|
||
{
|
||
if (clientModel2.IsConnected)
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(100);
|
||
clientModel2.DisConnect();
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(200);
|
||
|
||
if (clientModel2.DoConnect(SocketInfo2))
|
||
{
|
||
// EM.Socket2ConMessage = string.Format("IP:{0} \r\n端口号:{1}", SocketInfo2.IP, SocketInfo2.Port.ToString());
|
||
//更新下App.config中的配置信息
|
||
Tools.UpdateAppSettings("SYZ_Client_IP2", SocketInfo2.IP);
|
||
Tools.UpdateAppSettings("SYZ_Client_Port2", SocketInfo2.Port.ToString());
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// DoSocketDZY1Connect连接
|
||
/// </summary>
|
||
/// <param name="o"></param>
|
||
public void DoSocketDZY1Connect(object o)
|
||
{
|
||
if (clientModelDZY1.IsConnected)
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(100);
|
||
clientModelDZY1.DisConnect();
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(150);
|
||
|
||
if (clientModelDZY1.DoConnect(SocketInfoDZY1))
|
||
{
|
||
//EM.Socket1ConMessage = string.Format("IP:{0} \r\n端口号:{1}", SocketInfo1.IP, SocketInfo1.Port.ToString());
|
||
//更新下App.config中的配置信息
|
||
Tools.UpdateAppSettings("DZY_Client_IP1", SocketInfoDZY1.IP);
|
||
Tools.UpdateAppSettings("DZY_Client_Port1", SocketInfoDZY1.Port.ToString());
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// DoSocketDZY2Connect连接
|
||
/// </summary>
|
||
/// <param name="o"></param>
|
||
public void DoSocketDZY2Connect(object o)
|
||
{
|
||
if (clientModelDZY2.IsConnected)
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(100);
|
||
clientModelDZY2.DisConnect();
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
Task.Run(new Action(async () =>
|
||
{
|
||
await Task.Delay(200);
|
||
|
||
if (clientModelDZY2.DoConnect(SocketInfoDZY1))
|
||
{
|
||
// EM.Socket2ConMessage = string.Format("IP:{0} \r\n端口号:{1}", SocketInfo2.IP, SocketInfo2.Port.ToString());
|
||
//更新下App.config中的配置信息
|
||
Tools.UpdateAppSettings("DZY_Client_IP2", SocketInfoDZY1.IP);
|
||
Tools.UpdateAppSettings("DZY_Client_Port2", SocketInfoDZY1.Port.ToString());
|
||
}
|
||
}));
|
||
}
|
||
}
|
||
|
||
|
||
#region Useless
|
||
//public void Com1DoConnect(object o)
|
||
//{
|
||
// if (comModel1.IsConnected)
|
||
// {
|
||
// Task.Run(new Action(async () =>
|
||
// {
|
||
// await Task.Delay(100);
|
||
// comModel1.DisConnect();
|
||
// }));
|
||
|
||
// }
|
||
// else
|
||
// {
|
||
// Task.Run(new Action(async () =>
|
||
// {
|
||
// await Task.Delay(100);
|
||
|
||
// if (comModel1.DoConnect(SerialInfo1))
|
||
// {
|
||
// //EM.ComConMessage = string.Format("串口号:{0} \r\n波特率:{1}", SerialInfo.PortName, SerialInfo.BaudRate.ToString());
|
||
// //更新下App.config中的配置信息
|
||
// //Tools.UpdateAppSettings("PortName", SerialInfo1.PortName);
|
||
// //Tools.UpdateAppSettings("BaudRate", SerialInfo1.BaudRate.ToString());
|
||
// }
|
||
// else
|
||
// {
|
||
// App.Current.Dispatcher.Invoke(() =>
|
||
// {
|
||
// // 更新UI的代码
|
||
// HandyControl.Controls.Dialog.Show(new TextDialog("串口连接初始化失败!\n请检查设备连接状态!"));
|
||
// });
|
||
// }
|
||
// }));
|
||
// }
|
||
//}
|
||
|
||
|
||
|
||
//public void Com2DoConnect(object o)
|
||
//{
|
||
// if (comModel2.IsConnected)
|
||
// {
|
||
// Task.Run(new Action(async () =>
|
||
// {
|
||
// await Task.Delay(100);
|
||
// comModel2.DisConnect();
|
||
// }));
|
||
|
||
// }
|
||
// else
|
||
// {
|
||
// Task.Run(new Action(async () =>
|
||
// {
|
||
// await Task.Delay(100);
|
||
|
||
// if (comModel2.DoConnect(SerialInfo2))
|
||
// {
|
||
// //EM.ComConMessage = string.Format("串口号:{0} \r\n波特率:{1}", SerialInfo.PortName, SerialInfo.BaudRate.ToString());
|
||
// //更新下App.config中的配置信息
|
||
// //Tools.UpdateAppSettings("PortName", SerialInfo2.PortName);
|
||
// //Tools.UpdateAppSettings("BaudRate", SerialInfo2.BaudRate.ToString());
|
||
// }
|
||
// else
|
||
// {
|
||
// App.Current.Dispatcher.Invoke(() =>
|
||
// {
|
||
// // 更新UI的代码
|
||
// HandyControl.Controls.Dialog.Show(new TextDialog("串口连接初始化失败!\n请检查设备连接状态!"));
|
||
// });
|
||
// }
|
||
// }));
|
||
// }
|
||
//}
|
||
#endregion
|
||
#endregion
|
||
|
||
|
||
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
|
||
|
||
|
||
#region Remote Control (Seis Set)
|
||
private void TimerOpenSetMsgHidden_Tick(object sender, EventArgs e)
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Hidden;
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private void TimerCloseSetMsgHidden_Tick(object sender, EventArgs e)
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Hidden;
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private void TimerSeisZeroSetStart_Tick(object sender, EventArgs e)
|
||
{
|
||
if (!SeisZeroSetStartIsReceived)
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "请求凋零开启发送成功,但未接收到数据!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisZeroSetStartButtonIsEnabled = true;
|
||
SeisZeroSetStopButtonIsEnabled = true;
|
||
}
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private void TimerSeisZeroSetStop_Tick(object sender, EventArgs e)
|
||
{
|
||
if (!SeisZeroSetStopIsReceived)
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "请求调零停止发送成功,但未接收到数据!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisZeroSetStartButtonIsEnabled = true;
|
||
SeisZeroSetStopButtonIsEnabled = true;
|
||
}
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private void TimerSeisLevelSetStart_Tick(object sender, EventArgs e)
|
||
{
|
||
if (!SeisLevelSetStartIsReceived)
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "请求调平开始发送成功,但未接收到数据!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisLevelSetStopButtonIsEnabled = true;
|
||
SeisLevelSetStartButtonIsEnabled = true;
|
||
}
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private void TimerSeisLevelSetStop_Tick(object sender, EventArgs e)
|
||
{
|
||
if (!SeisLevelSetStopIsReceived)
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "请求调平停止发送成功,但未接收到数据!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisLevelSetStopButtonIsEnabled = true;
|
||
SeisLevelSetStartButtonIsEnabled = true;
|
||
}
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private string openSetMsg;
|
||
|
||
public string OpenSetMsg
|
||
{
|
||
get { return openSetMsg; }
|
||
set { openSetMsg = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Brush openSetMsgForeground;
|
||
|
||
public Brush OpenSetMsgForeground
|
||
{
|
||
get { return openSetMsgForeground; }
|
||
set { openSetMsgForeground = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Visibility openSetMsgVisibility = Visibility.Visible;
|
||
|
||
public Visibility OpenSetMsgVisibility
|
||
{
|
||
get { return openSetMsgVisibility; }
|
||
set { openSetMsgVisibility = value; this.DoNotify(); }
|
||
}
|
||
|
||
private string closeSetMsg;
|
||
|
||
public string CloseSetMsg
|
||
{
|
||
get { return closeSetMsg; }
|
||
set { closeSetMsg = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Brush closeSetMsgForeground;
|
||
|
||
public Brush CloseSetMsgForeground
|
||
{
|
||
get { return closeSetMsgForeground; }
|
||
set { closeSetMsgForeground = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Visibility closeSetMsgVisibility = Visibility.Visible;
|
||
|
||
public Visibility CloseSetMsgVisibility
|
||
{
|
||
get { return closeSetMsgVisibility; }
|
||
set { closeSetMsgVisibility = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool seisZeroSetStartButtonIsEnabled = true;
|
||
|
||
public bool SeisZeroSetStartButtonIsEnabled
|
||
{
|
||
get { return seisZeroSetStartButtonIsEnabled; }
|
||
set { seisZeroSetStartButtonIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool seisZeroSetStopButtonIsEnabled = true;
|
||
|
||
public bool SeisZeroSetStopButtonIsEnabled
|
||
{
|
||
get { return seisZeroSetStopButtonIsEnabled; }
|
||
set { seisZeroSetStopButtonIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool seisLevelSetStartButtonIsEnabled = true;
|
||
|
||
public bool SeisLevelSetStartButtonIsEnabled
|
||
{
|
||
get { return seisLevelSetStartButtonIsEnabled; }
|
||
set { seisLevelSetStartButtonIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool seisLevelSetStopButtonIsEnabled = true;
|
||
|
||
public bool SeisLevelSetStopButtonIsEnabled
|
||
{
|
||
get { return seisLevelSetStopButtonIsEnabled; }
|
||
set { seisLevelSetStopButtonIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool seisZeroSetStartIsReceived = false;
|
||
|
||
public bool SeisZeroSetStartIsReceived
|
||
{
|
||
get { return seisZeroSetStartIsReceived; }
|
||
set { seisZeroSetStartIsReceived = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool seisZeroSetStopIsReceived = false;
|
||
|
||
public bool SeisZeroSetStopIsReceived
|
||
{
|
||
get { return seisZeroSetStopIsReceived; }
|
||
set { seisZeroSetStopIsReceived = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool seisLevelSetStartIsReceived = false;
|
||
|
||
public bool SeisLevelSetStartIsReceived
|
||
{
|
||
get { return seisLevelSetStartIsReceived; }
|
||
set { seisLevelSetStartIsReceived = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool seisLevelSetStopIsReceived = false;
|
||
|
||
public bool SeisLevelSetStopIsReceived
|
||
{
|
||
get { return seisLevelSetStopIsReceived; }
|
||
set { seisLevelSetStopIsReceived = value; this.DoNotify(); }
|
||
}
|
||
|
||
//各个开关
|
||
public async void Btn_Switch(object o)
|
||
{
|
||
string[] msg = o.ToString().Split(',');
|
||
int switchNum = msg[1].Equals("True") ? 1 : 0;
|
||
string MessageContent = "";
|
||
switch (msg[0])
|
||
{
|
||
//case "SatcomPowerPicker":
|
||
// MessageContent = "卫通电源" + (msg[1].Equals("True") ? "打开" : "关闭");
|
||
// break;
|
||
//case "JBHPowerPicker":
|
||
// MessageContent = "接驳盒电源" + (msg[1].Equals("True") ? "打开" : "关闭");
|
||
// break;
|
||
//case "MainSeismograph":
|
||
// MessageContent = "主地震仪电源" + (msg[1].Equals("True") ? "打开" : "关闭");
|
||
// break;
|
||
//case "StandbySeismograph":
|
||
// MessageContent = "备用地震仪电源" + (msg[1].Equals("True") ? "打开" : "关闭");
|
||
// break;
|
||
case "SeisZeroSetStart": //凋零
|
||
if(msg[1].Equals("True")) //打开
|
||
{
|
||
SeisZeroSetStartButtonIsEnabled = false;
|
||
SeisZeroSetStopButtonIsEnabled = false;
|
||
SeisZeroSetStartIsReceived = 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
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x00 }); //DATA
|
||
checkByte.Clear();
|
||
checkByte.AddRange(new byte[] { 0xA0, 0x50 }); //CMD
|
||
checkByte.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
checkByte.AddRange(new byte[] { 0x00, 0x00 }); //DATA
|
||
checkCode = Tools.CRCCalc(checkByte.ToArray()); //CHK_SUM
|
||
sendDataSeis.AddRange(checkCode);
|
||
|
||
bool result = false;
|
||
if (station_id == 1)
|
||
{
|
||
if(clientModelDZY1.IsConnected)
|
||
{
|
||
result = clientModelDZY1.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "通信未连接!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisZeroSetStartButtonIsEnabled = true;
|
||
SeisZeroSetStopButtonIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (clientModelDZY2.IsConnected)
|
||
{
|
||
result = clientModelDZY2.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "通信未连接!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisZeroSetStartButtonIsEnabled = true;
|
||
SeisZeroSetStopButtonIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if(result)
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "请求调零开启发送成功!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Green);
|
||
timerSeisZeroSetStart.Start();
|
||
}
|
||
else
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "请求调零开启发送失败!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisZeroSetStartButtonIsEnabled = true;
|
||
SeisZeroSetStopButtonIsEnabled = true;
|
||
}
|
||
}
|
||
break;
|
||
case "SeisZeroSetStop": //凋零
|
||
if(!msg[1].Equals("True")) //关闭
|
||
{
|
||
SeisZeroSetStopButtonIsEnabled = false;
|
||
SeisZeroSetStartButtonIsEnabled = false;
|
||
SeisZeroSetStopIsReceived = false;
|
||
|
||
sendDataSeis.Clear();
|
||
sendDataSeis.AddRange(new byte[] { 0xBF, 0x13, 0x97, 0x74 }); //SYNC
|
||
sendDataSeis.AddRange(new byte[] { 0xA0, 0x51 }); //CMD
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x00 }); //DATA
|
||
checkByte.Clear();
|
||
checkByte.AddRange(new byte[] { 0xA0, 0x51 }); //CMD
|
||
checkByte.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
checkByte.AddRange(new byte[] { 0x00, 0x00 }); //DATA
|
||
checkCode = Tools.CRCCalc(checkByte.ToArray()); //CHK_SUM
|
||
sendDataSeis.AddRange(checkCode);
|
||
|
||
bool result = false;
|
||
if (station_id == 1)
|
||
{
|
||
if (clientModelDZY1.IsConnected)
|
||
{
|
||
result = clientModelDZY1.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "通信未连接!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisZeroSetStopButtonIsEnabled = true;
|
||
SeisZeroSetStartButtonIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (clientModelDZY2.IsConnected)
|
||
{
|
||
result = clientModelDZY2.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "通信未连接!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisZeroSetStopButtonIsEnabled = true;
|
||
SeisZeroSetStartButtonIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (result)
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "请求调零停止发送成功!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Green);
|
||
timerSeisZeroSetStop.Start();
|
||
}
|
||
else
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "请求调零停止发送失败!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisZeroSetStopButtonIsEnabled = true;
|
||
SeisZeroSetStartButtonIsEnabled = true;
|
||
}
|
||
}
|
||
break;
|
||
case "SeisLevelSetStart": //调平
|
||
if(msg[1].Equals("True")) //开启
|
||
{
|
||
SeisLevelSetStartButtonIsEnabled = false;
|
||
SeisLevelSetStopButtonIsEnabled = false;
|
||
SeisLevelSetStartIsReceived = false;
|
||
|
||
sendDataSeis.Clear();
|
||
sendDataSeis.AddRange(new byte[] { 0xBF, 0x13, 0x97, 0x74 }); //SYNC
|
||
sendDataSeis.AddRange(new byte[] { 0xA0, 0x90 }); //CMD
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x00 }); //DATA
|
||
checkByte.Clear();
|
||
checkByte.AddRange(new byte[] { 0xA0, 0x90 }); //CMD
|
||
checkByte.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
checkByte.AddRange(new byte[] { 0x00, 0x00 }); //DATA
|
||
checkCode = Tools.CRCCalc(checkByte.ToArray()); //CHK_SUM
|
||
sendDataSeis.AddRange(checkCode);
|
||
|
||
bool result = false;
|
||
if (station_id == 1)
|
||
{
|
||
if (clientModelDZY1.IsConnected)
|
||
{
|
||
result = clientModelDZY1.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "通信未连接!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisLevelSetStartButtonIsEnabled = true;
|
||
SeisLevelSetStopButtonIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (clientModelDZY2.IsConnected)
|
||
{
|
||
result = clientModelDZY2.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "通信未连接!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisLevelSetStartButtonIsEnabled = true;
|
||
SeisLevelSetStopButtonIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (result)
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "请求调平开启发送成功!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Green);
|
||
timerSeisLevelSetStart.Start();
|
||
}
|
||
else
|
||
{
|
||
OpenSetMsgVisibility = Visibility.Visible;
|
||
OpenSetMsg = "请求调平开启发送失败!";
|
||
timerOpenSetMsgHidden.Start();
|
||
OpenSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisLevelSetStartButtonIsEnabled = true;
|
||
SeisLevelSetStopButtonIsEnabled = true;
|
||
}
|
||
}
|
||
break;
|
||
case "SeisLevelSetStop": //调平
|
||
if(!msg[1].Equals("True")) //关闭
|
||
{
|
||
SeisLevelSetStopButtonIsEnabled = false;
|
||
SeisLevelSetStartButtonIsEnabled = false;
|
||
SeisLevelSetStopIsReceived = false;
|
||
|
||
sendDataSeis.Clear();
|
||
sendDataSeis.AddRange(new byte[] { 0xBF, 0x13, 0x97, 0x74 }); //SYNC
|
||
sendDataSeis.AddRange(new byte[] { 0xA0, 0x91 }); //CMD
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x00 }); //DATA
|
||
checkByte.Clear();
|
||
checkByte.AddRange(new byte[] { 0xA0, 0x91 }); //CMD
|
||
checkByte.AddRange(new byte[] { 0x00, 0x04 }); //LENGTH
|
||
checkByte.AddRange(new byte[] { 0x00, 0x00 }); //DATA
|
||
checkCode = Tools.CRCCalc(checkByte.ToArray()); //CHK_SUM
|
||
sendDataSeis.AddRange(checkCode);
|
||
|
||
bool result = false;
|
||
if (station_id == 1)
|
||
{
|
||
if (clientModelDZY1.IsConnected)
|
||
{
|
||
result = clientModelDZY1.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "通信未连接!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisLevelSetStopButtonIsEnabled = true;
|
||
SeisLevelSetStartButtonIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (clientModelDZY2.IsConnected)
|
||
{
|
||
result = clientModelDZY2.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "通信未连接!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisLevelSetStopButtonIsEnabled = true;
|
||
SeisLevelSetStartButtonIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (result)
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "请求调平停止发送成功!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Green);
|
||
timerSeisLevelSetStop.Start();
|
||
}
|
||
else
|
||
{
|
||
CloseSetMsgVisibility = Visibility.Visible;
|
||
CloseSetMsg = "请求调平停止发送失败!";
|
||
timerCloseSetMsgHidden.Start();
|
||
CloseSetMsgForeground = new SolidColorBrush(Colors.Red);
|
||
SeisLevelSetStopButtonIsEnabled = true;
|
||
SeisLevelSetStartButtonIsEnabled = true;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region Seis Para
|
||
private void TimerSeisParaMsgHidden_Tick(object sender, EventArgs e)
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Hidden;
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private void TimerEarthQuakeParaSet_Tick(object sender, EventArgs e)
|
||
{
|
||
if (!EarthQuakeParaSetIsReceived)
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "参数设置发送成功,但未接收到数据!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Red);
|
||
EarthQuakeParaSetBtnIsEnabled = true;
|
||
EarthQuakeParaReadBtnIsEnabled = true;
|
||
}
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private void TimerEarthQuakeParaRead_Tick(object sender, EventArgs e)
|
||
{
|
||
if (!EarthQuakeParaReadIsReceived)
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "参数读取发送成功,但未接收到数据!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Red);
|
||
EarthQuakeParaReadBtnIsEnabled = true;
|
||
EarthQuakeParaSetBtnIsEnabled = true;
|
||
}
|
||
|
||
// 停止定时器
|
||
(sender as DispatcherTimer).Stop();
|
||
}
|
||
|
||
private string seisParaMsg;
|
||
|
||
public string SeisParaMsg
|
||
{
|
||
get { return seisParaMsg; }
|
||
set { seisParaMsg = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Brush seisParaMsgForeground;
|
||
|
||
public Brush SeisParaMsgForeground
|
||
{
|
||
get { return seisParaMsgForeground; }
|
||
set { seisParaMsgForeground = value; this.DoNotify(); }
|
||
}
|
||
|
||
private Visibility seisParaMsgVisibility = Visibility.Visible;
|
||
|
||
public Visibility SeisParaMsgVisibility
|
||
{
|
||
get { return seisParaMsgVisibility; }
|
||
set { seisParaMsgVisibility = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool earthQuakeParaSetBtnIsEnabled = true;
|
||
|
||
public bool EarthQuakeParaSetBtnIsEnabled
|
||
{
|
||
get { return earthQuakeParaSetBtnIsEnabled; }
|
||
set { earthQuakeParaSetBtnIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool earthQuakeParaReadBtnIsEnabled = true;
|
||
|
||
public bool EarthQuakeParaReadBtnIsEnabled
|
||
{
|
||
get { return earthQuakeParaReadBtnIsEnabled; }
|
||
set { earthQuakeParaReadBtnIsEnabled = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool earthQuakeParaSetIsReceived = false;
|
||
|
||
public bool EarthQuakeParaSetIsReceived
|
||
{
|
||
get { return earthQuakeParaSetIsReceived; }
|
||
set { earthQuakeParaSetIsReceived = value; this.DoNotify(); }
|
||
}
|
||
|
||
private bool earthQuakeParaReadIsReceived = false;
|
||
|
||
public bool EarthQuakeParaReadIsReceived
|
||
{
|
||
get { return earthQuakeParaReadIsReceived; }
|
||
set { earthQuakeParaReadIsReceived = value; this.DoNotify(); }
|
||
}
|
||
|
||
public async void Btn_ParaSet(object o)
|
||
{
|
||
string[] msg = o.ToString().Split(',');
|
||
for (int i = 0; i < msg.Length; i++)
|
||
{
|
||
if (string.IsNullOrEmpty(msg[i]))
|
||
{
|
||
EM.ControlMessage = "失败! 请输入完整信息!";
|
||
return;
|
||
}
|
||
}
|
||
switch (msg[0])
|
||
{
|
||
//case "ParaSet":
|
||
// break;
|
||
//case "ReadParaSet":
|
||
// break;
|
||
case "EarthQuakeParaSetBtn":
|
||
EarthQuakeParaSetBtnIsEnabled = false;
|
||
EarthQuakeParaReadBtnIsEnabled = false;
|
||
earthQuakeParaSetIsReceived = false;
|
||
|
||
byte[] sationNo = Tools.IntToBytes(int.Parse(msg[1])); //台号
|
||
byte[] stationName = Encoding.UTF8.GetBytes(msg[2]); //台站名称
|
||
stationName = Tools.PadArrayWithZeros(stationName, 32);
|
||
byte[] stationShortName = Encoding.UTF8.GetBytes(msg[3]); //台站缩写
|
||
stationShortName = Tools.PadArrayWithZeros(stationShortName, 8);
|
||
byte[] earthQuakeCount = BitConverter.GetBytes(short.Parse(msg[4])); //地震计总数
|
||
earthQuakeCount = Tools.PadArrayWithZeros(earthQuakeCount, 2);
|
||
byte[] channelsNo = BitConverter.GetBytes(short.Parse(msg[5])); //总通道数
|
||
channelsNo = Tools.PadArrayWithZeros(channelsNo, 2);
|
||
byte[] wd = Tools.IntToBytes(int.Parse(msg[6])); //纬度
|
||
byte[] jd = Tools.IntToBytes(int.Parse(msg[7])); //经度
|
||
byte[] gaoCheng = Tools.IntToBytes(int.Parse(msg[8])); //高程
|
||
byte[] startTime = BitConverter.GetBytes(short.Parse(msg[9])); //起用日期
|
||
startTime = Tools.PadArrayWithZeros(startTime, 32);
|
||
byte[] stationid = BitConverter.GetBytes(short.Parse(msg[10])); //台网标志
|
||
stationid = Tools.PadArrayWithZeros(stationid, 4);
|
||
byte[] software_version = BitConverter.GetBytes(short.Parse(msg[11])); //软件版本
|
||
software_version = Tools.PadArrayWithZeros(software_version, 32);
|
||
|
||
sendDataSeis.Clear();
|
||
sendDataSeis.AddRange(new byte[] { 0xBF, 0x13, 0x97, 0x74 }); //SYNC
|
||
sendDataSeis.AddRange(new byte[] { 0xA0, 0x00 }); //CMD
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x82 }); //LENGTH
|
||
sendDataSeis.AddRange(sationNo);
|
||
sendDataSeis.AddRange(stationName);
|
||
sendDataSeis.AddRange(stationShortName);
|
||
sendDataSeis.AddRange(earthQuakeCount);
|
||
sendDataSeis.AddRange(channelsNo);
|
||
sendDataSeis.AddRange(wd);
|
||
sendDataSeis.AddRange(jd);
|
||
sendDataSeis.AddRange(gaoCheng);
|
||
sendDataSeis.AddRange(startTime);
|
||
sendDataSeis.AddRange(stationid);
|
||
sendDataSeis.AddRange(software_version);
|
||
checkByte.Clear();
|
||
checkByte.AddRange(new byte[] { 0xA0, 0x00 }); //CMD
|
||
checkByte.AddRange(new byte[] { 0x00, 0x82 }); //LENGTH
|
||
checkByte.AddRange(sationNo);
|
||
checkByte.AddRange(stationName);
|
||
checkByte.AddRange(stationShortName);
|
||
checkByte.AddRange(earthQuakeCount);
|
||
checkByte.AddRange(channelsNo);
|
||
checkByte.AddRange(wd);
|
||
checkByte.AddRange(jd);
|
||
checkByte.AddRange(gaoCheng);
|
||
checkByte.AddRange(startTime);
|
||
checkByte.AddRange(stationid);
|
||
checkByte.AddRange(software_version);
|
||
checkCode = Tools.CRCCalc(checkByte.ToArray()); //CHK_SUM
|
||
|
||
sendDataSeis.AddRange(checkCode);
|
||
|
||
bool result = false;
|
||
if (station_id == 1)
|
||
{
|
||
if (clientModelDZY1.IsConnected)
|
||
{
|
||
result = clientModelDZY1.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "通信未连接!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Red);
|
||
EarthQuakeParaSetBtnIsEnabled = true;
|
||
EarthQuakeParaReadBtnIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (clientModelDZY2.IsConnected)
|
||
{
|
||
result = clientModelDZY2.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "通信未连接!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Red);
|
||
EarthQuakeParaSetBtnIsEnabled = true;
|
||
EarthQuakeParaReadBtnIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (result)
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "设置参数发送成功!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Green);
|
||
timerEarthQuakeParaSet.Start();
|
||
}
|
||
else
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "设置参数发送失败!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Red);
|
||
EarthQuakeParaSetBtnIsEnabled = true;
|
||
EarthQuakeParaReadBtnIsEnabled = true;
|
||
}
|
||
break;
|
||
case "EarthQuakeParaReadBtn":
|
||
EarthQuakeParaSetBtnIsEnabled = false;
|
||
EarthQuakeParaReadBtnIsEnabled = false;
|
||
earthQuakeParaReadIsReceived = false;
|
||
|
||
sendDataSeis.Clear();
|
||
sendDataSeis.AddRange(new byte[] { 0xBF, 0x13, 0x97, 0x74 }); //SYNC
|
||
sendDataSeis.AddRange(new byte[] { 0xB0, 0x00 }); //CMD
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x02 }); //LENGTH
|
||
sendDataSeis.AddRange(new byte[] { 0x00, 0x00 }); //地震计号
|
||
checkByte.Clear();
|
||
checkByte.AddRange(new byte[] { 0xB0, 0x00 }); //CMD
|
||
checkByte.AddRange(new byte[] { 0x00, 0x02 }); //LENGTH
|
||
checkByte.AddRange(new byte[] { 0x00, 0x00 }); //地震计号
|
||
checkCode = Tools.CRCCalc(checkByte.ToArray()); //CHK_SUM
|
||
|
||
sendDataSeis.AddRange(checkCode);
|
||
|
||
result = false;
|
||
if (station_id == 1)
|
||
{
|
||
if (clientModelDZY1.IsConnected)
|
||
{
|
||
result = clientModelDZY1.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "通信未连接!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Red);
|
||
EarthQuakeParaSetBtnIsEnabled = true;
|
||
EarthQuakeParaReadBtnIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (clientModelDZY2.IsConnected)
|
||
{
|
||
result = clientModelDZY2.SendMessage(sendDataSeis.ToArray());
|
||
}
|
||
else
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "通信未连接!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Red);
|
||
EarthQuakeParaSetBtnIsEnabled = true;
|
||
EarthQuakeParaReadBtnIsEnabled = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (result)
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "设置参数发送成功!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Green);
|
||
timerEarthQuakeParaSet.Start();
|
||
}
|
||
else
|
||
{
|
||
SeisParaMsgVisibility = Visibility.Visible;
|
||
SeisParaMsg = "设置参数发送失败!";
|
||
timerSeisParaMsgHidden.Start();
|
||
SeisParaMsgForeground = new SolidColorBrush(Colors.Red);
|
||
EarthQuakeParaSetBtnIsEnabled = true;
|
||
EarthQuakeParaReadBtnIsEnabled = true;
|
||
}
|
||
break;
|
||
default:
|
||
return;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region Page Switching
|
||
public void DoNavChanged(object obj)
|
||
{
|
||
if (obj.ToString() == "1" || obj.ToString() == "2") //说明是站点切换按钮
|
||
{
|
||
if (station_id == Convert.ToInt32(obj)) //如果切换的界面和之前一样 那就不切换
|
||
return;
|
||
station_id = Convert.ToInt32(obj);
|
||
}
|
||
else if (obj.ToString() == "")
|
||
{
|
||
|
||
}
|
||
else
|
||
{
|
||
if (Title_Name == obj.ToString())
|
||
return;
|
||
Title_Name = obj.ToString();
|
||
}
|
||
|
||
//切换页面之前清理一下内存
|
||
Tools.ClearMemory(this);
|
||
|
||
Type type = Type.GetType("JiangsuEarthquake.Views." + Title_Name);
|
||
ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
|
||
FrameworkElement page = (FrameworkElement)cti.Invoke(null);
|
||
if (station_id == 1)
|
||
{
|
||
switch (Title_Name)
|
||
{
|
||
case "RealTimeDataView":
|
||
page.DataContext = realTimeDataViewModel1;
|
||
break;
|
||
case "SystemStateDataView":
|
||
page.DataContext = systemStateDataViewModel1;
|
||
break;
|
||
case "BoosterStationStateDataView":
|
||
page.DataContext = boosterStationStateDataViewModel1;
|
||
break;
|
||
case "SystemControlView":
|
||
SS = switchStateModel1;
|
||
EQPS = earthQuakeParaSetModel1;
|
||
EQSM = earthquakeSensorModel1;
|
||
break;
|
||
case "LogRecordView":
|
||
page.DataContext = logRecordViewModel1;
|
||
break;
|
||
case "AlarmRecordView":
|
||
page.DataContext = alarmRecordViewModel1;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
else if (station_id == 2)
|
||
{
|
||
switch (Title_Name)
|
||
{
|
||
case "RealTimeDataView":
|
||
page.DataContext = realTimeDataViewModel2;
|
||
break;
|
||
case "SystemStateDataView":
|
||
page.DataContext = systemStateDataViewModel2;
|
||
break;
|
||
case "BoosterStationStateDataView":
|
||
page.DataContext = boosterStationStateDataViewModel2;
|
||
break;
|
||
case "SystemControlView":
|
||
SS = switchStateModel2;
|
||
EQPS = earthQuakeParaSetModel2;
|
||
EQSM = earthquakeSensorModel2;
|
||
break;
|
||
case "LogRecordView":
|
||
page.DataContext = logRecordViewModel2;
|
||
break;
|
||
case "AlarmRecordView":
|
||
page.DataContext = alarmRecordViewModel2;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
this.PageContent = page;
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|