add-配方修改界面

master
liuwf 5 months ago
parent 9017d80757
commit deaccc01ee

@ -139,8 +139,27 @@ namespace SlnMesnac.Business
// 海康校验结果
bool hikFlag = false;
if (logoConfig.IsChecked == 1)
if (logoConfig.IsChecked == 0)
{
// 不需要校验
hikFlag = true;
RefreshMessageEvent?.Invoke("LOGO+PCI无需识别下发放行");
logger.LogInformation($"箱体码:{materialCodeStr}Logo无需识别下发放行");
}
else
{
// 需要检验但是还没设置配方
if(logoConfig.CheckKind == 0)
{
// 不需要校验
hikFlag = false;
Warning($"箱体码:{materialCodeStr}LOGO+PCI需要识别但是未设置PCI模版");
}
else
{
#region 拍照处理流程
Thread.Sleep(int.Parse(config.SleepStr));
// 1.触发相机拍照
tcpServer.SendCommand(config.CameraIP, logoConfig.CheckKind.ToString());
@ -159,30 +178,17 @@ namespace SlnMesnac.Business
//校验失败禁止放行
WarningAndStop($"LOGO+PCI识别失败禁止放行");
}
#endregion
}
else
{
// 不需要校验
hikFlag = true;
RefreshMessageEvent?.Invoke("LOGO+PCI无需识别下发放行");
logger.LogInformation($"箱体码:{materialCodeStr}Logo无需识别下发放行");
}
#region 更新数据库
LogoIdentify record = new LogoIdentify();
record.ProductCode = materialCodeStr;
record.MaterialType = logoConfig.MaterialType;
record.MaterialName = logoConfig.MaterialName;
record.isChecked = logoConfig.IsChecked;
record.Result = hikFlag ? 1 : 0;
record.RecordTime = DateTime.Now;
logoIdentifyService.InsertRecord(record);
#endregion
// 刷新界面、刷新图片,照片按照日期存储本地
RefreshBoxInfoEvent?.Invoke(materialCodeStr, DateTime.Now.ToString(), logoConfig.MaterialName, hikFlag);
//需要检测并且设置过配方的条码等待照片
if(logoConfig.IsChecked == 1 && logoConfig.CheckKind != 0)
{
await Task.Run(() =>
{
Thread.Sleep(int.Parse(config.PictureSleep));
@ -200,11 +206,24 @@ namespace SlnMesnac.Business
}
});
}
#region 更新数据库
LogoIdentify record = new LogoIdentify();
record.ProductCode = materialCodeStr;
record.MaterialType = logoConfig.MaterialType;
record.MaterialName = logoConfig.MaterialName;
record.isChecked = logoConfig.IsChecked;
record.Result = hikFlag ? 1 : 0;
record.RecordTime = DateTime.Now;
logoIdentifyService.InsertRecord(record);
#endregion
}
catch (Exception ex)
{
WarningAndStop($"BarCodeHandler异常,识别Logo失败,原因:{ex.Message},箱体条码:{materialCodeStr}");
Warning($"BarCodeHandler异常,识别Logo失败,原因:{ex.Message},箱体条码:{materialCodeStr}");
}
}

