登录用户超时注销、登录日志记录
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace JinYuan.Helper
|
||||
{
|
||||
public class InputMessageFilter : IMessageFilter
|
||||
{
|
||||
private Action onActivity;
|
||||
|
||||
public InputMessageFilter(Action onActivity)
|
||||
{
|
||||
this.onActivity = onActivity;
|
||||
}
|
||||
|
||||
public bool PreFilterMessage(ref Message m)
|
||||
{
|
||||
// 鼠标移动(0x0200)、鼠标按下(0x0201)、键盘按下(0x0100)等
|
||||
if (m.Msg == 0x0200 || m.Msg == 0x0201 || m.Msg == 0x0204
|
||||
|
||||
|| m.Msg == 0x0100 || m.Msg == 0x0101)
|
||||
{
|
||||
onActivity?.Invoke();
|
||||
}
|
||||
return false; // 不拦截消息,继续传递
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,6 +140,7 @@
|
||||
<Compile Include="FileHelper.cs" />
|
||||
<Compile Include="IniConfigHelper.cs" />
|
||||
<Compile Include="IniFileHelper.cs" />
|
||||
<Compile Include="InputMessageFilter.cs" />
|
||||
<Compile Include="JsonHelper.cs" />
|
||||
<Compile Include="Logger.cs" />
|
||||
<Compile Include="MockDataGenerator.cs" />
|
||||
|
||||
@@ -530,7 +530,7 @@ namespace JinYuan.MES
|
||||
ProcessGradeResponse(mesResponse, listCode, ref message, ref materialGrades); // 处理返回结果
|
||||
//resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用查询电芯档位接口:{url},请求数据为:{postcontent},\n{nowDate.AddMilliseconds(sw.ElapsedMilliseconds).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{sw.ElapsedMilliseconds}ms,返回结果:{result}";
|
||||
//TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\查询电芯档位\{nowDate.ToString("HH")}.txt", resJson);
|
||||
if (success)
|
||||
if (success && mesResType == MesResType.D)
|
||||
{
|
||||
message = $"查询电芯档位成功,共获取 {materialGrades.Count} 个档位信息";
|
||||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\查询电芯档位\{nowDate.ToString("HH")}.txt", message);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JinYuan.Models
|
||||
{
|
||||
public class ConstValue
|
||||
{
|
||||
#region 日志文件夹名称
|
||||
/// <summary>
|
||||
/// 操作日志存储
|
||||
/// </summary>
|
||||
public const string USER_LOG = "OperaLog";
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,7 @@
|
||||
<Compile Include="BatteryReplace.cs" />
|
||||
<Compile Include="BatteryStatus.cs" />
|
||||
<Compile Include="CapSize.cs" />
|
||||
<Compile Include="ConstValue.cs" />
|
||||
<Compile Include="SysConfig\CartainerConfig.cs" />
|
||||
<Compile Include="NgCodeEntity.cs" />
|
||||
<Compile Include="AlarmCountEntry.cs" />
|
||||
|
||||
@@ -138,6 +138,5 @@
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,11 +227,11 @@ namespace JinYuan.VirtualDataLibrary
|
||||
private Dictionary<string, Dictionary<string, string>> userPLCAddr_Mapping = new Dictionary<string, Dictionary<string, string>>()
|
||||
{
|
||||
{ "1-1", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
|
||||
{ "1-2", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
|
||||
{ "1-3", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
|
||||
{ "2-1", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
|
||||
{ "2-2", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
|
||||
{ "2-3", new Dictionary<string, string> {{"user", "D22"}, {"right", "D21"}} },
|
||||
{ "1-2", new Dictionary<string, string> {{"user", "D24" }, {"right", "D23" } } },
|
||||
{ "1-3", new Dictionary<string, string> {{"user", "D26" }, {"right", "D25" } } },
|
||||
{ "2-1", new Dictionary<string, string> {{"user", "D22" }, {"right", "D21" } } },
|
||||
{ "2-2", new Dictionary<string, string> {{"user", "D24" }, {"right", "D23" } } },
|
||||
{ "2-3", new Dictionary<string, string> {{"user", "D26" }, {"right", "D25" } } },
|
||||
};
|
||||
|
||||
public Dictionary<string, string> GetHMIUserRightAddr()
|
||||
|
||||
@@ -101,8 +101,9 @@ namespace LargeSquareOne
|
||||
// AlarmType = isError ? "错误".Translated() : "信息".Translated(),
|
||||
// Operater = CommonMethods.currentAdmin.LoginName
|
||||
//});
|
||||
|
||||
|
||||
string opeType = isError ? "错误" : "信息";
|
||||
string logInfo = $"操作时间: {CurrentTime}, 操作类型: {opeType}, 操作信息: {info}";
|
||||
LogHelper.Instance.WriteLog(logInfo, ConstValue.USER_LOG);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -94,6 +94,11 @@ namespace LargeSquareOne
|
||||
}
|
||||
};
|
||||
|
||||
Application.AddMessageFilter(new InputMessageFilter(() =>
|
||||
{
|
||||
lastActivityTime = DateTime.Now;
|
||||
}));
|
||||
|
||||
// 双缓冲全覆盖
|
||||
this.DoubleBuffered = true;
|
||||
InitializeOptimizedControlStyles();
|
||||
@@ -178,6 +183,9 @@ namespace LargeSquareOne
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime lastActivityTime;
|
||||
private System.Windows.Forms.Timer idleTimer;
|
||||
|
||||
// 定时器初始化优化
|
||||
private void InitializeTimersOptimized()
|
||||
{
|
||||
@@ -192,6 +200,21 @@ namespace LargeSquareOne
|
||||
storeTimer.Elapsed += StoreTimer_Elapsed;
|
||||
storeTimer.AutoReset = true;
|
||||
storeTimer.Start();
|
||||
|
||||
// 定时退出当前用户
|
||||
idleTimer = new System.Windows.Forms.Timer();
|
||||
idleTimer.Interval = 1000;
|
||||
idleTimer.Tick += (s, e) =>
|
||||
{
|
||||
if ((DateTime.Now - lastActivityTime).TotalMinutes >= 1)
|
||||
{
|
||||
idleTimer.Stop();
|
||||
|
||||
// 处理用户超时
|
||||
this.BeginInvoke(new Action(() => LoginLocalOut()));
|
||||
}
|
||||
};
|
||||
idleTimer.Start();
|
||||
}
|
||||
|
||||
|
||||
@@ -902,6 +925,9 @@ namespace LargeSquareOne
|
||||
updateTimer?.Dispose();
|
||||
storeTimer?.Dispose();
|
||||
|
||||
idleTimer?.Stop();
|
||||
storeTimer?.Dispose();
|
||||
|
||||
if (ControlCenter.Instance != null)
|
||||
{
|
||||
ControlCenter.Instance.DisconnectAllPlcs(); // 假设存在断开PLC的方法
|
||||
@@ -1266,6 +1292,7 @@ namespace LargeSquareOne
|
||||
CommonMethods.AddOPLog(false, "退出成功".Translated() + "," + "退出用户".Translated() + $":{CommonMethods.currentAdmin?.LoginName}," + "权限".Translated() + $":{CommonMethods.currentAdmin?.LoginLevel}");
|
||||
LogHelper.Instance.WriteLog("用户".Translated() + $":{CommonMethods.currentAdmin?.LoginName} - " + "退出".Translated());
|
||||
CommonMethods.LoginOut = true;
|
||||
CommonMethods.IsLoginOk = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user