add-压缩后的照片保存到数据库

master
liuwf 5 months ago
parent deaccc01ee
commit 5bc34aa758

@ -54,6 +54,8 @@ namespace SlnMesnac.Business
public delegate void RefreshMessage(string message, bool isWarning = false); public delegate void RefreshMessage(string message, bool isWarning = false);
public static event RefreshMessage? RefreshMessageEvent; public static event RefreshMessage? RefreshMessageEvent;
public delegate void RefreshDataGrid();
public static event RefreshDataGrid? RefreshDataGridEvent;
#endregion #endregion
@ -111,6 +113,8 @@ namespace SlnMesnac.Business
Console.WriteLine("相机流程开始:"); Console.WriteLine("相机流程开始:");
// 传入照片 // 传入照片
byte[] ImageData = null; byte[] ImageData = null;
// 压缩后的图片
byte[] compressedImageData = null;
try try
{ {
#region 初始操作:复位海康上次结果,删除海康上次保存文件 #region 初始操作:复位海康上次结果,删除海康上次保存文件
@ -196,7 +200,7 @@ namespace SlnMesnac.Business
if (ImageData != null) if (ImageData != null)
{ {
// 图片压缩 // 图片压缩
byte[] compressedImageData = FileHelper.CompressImageData(ImageData, 20); compressedImageData = FileHelper.CompressImageData(ImageData, 20);
FileHelper.SaveImage(compressedImageData, materialCodeStr + ".jpg", PicturePath); FileHelper.SaveImage(compressedImageData, materialCodeStr + ".jpg", PicturePath);
RefreshPictureEvent?.Invoke(ImageData); RefreshPictureEvent?.Invoke(ImageData);
} }
@ -216,9 +220,13 @@ namespace SlnMesnac.Business
record.isChecked = logoConfig.IsChecked; record.isChecked = logoConfig.IsChecked;
record.Result = hikFlag ? 1 : 0; record.Result = hikFlag ? 1 : 0;
record.RecordTime = DateTime.Now; record.RecordTime = DateTime.Now;
if (compressedImageData != null)
{
record.Picture = compressedImageData;
}
logoIdentifyService.InsertRecord(record); logoIdentifyService.InsertRecord(record);
#endregion #endregion
RefreshDataGridEvent?.Invoke();
} }
catch (Exception ex) catch (Exception ex)

@ -52,7 +52,12 @@ namespace SlnMesnac.Model.domain
[SugarColumn(ColumnName = "RECORD_TIME")] [SugarColumn(ColumnName = "RECORD_TIME")]
public DateTime RecordTime { get; set; } public DateTime RecordTime { get; set; }
/// <summary>
/// 记录时间
/// </summary>
[SugarColumn(ColumnName = "PICTURE")]
public Byte[]? Picture { get; set; }
} }
} }

@ -15,8 +15,8 @@ namespace SlnMesnac.Repository.service
/// <returns></returns> /// <returns></returns>
Task<List<LogoIdentify>> GetAllRecordAsync(); Task<List<LogoIdentify>> GetAllRecordAsync();
/// <summary> /// <summary>
/// 时间段条件查询 /// 时间段条件查询

@ -17,6 +17,7 @@ using SqlSugar;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -54,6 +55,7 @@ namespace SlnMesnac.WPF.ViewModel
LogoBusiness.RefreshMessageEvent += RefreshMessage; LogoBusiness.RefreshMessageEvent += RefreshMessage;
LogoBusiness.RefreshBoxInfoEvent += RefreshBoxInfo; LogoBusiness.RefreshBoxInfoEvent += RefreshBoxInfo;
LogoBusiness.RefreshPictureEvent += RefreshPicture; LogoBusiness.RefreshPictureEvent += RefreshPicture;
LogoBusiness.RefreshDataGridEvent += RefreshDataGrid;
ResetCommand = new RelayCommand(Reset); ResetCommand = new RelayCommand(Reset);
RefreshDataGrid(); RefreshDataGrid();
@ -83,7 +85,7 @@ namespace SlnMesnac.WPF.ViewModel
logoBusiness.Pass(); logoBusiness.Pass();
} }
/// <summary> /// <summary>
/// 测试方法 /// 测试方法
/// </summary> /// </summary>
@ -148,9 +150,7 @@ namespace SlnMesnac.WPF.ViewModel
BoxCode = boxCode; BoxCode = boxCode;
BoxTime = boxTime; BoxTime = boxTime;
ProductModel = model; ProductModel = model;
RefreshResultColor(isSuccess); RefreshResultColor(isSuccess);
RefreshDataGrid();
if (!isSuccess) if (!isSuccess)
{ {
ImageData = null; ImageData = null;

Loading…
Cancel
Save