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.
231 lines
6.2 KiB
C#
231 lines
6.2 KiB
C#
using HslCommunication.LogNet;
|
|
using HZH_Controls.Forms;
|
|
|
|
using NewLife.Threading;
|
|
|
|
using System;
|
|
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;
|
|
using System.Security.Principal;
|
|
using DB.Entity;
|
|
using DB;
|
|
using System.Threading;
|
|
using DB.Service;
|
|
using NewLife.Caching;
|
|
using Tool.Model;
|
|
|
|
namespace RfidWeb
|
|
{
|
|
public partial class FormMain : Form
|
|
{
|
|
private ILogNet logNet = ILogNetFactory.GetLogNet;
|
|
private ICache cache;
|
|
TimerX _timer;
|
|
List<Button> buttons=new List<Button>();
|
|
public FormMain()
|
|
{
|
|
cache=Cache.Default;
|
|
|
|
DbInfo.Init(typeof(UserInfo).Assembly);
|
|
|
|
var rfidSetting = RfidSetting.Current;
|
|
InitializeComponent();
|
|
//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) =>
|
|
{
|
|
Console.WriteLine(e.HslMessage.ToString());
|
|
};
|
|
logNet.ConsoleOutput = true;
|
|
logNet.WriteInfo("nihao");
|
|
buttons.Clear();
|
|
buttons.Add(btnShow);
|
|
buttons.Add(btnMain);
|
|
buttons.Add(btnArgument);
|
|
buttons.Add(btnAlarm);
|
|
buttons.Add(btnAccount);
|
|
buttons.Add(btnMes);
|
|
|
|
btnShow_Click(new object(), new EventArgs());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>移除过期的缓存项</summary>
|
|
void TimeState(Object state)
|
|
{
|
|
var dataTime = DateTime.Now;
|
|
this.Invoke(() =>
|
|
{
|
|
});
|
|
|
|
ThreadPoolX.QueueUserWorkItem(UpdateLog);
|
|
}
|
|
|
|
private UpdateLogService updateLogService = new UpdateLogService();
|
|
|
|
|
|
private void UpdateLog()
|
|
{
|
|
if(cache.ContainsKey(CacheKeyManager.UpdateLog)) return;
|
|
|
|
cache.Set(CacheKeyManager.UpdateLog, DateTime.Now, TimeSpan.FromSeconds(5));
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
cache.Remove(CacheKeyManager.UpdateLog);
|
|
|
|
|
|
}
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
if (FrmDialog.ShowDialog(this, "是否退出系统?", "提示窗体", true)
|
|
== System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void btnMain_Click(object sender, EventArgs e)
|
|
{
|
|
panContent.Controls.Clear();
|
|
panContent.Controls.Add(new UserMain());
|
|
|
|
}
|
|
|
|
private void btnArgument_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
//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());
|
|
|
|
}
|
|
}
|
|
|
|
private void btnAlarm_Click(object sender, EventArgs e)
|
|
{
|
|
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());
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 帐号管理
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnAccount_Click(object sender, EventArgs e)
|
|
{
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
btn.BackColor = checkColor;
|
|
}
|
|
|
|
private void btnShow_Click(object sender, EventArgs e)
|
|
{
|
|
panContent.Controls.Clear();
|
|
panContent.Controls.Add(new UserAlarmShow());
|
|
CheckButton(btnShow);
|
|
}
|
|
}
|
|
}
|