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.

199 lines
5.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using HighWayIot.Repository.domain;
using HighWayIot.TouchSocket;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TouchSocket.Sockets;
namespace RFIDSocket
{
public partial class RFIDSocket : Form
{
private static TcpServer Server = TcpServer.Instance;
private static ServerDataAnalysis RFIDData = ServerDataAnalysis.Instance;
Configuration Config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
string Port = string.Empty;
string IP = string.Empty;
int PageNo = 1;
public RFIDSocket()
{
InitializeComponent();
InitAction();
}
private void InitAction()
{
if (Server.State != ServerState.Running)
{
MonitorState.Text = "关";
MonitorState.BackColor = Color.Yellow;
}
else if (Server.State == ServerState.Running)
{
MonitorState.Text = "开";
MonitorState.BackColor = Color.LightGreen;
}
IPText.Text = ConfigurationManager.AppSettings["IpSetting"];
PortText.Text = ConfigurationManager.AppSettings["PortSetting"];
Port = PortText.Text;
IP = IPText.Text;
}
private void MonitorOnOff_Click(object sender, EventArgs e)
{
if (Server.State != ServerState.Running)
{
if (Server.ServerStart(IP, Port))
{
MessageBox.Show("监听服务启动成功如更改ip端口号请重新启动监听");
TableTimer.Enabled = true;
}
else
{
MessageBox.Show("监听服务启动失败!");
}
}
else if (Server.State == ServerState.Running)
{
if (Server.ServerStop())
{
MessageBox.Show("监听服务关闭成功!");
TableTimer.Enabled = false;
}
else
{
MessageBox.Show("监听服务关闭失败!");
}
}
}
private void SetPort_Click(object sender, EventArgs e)
{
Config.AppSettings.Settings["IpSetting"].Value = IPText.Text;
Config.AppSettings.Settings["PortSetting"].Value = PortText.Text;
Config.Save();
Port = PortText.Text;
IP = IPText.Text;
MessageBox.Show("服务端IP端口号设置成功");
}
private void TableTimer_Tick(object sender, EventArgs e)
{
if (Server.State != ServerState.Running)
{
MonitorOnOff.Text = "启动监听";
MonitorState.Text = "关";
MonitorState.BackColor = Color.Yellow;
}
else if (Server.State == ServerState.Running)
{
MonitorOnOff.Text = "关闭监听";
MonitorState.Text = "开";
MonitorState.BackColor = Color.LightGreen;
}
RFIDData.GetData();
ConnectCountLabel.Text = Server.ConnectCount.ToString();
CotentData.DataSource = null;
StateData.DataSource = null;
HeartbeatData.DataSource = null;
ContentPages();
StateData.DataSource = RFIDData.AlarmState;
HeartbeatData.DataSource = RFIDData.HeartbeatsState;
}
private void RFIDSocket_FormClosing(object sender, FormClosingEventArgs e)
{
if (Server.State == ServerState.Running)
{
if (!Server.ServerStop())
{
MessageBox.Show("监听服务关闭失败! 请成功关闭后再退出");
e.Cancel = true;
}
if (!Server.ServerDispose())
{
MessageBox.Show("监听服务释放失败! 请再次尝试退出");
e.Cancel = true;
}
}
}
private void ContentPages()
{
CotentData.DataSource = RFIDData.rFIDContents.Skip((PageNo - 1) * 50).Take(50).ToList();
PageRange.Text = $"{((PageNo - 1) * 50) + 1} - {PageNo * 50}";
}
private void PgUp_Click(object sender, EventArgs e)
{
if(PageNo == 1)
{
MessageBox.Show("已经是首页!");
return;
}
PageNo--;
ContentPages();
}
private void PgDn_Click(object sender, EventArgs e)
{
if (PageNo == 4)
{
MessageBox.Show("已经是尾页!");
return;
}
PageNo++;
ContentPages();
}
private void LogStart_Click(object sender, EventArgs e)
{
RFIDLog rFIDLog = new RFIDLog();
rFIDLog.Show();
}
/// <summary>
/// 清除所有报警
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ClearError_Click(object sender, EventArgs e)
{
if (RFIDData.ClearAllError())
{
MessageBox.Show("设备异常清除成功");
}
else
{
MessageBox.Show("设备异常清除失败");
}
}
private void BinAudlt_Click(object sender, EventArgs e)
{
RFIDBinAudlt form = new RFIDBinAudlt();
form.Show();
}
}
}