From deaccc01ee866e26bac1392dee436839ec68d44a Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 26 Jun 2024 23:15:00 +0800 Subject: [PATCH] =?UTF-8?q?add-=E9=85=8D=E6=96=B9=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Business/LogoBusiness.cs | 97 ++++++++++------- .../ViewModel/FormulaWindowViewModel.cs | 1 + .../ViewModel/SetKindWindowViewModel.cs | 100 +++++++++++++++++- SlnMesnac.WPF/Views/SetKindWindow.xaml | 6 +- .../Views/StatisticsPageView.xaml.cs | 4 + SlnMesnac.WPF/appsettings.json | 6 +- 6 files changed, 168 insertions(+), 46 deletions(-) diff --git a/SlnMesnac.Business/LogoBusiness.cs b/SlnMesnac.Business/LogoBusiness.cs index 3ce0fa7..446fcea 100644 --- a/SlnMesnac.Business/LogoBusiness.cs +++ b/SlnMesnac.Business/LogoBusiness.cs @@ -139,34 +139,73 @@ namespace SlnMesnac.Business // 海康校验结果 bool hikFlag = false; - if (logoConfig.IsChecked == 1) + if (logoConfig.IsChecked == 0) { - Thread.Sleep(int.Parse(config.SleepStr)); - // 1.触发相机拍照 - tcpServer.SendCommand(config.CameraIP, logoConfig.CheckKind.ToString()); - // 需要校验 - // 2.等待接收海康结果 - hikFlag = await JudgeIsSuccessAsync(); - if (hikFlag) + // 不需要校验 + hikFlag = true; + + RefreshMessageEvent?.Invoke("LOGO+PCI无需识别,下发放行"); + logger.LogInformation($"箱体码:{materialCodeStr},Logo无需识别,下发放行"); + } + else + { + // 需要检验但是还没设置配方 + if(logoConfig.CheckKind == 0) { - //校验成功放行 + // 不需要校验 + hikFlag = false; - RefreshMessageEvent?.Invoke("LOGO+PCI识别成功,下发放行"); - logger.LogInformation($"箱体码:{materialCodeStr},Logo识别成功,下发放行"); + Warning($"箱体码:{materialCodeStr},LOGO+PCI需要识别,但是未设置PCI模版"); } else { - //校验失败禁止放行 - WarningAndStop($"LOGO+PCI识别失败,禁止放行"); + #region 拍照处理流程 + Thread.Sleep(int.Parse(config.SleepStr)); + // 1.触发相机拍照 + tcpServer.SendCommand(config.CameraIP, logoConfig.CheckKind.ToString()); + // 需要校验 + // 2.等待接收海康结果 + hikFlag = await JudgeIsSuccessAsync(); + if (hikFlag) + { + //校验成功放行 + + RefreshMessageEvent?.Invoke("LOGO+PCI识别成功,下发放行"); + logger.LogInformation($"箱体码:{materialCodeStr},Logo识别成功,下发放行"); + } + else + { + //校验失败禁止放行 + WarningAndStop($"LOGO+PCI识别失败,禁止放行"); + } + #endregion } } - else + + + // 刷新界面、刷新图片,照片按照日期存储本地 + RefreshBoxInfoEvent?.Invoke(materialCodeStr, DateTime.Now.ToString(), logoConfig.MaterialName, hikFlag); + + //需要检测并且设置过配方的条码等待照片 + if(logoConfig.IsChecked == 1 && logoConfig.CheckKind != 0) { - // 不需要校验 - hikFlag = true; + await Task.Run(() => + { + Thread.Sleep(int.Parse(config.PictureSleep)); + ImageData = FileHelper.FindPhoto(config.CameraFilePath); + if (ImageData != null) + { + // 图片压缩 + byte[] compressedImageData = FileHelper.CompressImageData(ImageData, 20); + FileHelper.SaveImage(compressedImageData, materialCodeStr + ".jpg", PicturePath); + RefreshPictureEvent?.Invoke(ImageData); + } + else + { + // WarningAndStop($"读取相机保存照片文件夹失败,请检查文件夹:{config.CameraFilePath}是否存在"); + } - RefreshMessageEvent?.Invoke("LOGO+PCI无需识别,下发放行"); - logger.LogInformation($"箱体码:{materialCodeStr},Logo无需识别,下发放行"); + }); } #region 更新数据库 @@ -180,31 +219,11 @@ namespace SlnMesnac.Business logoIdentifyService.InsertRecord(record); #endregion - // 刷新界面、刷新图片,照片按照日期存储本地 - RefreshBoxInfoEvent?.Invoke(materialCodeStr, DateTime.Now.ToString(), logoConfig.MaterialName, hikFlag); - - await Task.Run(() => - { - Thread.Sleep(int.Parse(config.PictureSleep)); - ImageData = FileHelper.FindPhoto(config.CameraFilePath); - if (ImageData != null) - { - // 图片压缩 - byte[] compressedImageData = FileHelper.CompressImageData(ImageData, 20); - FileHelper.SaveImage(compressedImageData, materialCodeStr + ".jpg", PicturePath); - RefreshPictureEvent?.Invoke(ImageData); - } - else - { - // WarningAndStop($"读取相机保存照片文件夹失败,请检查文件夹:{config.CameraFilePath}是否存在"); - } - - }); } catch (Exception ex) { - WarningAndStop($"BarCodeHandler异常,识别Logo失败,原因:{ex.Message},箱体条码:{materialCodeStr}"); + Warning($"BarCodeHandler异常,识别Logo失败,原因:{ex.Message},箱体条码:{materialCodeStr}"); } } diff --git a/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs index 3e56b82..d180e7e 100644 --- a/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs @@ -18,6 +18,7 @@ namespace SlnMesnac.WPF.ViewModel public class FormulaWindowViewModel : ObservableObject { private ILogoFormulaService? formulaService; + public FormulaWindowViewModel() { diff --git a/SlnMesnac.WPF/ViewModel/SetKindWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/SetKindWindowViewModel.cs index d7acf3f..ce50f6a 100644 --- a/SlnMesnac.WPF/ViewModel/SetKindWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/SetKindWindowViewModel.cs @@ -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 TypeCache = new Dictionary(); + public LogoConfig record = null; + + public delegate void SetKindWindowDelegate(); public SetKindWindowViewModel(string materialType) { - MaterialType = materialType; + formulaService = App.ServiceProvider.GetService(); + logoConfigService = App.ServiceProvider.GetService(); + 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 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 属性 /// @@ -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(); + // 可以在这里处理选中项变化后的逻辑 + } + } + /// + /// 下拉框集合 + /// + private ObservableCollection _materialTypes = new ObservableCollection(); + public ObservableCollection MaterialTypes + { + get { return _materialTypes; } + set + { + _materialTypes = value; + RaisePropertyChanged(); + } + } + #endregion + public RelayCommand SaveCommand { get; set; } } } diff --git a/SlnMesnac.WPF/Views/SetKindWindow.xaml b/SlnMesnac.WPF/Views/SetKindWindow.xaml index e84d7ff..0d8a8ed 100644 --- a/SlnMesnac.WPF/Views/SetKindWindow.xaml +++ b/SlnMesnac.WPF/Views/SetKindWindow.xaml @@ -77,7 +77,7 @@ - + @@ -86,8 +86,8 @@ - - + +