开药箱添加日志及客户端提示

This commit is contained in:
maqiao 2024-12-21 21:02:52 +08:00
parent ee624a7c0d
commit 74da88a362
12 changed files with 561 additions and 463 deletions

View File

@ -3,7 +3,7 @@
<connectionStrings>
<!-- 数据库连接字符串 -->
<!--<add name="database" connectionString="server=127.0.0.1;database=wpf_dm_program;userid=root;password=qq1223" />-->
<add name="database" connectionString="server=127.0.0.1;port=3306;database=xx_xiangchang2;userid=root;password=root" />
<add name="database" connectionString="server=127.0.0.1;port=3306;database=xiangxiang_xianchang;userid=root;password=root" />
</connectionStrings>
<!--<runtime>
--><!--配置之后Appdomain.CurrentDomain.UnhandledException 事件的 IsTerminating 就变成了 false 啦!也就是说,程序并不会因为这次的异常而崩溃退出。--><!--
@ -37,7 +37,7 @@
<!-- 按处方还药或者按取药记录还药 1:处方ReturnDrugWindow22药品ReturnDrugWindow-->
<add key="returnDrugMode" value="2" />
<!-- 自动退出时间单位秒为0时不自动退出 -->
<add key="autoExit" value="0"/>
<add key="autoExit" value="80"/>
<!-- 无操作退出录像时间单位秒为0时不退出录像 -->
<add key="stopRecord" value="180"/>
@ -99,7 +99,7 @@
<!-- 指纹机号码 -->
<add key="machineNumber" value="1"/>
<!-- 指纹机ip -->
<add key="fingerIp" value="192.168.50.201"/>
<add key="fingerIp" value="10.1.100.11"/>
<!-- 多处方取药 0:不启用 1启用-->
<add key="MultiOrder" value="1"/>
@ -108,7 +108,7 @@
<add key="MultiBatch" value="0"/>
<!--海康威视IP-->
<add key="HIKIP" value="192.168.1.15"/>
<add key="HIKIP" value="10.1.100.15"/>
<!--海康威视端口-->
<add key="HIKPort" value="8000"/>
<!--海康威视用户名-->

View File

