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

201 lines
5.3 KiB
C#

using HslCommunication.LogNet;
using HZH_Controls.Forms;
using NewLife.Threading;
using System;
1 month ago
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RfidWeb.Frm;
using Tool;
1 month ago
using System.Security.Principal;
using DB.Entity;
using DB;
2 weeks ago
using System.Threading;
using DB.Service;
using NewLife.Caching;
using Tool.Model;
1 month ago
namespace RfidWeb
{
public partial class FormMain : Form
{
private ILogNet logNet = ILogNetFactory.GetLogNet;
2 weeks ago
private ICache cache;
TimerX _timer;
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, 10, 1000);
// 如果所有的日志在记录之前需要在控制台显示出来
logNet.BeforeSaveToFile += (object sender, HslEventArgs e) =>
1 month ago
{
Console.WriteLine(e.HslMessage.ToString());
};
logNet.ConsoleOutput = true;
logNet.WriteInfo("nihao");
this.panContent.Controls.Clear();
this.panContent.Controls.Add(new UserMain());
2 weeks ago
}
/// <summary>移除过期的缓存项</summary>
void TimeState(Object state)
{
var dataTime = DateTime.Now;
this.Invoke(() =>
1 month ago
{
});
2 weeks ago
ThreadPoolX.QueueUserWorkItem(UpdateLog);
}
private UpdateLogService updateLogService = new UpdateLogService();
private void UpdateLog()
{
2 weeks ago
if(cache.ContainsKey(CacheKeyManager.UpdateLog)) return;
2 weeks ago
2 weeks ago
cache.Set(CacheKeyManager.UpdateLog, DateTime.Now, TimeSpan.FromSeconds(5));
2 weeks ago
var plc = PlcConnect.Instance;
var userDto = TestFactory.TestUser();
var strings = HmiPoint.GetValue();
foreach (var se in strings)
{
var res = plc.ReadUInt32(se);
if (res.IsSuccess)
{
updateLogService.AddOrUpdateLog(userDto, se, res.Content);
}
}
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 btnMain_Click(object sender, EventArgs e)
{
1 month ago
panContent.Controls.Clear();
panContent.Controls.Add(new UserMain());
2 weeks ago
}
private void btnArgument_Click(object sender, EventArgs e)
{
4 weeks ago
//FormPar
bool isLogin = UserManager.IsExit();
if (!isLogin)
{
FormLogin loigLogin = new FormLogin();
loigLogin.StartPosition = FormStartPosition.CenterScreen; // 设置窗口显示在屏幕中央
loigLogin.ShowDialog();
}
isLogin = UserManager.IsExit();
if (isLogin)
{
panContent.Controls.Clear();
panContent.Controls.Add(new FormPar());
2 weeks ago
4 weeks ago
}
}
private void btnAlarm_Click(object sender, EventArgs e)
{
1 month ago
bool isLogin = UserManager.IsExit();
if (!isLogin)
{
FormLogin loigLogin = new FormLogin();
loigLogin.StartPosition = FormStartPosition.CenterScreen; // 设置窗口显示在屏幕中央
loigLogin.ShowDialog();
}
isLogin = UserManager.IsExit();
if (isLogin)
{
panContent.Controls.Clear();
panContent.Controls.Add(new FormAlarm());
2 weeks ago
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)
{
1 month ago
bool isLogin = UserManager.IsExit();
if (!isLogin)
{
FormLogin loigLogin = new FormLogin();
loigLogin.StartPosition = FormStartPosition.CenterScreen; // 设置窗口显示在屏幕中央
loigLogin.ShowDialog();
}
isLogin = UserManager.IsExit();
if (isLogin)
{
panContent.Controls.Clear();
panContent.Controls.Add(new FormAccount());
2 weeks ago
1 month ago
}
1 month ago
}
1 month ago
}
}