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.
279 lines
9.1 KiB
C#
279 lines
9.1 KiB
C#
using HighWayIot.Repository.domain;
|
|
using HighWayIot.Repository.service.Impl;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Windows.Forms;
|
|
|
|
namespace RFIDSocket
|
|
{
|
|
public partial class RFIDLog : Form
|
|
{
|
|
|
|
List<RFIDContent> rFIDContents = new List<RFIDContent>();
|
|
BaseContentServiceImpl sql = new BaseContentServiceImpl();
|
|
public RFIDLog()
|
|
{
|
|
InitializeComponent();
|
|
StartTime.Value = DateTime.Now.AddDays(-3);
|
|
Dictionary<string, string> dict = new Dictionary<string, string>()
|
|
{
|
|
{ "", "" },
|
|
{ "正常", "GR" },
|
|
{ "无读", "NB" },
|
|
{ "多标签", "MR" },
|
|
};
|
|
BindingSource bs = new BindingSource();
|
|
bs.DataSource = dict;
|
|
ReadKind.DataSource = bs;
|
|
ReadKind.DisplayMember = "Key";
|
|
ReadKind.ValueMember = "Value";
|
|
txtPath.Text = Environment.CurrentDirectory.ToString();
|
|
Init();
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
rFIDContents = sql.GetContentInfos();
|
|
}
|
|
|
|
private void TimeSelect_Click(object sender, EventArgs e)
|
|
{
|
|
if (LogContent != null)
|
|
{
|
|
var list = LogControl.LogTimeSelect(rFIDContents, StartTime.Value, EndTime.Value);
|
|
LogContent.DataSource = null;
|
|
LogContent.DataSource = ServerDataAnalysis.ChangeReadResult(list);
|
|
NumCount(list);
|
|
}
|
|
}
|
|
|
|
private void ReadKindSelect_Click(object sender, EventArgs e)
|
|
{
|
|
if (LogContent != null)
|
|
{
|
|
var list = LogControl.LogReadKindSelect(rFIDContents, ReadKind.SelectedValue.ToString());
|
|
LogContent.DataSource = null;
|
|
LogContent.DataSource = ServerDataAnalysis.ChangeReadResult(list);
|
|
NumCount(list);
|
|
}
|
|
}
|
|
|
|
private void DeviceNoSelect_Click(object sender, EventArgs e)
|
|
{
|
|
int no;
|
|
if (string.IsNullOrEmpty(DeviceNo.Text))
|
|
{
|
|
no = -1;
|
|
goto next;
|
|
}
|
|
if(!int.TryParse(DeviceNo.Text, out no))
|
|
{
|
|
MessageBox.Show("设备编号格式不正确");
|
|
return;
|
|
}
|
|
next:
|
|
if (LogContent != null)
|
|
{
|
|
|
|
var list = LogControl.LogDeviceNoSelect(rFIDContents, no);
|
|
LogContent.DataSource = null;
|
|
LogContent.DataSource = ServerDataAnalysis.ChangeReadResult(list);
|
|
NumCount(list);
|
|
}
|
|
}
|
|
|
|
private void ContentSelect_Click(object sender, EventArgs e)
|
|
{
|
|
if (LogContent != null)
|
|
{
|
|
var list = LogControl.LogContentSelect(rFIDContents, Content.Text);
|
|
LogContent.DataSource = null;
|
|
LogContent.DataSource = ServerDataAnalysis.ChangeReadResult(list);
|
|
NumCount(list);
|
|
}
|
|
}
|
|
|
|
private void SelectAll_Click(object sender, EventArgs e)
|
|
{
|
|
int no;
|
|
if (string.IsNullOrEmpty(DeviceNo.Text))
|
|
{
|
|
no = -1;
|
|
goto next;
|
|
}
|
|
if (!int.TryParse(DeviceNo.Text, out no))
|
|
{
|
|
MessageBox.Show("设备编号格式不正确");
|
|
return;
|
|
}
|
|
next:
|
|
if (LogContent != null)
|
|
{
|
|
var list = LogControl.LogTimeSelect(
|
|
LogControl.LogReadKindSelect(
|
|
LogControl.LogDeviceNoSelect(
|
|
LogControl.LogContentSelect(rFIDContents,
|
|
Content.Text),
|
|
no),
|
|
ReadKind.SelectedValue.ToString()),
|
|
StartTime.Value, EndTime.Value);
|
|
LogContent.DataSource = null;
|
|
LogContent.DataSource = ServerDataAnalysis.ChangeReadResult(list);
|
|
NumCount(list);
|
|
}
|
|
}
|
|
|
|
private void NumCount(List<RFIDContent> list)
|
|
{
|
|
int normalCount = list.Where(x => x.ReadKind == "正常").Count();
|
|
int totalCount = list.Count();
|
|
|
|
TotalReadCount.Text = totalCount.ToString();
|
|
NormalReadNum.Text = normalCount.ToString();
|
|
ErrorReadNum.Text = (totalCount - normalCount).ToString();
|
|
|
|
//算比例
|
|
float percent = (float)normalCount / (float)list.Count;
|
|
percent *= 100f;
|
|
|
|
ReadSuccessPercent.Text = $"%{percent}";
|
|
|
|
rFIDContents = sql.GetContentInfos();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询内容导出Excel
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ExcelOutPut_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
|
|
// 列强制转换
|
|
for (int count = 0; count < LogContent.Columns.Count; count++)
|
|
{
|
|
DataColumn dc = new DataColumn(LogContent.Columns[count].HeaderText.ToString());
|
|
dt.Columns.Add(dc);
|
|
}
|
|
|
|
// 循环行
|
|
for (int count = 0; count < LogContent.Rows.Count; count++)
|
|
{
|
|
DataRow dr = dt.NewRow();
|
|
for (int countsub = 0; countsub < LogContent.Columns.Count; countsub++)
|
|
{
|
|
dr[countsub] = $"{Convert.ToString(LogContent.Rows[count].Cells[countsub].Value)} ";
|
|
}
|
|
dt.Rows.Add(dr);
|
|
}
|
|
ExportExcel(dt);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 全部内容导出Excel
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
var data = sql.GetContentInfos();
|
|
dt.Columns.Add("ID", typeof(string));
|
|
dt.Columns.Add("格口编号", typeof(string));
|
|
dt.Columns.Add("状态码", typeof(string));
|
|
dt.Columns.Add("读取内容", typeof(string));
|
|
dt.Columns.Add("读取时间", typeof(string));
|
|
|
|
foreach(var d in data)
|
|
{
|
|
dt.Rows.Add(d.ID.ToString(), d.DeviceNo.ToString(), d.ReadKind, $"{d.Content} ", d.LogTime.ToString());
|
|
}
|
|
ExportExcel(dt);
|
|
}
|
|
|
|
public void ExportExcel(DataTable dt)
|
|
{
|
|
//设置导出文件路径
|
|
string path = txtPath.Text;
|
|
|
|
//设置新建文件路径及名称
|
|
string savePath = $"{path}{DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")}.xls";
|
|
|
|
//创建文件
|
|
FileStream file = new FileStream(savePath, FileMode.CreateNew, FileAccess.Write);
|
|
|
|
//以指定的字符编码向指定的流写入字符
|
|
StreamWriter sw = new StreamWriter(file, Encoding.GetEncoding("GB2312"));
|
|
|
|
StringBuilder strbu = new StringBuilder();
|
|
try
|
|
{
|
|
//写入标题
|
|
for (int i = 0; i < dt.Columns.Count; i++)
|
|
{
|
|
strbu.Append(dt.Columns[i].ColumnName.ToString() + "\t");
|
|
}
|
|
//加入换行字符串
|
|
strbu.Append(Environment.NewLine);
|
|
|
|
//写入内容
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
for (int j = 0; j < dt.Columns.Count; j++)
|
|
{
|
|
strbu.Append(dt.Rows[i][j].ToString() + "\t");
|
|
}
|
|
strbu.Append(Environment.NewLine);
|
|
}
|
|
|
|
sw.Write(strbu.ToString());
|
|
sw.Flush();
|
|
file.Flush();
|
|
|
|
sw.Close();
|
|
sw.Dispose();
|
|
|
|
file.Close();
|
|
file.Dispose();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
MessageBox.Show($"导出文件发生错误{ex.Message}");
|
|
sw.Close();
|
|
sw.Dispose();
|
|
|
|
file.Close();
|
|
file.Dispose();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 文件路径选择
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void label2_Click(object sender, EventArgs e)
|
|
{
|
|
folderBrowserDialog1.Description = "请选择文件夹";
|
|
folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer;
|
|
folderBrowserDialog1.ShowNewFolderButton = true;
|
|
if (txtPath.Text.Length > 0) folderBrowserDialog1.SelectedPath = txtPath.Text;
|
|
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
txtPath.Text = folderBrowserDialog1.SelectedPath;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|