@ -1,6 +1,8 @@
using DM_Weight.Finger;
using DM_Weight.msg;
using DM_Weight.util;
using DM_Weight.ViewModels;
using DM_Weight.Views;
using log4net;
using log4net.Repository.Hierarchy;
using Modbus.Device;
@ -29,17 +31,11 @@ namespace DM_Weight.Port
private Socket socket;
private TcpClient client;
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
string ip = ConfigurationManager.AppSettings["modbusIp"].ToString();
int port = Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
private static object _lock = new object();
public static bool BoxOperate { get; set; }
private ModbusHelper()
public ModbusHelper()
{
logger.Info("ModbusHelper");
socket = KeepALiveSocket.MakeKeepALiveSocket(ip, port);
//socket = CreateSocket();
socket = MakeKeepALiveSocket();
client = new TcpClient();
client.Client = socket;
master = ModbusIpMaster.CreateIp(client);
@ -51,105 +47,62 @@ namespace DM_Weight.Port
{
if (instance == null)
{
//lock (objLock)
//{
// if (instance == null)
instance = new ModbusHelper();
//}
}
return instance;
}
}
private void SetModusIpMaster()
{
logger.Info("SetModusIpMaster");
socket = KeepALiveSocket.MakeKeepALiveSocket(ip, port);
socket = MakeKeepALiveSocket();
client = new TcpClient();
client.Client = socket;
master = ModbusIpMaster.CreateIp(client);
}
public bool[] GetAllBoxState()
{
//bool[] bools = Policy.Handle<Exception>()
// .Retry(3, (exception, retryCount) =>
// {
// this.Dispose();
// //Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
// logger.Info($"获取所有箱子门状态出错,第{retryCount}次重试, 异常信息{exception}");
// Thread.Sleep(50);
// this.SetModusIpMaster();
// BoxOperate = false;
// // return TimeSpan.FromSeconds (1);
// }).Execute<bool[]>(() =>
// {
// bool[] flags = new bool[18];
// try
// {
// if (master == null)
// {
// this.SetModusIpMaster();
// }
// var result = master.ReadInputRegisters(1, 0x0033, 2);
// var r1 = Convert.ToString(((int)result[0] >> 14) | ((int)result[1] << 2), 2).PadLeft(18, '0');
// var r2 = r1.ToCharArray();
// logger.Info("r2=>" + string.Join(", ", r2));
// //var r2=new char[18] { '0','0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
// for (int i = 0; i < 18; i++)
// {
// flags[i] = r2[17 - i] == '1' ? true : false;
// }
// logger.Info($"获取所有箱子门状态返回:{string.Join(',', flags)};");
// }
// catch (Exception)
// {
// this.Dispose();
// //Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
// logger.Info($"获取所有箱子门状态出错,第{retryCount}次重试, 异常信息{exception}");
// Thread.Sleep(50);
// this.SetModusIpMaster();
// BoxOperate = false;
// }
// return flags;
// });
lock (_lock)
{
bool successFlag = true;
bool[] bools = new bool[18];
int iCount = 0;
do
bool[] bools = Policy.Handle<Exception>()
.Retry(3, (exception, retryCount) =>
{
try
this.Dispose();
//Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
logger.Info($"获取所有箱子门状态出错,第{retryCount}次重试, 异常信息{exception}");
Thread.Sleep(50);
BoxOperate = false;
this.SetModusIpMaster();
// return TimeSpan.FromSeconds (1);
Task.Factory.StartNew(() =>
{
bool[] flags = new bool[18];
if (master == null)
{
this.SetModusIpMaster();
}
var result = master.ReadInputRegisters(1, 0x0033, 2);
var r1 = Convert.ToString(((int)result[0] >> 14) | ((int)result[1] << 2), 2).PadLeft(18, '0');
var r2 = r1.ToCharArray();
logger.Info("r2=>" + string.Join(", ", r2));
//var r2=new char[18] { '0','0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
for (int i = 0; i < 18; i++)
{
bools[i] = r2[17 - i] == '1' ? true : false;
}
logger.Info($"获取所有箱子门状态返回:{string.Join(',', bools)};");
successFlag = true;
}
catch (Exception exception)
{
if (iCount >= 3)
break;
iCount++;
successFlag = false;
this.Dispose();
//Debug.WriteLine($"获取所有箱子门状态出错,第{retryCount}次重试", exception);
logger.Info($"获取所有箱子门状态出错,第{iCount}次重试,异常信息{exception}");
Thread.Sleep(500);
this.SetModusIpMaster();
BoxOperate = false;
FingerprintUtil.FingerDisconnect();
});
}).Execute<bool[]>(() =>
{
bool[] flags = new bool[18];
if (master == null)
{
this.SetModusIpMaster();
}
} while (!successFlag);
var result = master.ReadInputRegisters(1, 0x0033, 2);
var r1 = Convert.ToString(((int)result[0] >> 14) | ((int)result[1] << 2), 2).PadLeft(18, '0');
var r2 = r1.ToCharArray();
logger.Info("r2=>" + string.Join(", ", r2));
for (int i = 0; i < 18; i++)
{
flags[i] = r2[17 - i] == '1' ? true : false;
}
logger.Info($"获取所有箱子门状态返回:{string.Join(',', flags)}");
return flags;
});
return bools;
}
}
@ -158,10 +111,6 @@ namespace DM_Weight.Port
lock (_lock)
{
BoxOperate = true;
//if (ConfigurationManager.AppSettings["test"]!=null&& ConfigurationManager.AppSettings["test"].ToString()=="Y")
//{
// return true;
//}
bool bFlag = false;
Thread.Sleep(50);
Policy.Handle<Exception>().Retry(3, ((exception, retryCount) =>
@ -169,19 +118,20 @@ namespace DM_Weight.Port
this.Dispose();
//Debug.WriteLine($"打开箱子出错,第{retryCount}次重试", exception);
logger.Info($"打开箱子出错,第{retryCount}次重试,异常信息{exception}");
//SpeakAsync("药箱连接失败,正在尝试重新打开");
Thread.Sleep(500);
Thread.Sleep(50);
this.SetModusIpMaster();
Task.Factory.StartNew(() =>
{
FingerprintUtil.FingerDisconnect();
});
//return TimeSpan.FromSeconds (1);
})).Execute(() =>
{
logger.Info($"正在打开{boxNum}号药箱");
master.WriteSingleRegister(1, (ushort)boxNum, 20);
logger.Info($"开门指令已发送{(ushort)boxNum}");
SpeakAsync("请及时关闭药箱");
//Console.WriteLine($"开门指令已发送{(ushort)boxNum}");
bFlag = true;
FingerprintUtil.FingerDisconnect();
});
return bFlag;
}
@ -193,36 +143,37 @@ namespace DM_Weight.Port
client.Close();
master.Dispose();
}
public static Socket MakeKeepALiveSocket()
{
uint dummy = 0;
byte[] inOptionValues = new byte[Marshal.SizeOf(dummy) * 3];
BitConverter.GetBytes((uint)1).CopyTo(inOptionValues, 0);//启用Keep-Alive
BitConverter.GetBytes((uint)10000).CopyTo(inOptionValues, Marshal.SizeOf(dummy));//在这个时间间隔内没有数据交互,则发送探测包
BitConverter.GetBytes((uint)10000).CopyTo(inOptionValues, Marshal.SizeOf(dummy) * 2);//发探测包时间间隔
//IPEndPoint iep = new IPEndPoint(IPAddress.Parse("192.168.1.13"), 502);
string modbusIp = ConfigurationManager.AppSettings["modbusIp"].ToString();
int modbusPort = Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(modbusIp), modbusPort);
Socket _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_socket = Policy.Handle<Exception>()
.Retry(3, (exception, retryCount) =>
{
Console.WriteLine($"建立Socket,第{retryCount}次重试", exception);
// return TimeSpan.FromSeconds (1);
})
.Execute<Socket>(() =>
{
_socket.IOControl(IOControlCode.KeepAliveValues, inOptionValues, null);
_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
_socket.Connect(iep);
return _socket;
});
return _socket;
}
private static SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
public static void SpeakAsync(string textinfo)
{
speechSynthesizer.Rate = 2;
speechSynthesizer.SpeakAsync(textinfo);
}
private Socket CreateSocket()
{
Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
string serverIp = "127.0.0.1"; // 服务器IP地址
int port = 4002; // 服务器端口
IPAddress serverAddress = IPAddress.Parse(serverIp);
IPEndPoint remoteEP = new IPEndPoint(serverAddress, port);
clientSocket.Connect(remoteEP);
if (clientSocket.Connected)
{
// 发送数据
//byte[] msg = Encoding.ASCII.GetBytes("This is a test<EOF>");
//clientSocket.Send(msg);
// 关闭socket
//clientSocket.Shutdown(SocketShutdown.Both);
//clientSocket.Close();
}
return clientSocket;
}
}
}

View File

@ -28,14 +28,16 @@ namespace DM_Weight.Port
byte functionCode = input.Get(7);
if (functionCode == 4)
{
int a = input.Get(length - 2);
int b = input.Get(length - 1);
Console.WriteLine("a");
Console.WriteLine(a);
Console.WriteLine("b");
Console.WriteLine(b);
var r = Convert.ToString((a >> 14) | (b << 2), 2).PadLeft(18, '0').ToCharArray();
bool f = r.Any(c => c == '1');
int c = input.Get(length - 3);
int d = input.Get(length - 4); logger.Info($"查状态收到返回a:{a};b:{b};c:{c};d:{d}");
bool f = false;
if (a > 0 || b > 0 || c > 0 || d > 0)
{
f = true;
}
output.Write(f);
}
input.Position = length;

View File

