refactor - 切换分支

read_card
SoulStar 6 days ago
parent 154fd0ebfb
commit 6eef9f7760

@ -22,7 +22,7 @@ namespace SlnMesnac.Repository
/// Nullable:False
/// </summary>
[PrimaryKey]
public int objid { get; set; }
public string objid { get; set; }
/// <summary>
/// Desc:
@ -38,6 +38,13 @@ namespace SlnMesnac.Repository
/// </summary>
public string lineno { get; set; }
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public string bindno { get; set; }
/// <summary>
/// Desc:
/// Default:

@ -189,6 +189,9 @@ namespace SlnMesnac.WPF.Model
}
}
/// <summary>
/// 带号
/// </summary>
private string _NextProductNo = "";
public string NextProductNo
{

@ -1,72 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.WPF.Model
{
public class RfidInfo : INotifyPropertyChanged
{
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public string Deviceid { get; set; } = null!;
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public string? Name { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public string? Connectstr { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public decimal? Connectmode { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public string? Devicetype { get; set; }
/// <summary>
/// 备 注:所属汇集软件ID
/// 默认值:
///</summary>
public string? Collectid { get; set; }
private string _isOnline ="未连接";
public string IsOnline
{
get { return _isOnline; }
set
{
if (_isOnline != value)
{
_isOnline = value;
OnPropertyChanged(nameof(IsOnline));
}
}
}
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

@ -1,92 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.WPF.Model
{
public class SenorInfo : INotifyPropertyChanged
{
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public string Sensorid { get; set; } = null!;
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public string Combineid { get; set; } = null!;
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public string? Name { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public decimal? Sensorser { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public decimal? Sensortypeid { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public string? Deviceid { get; set; }
/// <summary>
/// 备 注:
/// 默认值:
///</summary>
public decimal? Readinterval { get; set; }
private string _readtime;
public string Readtime
{
get { return _readtime; }
set
{
if (_readtime != value)
{
_readtime = value;
OnPropertyChanged(nameof(Readtime));
}
}
}
private string _readdata;
public string Readdata
{
get { return _readdata; }
set
{
if (_readdata != value)
{
_readdata = value;
OnPropertyChanged(nameof(Readdata));
}
}
}
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

@ -175,7 +175,6 @@
<DataGridTextColumn Binding="{Binding objid}" Header="序号" Width="0.5*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding orderno}" Header="订单号" Width="1.2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding lineno}" Header="产线号" Width="0.5*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding producttype}" Header="产品类型" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding rfidepc}" Header="原始EPC" Width="1.1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding rfidascii}" Header="RFID编码" Width="3*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding readtime,StringFormat=\{0:yyyy-MM-dd HH:mm:ss\}}" Header="读取时间" Width="1.5*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>

@ -200,21 +200,22 @@ Content="查询" Width="200" Visibility="Hidden" FontSize="20" Command="{Binding
<WrapPanel Orientation="Horizontal" ItemHeight="50">
<TextBlock Text="RFID写入列表" FontSize="15" VerticalAlignment="Center" Margin="10,0,0,0"/>
<Label Content="订单号:" FontSize="15" Foreground="Black" VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding MesOrderNo,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding OrderNo,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<Label Content="产线号:" FontSize="15" Foreground="Black" VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding MesOrderNo,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding LineNo,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<Label Content="带号:" FontSize="15" Foreground="Black" VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding MesOrderNo,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding BindNo,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<Label Content="写入数量:" FontSize="15" Foreground="Black" VerticalAlignment="Center" Margin="10,0,0,0"/>
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding MesOrderNo,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<TextBox IsReadOnly="False" IsEnabled="True" Text="{Binding WriteCount,Mode=TwoWay}" Width="100" Height="30" FontSize="15" Foreground="Black" Margin="0,0,0,0" />
<Button Content="生成编码" Width="100" Height="30" FontSize="15" Command="{Binding GenerateCodeCommand}" Background="#009999" Style="{StaticResource BUTTON_AGREE}" Margin="10,0,0,0"/>
<Button Content="清除数据" Width="100" Height="30" FontSize="15" Command="{Binding ListClearCommand}" Background="#009999" Style="{StaticResource BUTTON_AGREE}" Margin="10,0,0,0"/>
<Button Content="清除数据" Width="100" Height="30" FontSize="15" Command="{Binding AutoWriteCommand}" Background="#009999" Style="{StaticResource BUTTON_AGREE}" Margin="10,0,0,0"/>
</WrapPanel>
</Grid>
<!-- 数据表格绑定ViewModel中的历史记录 -->
<Grid Grid.Row="1">
<ScrollViewer VerticalScrollBarVisibility="Auto" Padding="0">
<DataGrid x:Name="PrePareWriteDataGrid" Grid.Row="0" ItemsSource="{Binding RFIDHistoryRecords}" Background="#00000000"
<DataGrid x:Name="PrePareWriteDataGrid" Grid.Row="0" ItemsSource="{Binding PrepareedWriteList}" Background="#00000000"
ColumnHeaderHeight="35" Height="{Binding Path=ActualHeight, ElementName=ScanPanel}"
RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0" FontSize="15"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto"
@ -233,7 +234,7 @@ Content="查询" Width="200" Visibility="Hidden" FontSize="20" Command="{Binding
<DataGridTemplateColumn Header="操作" Width="2*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="写入" Height="40" Width="100" Command="{Binding DataContext.UpdateCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
<Button Content="写入" Height="40" Width="100" Command="{Binding DataContext.WriteCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
CommandParameter="{Binding}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
@ -266,7 +267,7 @@ Content="查询" Width="200" Visibility="Hidden" FontSize="20" Command="{Binding
<!-- 数据表格绑定ViewModel中的历史记录 -->
<Grid Grid.Row="1">
<ScrollViewer VerticalScrollBarVisibility="Auto" Padding="0">
<DataGrid x:Name="senorlistDataGrid" Grid.Row="0" ItemsSource="{Binding RFIDHistoryRecords}" Background="#00000000"
<DataGrid x:Name="senorlistDataGrid" Grid.Row="0" ItemsSource="{Binding TempRecordList}" Background="#00000000"
ColumnHeaderHeight="35" Height="{Binding Path=ActualHeight, ElementName=ScanPanel}"
RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0" FontSize="15"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto"

@ -45,7 +45,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
public List<RfidAbsractFactory> rfidList;
private AppConfig appConfig;
private DispatcherTimer _timer;
private ObservableCollection<RFIDRecord> _rfidHistoryRecords = new ObservableCollection<RFIDRecord>();
private RealReadDataService dataService = RealReadDataService.Instance;
#region 关联属性
@ -61,13 +60,25 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
}
}
public ObservableCollection<RFIDRecord> RFIDHistoryRecords
private ObservableCollection<real_readdata> _preparedWriteList = new ObservableCollection<real_readdata>();
public ObservableCollection<real_readdata> PreparedWriteList
{
get { return _rfidHistoryRecords; }
get { return _preparedWriteList; }
set
{
_rfidHistoryRecords = value;
RaisePropertyChanged(() => RFIDHistoryRecords);
_preparedWriteList = value;
RaisePropertyChanged(() => PreparedWriteList);
}
}
private ObservableCollection<real_readdata> _tempRecordList = new ObservableCollection<real_readdata>();
public ObservableCollection<real_readdata> TempRecordList
{
get { return _tempRecordList; }
set
{
_tempRecordList = value;
RaisePropertyChanged(() => TempRecordList);
}
}
@ -122,15 +133,93 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
}
}
public RelayCommand<object> GetOrderInfoCommand { get; set; }
/// <summary>
/// 订单号
/// </summary>
private string _orderNo;
public string OrderNo
{
get => _orderNo;
set
{
if (_orderNo != value)
{
_orderNo = value;
RaisePropertyChanged(() => OrderNo);
}
}
}
/// <summary>
/// 产线号
/// </summary>
private string _lineNo;
public string LineNo
{
get => _lineNo;
set
{
if (_lineNo != value)
{
_lineNo = value;
RaisePropertyChanged(() => LineNo);
}
}
}
/// <summary>
/// 带号
/// </summary>
private string _bindNo;
public string BindNo
{
get => _bindNo;
set
{
if (_bindNo != value)
{
_bindNo = value;
RaisePropertyChanged(() => BindNo);
}
}
}
/// <summary>
/// 写入数量
/// </summary>
private string _writeCount;
public string WriteCount
{
get => _writeCount;
set
{
if (_writeCount != value)
{
_writeCount = value;
RaisePropertyChanged(() => WriteCount);
}
}
}
public RelayCommand<object> GenerateCodeCommand { get; set; }
public RelayCommand<object> ListClearCommand { get; set; }
public RelayCommand<object> HistoryClearCommand { get; set; }
public RelayCommand<object> HistoryPageCommand { get; set; }
public RelayCommand<object> AutoWriteCommand { get; set; }
public RelayCommand<object> RFIDWriteCommand { get; set; }
#endregion
public ProductionLineViewModel()
{
GetOrderInfoCommand = new RelayCommand<object>(t => RefreshData(t));
GenerateCodeCommand = new RelayCommand<object>(t => GenerateCode(t));
ListClearCommand = new RelayCommand<object>(t => ListClear(t));
HistoryClearCommand = new RelayCommand<object>(t => HistoryClear(t));
HistoryPageCommand = new RelayCommand<object>(t => HistoryPage(t));
AutoWriteCommand = new RelayCommand<object>(t => AutoWrite(t));
RFIDWriteCommand = new RelayCommand<object>(t => RFIDWrite(t));
// 构造函数里注册
WeakReferenceMessenger.Default.Register<Real_DataInfo>(this, RefreshOrderNo);
_StringChange = App.ServiceProvider.GetService<StringChange>();
_logger = App.ServiceProvider.GetService<SerilogHelper>();
appConfig = App.ServiceProvider.GetService<AppConfig>();
@ -141,7 +230,6 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
rfid._Action += RecvIdentifyData_Instance;
//rfid._RefreshLogMessageAction += RefreshLogMessage;
});
LoadDeviceInfo();
StartCheckStatus();
//GetRFIDHistoryRecords();
_currentDateTime = DateTime.Now;
@ -157,111 +245,78 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
Log.Information("RFID输送带系统启动");
}
private void RefreshData(object? t)
/// <summary>
/// 编码生成
/// </summary>
/// <param name="obj"></param>
private void GenerateCode(object obj)
{
Random random = new Random();
string ss = random.Next(10, 99).ToString();
string EPCstring = "JSSD" + ss;
List<TagInfo> tagInfos = new List<TagInfo>();
TagInfo tagInfo = new TagInfo()
PreparedWriteList.Clear();
if(!int.TryParse(WriteCount, out int count))
{
EPCstring = "JSSD" + ss,
EPC = Encoding.ASCII.GetBytes(EPCstring),
};
tagInfos.Add(tagInfo);
Deviceinfo.FirstOrDefault(x => x.Deviceid == "10001").RfidEPC = _StringChange.bytesToHexStr(tagInfos[0].EPC, tagInfos[0].EPC.Length);
Deviceinfo.FirstOrDefault(x => x.Deviceid == "10001").RfidASCII = EPCstring;
Deviceinfo.FirstOrDefault(x => x.Deviceid == "10001").WriteStatus = "成功";
Deviceinfo.FirstOrDefault(x => x.Deviceid == "10001").ReadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Deviceinfo.FirstOrDefault(x => x.Deviceid == "10001").WriteTime = DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd HH:mm:ss");
RecvIdentifyData_Instance("10001", tagInfos);
MessageBox.Show("请输入有效的写入数量!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
for(int i = 1; i <= count; i++)
{
PreparedWriteList.Add(new real_readdata()
{
objid = Guid.NewGuid().ToString(),
orderno = OrderNo,
lineno = LineNo,
bindno = BindNo,
serialno = i.ToString("D2"),
private void RefreshOrderNo(object recipient, Real_DataInfo real_Data)
{
//查询当前订单产线最大序列号
List<real_readdata> real_Readdatas = dataService.Helper.Query(x => x.orderno == real_Data.OrderNo && x.lineno == real_Data.LineNo);
string SNo = "";
if (real_Readdatas.Count > 0)
{
SNo = real_Readdatas.Max(x => x.serialno);
SNo = (Convert.ToInt32(SNo) + 1).ToString("D2");
}
else
{
SNo = "1";
}
Deviceinfo.FirstOrDefault(x => x.Deviceid == real_Data.Deviceid).SerialNo = Convert.ToInt32(SNo).ToString("D2");
Deviceinfo.FirstOrDefault(x => x.Deviceid == real_Data.Deviceid).OrderNo = real_Data.OrderNo;
Deviceinfo.FirstOrDefault(x => x.Deviceid == real_Data.Deviceid).ProductType = real_Data.ProductType;
Deviceinfo.FirstOrDefault(x => x.Deviceid == real_Data.Deviceid).LineNo = real_Data.LineNo;
Deviceinfo.FirstOrDefault(x => x.Deviceid == real_Data.Deviceid).RfidCount = real_Data.RfidCount;
Deviceinfo.FirstOrDefault(x => x.Deviceid == real_Data.Deviceid).NextProductNo = real_Data.NextProductNo;
rfidList.FirstOrDefault(x => x.deviceid == real_Data.Deviceid).Set_BeginIdentify().GetAwaiter().GetResult();
}
private void LoadDeviceInfo()
{
List<DeviceInfoConfig> DeviceInfos = appConfig.deviceInfoConfig.Where(x => x.Collectid == appConfig.StationCode && x.Deleteflag == 0).ToList();
List<Real_DataInfo> real_DataInfos = new List<Real_DataInfo>();
foreach (var item in DeviceInfos)
{
Real_DataInfo real_DataInfo = new Real_DataInfo()
{
Name = item.Name,
Deviceid = item.Deviceid,
Connectstr = item.Connectstr,
LineName = item.Name,
LineNo = item.Addr,
OrderNo = "",
ProductType = "",
WriteCount = "",
RfidCount = "",
IsOnline = "未连接",
RfidASCII = "",
RfidEPC = "",
ReadTime = "",
WriteTime = "",
ProductStatus = "",
WriteStatus = "",
};
real_DataInfos.Add(real_DataInfo);
}
App.Current.Dispatcher.Invoke(() =>
{
Deviceinfo.Clear();
foreach (var item in real_DataInfos)
{
Real_DataInfo real_DataInfo = new Real_DataInfo()
{
Name = item.Name,
Deviceid = item.Deviceid,
Connectstr = item.Connectstr,
LineName = item.Name,
LineNo = item.LineNo,
OrderNo = item.OrderNo,
ProductType = item.ProductType,
WriteCount = item.WriteCount,
RfidCount = item.RfidCount,
IsOnline = item.IsOnline,
RfidASCII = item.RfidASCII,
ReadTime = item.ReadTime,
WriteTime = item.WriteTime,
ProductStatus = item.ProductStatus,
WriteStatus = item.WriteStatus,
RfidEPC = item.RfidEPC,
};
Deviceinfo.Add(real_DataInfo);
}
});
}
}
/// <summary>
/// 清除生成编码数据
/// </summary>
/// <param name="obj"></param>
private void ListClear(object obj)
{
}
/// <summary>
/// 清除历史数据
/// </summary>
/// <param name="obj"></param>
private void HistoryClear(object obj)
{
}
/// <summary>
/// 历史记录页面
/// </summary>
/// <param name="obj"></param>
private void HistoryPage(object obj)
{
}
/// <summary>
/// 自动写入
/// </summary>
/// <param name="obj"></param>
private void AutoWrite(object obj)
{
}
/// <summary>
/// 自动写入
/// </summary>
/// <param name="obj"></param>
private void RFIDWrite(object obj)
{
}
/// <summary>
/// 接收到连续盘点标签返回
@ -362,23 +417,12 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
}
}
public void RefreshEventArgs(string iCombineId, List<TagInfo> tagInfos)
{
try
{
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidEPC = tagInfos[0].EPCstring;
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).RfidASCII = Encoding.ASCII.GetString(tagInfos[0].EPC);
Deviceinfo.FirstOrDefault(x => x.Deviceid == iCombineId).ReadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}));
}
catch (Exception ex)
{
Log.Information($"异常:{ex.Message}");
}
}
// 添加数据的方法(核心:添加前/后判断行数)
/// <summary>
/// 添加数据的方法(核心:添加前/后判断行数)
/// </summary>
/// <param name="iCombineId"></param>
/// <param name="tagInfos"></param>
public void AddRFIDData(string iCombineId, List<TagInfo> tagInfos)
{
//// 1. 判断当前行数是否>10是则清空
@ -404,6 +448,8 @@ namespace SlnMesnac.WPF.ViewModel.IndexPage
});
}
#region 心跳检测
private void StartCheckStatus()

Loading…
Cancel
Save