diff --git a/InSituLaboratory/Common/DataParsing.cs b/InSituLaboratory/Common/DataParsing.cs index ee78e8d..1a57283 100644 --- a/InSituLaboratory/Common/DataParsing.cs +++ b/InSituLaboratory/Common/DataParsing.cs @@ -178,6 +178,9 @@ namespace InSituLaboratory.Common currentSequentiual.Sequentiual1Status = "不存在时序"; break; case 0x05: + currentSequentiual.Sequentiual1Status = "时序状态变更交替中"; + break; + case 0x06: currentSequentiual.Sequentiual1Status = "异常"; break; default: diff --git a/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs b/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs index 76c97c4..9f625f6 100644 --- a/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/RelayViewModel.cs @@ -937,24 +937,40 @@ namespace InSituLaboratory.ViewModels.Pages opendata += data[i]; opendata = opendata + "、"; } - if (System.Windows.Forms.MessageBox.Show("当前处于打开状态的设备有" + opendata + "确认需要一键还原吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) + DialogResult s1= System.Windows.Forms.MessageBox.Show("当前处于打开状态的设备有" + opendata + "确认需要一键还原且进行强制关闭吗?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + if (s1 == DialogResult.Yes) { - if (System.Windows.Forms.MessageBox.Show("再次确定需要一键还原吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) - { - //消息体 - byte[] byteaq = new byte[] { 0x93, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00 }; + //消息体 + //强制关闭 + byte[] byteaq = new byte[] { 0x93, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01 }; - List buffer = Escape(byteaq); - string list = tools.byteToHexStr(buffer.ToArray()); - byte[] bytea = tools.ConvertHexStringToBytes(list); - clientModel.SendData(bytea); + List buffer = Escape(byteaq); + string list = tools.byteToHexStr(buffer.ToArray()); + byte[] bytea = tools.ConvertHexStringToBytes(list); + clientModel.SendData(bytea); - logModel = new LogModel(); - logModel.CreateTime = DateTime.Now; - logModel.Remark = "一键还原指令已下发"; - _logService.Insert(logModel); - this.Refresh(); - } + logModel = new LogModel(); + logModel.CreateTime = DateTime.Now; + logModel.Remark = "一键还原指令已下发"; + _logService.Insert(logModel); + this.Refresh(); + + } + else if (s1 == DialogResult.No) + { + //非强制关闭 + byte[] byteaq = new byte[] { 0x93, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + List buffer = Escape(byteaq); + string list = tools.byteToHexStr(buffer.ToArray()); + byte[] bytea = tools.ConvertHexStringToBytes(list); + clientModel.SendData(bytea); + + logModel = new LogModel(); + logModel.CreateTime = DateTime.Now; + logModel.Remark = "一键还原指令已下发"; + _logService.Insert(logModel); + this.Refresh(); } } else @@ -964,6 +980,7 @@ namespace InSituLaboratory.ViewModels.Pages logModel.CreateTime = DateTime.Now; logModel.Remark = "服务端未连接"; } + } /// diff --git a/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs b/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs index 2b10b90..920a26e 100644 --- a/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs +++ b/InSituLaboratory/ViewModels/Pages/SequentialDistributionViewModel.cs @@ -16,6 +16,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Forms; +using System.Windows.Markup; namespace InSituLaboratory.ViewModels.Pages { @@ -115,46 +116,97 @@ namespace InSituLaboratory.ViewModels.Pages /// public override void DoModifyS1(object model) { + var status = ""; + var datalist1 = _sysSequentialService.Query(m => m.StartTime == sequentStatusModel.SequentialStartTime1 && m.EndTime == sequentStatusModel.SequentialEndTime1 && m.IsDelete == 0 && m.Sequential == "时序1").ToList(); if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) { System.Windows.Forms.MessageBox.Show("时序1: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { - DateTime expirationDate = (DateTime)sequentStatusModel.SequentialStartTime1; - DateTime expirationDate1 = (DateTime)sequentStatusModel.SequentialEndTime1; - DateTime dateTime = DateTime.Now; + if (datalist1.Count() != 0) + { + foreach (var item in datalist1) + { + status = item.Status; + } + if (status == "已生成未下发") + { + DateTime expirationDate = (DateTime)sequentStatusModel.SequentialStartTime1; + DateTime expirationDate1 = (DateTime)sequentStatusModel.SequentialEndTime1; + DateTime dateTime = DateTime.Now; - if (expirationDate < dateTime) - { - System.Windows.Forms.MessageBox.Show("时序1: 开始时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - else if (expirationDate1 < dateTime) - { - System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } - else if (expirationDate >= expirationDate1) - { - System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于开始时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + if (expirationDate < dateTime) + { + System.Windows.Forms.MessageBox.Show("时序1: 开始时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else if (expirationDate1 < dateTime) + { + System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else if (expirationDate >= expirationDate1) + { + System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于开始时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + DialogParameters ps = new DialogParameters(); + ps.Add("model", model); + ps.Add("sequentialStartTime", sequentStatusModel.SequentialStartTime1); + ps.Add("sequentialEndTime", sequentStatusModel.SequentialEndTime1); + ps.Add("kind", "时序1"); + _dialogService.ShowDialog("ModifySequentialView", ps, result => + { + // 判断子窗口的返回状态,如果OK,刷新当前页面,否则不管 + if (result.Result == ButtonResult.OK) + { + this.RefreshS1(); + } + }); + } + } + else + { + System.Windows.Forms.MessageBox.Show(" 当前时序已下发!!! \n 若要设置新的时序,您可以修改时序的开始时间和结束时间即可!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } } else { - DialogParameters ps = new DialogParameters(); - ps.Add("model", model); - ps.Add("sequentialStartTime", sequentStatusModel.SequentialStartTime1); - ps.Add("sequentialEndTime", sequentStatusModel.SequentialEndTime1); - ps.Add("kind", "时序1"); - _dialogService.ShowDialog("ModifySequentialView", ps, result => + DateTime expirationDate = (DateTime)sequentStatusModel.SequentialStartTime1; + DateTime expirationDate1 = (DateTime)sequentStatusModel.SequentialEndTime1; + DateTime dateTime = DateTime.Now; + + if (expirationDate < dateTime) { - // 判断子窗口的返回状态,如果OK,刷新当前页面,否则不管 - if (result.Result == ButtonResult.OK) + System.Windows.Forms.MessageBox.Show("时序1: 开始时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else if (expirationDate1 < dateTime) + { + System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于当前时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else if (expirationDate >= expirationDate1) + { + System.Windows.Forms.MessageBox.Show("时序1: 结束时间不得早于开始时间!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + else + { + DialogParameters ps = new DialogParameters(); + ps.Add("model", model); + ps.Add("sequentialStartTime", sequentStatusModel.SequentialStartTime1); + ps.Add("sequentialEndTime", sequentStatusModel.SequentialEndTime1); + ps.Add("kind", "时序1"); + _dialogService.ShowDialog("ModifySequentialView", ps, result => { - this.RefreshS1(); - } - }); + // 判断子窗口的返回状态,如果OK,刷新当前页面,否则不管 + if (result.Result == ButtonResult.OK) + { + this.RefreshS1(); + } + }); + } + } } - } /// @@ -165,30 +217,43 @@ namespace InSituLaboratory.ViewModels.Pages { try { - if (System.Windows.Forms.MessageBox.Show("是否确定删除此项?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) + var status = ""; + var datalist1 = _sysSequentialService.Query(m => m.StartTime == sequentStatusModel.SequentialStartTime1 && m.EndTime == sequentStatusModel.SequentialEndTime1 && m.IsDelete == 0 && m.Sequential == "时序1").ToList(); + foreach (var item in datalist1) { - // 软删除 - var data = _sysSequentialService.Find((model as SysSequentialDetails).Number); - data.IsDelete = 1; - _sysSequentialService.Update(data); - - //查询删除后子表是否还存在时序配置 - var list = _sysSequentialService.GetSequentialDetails(data.SysSquentialID).ToList(); - //若子表不存在当前时序下配置信息,则删除对应的母表时序 - if (list.Count() == 0) + status += item.Status; + } + if (status == "已生成未下发") + { + if (System.Windows.Forms.MessageBox.Show("是否确定删除此项?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) { - var SysSequential = _sysSequentialService.Find(data.SysSquentialID); - SysSequential.IsDelete = 1; - _sysSequentialService.Update(SysSequential); + // 软删除 + var data = _sysSequentialService.Find((model as SysSequentialDetails).Number); + data.IsDelete = 1; + _sysSequentialService.Update(data); + + //查询删除后子表是否还存在时序配置 + var list = _sysSequentialService.GetSequentialDetails(data.SysSquentialID).ToList(); + //若子表不存在当前时序下配置信息,则删除对应的母表时序 + if (list.Count() == 0) + { + var SysSequential = _sysSequentialService.Find(data.SysSquentialID); + SysSequential.IsDelete = 1; + _sysSequentialService.Update(SysSequential); + } + + ///更新时序总表 + var data1 = _sysSequentialService.Find((model as SysSequentialDetails).Number); + data1.IsDelete = 1; + _sysSequentialService.Update(data1); + + System.Windows.Forms.MessageBox.Show("删除完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + this.RefreshS1(); } - - ///更新时序总表 - var data1 = _sysSequentialService.Find((model as SysSequentialDetails).Number); - data1.IsDelete = 1; - _sysSequentialService.Update(data1); - - System.Windows.Forms.MessageBox.Show("删除完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - this.RefreshS1(); + } + else + { + System.Windows.Forms.MessageBox.Show(" 当前时序已下发!!! \n 无法删除!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) @@ -203,21 +268,70 @@ namespace InSituLaboratory.ViewModels.Pages /// public override void SendS1() { + var status = ""; + var datalist1 = _sysSequentialService.Query(m => m.StartTime == sequentStatusModel.SequentialStartTime1 && m.EndTime == sequentStatusModel.SequentialEndTime1 && m.IsDelete == 0 && m.Sequential == "时序1").ToList(); + if (sequentStatusModel.SequentialStartTime1 == null || sequentStatusModel.SequentialEndTime1 == null) { System.Windows.Forms.MessageBox.Show("时序1: 开始时间和结束时间不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } + else if (datalist1.Count() == 0) + { + System.Windows.Forms.MessageBox.Show("时序1中未有设备,无法下发!!!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } else { if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") { - List byteaq = encode((DateTime)sequentStatusModel.SequentialStartTime1, (DateTime)sequentStatusModel.SequentialEndTime1, 0x01, "时序1"); - List buffer = Escape(byteaq.ToArray()); - string list = tools.byteToHexStr(buffer.ToArray()); - byte[] bytea = tools.ConvertHexStringToBytes(list); - RelayViewModel.clientModel.SendData(bytea); - System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + DateTime startTime = (DateTime)sequentStatusModel.SequentialStartTime1; + DateTime endTime = (DateTime)sequentStatusModel.SequentialEndTime1; + foreach (var item in datalist1) + { + status = item.Status; + } + if (status == "已生成未下发") + { + System.Windows.Forms.DialogResult s1 = System.Windows.Forms.MessageBox.Show("是否修改并等待当前工作设备工作完最短周期后生效新时序? \n若选择否,则修改且关闭该时序所有设备!!!", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + //修改并等待当前工作设备工作完最短周期后生效新时序 + if (s1 == System.Windows.Forms.DialogResult.Yes) + { + //计算设备功耗是否超总功耗及设备运行时长是否超时 + + + + List byteaq = encode(startTime, endTime, 0x01, "时序1"); + List buffer = Escape(byteaq.ToArray()); + string list = tools.byteToHexStr(buffer.ToArray()); + byte[] bytea = tools.ConvertHexStringToBytes(list); + RelayViewModel.clientModel.SendData(bytea); + + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已下发"); + System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + //修改且关闭该时序所有设备 + else if (s1 == System.Windows.Forms.DialogResult.No) + { + //计算设备功耗是否超总功耗及设备运行时长是否超时 + + + List byteaq = encode((DateTime)sequentStatusModel.SequentialStartTime1, (DateTime)sequentStatusModel.SequentialEndTime1, 0x02, "时序1"); + List buffer = Escape(byteaq.ToArray()); + string list = tools.byteToHexStr(buffer.ToArray()); + byte[] bytea = tools.ConvertHexStringToBytes(list); + RelayViewModel.clientModel.SendData(bytea); + + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已下发"); + System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + else + { + System.Windows.Forms.MessageBox.Show("当前时序已下发!!!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + this.RefreshS1(); } else { @@ -239,8 +353,27 @@ namespace InSituLaboratory.ViewModels.Pages { if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") { - dosend(0x01, 0x02); + DateTime startTime = (DateTime)sequentStatusModel.SequentialStartTime1; + DateTime endTime = (DateTime)sequentStatusModel.SequentialEndTime1; + + System.Windows.Forms.DialogResult s1 = System.Windows.Forms.MessageBox.Show("是否清空并等待当前工作设备工作完最短周期? \n若选择否,则清空且关闭该时序所有设备!!!", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + + //清空并等待当前工作设备工作完最短周期 + if (s1 == System.Windows.Forms.DialogResult.Yes) + { + dosend(0x01, 0x03); + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已清空并等待"); + } + //清空且关闭该时序所有设备 + else if (s1 == System.Windows.Forms.DialogResult.No) + { + dosend(0x01, 0x04); + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已清空并关闭"); + } System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + this.RefreshS1(); } else { @@ -262,8 +395,14 @@ namespace InSituLaboratory.ViewModels.Pages { if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") { - dosend(0x01, 0x03); + DateTime startTime = (DateTime)sequentStatusModel.SequentialStartTime1; + DateTime endTime = (DateTime)sequentStatusModel.SequentialEndTime1; + dosend(0x01, 0x05); + + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已启动"); System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + this.RefreshS1(); } else { @@ -285,8 +424,27 @@ namespace InSituLaboratory.ViewModels.Pages { if (RelayViewModel.SocketInfo.ConnectionMessage == "断开") { - dosend(0x01, 0x04); + DateTime startTime = (DateTime)sequentStatusModel.SequentialStartTime1; + DateTime endTime = (DateTime)sequentStatusModel.SequentialEndTime1; + + System.Windows.Forms.DialogResult s1 = System.Windows.Forms.MessageBox.Show("是否暂停并等待当前工作设备工作完最短周期? \n若选择否,则暂停且关闭该时序所有设备!!!", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); + + //暂停并等待当前工作设备工作完最短周期 + if (s1 == System.Windows.Forms.DialogResult.Yes) + { + dosend(0x01, 0x07); + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已暂停并等待"); + } + //暂停且关闭该时序所有设备 + else if (s1 == System.Windows.Forms.DialogResult.No) + { + dosend(0x01, 0x08); + //更新时序母表及时序总表状态字段 + UpdateData(startTime, endTime, "时序1", "已暂停并关闭"); + } System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + this.RefreshS1(); } else { @@ -1343,5 +1501,34 @@ namespace InSituLaboratory.ViewModels.Pages } return byteaq; } + + /// + /// 更新时序母表及时序总表状态字段 + /// + /// 时序开始时间 + /// 时序结束时间 + /// 时序号 + /// 更新内容 + public void UpdateData(DateTime StartTime, DateTime EndTime, string kind, string action) + { + var datalist = _sysSequentialService.Query(m => m.StartTime == StartTime && m.EndTime == EndTime && m.IsDelete == 0 && m.Sequential == kind).OrderBy(n => n.SequenceGroup).ThenBy(s => s.CreateTime).ToArray(); + + //更新时序总表状态字段 已生成未下发 -> action + foreach (var item in datalist) + { + var data = _sysSequentialService.Find(item.ID); + data.Status = action; + _sysSequentialService.Update(data); + } + var datalist1 = _sysSequentialService.Query(m => m.StartTime == StartTime && m.EndTime == EndTime && m.IsDelete == 0 && m.Sequential == kind); + + //更新时序母表状态 已生成未下发 -> action + foreach (var item in datalist1) + { + var data = _sysSequentialService.Find(item.Number); + data.Status = action; + _sysSequentialService.Update(data); + } + } } }