@ -1,9 +1,14 @@
using DM_Weight.ViewModels;
using DM_Weight.Models;
using DM_Weight.msg;
using DM_Weight.util;
using DM_Weight.ViewModels;
using DM_Weight.Views;
using log4net;
using Mina.Core.Future;
using Mina.Filter.Codec;
using Mina.Filter.Logging;
using Mina.Transport.Socket;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Configuration;
@ -21,11 +26,24 @@ namespace DM_Weight.Port
AsyncSocketConnector acceptor = new AsyncSocketConnector();
IConnectFuture iConnectFuture;
public bool OpenStatus=false;
//多线程退出标识
public bool IsMultiThread = false;
string ip = ConfigurationManager.AppSettings["modbusIp"].ToString();
int port =Convert.ToInt32(ConfigurationManager.AppSettings["modbusPort"]);
public SocketHelper()
IEventAggregator _eventAggregator;
public SocketHelper(IEventAggregator eventAggregator)
{
acceptor.ExceptionCaught += (o, e) => logger.Error(e.Exception);
_eventAggregator=eventAggregator;
acceptor.ExceptionCaught += (o, e) =>
{
logger.Error($"网口通信超时:{e.Exception}");
AlertMsg alertMsg = new AlertMsg
{
Message = $"网口通信超时,正在重试!",
Type = MsgType.ERROR
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
};
//acceptor.FilterChain.AddLast("logger", new LoggingFilter());
acceptor.FilterChain.AddLast("encoding", new ProtocolCodecFilter(new MyMinaCodecFactory()));
@ -36,13 +54,24 @@ namespace DM_Weight.Port
{
OpenStatus = (bool)e.Message;
logger.Info("MessageReceived>>>>>>>>>>>>>>>>" + OpenStatus);
if(OpenStatus)
{
HomeWindow.idleTimer.Stop();
}
else
{
HomeWindow.idleTimer.AutoReset = true;
HomeWindow.idleTimer.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0") * 1000;
HomeWindow.idleTimer.Start();
}
};
acceptor.SessionClosed += (o, e) =>
{
logger.Info("SessionClosed");
Task.Delay(50).Wait();
//Task.Delay(50).Wait();
SocketConnect();
};
this.SocketConnect();

View File

@ -11,14 +11,17 @@ using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Xml;
namespace DM_Weight.ViewModels
{
@ -393,7 +396,7 @@ namespace DM_Weight.ViewModels
//TotalCount = totalCount;
PageCount = (int)Math.Ceiling((double)TotalCount / PageSize);
if (Convert.ToDateTime(currentList.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
if (currentList != null && currentList.EffDate != null && Convert.ToDateTime(currentList.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
{
switch (DrawerNo)
{
@ -464,7 +467,7 @@ namespace DM_Weight.ViewModels
for (int i = 0; i < chlList.Count; i++)
{
ChannelList chl = chlList[i];
if (Convert.ToDateTime(chl.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
if (chl != null && chl.EffDate != null)
{
switch (chl.DrawerNo)
{
@ -828,16 +831,16 @@ namespace DM_Weight.ViewModels
{
//bool[] bools = ModbusHelper.GetInstance().GetAllBoxState();
//bool allFalse = Array.TrueForAll(bools, b => b == false);
//if (!allFalse)
//{
// Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
// return;
//}
if (_socketHelper.OpenStatus)
{
ModbusHelper.SpeakAsync("请关闭药箱后再打开");
return;
}
//if (_socketHelper.OpenStatus)
//{
// ModbusHelper.SpeakAsync("请关闭药箱后再打开");
// return;
//}
DrawerNo = Convert.ToInt32(strDrawerNo);
MachineRecord machineRecord = new MachineRecord();
machineRecord.MachineId = "DM5";
@ -856,62 +859,99 @@ namespace DM_Weight.ViewModels
ModbusHelper.SpeakAsync($"正在打开{DrawerNo + 1}号药箱");
//记录开药箱日志
SqlSugarHelper.Db.Insertable(machineRecord).ExecuteCommand();
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo - 1) });
try
{
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo) });
}
catch (Exception ex)
{
AlertMsg alertMsg = new AlertMsg
{
Message = $"网口连接异常,正在重试{ex.Message}",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
}
_socketHelper.OpenStatus = true;
Thread.Sleep(200);
int i = 10;
new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
{
i--;
if (_socketHelper.OpenStatus)
_socketHelper.IsMultiThread = true;
try
{
//bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = 0x33, functionCode = 4, delay = 2 });
//ModbusHelper.SpeakAsync($"i为{i};状态为:{_socketHelper.OpenStatus}");
//bool state = Array.TrueForAll(boolsl, b => b == false);
i--;
if (_socketHelper.OpenStatus)
{
if (i == 0)
//bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = 0x33, functionCode = 4, delay = 2 });
//ModbusHelper.SpeakAsync($"i为{i};状态为:{_socketHelper.OpenStatus}");
//bool state = Array.TrueForAll(boolsl, b => b == false);
if (_socketHelper.OpenStatus)
{
ModbusHelper.SpeakAsync("请及时关闭药箱");
i = 10;
if (i == 0)
{
ModbusHelper.SpeakAsync("请及时关闭药箱");
i = 10;
}
next();
}
else
{
stop();
}
next();
}
else
{
_socketHelper.IsMultiThread = false;
stop();
}
}
else
catch (Exception ex)
{
stop();
_socketHelper.OpenStatus = false;
AlertMsg alertMsg = new AlertMsg
{
Message = $"网口连接异常,正在重试{ex.Message}",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
}
});
//ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo);
//Task.Factory.StartNew(async () =>
//ModbusHelper.BoxOperate = false;
//int i = 10;
//Task.Factory.StartNew(() =>
//{
// bool loop = true;
// while (loop)
// while (!ModbusHelper.BoxOperate)
// {
// await Task.Delay(5000);
// bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
// bool state = Array.TrueForAll(boolsl, b => b == false);
// if (state)
// Thread.Sleep(500);
// ModbusHelper.BoxOperate = ModbusHelper.GetInstance().GetAllBoxState();
// if (!ModbusHelper.BoxOperate)
// {
// loop = false;
// ModbusHelper.BoxOperate = false;
// if (i == 0)
// {
// ModbusHelper.SpeakAsync("请及时关闭药箱");
// }
// }
// else
// i--;
// if (i == 5)
// {
// ModbusHelper.BoxOperate = true;
// ModbusHelper.SpeakAsync("药箱已打开,请及时关闭");
// i = 0;
// }
// }
//});
//管理员开对应药师的药箱后颜色消失
ChannelList iList = SqlSugarHelper.Db.Queryable<ChannelList>().Where(cl => cl.MachineId == "DM5" && cl.DrawerNo == DrawerNo + 1).First();
if (iList != null)
{
iList.EffDate = null;
SqlSugarHelper.Db.Updateable(iList).UpdateColumns(it => new { it.EffDate }).ExecuteCommand();
}
}
}
@ -921,9 +961,9 @@ namespace DM_Weight.ViewModels
List<ChannelList> listCls = SqlSugarHelper.Db.Queryable<ChannelList>()
.LeftJoin<UserList>((cl, ul) => ul.UserBarcode == cl.BelongUser)
.Where(cl => cl.MachineId == "DM5")
.GroupBy(cl=>cl.DrawerNo)
.GroupBy(cl => cl.DrawerNo)
.Select((cl, ul) => new ChannelList { DrawerNo = cl.DrawerNo, BelongUserName = ul.Nickname }).ToList();
if (listCls != null && listCls.Count>0)
if (listCls != null && listCls.Count > 0)
{
for (int i = 0; i < listCls.Count; i++)
{

View File

@ -156,83 +156,83 @@ namespace DM_Weight.ViewModels
{
//if (!_portUtil.Operate)
//{
if (SelectedChildMenu != null)
if (SelectedChildMenu != null)
{
if (SelectedChildMenu.PremissionPath.Equals("TakeRecordWindow"))
{
if (SelectedChildMenu.PremissionPath.Equals("TakeRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 2);
_regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys);
}
else if (SelectedChildMenu.PremissionPath.Equals("AddRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 2);
_regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys);
}
else if (SelectedChildMenu.PremissionPath.Equals("AddRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 1);
_regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys);
}
else if (SelectedChildMenu.PremissionPath.Equals("ReturnRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 1);
_regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys);
}
else if (SelectedChildMenu.PremissionPath.Equals("ReturnRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 3);
_regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys);
}
else if (SelectedChildMenu.PremissionPath.Equals("RetrunEmptyRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 3);
_regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys);
}
else if (SelectedChildMenu.PremissionPath.Equals("RetrunEmptyRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 3);
_regionManager.RequestNavigate("ContentRegion", SelectedChildMenu.PremissionPath, keys);
}
else if (SelectedChildMenu.PremissionPath.Equals("CheckRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 3);
_regionManager.RequestNavigate("ContentRegion", SelectedChildMenu.PremissionPath, keys);
}
else if (SelectedChildMenu.PremissionPath.Equals("CheckRecordWindow"))
{
//定义传参变量
NavigationParameters keys = new NavigationParameters();
//添加参数,键值对格式
keys.Add("Type", 4);
_regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys);
}
else
//添加参数,键值对格式
keys.Add("Type", 4);
_regionManager.RequestNavigate("ContentRegion", "MachineRecordWindow", keys);
}
else
{
if (SelectedChildMenu.PremissionPath.Equals("ReturnDrugWindow") || SelectedChildMenu.PremissionPath.Equals("ReturnDrugWindow2"))
{
if (SelectedChildMenu.PremissionPath.Equals("ReturnDrugWindow") || SelectedChildMenu.PremissionPath.Equals("ReturnDrugWindow2"))
if (ConfigurationManager.AppSettings["returnDrugMode"].ToString().Equals("1"))
{
if (ConfigurationManager.AppSettings["returnDrugMode"].ToString().Equals("1"))
{
_regionManager.RequestNavigate("ContentRegion", "ReturnDrugWindow2");
}
else
{
_regionManager.RequestNavigate("ContentRegion", "ReturnDrugWindow");
}
}
else if (SelectedChildMenu.PremissionPath.Equals("SettingMainWindow") || SelectedChildMenu.PremissionPath.Equals("SettingWindow"))
{
if (Convert.ToInt32(ConfigurationManager.AppSettings["hasFridge"]) > 0)
{
_regionManager.RequestNavigate("ContentRegion", "SettingMainWindow");
}
else
{
_regionManager.RequestNavigate("ContentRegion", "SettingWindow");
}
_regionManager.RequestNavigate("ContentRegion", "ReturnDrugWindow2");
}
else
{
_regionManager.RequestNavigate("ContentRegion", SelectedChildMenu.PremissionPath);
_regionManager.RequestNavigate("ContentRegion", "ReturnDrugWindow");
}
}
else if (SelectedChildMenu.PremissionPath.Equals("SettingMainWindow") || SelectedChildMenu.PremissionPath.Equals("SettingWindow"))
{
if (Convert.ToInt32(ConfigurationManager.AppSettings["hasFridge"]) > 0)
{
_regionManager.RequestNavigate("ContentRegion", "SettingMainWindow");
}
else
{
_regionManager.RequestNavigate("ContentRegion", "SettingWindow");
}
}
else
{
_regionManager.RequestNavigate("ContentRegion", SelectedChildMenu.PremissionPath);
}
}
}
//}
}
@ -291,6 +291,7 @@ namespace DM_Weight.ViewModels
//bool allTrue = Array.TrueForAll(boolArrs, b => b);
//false是关着,true是开着
if (!_socketHelper.OpenStatus)
//if (ModbusHelper.BoxOperate)
{
logger.Info($"用户【{Operator?.Nickname}】退出登录");
Operator = null;
@ -300,7 +301,7 @@ namespace DM_Weight.ViewModels
else
{
//还有药箱开着不能退出
_portUtil.SpeakAsync("请关闭药箱后再退出");
ModbusHelper.SpeakAsync("请关闭药箱后再退出");
SelectedMenu = _premissionDmList[0];
}
}
@ -311,7 +312,7 @@ namespace DM_Weight.ViewModels
//SelectedChildMenu = SelectedMenu.Children[0];
//if (!_portUtil.Operate)
//{
_regionManager.RequestNavigate("ContentRegion", SelectedMenu.Children[0].PremissionPath);
_regionManager.RequestNavigate("ContentRegion", SelectedMenu.Children[0].PremissionPath);
//}
}
}
@ -685,10 +686,29 @@ namespace DM_Weight.ViewModels
//_chkFunction.HIKStopDVRRecord();
Operator = null;
Reviewer = null;
//Application.Current.Dispatcher.Invoke(() =>
//{
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
//});
try
{
if (_socketHelper.IsMultiThread)
{
Application.Current.Dispatcher.BeginInvoke(() =>
{
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
});
}
else
{
Application.Current.Dispatcher.Invoke(() =>
{
_regionManager.RequestNavigate("MainRegion", "LoginWindow");
});
}
}
catch (Exception ex)
{
logger.Info($"自动退出异常:{ex.Message}");
}
}
}

View File

@ -18,6 +18,7 @@ using Unity;
using DM_Weight.HIKVISION;
using log4net.Repository.Hierarchy;
using log4net;
using System.Windows;
namespace DM_Weight.ViewModels
{
@ -67,7 +68,8 @@ namespace DM_Weight.ViewModels
IUnityContainer _container;
//private CHKFunction _cHKFunction;
private readonly ILog logger = LogManager.GetLogger(typeof(PortUtil));
public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil)
SocketHelper _socketHelper;
public MainWindowViewModel(IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator, FingerprintUtil fingerprintUtil, SocketHelper socketHelper)
{
//_portUtil = portUtil;
this.eventAggregator = eventAggregator;
@ -80,8 +82,9 @@ namespace DM_Weight.ViewModels
//System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
//{
_container.RegisterType<object, LoginWindow>("LoginWindow");
_container.RegisterType<object, LoginWindow>("LoginWindow");
_regionManager.RegisterViewWithRegion("MainRegion", "LoginWindow");
_socketHelper = socketHelper;
//}));
@ -101,7 +104,19 @@ namespace DM_Weight.ViewModels
this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00e676"));
break;
}
SnackbarMessageQueue.Enqueue(msg.Message);
if (_socketHelper.IsMultiThread)
{
Application.Current.Dispatcher.Invoke(new Action(() => {
this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#b71c1c"));
SnackbarMessageQueue.Enqueue(msg.Message);
}));
}
else
{
SnackbarMessageQueue.Enqueue(msg.Message);
}
}
}

View File

@ -22,7 +22,7 @@ using System.Windows.Media;
namespace DM_Weight.ViewModels
{
public class OpenBoxNewWindowViewModel : BindableBase, IRegionMemberLifetime//, INavigationAware
public class OpenBoxNewWindowViewModel : BindableBase, IRegionMemberLifetime, INavigationAware
{
//定时查询药箱状态
//System.Timers.Timer StateTimer = new System.Timers.Timer(5000);
@ -538,7 +538,7 @@ namespace DM_Weight.ViewModels
for (int i = 0; i < chlList.Count; i++)
{
ChannelList chl = chlList[i];
if (Convert.ToDateTime(chl.EffDate).ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd"))
if (chl != null && chl.EffDate != null)
{
SetBtnColor(chl.DrawerNo);
}
@ -657,81 +657,110 @@ namespace DM_Weight.ViewModels
channelList.DrawerState = SelfContent.Substring(0, 1) == "取" ? 0 : 1;
SqlSugarHelper.Db.Updateable(channelList).UpdateColumns(it => new { it.EffDate, it.DrawerState }).ExecuteCommand();
//StateTimer.Elapsed += OnTimerElapsed;
//if (StateTimer.Enabled)
//{
// StateTimer.Stop();
// logger.Info($"停止定时查询状态方法");
// Thread.Sleep(100);
//}
//else
ModbusHelper.SpeakAsync($"正在打开{DrawerNo}号药箱");
try
{
ModbusHelper.SpeakAsync($"正在打开{DrawerNo}号药箱");
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo - 1) });
}
//ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo - 1);
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo - 1) });
_socketHelper.OpenStatus = true;
int i = 10;
new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
catch (Exception ex)
{
i--;
if (_socketHelper.OpenStatus)
AlertMsg alertMsg = new AlertMsg
{
Message = $"网口连接异常,正在重试{ex.Message}",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
return;
}
_socketHelper.OpenStatus = true;
//_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo - 1) });
//_socketHelper.OpenStatus = true;
//bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = 0x33, functionCode = 4, delay = 2 });
//ModbusHelper.SpeakAsync($"i为{i};状态为:{_socketHelper.OpenStatus}");
//bool state = Array.TrueForAll(boolsl, b => b == false);
if (_socketHelper.OpenStatus)
{
if (i == 0)
{
ModbusHelper.SpeakAsync("请及时关闭药箱");
i = 10;
}
next();
}
else
{
stop();
}
}
else
{
stop();
}
});
//Task.Factory.StartNew(async() =>
//int i = 10;
//new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
//{
// int i = 0;
// while (_socketHelper.OpenStatus)
// i--;
// if (_socketHelper.OpenStatus)
// {
// await Task.Delay(5000);
// //bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
// _socketHelper.SendMessage(new MyBaseMessage() { lockNo = 0x33, functionCode = 4, delay = 2 });
// //ModbusHelper.SpeakAsync($"i为{i};状态为:{_socketHelper.OpenStatus}");
// //bool state = Array.TrueForAll(boolsl, b => b == false);
// if(_socketHelper.OpenStatus&&i==0)
// if (_socketHelper.OpenStatus)
// {
// ModbusHelper.SpeakAsync("请及时关闭药箱");
// if (i == 0)
// {
// ModbusHelper.SpeakAsync("请及时关闭药箱");
// i = 10;
// }
// next();
// }
// i++;
// if(i==5)
// else
// {
// i = 0;
// stop();
// }
// }
// else
// {
// stop();
// }
//});
Thread.Sleep(200);
int i = 10;
new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
{
_socketHelper.IsMultiThread = true;
try
{
i--;
if (_socketHelper.OpenStatus)
{
//bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = 0x33, functionCode = 4, delay = 2 });
//ModbusHelper.SpeakAsync($"i为{i};状态为:{_socketHelper.OpenStatus}");
//bool state = Array.TrueForAll(boolsl, b => b == false);
if (_socketHelper.OpenStatus)
{
if (i == 0)
{
ModbusHelper.SpeakAsync("请及时关闭药箱");
i = 10;
}
next();
}
else
{
stop();
}
}
else
{
_socketHelper.IsMultiThread = false;
stop();
}
}
catch (Exception ex)
{
_socketHelper.OpenStatus = false;
AlertMsg alertMsg = new AlertMsg
{
Message = $"网口连接异常,正在重试{ex.Message}",
Type = MsgType.ERROR,
};
_eventAggregator.GetEvent<SnackbarEvent>().Publish(alertMsg);
}
});
//StateTimer.Start();
SelfStatus = 0;
//PublicEnable = true;
//SelfEnable = true;
DrawerType = -1;
//DrawerType = -1;
}
}
//private void OnTimerElapsed(object sender, ElapsedEventArgs e)
@ -759,20 +788,20 @@ namespace DM_Weight.ViewModels
// break;
// }
//}
//public void OnNavigatedTo(NavigationContext navigationContext)
//{
// _eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
// RequestData();
//}
public void OnNavigatedTo(NavigationContext navigationContext)
{
// _eventAggregator.GetEvent<PortUtilEvent>().Subscribe(DoMyPrismEvent);
RequestData();
}
//public bool IsNavigationTarget(NavigationContext navigationContext)
//{
// return true;
//}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
//public void OnNavigatedFrom(NavigationContext navigationContext)
//{
// _eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
//}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
//_eventAggregator.GetEvent<PortUtilEvent>().Unsubscribe(DoMyPrismEvent);
}
}
}

