编写计算设备功耗是否超总功耗及设备运行时长是否超时的功能

This commit is contained in:
MoYue 2024-06-22 11:33:16 +08:00
parent 9f2387b551
commit fd091e4f3f
3 changed files with 278 additions and 71 deletions

View File

@ -178,6 +178,9 @@ namespace InSituLaboratory.Common
currentSequentiual.Sequentiual1Status = "不存在时序";
break;
case 0x05:
currentSequentiual.Sequentiual1Status = "时序状态变更交替中";
break;
case 0x06:
currentSequentiual.Sequentiual1Status = "异常";
break;
default:

View File

@ -937,12 +937,29 @@ namespace InSituLaboratory.ViewModels.Pages
opendata += data[i];
opendata = opendata + "、";
}
if (System.Windows.Forms.MessageBox.Show("当前处于打开状态的设备有" + opendata + "确认需要一键还原吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
if (System.Windows.Forms.MessageBox.Show("再次确定需要一键还原吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
DialogResult s1= System.Windows.Forms.MessageBox.Show("当前处于打开状态的设备有" + opendata + "确认需要一键还原且进行强制关闭吗?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (s1 == DialogResult.Yes)
{
//消息体
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<byte> 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>(logModel);
this.Refresh();
}
else if (s1 == DialogResult.No)
{
//非强制关闭
byte[] byteaq = new byte[] { 0x93, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };
List<byte> buffer = Escape(byteaq);
string list = tools.byteToHexStr(buffer.ToArray());
@ -956,7 +973,6 @@ namespace InSituLaboratory.ViewModels.Pages
this.Refresh();
}
}
}
else
{
System.Windows.Forms.MessageBox.Show("请先连接服务端!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
@ -964,6 +980,7 @@ namespace InSituLaboratory.ViewModels.Pages
logModel.CreateTime = DateTime.Now;
logModel.Remark = "服务端未连接";
}
}
/// <summary>

View File

@ -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,11 +116,61 @@ namespace InSituLaboratory.ViewModels.Pages
/// <param name="model"></param>
public override void DoModifyS1(object model)
{
var status = "";
var datalist1 = _sysSequentialService.Query<SysSequential>(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)
{
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);
}
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
{
DateTime expirationDate = (DateTime)sequentStatusModel.SequentialStartTime1;
DateTime expirationDate1 = (DateTime)sequentStatusModel.SequentialEndTime1;
@ -153,9 +204,10 @@ namespace InSituLaboratory.ViewModels.Pages
}
});
}
}
}
}
}
/// <summary>
/// 删除
@ -164,6 +216,14 @@ namespace InSituLaboratory.ViewModels.Pages
public override void DoDeleteS1(object model)
{
try
{
var status = "";
var datalist1 = _sysSequentialService.Query<SysSequential>(m => m.StartTime == sequentStatusModel.SequentialStartTime1 && m.EndTime == sequentStatusModel.SequentialEndTime1 && m.IsDelete == 0 && m.Sequential == "时序1").ToList();
foreach (var item in datalist1)
{
status += item.Status;
}
if (status == "已生成未下发")
{
if (System.Windows.Forms.MessageBox.Show("是否确定删除此项?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
{
@ -191,6 +251,11 @@ namespace InSituLaboratory.ViewModels.Pages
this.RefreshS1();
}
}
else
{
System.Windows.Forms.MessageBox.Show(" 当前时序已下发!!! \n 无法删除!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
@ -203,21 +268,70 @@ namespace InSituLaboratory.ViewModels.Pages
/// </summary>
public override void SendS1()
{
var status = "";
var datalist1 = _sysSequentialService.Query<SysSequential>(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<byte> byteaq = encode((DateTime)sequentStatusModel.SequentialStartTime1, (DateTime)sequentStatusModel.SequentialEndTime1, 0x01, "时序1");
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<byte> byteaq = encode(startTime, endTime, 0x01, "时序1");
List<byte> 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);
//更新时序母表及时序总表状态字段
UpdateData(startTime, endTime, "时序1", "已下发");
System.Windows.Forms.MessageBox.Show("命令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
//修改且关闭该时序所有设备
else if (s1 == System.Windows.Forms.DialogResult.No)
{
//计算设备功耗是否超总功耗及设备运行时长是否超时
List<byte> byteaq = encode((DateTime)sequentStatusModel.SequentialStartTime1, (DateTime)sequentStatusModel.SequentialEndTime1, 0x02, "时序1");
List<byte> 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;
}
/// <summary>
/// 更新时序母表及时序总表状态字段
/// </summary>
/// <param name="StartTime">时序开始时间</param>
/// <param name="EndTime">时序结束时间</param>
/// <param name="kind">时序号</param>
/// <param name="action">更新内容</param>
public void UpdateData(DateTime StartTime, DateTime EndTime, string kind, string action)
{
var datalist = _sysSequentialService.Query<SysSequentialTotal>(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<SysSequentialTotal>(item.ID);
data.Status = action;
_sysSequentialService.Update(data);
}
var datalist1 = _sysSequentialService.Query<SysSequential>(m => m.StartTime == StartTime && m.EndTime == EndTime && m.IsDelete == 0 && m.Sequential == kind);
//更新时序母表状态 已生成未下发 -> action
foreach (var item in datalist1)
{
var data = _sysSequentialService.Find<SysSequential>(item.Number);
data.Status = action;
_sysSequentialService.Update(data);
}
}
}
}