|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void InitAction()
|
|
|
|
|
{
|
|
|
|
|
ErrorCountDataGridView.AutoGenerateColumns = false;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 监视启停按钮
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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("监听服务关闭失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务端IP端口设置
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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端口号设置成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Timer刷新
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
int normalCount = RFIDData.rFIDContents.Where(x => x.ReadKind == "GR").Count();
|
|
|
|
|
int errorCount = RFIDData.rFIDContents.Where(x => x.ReadKind == "MR" || x.ReadKind == "NB").Count();
|
|
|
|
|
|
|
|
|
|
NormalReadNum.Text = normalCount.ToString();
|
|
|
|
|
ErrorReadNum.Text = errorCount.ToString();
|
|
|
|
|
|
|
|
|
|
//算比例
|
|
|
|
|
float percent = (float)normalCount / (float)RFIDData.rFIDContents.Count;
|
|
|
|
|
percent *= 100f;
|
|
|
|
|
|
|
|
|
|
ReadSuccessPercent.Text = $"%{percent}";
|
|
|
|
|
|
|
|
|
|
//展示格口号
|
|
|
|
|
string text = string.Empty;
|
|
|
|
|
List<int> list = new List<int>(); // 错误的设备编号
|
|
|
|
|
foreach (var entity in RFIDData.rFIDContents)
|
|
|
|
|
{
|
|
|
|
|
if (entity.ReadKind == "MR" || entity.ReadKind == "NB")
|
|
|
|
|
{
|
|
|
|
|
list.Add(entity.DeviceNo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var deviceNoGroup = list.GroupBy(x => x);
|
|
|
|
|
DataTable dataTable = new DataTable();
|
|
|
|
|
{
|
|
|
|
|
dataTable.Columns.Add("BinNo");
|
|
|
|
|
dataTable.Columns.Add("ErrorCount");
|
|
|
|
|
};
|
|
|
|
|
foreach (var data in deviceNoGroup)
|
|
|
|
|
{
|
|
|
|
|
int deviceNo = data.LastOrDefault();
|
|
|
|
|
int deviceErrorCount = data.Count();
|
|
|
|
|
dataTable.Rows.Add(deviceNo.ToString(), deviceErrorCount.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ErrorCountDataGridView.DataSource = null;
|
|
|
|
|
ErrorCountDataGridView.DataSource = dataTable;
|
|
|
|
|
|
|
|
|
|
ContentPages();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 窗口关闭
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新页面
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ContentPages()
|
|
|
|
|
{
|
|
|
|
|
var list = RFIDData.rFIDContents.Skip((PageNo - 1) * 50).Take(50).ToList();
|
|
|
|
|
CotentData.DataSource = null;
|
|
|
|
|
CotentData.DataSource = ServerDataAnalysis.ChangeReadResult(list);
|
|
|
|
|
PageRange.Text = $"{((PageNo - 1) * 50) + 1} - {PageNo * 50}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下一页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void PgUp_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (PageNo == 1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("已经是首页!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PageNo--;
|
|
|
|
|
ContentPages();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上一页
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void PgDn_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (PageNo == 4)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("已经是尾页!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
PageNo++;
|
|
|
|
|
ContentPages();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 日志界面
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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("设备异常清除失败");
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 格口盘点界面
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void BinAudlt_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RFIDBinAudlt form = new RFIDBinAudlt();
|
|
|
|
|
form.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|