View File

@ -194,101 +194,102 @@ namespace DM_Weight.ViewModels
);
}
//打开药箱
public DelegateCommand OpenBox
{
get => new DelegateCommand(() =>
{
if (DrawerNo > 0)
{
//bool[] bools = ModbusHelper.GetInstance().GetAllBoxState();
//bool allFalse = Array.TrueForAll(bools, b => b == false);
//if (!allFalse)
if (_socketHelper.OpenStatus)
{
Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
return;
}
IsEnable = false;
Status = 1;
//_portUtil.SpeakAsync("正在打开药箱");
//_portUtil.DrawerNo = DrawerNo;
//_portUtil.OpenBox();
_portUtil.SpeakAsync($"正在打开{DrawerNo}号药箱");//记录开药箱日志
SqlSugarHelper.Db.Insertable(new MachineRecord()
{
MachineId = "DM5",
DrawerNo = DrawerNo,
Operator = HomeWindowViewModel.Operator?.Id,
OperationTime = DateTime.Now,
Type = 55,
InvoiceId = $"打开{DrawerNo}号药箱",
}).ExecuteCommand();
//public DelegateCommand OpenBox
//{
// get => new DelegateCommand(() =>
// {
// if (DrawerNo > 0)
// {
// //bool[] bools = ModbusHelper.GetInstance().GetAllBoxState();
// //bool allFalse = Array.TrueForAll(bools, b => b == false);
// //if (!allFalse)
// if (ModbusHelper.BoxOperate)
// {
// Task.Factory.StartNew(() => { ModbusHelper.SpeakAsync("请关闭药箱后再打开"); });
// return;
// }
// IsEnable = false;
// Status = 1;
// //_portUtil.SpeakAsync("正在打开药箱");
// //_portUtil.DrawerNo = DrawerNo;
// //_portUtil.OpenBox();
// _portUtil.SpeakAsync($"正在打开{DrawerNo}号药箱");//记录开药箱日志
// SqlSugarHelper.Db.Insertable(new MachineRecord()
// {
// MachineId = "DM5",
// DrawerNo = DrawerNo,
// Operator = HomeWindowViewModel.Operator?.Id,
// OperationTime = DateTime.Now,
// Type = 55,
// InvoiceId = $"打开{DrawerNo}号药箱",
// }).ExecuteCommand();
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo - 1) });
_socketHelper.OpenStatus = true;
// //_socketHelper.SendMessage(new MyBaseMessage() { lockNo = (short)(DrawerNo - 1) });
// //_socketHelper.OpenStatus = true;
int i = 10;
new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
{
i--;
if (_socketHelper.OpenStatus)
{
// //int i = 10;
// //new PromiseUtil<int>().taskAsyncLoop(500, 0, async (options, next, stop) =>
// //{
// // i--;
// // if (_socketHelper.OpenStatus)
// // {
//bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
_socketHelper.SendMessage(new MyBaseMessage() { lockNo = 0x33, functionCode = 4, delay = 2 });
// // //bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
// // _socketHelper.SendMessage(new MyBaseMessage() { lockNo = 0x33, functionCode = 4, delay = 2 });
//ModbusHelper.SpeakAsync($"i为{i};状态为:{_socketHelper.OpenStatus}");
//bool state = Array.TrueForAll(boolsl, b => b == false);
if (_socketHelper.OpenStatus)
{
IsEnable = true;
Status = 0;
if (i == 0)
{
ModbusHelper.SpeakAsync("请及时关闭药箱");
i = 10;
}
next();
}
else
{
stop();
}
}
else
{
stop();
}
});
//ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo - 1);
////if (bFlag)
//{
// IsEnable = true;
// Status = 0;
//}
//Task.Factory.StartNew(async () =>
//{
// bool loop = true;
// while (loop)
// {
// await Task.Delay(5000);
// bool[] boolsl = ModbusHelper.GetInstance().GetAllBoxState();
// bool state = Array.TrueForAll(boolsl, b => b == false);
// if (state)
// {
// loop = false;
// ModbusHelper.BoxOperate = false;
// }
// else
// {
// ModbusHelper.BoxOperate = true;
// ModbusHelper.SpeakAsync("药箱已打开,请及时关闭");
// }
// }
//});
}
});
}
// // //ModbusHelper.SpeakAsync($"i为{i};状态为:{_socketHelper.OpenStatus}");
// // //bool state = Array.TrueForAll(boolsl, b => b == false);
// // if (_socketHelper.OpenStatus)
// // {
// // IsEnable = true;
// // Status = 0;
// // if (i == 0)
// // {
// // ModbusHelper.SpeakAsync("请及时关闭药箱");
// // i = 10;
// // }
// // next();
// // }
// // else
// // {
// // stop();
// // }
// // }
// // else
// // {
// // stop();
// // }
// //});
// ModbusHelper.GetInstance().OpenBoxDoor(DrawerNo - 1);
// //if (bFlag)
// {
// IsEnable = true;
// Status = 0;
// }
// int i = 10;
// Task.Factory.StartNew(async () =>
// {
// while (ModbusHelper.BoxOperate)
// {
// await Task.Delay(500);
// ModbusHelper.BoxOperate = ModbusHelper.GetInstance().GetAllBoxState();
// if(ModbusHelper.BoxOperate)
// {
// if (i == 0)
// {
// ModbusHelper.SpeakAsync("药箱已打开,请及时关闭");
// }
// i--;
// }
// else
// {
// ModbusHelper.BoxOperate = false;
// }
// }
// });
// }
// });
//}
public DelegateCommand SaveSetting
{

View File

@ -10,10 +10,6 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:convert="clr-namespace:DM_Weight.Converter"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
MinWidth="880"
MinHeight="615"
Width="Auto"
Height="Auto"
mc:Ignorable="d">
<UserControl.Resources>
<convert:DrawerSelectConverter x:Key="DrawerSelectConverter" />
@ -44,7 +40,7 @@
</Grid.RowDefinitions>-->
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="15*" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
@ -74,7 +70,7 @@
Content="{materialDesign:PackIcon Refresh}"/>
</StackPanel>
</Grid>-->
<Grid Margin="6" Grid.Column="0" Width="300" Height="570">
<Grid Margin="6" Grid.Column="0">
<Grid.Resources>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignPaperLightButton}">
<Setter Property="Foreground" Value="#00a0ea" />
@ -119,36 +115,36 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Width="120" Content="1号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="1" />
<Button Grid.Row="1" Grid.Column="0" Width="120" Content="2号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="2" />
<Button Grid.Row="2" Grid.Column="0" Width="120" Content="3号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="3" />
<Button Grid.Row="3" Grid.Column="0" Width="120" Content="4号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="4" />
<Button Grid.Row="4" Grid.Column="0" Width="120" Content="5号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="5" />
<Button Grid.Row="5" Grid.Column="0" Width="120" Content="6号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="6" />
<Button Grid.Row="6" Grid.Column="0" Width="120" Content="7号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="7" />
<Button Grid.Row="7" Grid.Column="0" Width="120" Content="8号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="8" />
<Button Margin="0 0 3 0" Grid.Row="0" Grid.Column="0" Width="120" Content="1号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="1" />
<Button Margin="0 0 3 0" Grid.Row="1" Grid.Column="0" Width="120" Content="2号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="2" />
<Button Margin="0 0 3 0" Grid.Row="2" Grid.Column="0" Width="120" Content="3号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="3" />
<Button Margin="0 0 3 0" Grid.Row="3" Grid.Column="0" Width="120" Content="4号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="4" />
<Button Margin="0 0 3 0" Grid.Row="4" Grid.Column="0" Width="120" Content="5号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="5" />
<Button Margin="0 0 3 0" Grid.Row="5" Grid.Column="0" Width="120" Content="6号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="6" />
<Button Margin="0 0 3 0" Grid.Row="6" Grid.Column="0" Width="120" Content="7号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="7" />
<Button Margin="0 0 3 0" Grid.Row="7" Grid.Column="0" Width="120" Content="8号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="8" />
<Button Grid.Row="8" Grid.Column="0" Width="120" Content="9号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="9" />
<Button Grid.Row="0" Grid.Column="1" Width="120" Content="10号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="10" />
<Button Grid.Row="1" Grid.Column="1" Width="120" Content="11号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="11" />
<Button Grid.Row="2" Grid.Column="1" Width="120" Content="12号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="12" />
<Button Grid.Row="3" Grid.Column="1" Width="120" Content="13号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="13" />
<Button Grid.Row="4" Grid.Column="1" Width="120" Content="14号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="14" />
<Button Grid.Row="5" Grid.Column="1" Width="120" Content="15号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="15" />
<Button Grid.Row="6" Grid.Column="1" Width="120" Content="16号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="16" />
<Button Grid.Row="7" Grid.Column="1" Width="120" Content="17号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="17" />
<Button Grid.Row="8" Grid.Column="1" Width="120" Content="18号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="18" />
<Button Margin="0 0 3 0" Grid.Row="8" Grid.Column="0" Width="120" Content="9号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="9" />
<Button Margin="0 0 3 0" Grid.Row="0" Grid.Column="1" Width="120" Content="10号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="10" />
<Button Margin="0 0 3 0" Grid.Row="1" Grid.Column="1" Width="120" Content="11号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="11" />
<Button Margin="0 0 3 0" Grid.Row="2" Grid.Column="1" Width="120" Content="12号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="12" />
<Button Margin="0 0 3 0" Grid.Row="3" Grid.Column="1" Width="120" Content="13号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="13" />
<Button Margin="0 0 3 0" Grid.Row="4" Grid.Column="1" Width="120" Content="14号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="14" />
<Button Margin="0 0 3 0" Grid.Row="5" Grid.Column="1" Width="120" Content="15号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="15" />
<Button Margin="0 0 3 0" Grid.Row="6" Grid.Column="1" Width="120" Content="16号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="16" />
<Button Margin="0 0 3 0" Grid.Row="7" Grid.Column="1" Width="120" Content="17号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="17" />
<Button Margin="0 0 3 0" Grid.Row="8" Grid.Column="1" Width="120" Content="18号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="18" />
<!--<Button Grid.Row="8" Grid.Column="1" Width="120" Content="19号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="19" />
<Button Grid.Row="9" Grid.Column="1" Width="120" Content="20号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="20" />-->
</Grid>
</Grid>
<Grid Grid.Column="2" Margin="6">
<Grid Grid.Column="1" Margin="6">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.ColumnSpan="2">
<ComboBox
Margin="0 0 6 0"
Grid.Column="0"
@ -213,6 +209,12 @@
<GridViewColumn Width="200"
DisplayMemberBinding="{Binding DrugInfo.DrugName}"
Header="药品名称"/>
<GridViewColumn Width="200"
DisplayMemberBinding="{Binding DrugInfo.Manufactory}"
Header="厂家"/>
<GridViewColumn Width="200"
DisplayMemberBinding="{Binding DrugInfo.DrugSpec}"
Header="规格"/>
<GridViewColumn Width="100"
DisplayMemberBinding="{Binding BaseQuantity}"
Header="药品基数"/>
@ -220,8 +222,8 @@
DisplayMemberBinding="{Binding Quantity}"
Header="药品库存"/>
</GridView>
</ListView.View>
</GridView>
</ListView.View>
</ListView>
<materialDesign:Snackbar
Background="{Binding SnackbarBackground}"

