You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/RfidWeb/FormMain.cs

293 lines
8.0 KiB
C#

2 weeks ago
using DB;
using DB.Entity;
using DB.Service;
using HslCommunication.LogNet;
using HZH_Controls.Forms;
2 weeks ago
using NewLife.Caching;
using NewLife.Threading;
2 weeks ago
using RfidWeb.Frm;
using System;
1 month ago
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
2 weeks ago
using Tool;
2 weeks ago
using Tool.Model;
1 month ago
namespace RfidWeb
{
1 week ago
1 month ago
public partial class FormMain : Form
{
private ILogNet logNet = ILogNetFactory.GetLogNet;
2 weeks ago
private ICache cache;
TimerX _timer;
2 weeks ago
List<Button> buttons=new List<Button>();
1 week ago
1 month ago
public FormMain()
{
2 weeks ago
cache=Cache.Default;
1 month ago
DbInfo.Init(typeof(UserInfo).Assembly);
2 weeks ago
var rfidSetting = RfidSetting.Current;
1 month ago
InitializeComponent();
2 weeks ago
if (this.FormBorderStyle == FormBorderStyle.None)
{
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.WindowState = FormWindowState.Normal;
}
else
{
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
Init();
}
private void Init()
{
_timer = new TimerX(TimeState, null, 2000, 1000);
// 如果所有的日志在记录之前需要在控制台显示出来
logNet.BeforeSaveToFile += (object sender, HslEventArgs e) =>
1 month ago
{
Console.WriteLine(e.HslMessage.ToString());
};
logNet.ConsoleOutput = true;
2 weeks ago
2 weeks ago
buttons.Clear();
buttons.Add(btnShow);
2 weeks ago
2 weeks ago
buttons.Add(btnArgument);
buttons.Add(btnAlarm);
buttons.Add(btnAccount);
buttons.Add(btnMes);
1 week ago
buttons.Add(buttonUpdateLog);
2 weeks ago
btnShow_Click(new object(), EventArgs.Empty);
2 weeks ago
}
/// <summary>移除过期的缓存项</summary>
void TimeState(Object state)
{
1 week ago
2 weeks ago
bool isExit = UserManager.IsExit();
this.Invoke(() =>
1 month ago
{
2 weeks ago
labTime.Text = DateTime.Now.ToFullString();
1 week ago
2 weeks ago
this.Invoke(() =>
{
1 week ago
2 weeks ago
//不存在
if (!isExit)
{
labUser.ForeColor= System.Drawing.SystemColors.Window;
labUser.Text = "未登录(未授权)";
}
else
{
var dto = UserManager.GetUser();
labUser.Text = $"{dto.UserName}({dto.RoleName})";
labUser.ForeColor = Color.FromArgb(21, 182, 173);
}
});
});
2 weeks ago
1 week ago
ThreadPoolX.QueueUserWorkItem(ShowLed);
2 weeks ago
ThreadPoolX.QueueUserWorkItem(UpdateLog);
1 week ago
2 weeks ago
}
private UpdateLogService updateLogService = new UpdateLogService();
2 weeks ago
private PointService pointService = new PointService();
1 week ago
private void ShowLed()
{
if (cache.ContainsKey(CacheKeyManager.Home)) return;
cache.Set(CacheKeyManager.Home, DateTime.Now, TimeSpan.FromSeconds(10));
bool result =PlcConnect.Instance.ReadPlcType().IsSuccess;
hslLanternSimplePlc.LanternBackground = result ? Color.LimeGreen : Color.Red;
cache.Remove(CacheKeyManager.Home);
}
2 weeks ago
1 week ago
/// <summary>
/// 参数变化
/// </summary>
2 weeks ago
private void UpdateLog()
{
2 weeks ago
if (UserManager.IsExit())
{
2 weeks ago
var dic = pointService.GetValueName();
2 weeks ago
if (cache.ContainsKey(CacheKeyManager.UpdateLog)) return;
cache.Set(CacheKeyManager.UpdateLog, DateTime.Now, TimeSpan.FromSeconds(5));
var plc = PlcConnect.Instance;
2 weeks ago
var userDto = UserManager.GetUser();
var strings = dic.Keys;
2 weeks ago
foreach (var se in strings)
2 weeks ago
{
2 weeks ago
var res = plc.ReadUInt32(se);
if (res.IsSuccess)
{
2 weeks ago
string name = dic[se];
updateLogService.AddOrUpdateLog(userDto, name, res.Content);
2 weeks ago
}
2 weeks ago
}
2 weeks ago
cache.Remove(CacheKeyManager.UpdateLog);
}
2 weeks ago
1 month ago
}
private void btnExit_Click(object sender, EventArgs e)
{
if (FrmDialog.ShowDialog(this, "是否退出系统?", "提示窗体", true)
== System.Windows.Forms.DialogResult.OK)
{
Application.Exit();
}
}
2 weeks ago
private void btnArgument_Click(object sender, EventArgs e)
{
4 weeks ago
//FormPar
2 weeks ago
CheckLogin();
var isLogin = UserManager.IsExit();
4 weeks ago
if (isLogin)
{
panContent.Controls.Clear();
panContent.Controls.Add(new FormPar());
2 weeks ago
4 weeks ago
}
}
2 weeks ago
private void CheckLogin()
{
1 month ago
bool isLogin = UserManager.IsExit();
if (!isLogin)
{
FormLogin loigLogin = new FormLogin();
loigLogin.StartPosition = FormStartPosition.CenterScreen; // 设置窗口显示在屏幕中央
loigLogin.ShowDialog();
}
2 weeks ago
}
private void btnAlarm_Click(object sender, EventArgs e)
{
CheckLogin();
1 month ago
2 weeks ago
var isLogin = UserManager.IsExit();
1 month ago
if (isLogin)
{
panContent.Controls.Clear();
2 weeks ago
panContent.Controls.Add(new FromAlarmLog());
CheckButton(btnAlarm);
1 month ago
}
1 month ago
}
1 month ago
/// <summary>
/// 帐号管理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAccount_Click(object sender, EventArgs e)
{
2 weeks ago
CheckLogin();
var isLogin = UserManager.IsExit();
1 month ago
if (isLogin)
{
panContent.Controls.Clear();
panContent.Controls.Add(new FormAccount());
2 weeks ago
CheckButton(btnAccount);
1 month ago
}
1 month ago
}
2 weeks ago
Color checkColor = System.Drawing.Color.FromArgb(168, 188, 195);
Color defaultColor = System.Drawing.Color.FromArgb(21, 181, 173);
private void CheckButton(Button btn)
{
foreach (var bt in buttons)
{
if (bt.BackColor != defaultColor)
{
bt.BackColor = defaultColor;
}
}
2 weeks ago
btn.Focus();
2 weeks ago
btn.BackColor = checkColor;
}
private void btnShow_Click(object sender, EventArgs e)
{
panContent.Controls.Clear();
panContent.Controls.Add(new UserAlarmShow());
CheckButton(btnShow);
2 weeks ago
2 weeks ago
}
2 weeks ago
2 weeks ago
private void labUser_Click(object sender, EventArgs e)
{
if (labUser.Text != "未登录(未授权)")
{
if (FrmDialog.ShowDialog(this, "退出登录", "提示窗体", true)
== System.Windows.Forms.DialogResult.OK)
{
cache.Remove(CacheKeyManager.User);
btnShow_Click(new object(), EventArgs.Empty);
}
}
}
2 weeks ago
private void buttonUpdateLog_Click(object sender, EventArgs e)
{
panContent.Controls.Clear();
panContent.Controls.Add(new FromUploadLog());
CheckButton(buttonUpdateLog);
}
1 week ago
private void btnMes_Click(object sender, EventArgs e)
{
//
CheckLogin();
var isLogin = UserManager.IsExit();
if (isLogin)
{
panContent.Controls.Clear();
panContent.Controls.Add(new FrmPlan());
CheckButton(btnMes);
}
}
1 month ago
}
}