|
|
|
|
using HighWayIot.Repository.domain;
|
|
|
|
|
using HighWayIot.TouchSocket;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
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;
|
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
|
using TcpClient = HighWayIot.TouchSocket.TcpClient;
|
|
|
|
|
|
|
|
|
|
namespace RFIDSocket
|
|
|
|
|
{
|
|
|
|
|
public partial class RFIDSocket : Form
|
|
|
|
|
{
|
|
|
|
|
private static TcpClient Server = TcpClient.Instance;
|
|
|
|
|
|
|
|
|
|
private static DataAnalysis RFIDData = DataAnalysis.Instance;
|
|
|
|
|
|
|
|
|
|
string Port = "1234";
|
|
|
|
|
string IP = "127.0.0.1";
|
|
|
|
|
|
|
|
|
|
int PageNo = 1;
|
|
|
|
|
|
|
|
|
|
List<string> IPs = new List<string>();
|
|
|
|
|
private List<RFIDContent> Content = new List<RFIDContent>();
|
|
|
|
|
|
|
|
|
|
BindingSource bs = new BindingSource();
|
|
|
|
|
|
|
|
|
|
public RFIDSocket()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitAction();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitAction()
|
|
|
|
|
{
|
|
|
|
|
if (!Server.State)
|
|
|
|
|
{
|
|
|
|
|
MonitorState.Text = "关";
|
|
|
|
|
MonitorState.BackColor = Color.Yellow;
|
|
|
|
|
}
|
|
|
|
|
else if (Server.State)
|
|
|
|
|
{
|
|
|
|
|
MonitorState.Text = "开";
|
|
|
|
|
MonitorState.BackColor = Color.LightGreen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Port = PortText.Text;
|
|
|
|
|
IP = IPText.Text;
|
|
|
|
|
|
|
|
|
|
IPs = RFIDData.GetAllIP();
|
|
|
|
|
|
|
|
|
|
bs.DataSource = IPs;
|
|
|
|
|
MonitorAddress.DataSource = bs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MonitorOnOff_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!Server.State)
|
|
|
|
|
{
|
|
|
|
|
if (Server.ClientStart(IP, Port))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("监听服务启动成功!");
|
|
|
|
|
TableTimer.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("监听服务启动失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (Server.State)
|
|
|
|
|
{
|
|
|
|
|
if (Server.ClientStop())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("监听服务关闭成功!");
|
|
|
|
|
TableTimer.Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("监听服务关闭失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetPort_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Port = PortText.Text;
|
|
|
|
|
IP = IPText.Text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TableTimer_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!Server.State)
|
|
|
|
|
{
|
|
|
|
|
MonitorOnOff.Text = "启动监听";
|
|
|
|
|
MonitorState.Text = "关";
|
|
|
|
|
MonitorState.BackColor = Color.Yellow;
|
|
|
|
|
}
|
|
|
|
|
else if (Server.State)
|
|
|
|
|
{
|
|
|
|
|
MonitorOnOff.Text = "关闭监听";
|
|
|
|
|
MonitorState.Text = "开";
|
|
|
|
|
MonitorState.BackColor = Color.LightGreen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RFIDData.GetData();
|
|
|
|
|
|
|
|
|
|
IPs = RFIDData.GetAllIP();
|
|
|
|
|
bs.DataSource = IPs;
|
|
|
|
|
bs.ResetBindings(false);
|
|
|
|
|
|
|
|
|
|
CotentData.DataSource = null;
|
|
|
|
|
switch (PageNo)
|
|
|
|
|
{
|
|
|
|
|
case 1: ContentPages(0); PageRange.Text = "0 - 50"; break;
|
|
|
|
|
case 2: ContentPages(50); PageRange.Text = "51 - 100"; break;
|
|
|
|
|
case 3: ContentPages(100); PageRange.Text = "101 - 150"; break;
|
|
|
|
|
case 4: ContentPages(150); PageRange.Text = "151 - 200"; break;
|
|
|
|
|
default: ContentPages(0); PageRange.Text = "0 - 50"; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateRefresh();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RFIDSocket_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (Server.State)
|
|
|
|
|
{
|
|
|
|
|
if (!Server.ClientStop())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("监听服务关闭失败! 请成功关闭后再退出");
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
if (!Server.ClientDispose())
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("监听服务释放失败! 请再次尝试退出");
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StateRefresh()
|
|
|
|
|
{
|
|
|
|
|
if (RFIDData.HeartbeatsState.Where(x => x.IP == MonitorAddress.Text.ToString()).Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
ConnectPictureBox.Image = Properties.Resources.ConnectNormal;
|
|
|
|
|
ConnectState.Text = "正常";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ConnectPictureBox.Image = Properties.Resources.ConnectWarning;
|
|
|
|
|
ConnectState.Text = "异常";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (RFIDData.AlarmState.Where(x => x.IP == MonitorAddress.Text.ToString()).Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
DevicePictureBox.Image = Properties.Resources.ConnectNormal;
|
|
|
|
|
DeviceState.Text = "正常";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DevicePictureBox.Image = Properties.Resources.ConnectWarning;
|
|
|
|
|
DeviceState.Text = "异常";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TotalCount.Text = Content.Count.ToString();
|
|
|
|
|
NormalCount.Text = Content.Where(x => x.Tips == "ok").Count().ToString();
|
|
|
|
|
WarningCount.Text = Content.Where(x => x.Tips != "ok").Count().ToString();
|
|
|
|
|
NoReadCount.Text = Content.Where(x => x.Tips == "noread").Count().ToString();
|
|
|
|
|
NearCount.Text = Content.Where(x => x.Tips == "near").Count().ToString();
|
|
|
|
|
ShortCount.Text = Content.Where(x => x.Tips == "short").Count().ToString();
|
|
|
|
|
MultiCount.Text = Content.Where(x => x.Tips == "multi").Count().ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ContentPages(int skip)
|
|
|
|
|
{
|
|
|
|
|
Content = RFIDData.rFIDContents.Where(x => x.IP == MonitorAddress.Text.ToString()).Reverse<RFIDContent>().Take(200).ToList();
|
|
|
|
|
CotentData.DataSource = Content.Skip(skip).Take(50).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PgUp_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(PageNo == 1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("已经是首页!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PageNo--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PgDn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (PageNo == 4)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("已经是尾页!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PageNo++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LogStart_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RFIDLog rFIDLog = new RFIDLog();
|
|
|
|
|
rFIDLog.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|