View File

@ -3,6 +3,7 @@ using DM_Weight.Port;
using DM_Weight.ViewModels;
using log4net;
using log4net.Repository.Hierarchy;
using Microsoft.Extensions.Logging;
using Prism.Events;
using System;
using System.Collections.Generic;
@ -29,9 +30,9 @@ namespace DM_Weight.Views
/// </summary>
public partial class HomeWindow : UserControl
{
private readonly ILog logger = LogManager.GetLogger(typeof(CheckOrderNewWindowViewModel));
private readonly ILog logger = LogManager.GetLogger(typeof(HomeWindow));
int autoExit = Convert.ToInt32(ConfigurationManager.AppSettings["autoExit"] ?? "0");
System.Timers.Timer idleTimer;//= new System.Timers.Timer(60000);
public static System.Timers.Timer idleTimer;//= new System.Timers.Timer(60000);
IEventAggregator _eventAggregator;
SocketHelper _socketHelper;
public HomeWindow(IEventAggregator eventAggregator, SocketHelper socketHelper)
@ -52,6 +53,9 @@ namespace DM_Weight.Views
private void OnUserActivity(object sender, EventArgs e)
{
idleTimer.Stop();
idleTimer.AutoReset = true;
idleTimer.Interval =autoExit * 1000;
idleTimer.Start();
}
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
@ -59,13 +63,22 @@ namespace DM_Weight.Views
// 串口无人操作
//bool[] boolArrs = ModbusHelper.GetInstance().GetAllBoxState();
//bool allTrue = Array.TrueForAll(boolArrs, b => b == false);
logger.Info($"进入自动退出定时方法{_socketHelper.OpenStatus}");
if (_socketHelper.OpenStatus && idleTimer.Enabled)
logger.Info($"进入自动退出定时方法{ModbusHelper.BoxOperate}");
//if (ModbusHelper.BoxOperate)
if (!_socketHelper.OpenStatus)
{
idleTimer.Stop();
//无人操作,自动退出
_eventAggregator.GetEvent<LoginOutEvent>().Publish();
if (idleTimer.Enabled)
{
idleTimer.Stop();
//无人操作,自动退出
_eventAggregator.GetEvent<LoginOutEvent>().Publish();
}
}
//else
//{
// idleTimer.Interval = autoExit * 1000;
// idleTimer.AutoReset = true;
//}
}
}

