From caf075a26783ecf12bd81cd858217461ceaf1e66 Mon Sep 17 00:00:00 2001 From: MoYue Date: Wed, 19 Jun 2024 14:01:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=B6=E5=BA=8F=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=EF=BC=8C=E5=90=AF=E5=8A=A8=EF=BC=8C=E6=9A=82=E5=81=9C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/Pages/RelayViewModel.cs | 2 +- .../Pages/SequentialDistributionViewModel.cs | 355 +++++++++++++++++- .../ViewModels/Pages/ViewModelBase.cs | 23 +- .../Pages/SequentialDistributionView.xaml | 5 + 4 files changed, 379 insertions(+), 6 deletions(-) diff --git a/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs b/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs index a0a4bfc..76c97c4 100644 --- a/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs @@ -33,7 +33,7 @@ namespace InSituLaboratory.ViewModels.Pages public class RelayViewModel : ViewModelBase { #region Entity - public ClientModel clientModel { get; set; } = new ClientModel();//Socket 通信类 + public static ClientModel clientModel { get; set; } = new ClientModel();//Socket 通信类 public SysSensorModel sysSensorModel { get; set; } = new SysSensorModel(); // 传感器表 public SysSensorModels sysSensorModels { get; set; } = new SysSensorModels(); //传感器表 public LogModel logModel { get; set; } //日志记录表 diff --git a/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs b/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs index dd28b9a..4710bf8 100644 --- a/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs @@ -1,4 +1,5 @@ -using InSituLaboratory.Entities; +using InSituLaboratory.Common; +using InSituLaboratory.Entities; using InSituLaboratory.Entities.SqlSugar; using InSituLaboratory.IService; using InSituLaboratory.IService.Sensor; @@ -288,6 +289,10 @@ namespace InSituLaboratory.ViewModels.Pages int num = 0; for (int i = 0; i < datalist.Length; i++) { + if (datalist[1].SequenceGroup == datalist[i + 1].SequenceGroup) + { + + } @@ -307,6 +312,73 @@ namespace InSituLaboratory.ViewModels.Pages } + + /// + /// 时序清空 + /// + public override void ClearS1() + { + if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) + { + System.Windows.Forms.MessageBox.Show("时序1: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x01, 0x02); + System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序启动 + /// + public override void BeginS1() + { + if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) + { + System.Windows.Forms.MessageBox.Show("时序1: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x01, 0x03); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序暂停 + /// + public override void SuspendS1() + { + if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) + { + System.Windows.Forms.MessageBox.Show("时序1: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x01, 0x04); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } #endregion #region 时序 2 @@ -427,6 +499,72 @@ namespace InSituLaboratory.ViewModels.Pages } } + + /// + /// 时序清空 + /// + public override void ClearS2() + { + if (sequentStatusModel.SequentialStartTime2 == null || sequentStatusModel.SequentialEndTime2 == null) + { + System.Windows.Forms.MessageBox.Show("时序2: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x02, 0x02); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序启动 + /// + public override void BeginS2() + { + if (sequentStatusModel.SequentialStartTime2 == null || sequentStatusModel.SequentialEndTime2 == null) + { + System.Windows.Forms.MessageBox.Show("时序2: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x02, 0x03); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序暂停 + /// + public override void SuspendS2() + { + if (sequentStatusModel.SequentialStartTime2 == null || sequentStatusModel.SequentialEndTime2 == null) + { + System.Windows.Forms.MessageBox.Show("时序2: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x02, 0x04); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } #endregion #region 时序 3 @@ -547,6 +685,72 @@ namespace InSituLaboratory.ViewModels.Pages } } + + /// + /// 时序清空 + /// + public override void ClearS3() + { + if (sequentStatusModel.SequentialStartTime3 == null || sequentStatusModel.SequentialEndTime3 == null) + { + System.Windows.Forms.MessageBox.Show("时序3: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x03, 0x02); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序启动 + /// + public override void BeginS3() + { + if (sequentStatusModel.SequentialStartTime3 == null || sequentStatusModel.SequentialEndTime3 == null) + { + System.Windows.Forms.MessageBox.Show("时序3: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x03, 0x03); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序暂停 + /// + public override void SuspendS3() + { + if (sequentStatusModel.SequentialStartTime3 == null || sequentStatusModel.SequentialEndTime3 == null) + { + System.Windows.Forms.MessageBox.Show("时序3: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x03, 0x04); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } #endregion #region 时序 4 @@ -667,6 +871,72 @@ namespace InSituLaboratory.ViewModels.Pages } } + + /// + /// 时序清空 + /// + public override void ClearS4() + { + if (sequentStatusModel.SequentialStartTime4 == null || sequentStatusModel.SequentialEndTime4 == null) + { + System.Windows.Forms.MessageBox.Show("时序4: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x04, 0x02); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序启动 + /// + public override void BeginS4() + { + if (sequentStatusModel.SequentialStartTime4 == null || sequentStatusModel.SequentialEndTime4 == null) + { + System.Windows.Forms.MessageBox.Show("时序4: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x04, 0x03); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序暂停 + /// + public override void SuspendS4() + { + if (sequentStatusModel.SequentialStartTime4 == null || sequentStatusModel.SequentialEndTime4 == null) + { + System.Windows.Forms.MessageBox.Show("时序4: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x04, 0x04); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } #endregion #region 时序 5 @@ -787,6 +1057,72 @@ namespace InSituLaboratory.ViewModels.Pages } } + + /// + /// 时序清空 + /// + public override void ClearS5() + { + if (sequentStatusModel.SequentialStartTime5 == null || sequentStatusModel.SequentialEndTime5 == null) + { + System.Windows.Forms.MessageBox.Show("时序5: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x05, 0x02); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序启动 + /// + public override void BeginS5() + { + if (sequentStatusModel.SequentialStartTime5 == null || sequentStatusModel.SequentialEndTime5 == null) + { + System.Windows.Forms.MessageBox.Show("时序5: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x05, 0x03); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } + + /// + /// 时序暂停 + /// + public override void SuspendS5() + { + if (sequentStatusModel.SequentialStartTime5 == null || sequentStatusModel.SequentialEndTime5 == null) + { + System.Windows.Forms.MessageBox.Show("时序5: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") + { + dosend(0x05, 0x04); + } + else + { + System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + } #endregion @@ -852,5 +1188,22 @@ namespace InSituLaboratory.ViewModels.Pages return buffer; } + + + /// + /// 命令发送 + /// + /// 时序号 + /// 操作类型 + public void dosend(byte x1,byte x2) + { + //消息体 + byte[] byteaq = new byte[] { 0x91, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, x1, x2 }; + + List buffer = Escape(byteaq); + string list = tools.byteToHexStr(buffer.ToArray()); + byte[] bytea = tools.ConvertHexStringToBytes(list); + RelayViewModel.clientModel.SendData(bytea); + } } } diff --git a/InSituLaboratory/ViewModels/Pages/ViewModelBase.cs b/InSituLaboratory/ViewModels/Pages/ViewModelBase.cs index fd0f39c..d79074b 100644 --- a/InSituLaboratory/ViewModels/Pages/ViewModelBase.cs +++ b/InSituLaboratory/ViewModels/Pages/ViewModelBase.cs @@ -64,8 +64,8 @@ namespace InSituLaboratory.ViewModels.Pages public DelegateCommand StartCommand { get; set; }//一键启动 public DelegateCommand SynchronizationCommand { get; set; }//时间同步 - - #region 时序1-5 刷新 新增/编辑 删除 下发 启动 暂停 + + #region 时序1-5 刷新 新增/编辑 删除 下发 启动 暂停 清空 public DelegateCommand RefreshS1Command { get; set; } public DelegateCommand SendS1Command { get; set; } @@ -73,6 +73,7 @@ namespace InSituLaboratory.ViewModels.Pages public DelegateCommand DeleteS1Command { get; set; } public DelegateCommand BeginS1Command { get; set; } public DelegateCommand SuspendS1Command { get; set; } + public DelegateCommand ClearS1Command { get; set; } public DelegateCommand RefreshS2Command { get; set; } @@ -81,6 +82,7 @@ namespace InSituLaboratory.ViewModels.Pages public DelegateCommand DeleteS2Command { get; set; } public DelegateCommand BeginS2Command { get; set; } public DelegateCommand SuspendS2Command { get; set; } + public DelegateCommand ClearS2Command { get; set; } public DelegateCommand RefreshS3Command { get; set; } public DelegateCommand SendS3Command { get; set; } @@ -88,6 +90,7 @@ namespace InSituLaboratory.ViewModels.Pages public DelegateCommand DeleteS3Command { get; set; } public DelegateCommand BeginS3Command { get; set; } public DelegateCommand SuspendS3Command { get; set; } + public DelegateCommand ClearS3Command { get; set; } public DelegateCommand RefreshS4Command { get; set; } public DelegateCommand SendS4Command { get; set; } @@ -95,6 +98,7 @@ namespace InSituLaboratory.ViewModels.Pages public DelegateCommand DeleteS4Command { get; set; } public DelegateCommand BeginS4Command { get; set; } public DelegateCommand SuspendS4Command { get; set; } + public DelegateCommand ClearS4Command { get; set; } public DelegateCommand RefreshS5Command { get; set; } public DelegateCommand SendS5Command { get; set; } @@ -102,6 +106,7 @@ namespace InSituLaboratory.ViewModels.Pages public DelegateCommand DeleteS5Command { get; set; } public DelegateCommand BeginS5Command { get; set; } public DelegateCommand SuspendS5Command { get; set; } + public DelegateCommand ClearS5Command { get; set; } #endregion @@ -120,7 +125,7 @@ namespace InSituLaboratory.ViewModels.Pages StartCommand = new DelegateCommand(DoStart); SynchronizationCommand = new DelegateCommand(DoSynchronization); - #region 时序1-5 刷新 新增/编辑 删除 下发 启动 暂停 + #region 时序1-5 刷新 新增/编辑 删除 下发 启动 暂停 清空 RefreshS1Command = new DelegateCommand(RefreshS1); SendS1Command = new DelegateCommand(SendS1); @@ -128,6 +133,7 @@ namespace InSituLaboratory.ViewModels.Pages DeleteS1Command = new DelegateCommand(DoDeleteS1); BeginS1Command = new DelegateCommand(BeginS1); SuspendS1Command = new DelegateCommand(SuspendS1); + ClearS1Command = new DelegateCommand(ClearS1); RefreshS2Command = new DelegateCommand(RefreshS2); SendS2Command = new DelegateCommand(SendS2); @@ -135,6 +141,7 @@ namespace InSituLaboratory.ViewModels.Pages DeleteS2Command = new DelegateCommand(DoDeleteS2); BeginS2Command = new DelegateCommand(BeginS2); SuspendS2Command = new DelegateCommand(SuspendS2); + ClearS2Command = new DelegateCommand(ClearS2); RefreshS3Command = new DelegateCommand(RefreshS3); SendS3Command = new DelegateCommand(SendS3); @@ -142,6 +149,7 @@ namespace InSituLaboratory.ViewModels.Pages DeleteS3Command = new DelegateCommand(DoDeleteS3); BeginS3Command = new DelegateCommand(BeginS3); SuspendS3Command = new DelegateCommand(SuspendS3); + ClearS3Command = new DelegateCommand(ClearS3); RefreshS4Command = new DelegateCommand(RefreshS4); SendS4Command = new DelegateCommand(SendS4); @@ -149,6 +157,7 @@ namespace InSituLaboratory.ViewModels.Pages DeleteS4Command = new DelegateCommand(DoDeleteS4); BeginS4Command = new DelegateCommand(BeginS4); SuspendS4Command = new DelegateCommand(SuspendS4); + ClearS4Command = new DelegateCommand(ClearS4); RefreshS5Command = new DelegateCommand(RefreshS5); SendS5Command = new DelegateCommand(SendS5); @@ -156,6 +165,7 @@ namespace InSituLaboratory.ViewModels.Pages DeleteS5Command = new DelegateCommand(DoDeleteS5); BeginS5Command = new DelegateCommand(BeginS5); SuspendS5Command = new DelegateCommand(SuspendS5); + ClearS5Command = new DelegateCommand(ClearS5); #endregion } @@ -181,7 +191,7 @@ namespace InSituLaboratory.ViewModels.Pages private string PageName { get; set; } - #region 时序1-5 刷新 新增/编辑 删除 下发 启动 暂停 + #region 时序1-5 刷新 新增/编辑 删除 下发 启动 暂停 清空 public virtual void RefreshS1() { } public virtual void SendS1() { } @@ -189,6 +199,7 @@ namespace InSituLaboratory.ViewModels.Pages public virtual void DoDeleteS1(object model) { } public virtual void BeginS1() { } public virtual void SuspendS1() { } + public virtual void ClearS1() { } public virtual void RefreshS2() { } @@ -197,6 +208,7 @@ namespace InSituLaboratory.ViewModels.Pages public virtual void DoDeleteS2(object model) { } public virtual void BeginS2() { } public virtual void SuspendS2() { } + public virtual void ClearS2() { } public virtual void RefreshS3() { } @@ -205,6 +217,7 @@ namespace InSituLaboratory.ViewModels.Pages public virtual void DoDeleteS3(object model) { } public virtual void BeginS3() { } public virtual void SuspendS3() { } + public virtual void ClearS3() { } public virtual void RefreshS4() { } @@ -213,6 +226,7 @@ namespace InSituLaboratory.ViewModels.Pages public virtual void DoDeleteS4(object model) { } public virtual void BeginS4() { } public virtual void SuspendS4() { } + public virtual void ClearS4() { } public virtual void RefreshS5() { } @@ -221,6 +235,7 @@ namespace InSituLaboratory.ViewModels.Pages public virtual void DoDeleteS5(object model) { } public virtual void BeginS5() { } public virtual void SuspendS5() { } + public virtual void ClearS5() { } #endregion diff --git a/InSituLaboratory/Views/Pages/SequentialDistributionView.xaml b/InSituLaboratory/Views/Pages/SequentialDistributionView.xaml index c7e57f0..238eaad 100644 --- a/InSituLaboratory/Views/Pages/SequentialDistributionView.xaml +++ b/InSituLaboratory/Views/Pages/SequentialDistributionView.xaml @@ -164,6 +164,7 @@