|
|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
|
using GalaSoft.MvvmLight;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using NVelocity.Runtime.Directive;
|
|
|
|
|
using Serilog;
|
|
|
|
|
using SlnMesnac.Common;
|
|
|
|
|
using SlnMesnac.Config;
|
|
|
|
|
@ -25,6 +26,7 @@ using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
@ -53,6 +55,10 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
|
|
|
|
|
private ObservableCollection<RFIDRecord> _rfidHistoryRecords = new ObservableCollection<RFIDRecord>();
|
|
|
|
|
private RealReadDataImpl databaseService = RealReadDataImpl.Instance;
|
|
|
|
|
|
|
|
|
|
private bool IsVerify = false;
|
|
|
|
|
private string LastWrite;
|
|
|
|
|
private string LastRFIDEPC;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<RFIDRecord> RFIDHistoryRecords
|
|
|
|
|
{
|
|
|
|
|
get { return _rfidHistoryRecords; }
|
|
|
|
|
@ -63,6 +69,20 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ChangeTypeViewModel ChangeTypeView;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<Real_DataInfo> _Deviceinfo = new ObservableCollection<Real_DataInfo>();
|
|
|
|
|
public ObservableCollection<Real_DataInfo> Deviceinfo
|
|
|
|
|
{
|
|
|
|
|
get { return _Deviceinfo; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_Deviceinfo = value;
|
|
|
|
|
RaisePropertyChanged(() => Deviceinfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 日期时间
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -275,85 +295,118 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).OrderNo))
|
|
|
|
|
//二次验证
|
|
|
|
|
if (IsVerify)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请先获取MES订单号!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//读到停止连续盘点
|
|
|
|
|
//bool stopflag = await rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_StopIdentify();
|
|
|
|
|
//查询数据库是否已存在记录
|
|
|
|
|
|
|
|
|
|
string epcascii = Encoding.ASCII.GetString(tagInfos[0].EPC);
|
|
|
|
|
epcascii = epcascii.Replace("\0", "");
|
|
|
|
|
List<real_readdata> real_Readdatas = databaseService._helper.Query(x => x.rfidascii == epcascii);
|
|
|
|
|
|
|
|
|
|
//如果不存在则写入
|
|
|
|
|
if (real_Readdatas.Count <= 0)
|
|
|
|
|
//if (true)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo))
|
|
|
|
|
IsVerify = false;
|
|
|
|
|
//二次验证如果不通过
|
|
|
|
|
var judgeString = Encoding.ASCII.GetString(tagInfos[0].EPC);
|
|
|
|
|
judgeString = judgeString.Replace("\0", "");
|
|
|
|
|
if (judgeString != LastWrite)
|
|
|
|
|
{
|
|
|
|
|
rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_BeginIdentify().GetAwaiter().GetResult();
|
|
|
|
|
CurrentState = "盘点中";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).ReadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
//拼接订单号写入标签
|
|
|
|
|
string WriteData = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).OrderNo
|
|
|
|
|
+ Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).LineNo
|
|
|
|
|
+ DateTime.Now.ToString("yy")
|
|
|
|
|
+ Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).NextProductNo
|
|
|
|
|
+ Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo;
|
|
|
|
|
CurrentState = "写入中";
|
|
|
|
|
//写入 三次重写
|
|
|
|
|
bool writeflag = await rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_Write(tagInfos[0].EPC, WriteData);
|
|
|
|
|
if (!writeflag)
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"第一次写入失败,重试中...");
|
|
|
|
|
writeflag = await rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_Write(tagInfos[0].EPC, WriteData);
|
|
|
|
|
Log.Information($"验证成功");
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteStatus = "成功";
|
|
|
|
|
LastWriteState = "成功";
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidASCII = LastWrite;
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidEPC = LastRFIDEPC;
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo = (Convert.ToInt32(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo) + 1).ToString("D2");
|
|
|
|
|
//保存写入记录
|
|
|
|
|
real_readdata real_Readdata = new real_readdata()
|
|
|
|
|
{
|
|
|
|
|
objid = Guid.NewGuid().ToString(),
|
|
|
|
|
serialno = (Convert.ToInt32(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo) - 1).ToString("D2"),
|
|
|
|
|
orderno = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).OrderNo,
|
|
|
|
|
lineno = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).LineNo,
|
|
|
|
|
producttype = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).ProductType,
|
|
|
|
|
rfidepc = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidEPC,
|
|
|
|
|
rfidascii = LastWrite,
|
|
|
|
|
readtime = Convert.ToDateTime(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).ReadTime),
|
|
|
|
|
writetime = Convert.ToDateTime(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteTime),
|
|
|
|
|
writestatus = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteStatus
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var a = databaseService._helper.Insert(real_Readdata);
|
|
|
|
|
AddRFIDData(iCombineId, tagInfos);
|
|
|
|
|
|
|
|
|
|
rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_BeginIdentify().GetAwaiter().GetResult();
|
|
|
|
|
CurrentState = "盘点中";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else //正常写入
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).OrderNo))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请先获取MES订单号!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//读到停止连续盘点
|
|
|
|
|
//bool stopflag = await rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_StopIdentify();
|
|
|
|
|
//查询数据库是否已存在记录
|
|
|
|
|
|
|
|
|
|
string epcascii = Encoding.ASCII.GetString(tagInfos[0].EPC);
|
|
|
|
|
epcascii = epcascii.Replace("\0", "");
|
|
|
|
|
List<real_readdata> real_Readdatas = databaseService._helper.Query(x => x.rfidascii == epcascii);
|
|
|
|
|
|
|
|
|
|
//如果不存在则写入
|
|
|
|
|
if (real_Readdatas.Count <= 0)
|
|
|
|
|
//if (true)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).ReadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
//拼接订单号写入标签
|
|
|
|
|
string WriteData = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).OrderNo
|
|
|
|
|
+ Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).LineNo
|
|
|
|
|
+ DateTime.Now.ToString("yy")
|
|
|
|
|
+ Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).NextProductNo
|
|
|
|
|
+ Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo;
|
|
|
|
|
CurrentState = "写入中";
|
|
|
|
|
//写入 三次重写
|
|
|
|
|
bool writeflag = await rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_Write(tagInfos[0].EPC, WriteData);
|
|
|
|
|
if (!writeflag)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"第二次写入失败,重试中...");
|
|
|
|
|
Log.Error($"第一次写入失败,重试中...");
|
|
|
|
|
writeflag = await rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_Write(tagInfos[0].EPC, WriteData);
|
|
|
|
|
if (!writeflag)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"第三次写入失败,立即开始重新盘点");
|
|
|
|
|
LastWriteState = "失败";
|
|
|
|
|
rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_BeginIdentify().GetAwaiter().GetResult();
|
|
|
|
|
return;
|
|
|
|
|
Log.Error($"第二次写入失败,重试中...");
|
|
|
|
|
writeflag = await rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_Write(tagInfos[0].EPC, WriteData);
|
|
|
|
|
if (!writeflag)
|
|
|
|
|
{
|
|
|
|
|
Log.Error($"第三次写入失败,立即开始重新盘点");
|
|
|
|
|
LastWriteState = "失败";
|
|
|
|
|
rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_BeginIdentify().GetAwaiter().GetResult();
|
|
|
|
|
CurrentState = "盘点中";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LastWrite = WriteData;
|
|
|
|
|
LastRFIDEPC = tagInfos[0].EPCstring;
|
|
|
|
|
IsVerify = true;
|
|
|
|
|
rfidList.FirstOrDefault(x => x.deviceid == iCombineId).Set_BeginIdentify().GetAwaiter().GetResult();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteStatus = "成功";
|
|
|
|
|
LastWriteState = "成功";
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidASCII = WriteData;
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidEPC = tagInfos[0].EPCstring;
|
|
|
|
|
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo = (Convert.ToInt32(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo) + 1).ToString("D2");
|
|
|
|
|
//保存写入记录
|
|
|
|
|
real_readdata real_Readdata = new real_readdata()
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
objid = Guid.NewGuid().ToString(),
|
|
|
|
|
serialno = (Convert.ToInt32(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).SerialNo) - 1).ToString("D2"),
|
|
|
|
|
orderno = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).OrderNo,
|
|
|
|
|
lineno = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).LineNo,
|
|
|
|
|
producttype = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).ProductType,
|
|
|
|
|
rfidepc = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidEPC,
|
|
|
|
|
rfidascii = WriteData,
|
|
|
|
|
readtime = Convert.ToDateTime(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).ReadTime),
|
|
|
|
|
writetime = Convert.ToDateTime(Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteTime),
|
|
|
|
|
writestatus = Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).WriteStatus
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var a = databaseService._helper.Insert(real_Readdata);
|
|
|
|
|
AddRFIDData(iCombineId, tagInfos);
|
|
|
|
|
await Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(1000);
|
|
|
|
|
await rfidList.FirstOrDefault(x => x.deviceid == iCombineId)!.Set_BeginIdentify();
|
|
|
|
|
CurrentState = "盘点中";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(1000);
|
|
|
|
|
await rfidList.FirstOrDefault(x => x.deviceid == iCombineId)!.Set_BeginIdentify();
|
|
|
|
|
CurrentState = "盘点中";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
@ -362,6 +415,14 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Writes data to an RFID tag
|
|
|
|
|
/// </summary>
|
|
|
|
|
private async void WriteRFID(string iCombineId, List<TagInfo> tagInfos)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RefreshEventArgs(string iCombineId, List<TagInfo> tagInfos)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
@ -403,18 +464,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
|
|
|
|
|
//RFIDHistoryRecords.OrderByDescending(x => x.ReadTime).ToList();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<Real_DataInfo> _Deviceinfo = new ObservableCollection<Real_DataInfo>();
|
|
|
|
|
public ObservableCollection<Real_DataInfo> Deviceinfo
|
|
|
|
|
{
|
|
|
|
|
get { return _Deviceinfo; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_Deviceinfo = value;
|
|
|
|
|
RaisePropertyChanged(() => Deviceinfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void StartCheckStatus()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
|