View File

@ -9,10 +9,6 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:convert="clr-namespace:DM_Weight.Converter"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
MinWidth="880"
MinHeight="615"
Width="Auto"
Height="Auto"
mc:Ignorable="d">
<UserControl.Resources>
<convert:StatusConverter x:Key="StatusConverter" />
@ -24,7 +20,7 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Margin="6" Grid.Column="0" Width="300" Height="570">
<Grid Margin="6" Grid.Column="0">
<Grid.Resources>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignPaperLightButton}">
<Setter Property="Foreground" Value="#00a0ea" />
@ -69,25 +65,25 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button Grid.Row="0" Grid.Column="0" Width="120" Content="1号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="1" />
<Button Grid.Row="1" Grid.Column="0" Width="120" Content="2号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="2" />
<Button Grid.Row="2" Grid.Column="0" Width="120" Content="3号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="3" />
<Button Grid.Row="3" Grid.Column="0" Width="120" Content="4号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="4" />
<Button Grid.Row="4" Grid.Column="0" Width="120" Content="5号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="5" />
<Button Grid.Row="5" Grid.Column="0" Width="120" Content="6号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="6" />
<Button Grid.Row="6" Grid.Column="0" Width="120" Content="7号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="7" />
<Button Grid.Row="7" Grid.Column="0" Width="120" Content="8号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="8" />
<Button Margin="0 0 3 0" Grid.Row="0" Grid.Column="0" Width="120" Content="1号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="1" />
<Button Margin="0 0 3 0" Grid.Row="1" Grid.Column="0" Width="120" Content="2号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="2" />
<Button Margin="0 0 3 0" Grid.Row="2" Grid.Column="0" Width="120" Content="3号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="3" />
<Button Margin="0 0 3 0" Grid.Row="3" Grid.Column="0" Width="120" Content="4号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="4" />
<Button Margin="0 0 3 0" Grid.Row="4" Grid.Column="0" Width="120" Content="5号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="5" />
<Button Margin="0 0 3 0" Grid.Row="5" Grid.Column="0" Width="120" Content="6号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="6" />
<Button Margin="0 0 3 0" Grid.Row="6" Grid.Column="0" Width="120" Content="7号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="7" />
<Button Margin="0 0 3 0" Grid.Row="7" Grid.Column="0" Width="120" Content="8号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="8" />
<Button Grid.Row="8" Grid.Column="0" Width="120" Content="9号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="9" />
<Button Grid.Row="0" Grid.Column="1" Width="120" Content="10号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="10" />
<Button Grid.Row="1" Grid.Column="1" Width="120" Content="11号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="11" />
<Button Grid.Row="2" Grid.Column="1" Width="120" Content="12号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="12" />
<Button Grid.Row="3" Grid.Column="1" Width="120" Content="13号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="13" />
<Button Grid.Row="4" Grid.Column="1" Width="120" Content="14号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="14" />
<Button Grid.Row="5" Grid.Column="1" Width="120" Content="15号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="15" />
<Button Grid.Row="6" Grid.Column="1" Width="120" Content="16号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="16" />
<Button Grid.Row="7" Grid.Column="1" Width="120" Content="17号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="17" />
<Button Grid.Row="8" Grid.Column="1" Width="120" Content="18号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="18" />
<Button Margin="0 0 3 0" Grid.Row="8" Grid.Column="0" Width="120" Content="9号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="9" />
<Button Margin="0 0 3 0" Grid.Row="0" Grid.Column="1" Width="120" Content="10号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="10" />
<Button Margin="0 0 3 0" Grid.Row="1" Grid.Column="1" Width="120" Content="11号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="11" />
<Button Margin="0 0 3 0" Grid.Row="2" Grid.Column="1" Width="120" Content="12号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="12" />
<Button Margin="0 0 3 0" Grid.Row="3" Grid.Column="1" Width="120" Content="13号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="13" />
<Button Margin="0 0 3 0" Grid.Row="4" Grid.Column="1" Width="120" Content="14号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="14" />
<Button Margin="0 0 3 0" Grid.Row="5" Grid.Column="1" Width="120" Content="15号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="15" />
<Button Margin="0 0 3 0" Grid.Row="6" Grid.Column="1" Width="120" Content="16号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="16" />
<Button Margin="0 0 3 0" Grid.Row="7" Grid.Column="1" Width="120" Content="17号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="17" />
<Button Margin="0 0 3 0" Grid.Row="8" Grid.Column="1" Width="120" Content="18号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="18" />
<!--<Button Grid.Row="8" Grid.Column="1" Width="120" Content="19号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="19" />
<Button Grid.Row="9" Grid.Column="1" Width="120" Content="20号药箱" Command="{Binding UpdateDrawerNo}" CommandParameter="20" />-->
@ -99,7 +95,7 @@
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button
<!--<Button
Margin="6 0 6 6"
ToolTip="打开药箱"
Content="打开药箱"
@ -107,7 +103,7 @@
Command="{Binding OpenBox}"
materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding Status, Converter={StaticResource StatusConverter}, ConverterParameter=opearBtnLoading}"
materialDesign:ButtonProgressAssist.IsIndeterminate="{Binding Status, Converter={StaticResource StatusConverter}, ConverterParameter=opearBtnLoading}"
Style="{StaticResource MaterialDesignOutlinedLightButton}" />
Style="{StaticResource MaterialDesignOutlinedLightButton}" />-->
<Button
Margin="6 0 6 6"
ToolTip="保存设置"