@ -19,6 +19,7 @@ namespace SlnMesnac.WPF.ViewModel
{
private ILogoFormulaService? formulaService;
public FormulaWindowViewModel()
{
formulaService = App.ServiceProvider.GetService<ILogoFormulaService>();

@ -1,20 +1,90 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace SlnMesnac.WPF.ViewModel
{
public class SetKindWindowViewModel : ObservableObject
{
private ILogoFormulaService? formulaService;
private ILogoConfigService? logoConfigService;
private string CachMaterialType;
// 缓存第一次查到的海康配方
public Dictionary<string, int> TypeCache = new Dictionary<string, int>();
public LogoConfig record = null;
public delegate void SetKindWindowDelegate();
public SetKindWindowViewModel(string materialType)
{
MaterialType = materialType;
formulaService = App.ServiceProvider.GetService<ILogoFormulaService>();
logoConfigService = App.ServiceProvider.GetService<ILogoConfigService>();
SaveCommand = new RelayCommand(Save);
// 初始加载内容
Init(materialType);
}
public void Init(string materialType)
{
record = logoConfigService.GetByMaterialType(materialType);
if (record == null) return;
MaterialType = record.MaterialName;
IsDetectionChecked = record.IsChecked == 0 ? false : true;
List<LogoFormula> list = formulaService.GetListAsync().Result;
if(list!=null && list.Count > 0)
{
foreach (var item in list)
{
MaterialTypes.Add(item.Value);
TypeCache.Add(item.Value, item.Key);
}
}
}
public void Save()
{
if (string.IsNullOrEmpty(_selectedMaterialType) && IsDetectionChecked)
{
MessageBox.Show("请选择型号");
return;
}
if (!string.IsNullOrEmpty(_selectedMaterialType)){
//需要检测
string select = _selectedMaterialType;
TypeCache.TryGetValue(select, out int key);
record.CheckKind = key;
}
#region 修改配方
if (record != null)
{
record.IsChecked = IsDetectionChecked ? 1 : 0;
if(record.IsChecked == 0)
{
// 不检测复位0
record.CheckKind = 0;
}
logoConfigService.updateByMaterialType(record);
}
#endregion
MessageBox.Show("修改完成");
}
#region 属性
/// <summary>
@ -37,7 +107,35 @@ namespace SlnMesnac.WPF.ViewModel
set { _IsDetectionChecked = value; RaisePropertyChanged(); }
}
private string _selectedMaterialType;
public string SelectedMaterialType
{
get { return _selectedMaterialType; }
set
{
_selectedMaterialType = value;
RaisePropertyChanged();
// 可以在这里处理选中项变化后的逻辑
}
}
/// <summary>
/// 下拉框集合
/// </summary>
private ObservableCollection<string> _materialTypes = new ObservableCollection<string>();
public ObservableCollection<string> MaterialTypes
{
get { return _materialTypes; }
set
{
_materialTypes = value;
RaisePropertyChanged();
}
}
#endregion
public RelayCommand SaveCommand { get; set; }
}
}

@ -77,7 +77,7 @@
<StackPanel Grid.Row="0" Background="#1157b9" Margin="1,1,5,5" Orientation="Horizontal" >
<TextBlock Text="型号:" FontSize="20" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="100 0 0 0"/>
<TextBox IsReadOnly="True" Text="{Binding MaterialType}" FontSize="20" Width="200" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" Margin="10 0 0 0"/>
<TextBox IsReadOnly="True" Text="{Binding MaterialType}" FontSize="20" Width="241" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" Margin="10 0 0 0"/>
</StackPanel>
<StackPanel Grid.Row="1" Background="#1157b9" Margin="1,1,5,5" Orientation="Horizontal">
<TextBlock Text="是否检测:" FontSize="20" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="100 0 0 0"/>
@ -86,8 +86,8 @@
<RadioButton Foreground="White" Content="否" GroupName="DetectionOptions" IsChecked="{Binding IsDetectionChecked, Converter={StaticResource InverseBooleanConverter}, Mode=TwoWay}" VerticalAlignment="Center" Margin="10 0 0 0"/>
</StackPanel>
<StackPanel Grid.Row="2" Background="#1157b9" Margin="1,1,5,5" Orientation="Horizontal" >
<TextBlock Text="识别类型:" FontSize="20" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="100 0 0 0"/>
<TextBox Text="{Binding MaterialType}" FontSize="20" Width="200" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" Margin="10 0 0 0"/>
<TextBlock Text="识别特征:" FontSize="20" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="100 0 0 0"/>
<ComboBox ItemsSource="{Binding MaterialTypes}" SelectedItem="{Binding SelectedMaterialType}" FontSize="20" Width="200" FontWeight="Bold" Foreground="Green" VerticalAlignment="Center" Margin="10 0 0 0"/>
</StackPanel>
<Border Grid.Row="3" Background="#1157b9" Margin="1,1,5,5" >
<Button Content="保 存" Command="{Binding SaveCommand}" Width="80"

@ -25,6 +25,10 @@ namespace SlnMesnac.WPF.Views
{
InitializeComponent();
this.DataContext = new StatisticsPageViewModel();
//BeginTime.SelectedDate = DateTime.Today.Date;
//EndTime.SelectedDate = DateTime.Today.Date.AddDays(1);
}
//在载入行的时候在行表头添加编号
private void dgvMH_LoadingRow(object sender, DataGridRowEventArgs e)

@ -8,7 +8,7 @@
},
"AllowedHosts": "*",
"AppConfig": {
"logPath": "E:\\桌面\\SlnMesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows",
"logPath": "E:\\c#\\Logo\\slnmesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows",
"SqlConfig": [
{
"configId": "AUCMA_Local",
@ -55,7 +55,7 @@
"equipKey": "test2",
"isFlage": false
}
],
]
//"ScannerConfig": [
// {
// "Id": 1,

Loading…
Cancel
Save