change-数据源由sqlite改为黄岛MES数据库;

add - 添加冰箱型号配置界面,界面数据展示
change-修改串口方法
master
liuwf 5 months ago
parent a05f3f0bc4
commit f8893916da

@ -52,6 +52,7 @@ namespace SlnMesnac.Business
plc= _plcPool.GetPlcByKey("plc");
}
@ -114,10 +115,10 @@ namespace SlnMesnac.Business
// TODO 回传MES信息
LogoIdentify record = new LogoIdentify();
record.BoxCode = materialCodeStr;
record.ProductModel = productName;
record.Result = flag ? "成功" : "失败";
record.RecordTime = DateTime.Now.ToString();
record.ProductCode = materialCodeStr;
record.MaterialName = productName;
record.Result = flag ? 1 : 0;
record.RecordTime = DateTime.Now;
logoIdentifyService.InsertRecord(record);
#endregion
// TODO , 传入照片

@ -1,148 +1,124 @@
//using Microsoft.Extensions.DependencyInjection;
//using System;
//using System.Collections.Generic;
//using System.IO.Ports;
//using System.Text;
//namespace SlnMesnac.Common
//{
// public sealed class GunHelper
// {
// private static SerialPort serialPort = new SerialPort();
// public static List<System.IO.Ports.SerialPort> serialPorts = new List<System.IO.Ports.SerialPort>();
// // 扫码枪绑定模型
// public static List<GunBindModel> gunBindModels = new List<GunBindModel>();
// #region 单例实现
// private static readonly GunHelper lazy = new GunHelper();
// /// <summary>
// /// 扫码委托 ,箱壳码1,内胆码2
// /// </summary>
// /// <param name="materialCodeStr"></param>
// /// <param name="ip"></param>
// public delegate void RefreshMaterialCodeStr(string shellCode, string linerCode);
// public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent;
// public static GunHelper Instance
// {
// get
// {
// return lazy;
// }
// }
// #endregion
// //初始化串口并启动接收数据
// public static void InstanceSerialPort3()
// {
// try
// {
// // string port = System.IO.Ports.SerialPort.GetPortNames().FirstOrDefault();
// // string port = appConfig.Port;
// var portList = appConfig.GetPortList();
// if (portList == null || portList.Count == 0)
// {
// Console.WriteLine("端口列表为空,无法初始化串口。");
// return;
// }
// //获取系统所有可打开的串口
// var availablePorts = System.IO.Ports.SerialPort.GetPortNames();
// foreach (var port in portList)
// {
// // 检查端口是否存在于可用端口列表中
// if (!availablePorts.Contains(port))
// {
// LogHelper.Instance.Info($"端口 {port} 不存在于设备管理器中,跳过初始化。");
// continue;
// }
// var serialPort = new System.IO.Ports.SerialPort();
// // 设置串口属性
// serialPort.PortName = port;
// serialPort.BaudRate = int.Parse(appConfig.BaudRate);
// serialPort.Parity = Parity.None;
// serialPort.StopBits = StopBits.One;
// serialPort.DataBits = 8;
// serialPort.DiscardNull = true;
// #region 将串口绑定模型添加到列表
// GunBindModel model = new GunBindModel();
// model.Port = port;
// gunBindModels.Add(model);
// #endregion
// // 为每个串口设置独立的数据接收事件
// serialPort.DataReceived += (sender, e) => SerialPort_DataReceived(sender, e, model);
// // 将串口添加到列表
// serialPorts.Add(serialPort);
// // 开启串口
// serialPort.Open();
// LogHelper.Instance.Info($"端口 {port} 实例化开启成功");
// }
// }
// catch (Exception ex)
// {
// LogHelper.Instance.Info($"实例化串口异常:{ex.Message}");
// }
// }
// private static void SerialPort_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e, GunBindModel model)
// {
// try
// {
// var serialPort = (System.IO.Ports.SerialPort)sender; // 获取引发事件的串口对象
// Thread.Sleep(50);
// int nums = serialPort.BytesToRead;
// byte[] receiveBytes = new byte[nums];
// serialPort.Read(receiveBytes, 0, nums);
// StringBuilder sb = new StringBuilder();
// string str = Encoding.ASCII.GetString(receiveBytes).Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
// if (str.Substring(0, 1) == "B")
// {
// model.ShellCode = str;
// }
// else if (str.Substring(0, 1) == "L")
// {
// model.LinerCode = str;
// }
// if (!string.IsNullOrEmpty(model.LinerCode) && !string.IsNullOrEmpty(model.ShellCode))
// {
// try
// {
// // 绑定事件
// RefreshMaterialCodeStrEvent(model.ShellCode, model.LinerCode);
// }
// catch (Exception ex)
// {
// LogHelper.Instance.Info($"串口{model.Port}绑定异常:{ex.Message}");
// }
// finally
// {
// model.ShellCode = "";
// model.LinerCode = "";
// }
// }
// sb.Clear();
// }
// catch (Exception ex)
// {
// LogHelper.Instance.Info($"串口{model.Port}接收数据异常:{ex.Message}");
// }
// }
// }
//}
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Config;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
namespace SlnMesnac.Common
{
public sealed class GunHelper
{
#region 单例实现
private static readonly GunHelper lazy = new GunHelper();
#region 变量定义
private static SerialPort serialPort = new SerialPort();
#endregion
/// <summary>
/// 扫码委托
/// </summary>
/// <param name="materialCodeStr"></param>
/// <param name="ip"></param>
public delegate void RefreshMaterialCodeStr(string code);
public static event RefreshMaterialCodeStr RefreshMaterialCodeStrEvent;
public static GunHelper Instance
{
get
{
return lazy;
}
}
#endregion
//初始化串口并启动接收数据
public static void InstanceSerialPort3()
{
try
{
string port = System.IO.Ports.SerialPort.GetPortNames().FirstOrDefault();
//实例化串行端口
//端口名 注:因为使用的是USB转RS232 所以去设备管理器中查看一下虚拟com口的名字
serialPort.PortName = port;// portName;
//波特率 霍尼威尔扫码枪115200,普通9600
serialPort.BaudRate = 9600;
//奇偶校验
serialPort.Parity = Parity.None;
//停止位
serialPort.StopBits = StopBits.One;
//数据位
serialPort.DataBits = 8;
//忽略null字节
serialPort.DiscardNull = true;
//接收事件
serialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort1_DataReceived);
//开启串口
serialPort.Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
}
/// <summary>
/// 接收数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
int nums = serialPort.BytesToRead;
byte[] receiveBytes = new byte[nums];
serialPort.Read(receiveBytes, 0, nums);
StringBuilder sb = new StringBuilder();
string str = Encoding.ASCII.GetString(receiveBytes).Replace("\r\n", "");
// 业务处理
RefreshMaterialCodeStrEvent?.Invoke(str);
sb.Clear();
}
/// <summary>
/// 发送数据方法
/// </summary>
/// <param name="data"></param>
public static void SendData(string data)
{
try
{
if (serialPort.IsOpen)
{
// 将需要发送的数据转换成字节数组
byte[] sendData = Encoding.ASCII.GetBytes(data);
// 向串口写入数据
serialPort.Write(sendData, 0, sendData.Length);
}
else
{
Console.WriteLine("串口未打开,请先初始化串口并打开连接。");
}
}
catch (Exception ex)
{
Console.WriteLine($"发送数据时发生错误:{ex.Message}");
}
}
}
}

@ -0,0 +1,42 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Linq;
namespace SlnMesnac.Model.domain
{
/// <summary>
/// 从MES同步过来信息
/// </summary>
[SugarTable("LOGO_CONFIG"), TenantAttribute("AUCMA_MES")]
public class LogoConfig
{
/// <summary>
/// 主键标识
///</summary>
[SugarColumn(ColumnName = "ID", IsPrimaryKey = true, IsIdentity = true,OracleSequenceName ="SEQ_LOGO_CONFIG")]
public int Id { get; set; }
/// <summary>
/// 型号
/// </summary>
[SugarColumn(ColumnName = "MATERIAL_TYPE")]
public string MaterialType { get; set; }
/// <summary>
/// 成品名称
/// </summary>
[SugarColumn(ColumnName = "MATERIAL_NAME")]
public string MaterialName { get; set; }
/// <summary>
/// 是否需要检测0不需要1需要
/// </summary>
[SugarColumn(ColumnName = "IS_CHECKED")]
public int IsChecked { get; set; }
}
}

@ -7,37 +7,50 @@ using System.Xml.Linq;
namespace SlnMesnac.Model.domain
{
[SugarTable("LOGO_IDENTIFY"), TenantAttribute("AUCMA_Local")]
[SugarTable("LOGO_IDENTIFY"), TenantAttribute("AUCMA_MES")]
public class LogoIdentify
{
/// <summary>
/// 主键标识
///</summary>
[SugarColumn(ColumnName = "ID", IsPrimaryKey = true, IsIdentity = true)]
[SugarColumn(ColumnName = "ID", IsPrimaryKey = true, IsIdentity = true,OracleSequenceName ="SEQ_LOGO_IDENTIFY")]
public int Id { get; set; }
/// <summary>
/// 箱体码
/// </summary>
[SugarColumn(ColumnName = "BOX_CODE")]
public string BoxCode { get; set; }
[SugarColumn(ColumnName = "PRODUCT_CODE")]
public string ProductCode { get; set; }
/// <summary>
/// 箱体型号
/// 型号
/// </summary>
[SugarColumn(ColumnName = "PRODUCT_MODEL")]
public string ProductModel { get; set; }
[SugarColumn(ColumnName = "MATERIAL_TYPE")]
public string MaterialType { get; set; }
/// <summary>
/// 成品名称
/// </summary>
[SugarColumn(ColumnName = "MATERIAL_NAME")]
public string MaterialName { get; set; }
/// <summary>
/// 是否需要检测0不需要1需要
/// </summary>
[SugarColumn(ColumnName = "IS_CHECKED")]
public int isChecked { get; set; }
/// <summary>
/// 结果
/// 检测结果0-失败1-成功
/// </summary>
[SugarColumn(ColumnName = "RESULT")]
public string Result { get; set; }
public int Result { get; set; }
/// <summary>
/// 记录时间
/// </summary>
[SugarColumn(ColumnName = "RECORD_TIME")]
public string RecordTime { get; set; }
public DateTime RecordTime { get; set; }

@ -0,0 +1,32 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
using System.Xml.Linq;
namespace SlnMesnac.Model.domain
{
/// <summary>
/// 从MES同步过来的型号实体
/// </summary>
public class ProductModel
{
/// <summary>
/// 型号
/// </summary>
[SugarColumn(ColumnName = "MATERIAL_CODE")]
public string MaterialCode { get; set; }
/// <summary>
/// 成品名称
/// </summary>
[SugarColumn(ColumnName = "MATERIAL_NAME")]
public string MaterialName { get; set; }
}
}

@ -63,6 +63,7 @@ namespace SlnMesnac.Repository
services.AddSingleton<IBaseUserService, BaseUserServiceImpl>();
services.AddSingleton<IBaseMaterialService, BaseMaterialServiceImpl>();
services.AddSingleton<ILogoIdentifyService, LogoIdentifyImpl>();
services.AddSingleton<ILogoConfigService, LogoConfigImpl>();
}
}
}

@ -0,0 +1,48 @@
using SlnMesnac.Model.domain;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.Repository.service
{
public interface ILogoConfigService
{
/// <summary>
/// 模糊查询,从本地查询某个型号
/// </summary>
/// <returns></returns>
Task<List<LogoConfig>> GetLikeByCode(string code);
/// <summary>
/// 从MES查询所有型号
/// </summary>
/// <returns></returns>
List<ProductModel> GetMesAllRecord();
/// <summary>
/// 从本地查询所有型号用来展示
/// </summary>
/// <returns></returns>
Task<List<LogoConfig>> GetLocalAllRecordAsync();
/// <summary>
///指定型号查询
/// </summary>
/// <returns></returns>
LogoConfig GetByMaterialType(string materialType);
/// <summary>
///指定型号修改是否校验
/// </summary>
/// <returns></returns>
bool updateByMaterialType(LogoConfig record);
/// <summary>
/// 批量插入型号
/// </summary>
/// <returns></returns>
Task<bool> InsertListAsync(List<LogoConfig> list);
}
}

@ -13,7 +13,7 @@ namespace SlnMesnac.Repository.service
/// 查询所有数据
/// </summary>
/// <returns></returns>
List<LogoIdentify> GetAllRecord();
Task<List<LogoIdentify>> GetAllRecordAsync();

@ -0,0 +1,123 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Model.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SlnMesnac.Repository.service.Impl
{
public class LogoConfigImpl : ILogoConfigService
{
private readonly ILogger<LogoConfigImpl> _logger;
private readonly Repository<LogoConfig> _rep;
public LogoConfigImpl(ILogger<LogoConfigImpl> logger, Repository<LogoConfig> rep)
{
_logger = logger;
_rep = rep;
}
/// <summary>
/// 从MES查询所有型号
/// </summary>
/// <returns></returns>
public List<ProductModel> GetMesAllRecord()
{
List<ProductModel> list = null;
try
{
// 查询MES所有型号
list = _rep.Context.SqlQueryable<ProductModel>(@"SELECT
*
FROM
(
SELECT
a.MATERIAL_CODE,
a.MATERIAL_NAME
FROM
(
SELECT
T.MATERIAL_CODE,
( SELECT MAX( B.MATERIAL_NAME ) FROM IMOS_TA_MATERIAL B WHERE B.MATERIAL_CODE = T.MATERIAL_CODE ) AS MATERIAL_NAME
FROM
IMOS_TA_MATERIAL t
WHERE
T.DETIAL_TYPE_NAME = ''
AND T.FACTORY_CODE = '2006'
) a
WHERE
( a.MATERIAL_CODE LIKE '%%' OR a.MATERIAL_NAME LIKE '%%' )
ORDER BY
a.MATERIAL_CODE,
a.MATERIAL_NAME
) T;").ToList();
}
catch (Exception ex)
{
_logger.LogError($"从MES查询数据库所有型号失败:{ex.Message}");
}
return list;
}
/// <summary>
/// 模糊查询,从本地查询某个型号
/// </summary>
/// <returns></returns>
public async Task<List<LogoConfig>> GetLikeByCode(string code)
{
List<LogoConfig> list = null;
list = await _rep.GetListAsync(x=>x.MaterialType.Contains(code) || x.MaterialName.Contains(code));
return list;
}
/// <summary>
/// 从本地查询所有型号用来展示
/// </summary>
/// <returns></returns>
public async Task<List<LogoConfig>> GetLocalAllRecordAsync()
{
List<LogoConfig> list = null;
list =await _rep.GetListAsync();
return list;
}
/// <summary>
///指定型号查询
/// </summary>
/// <returns></returns>
public LogoConfig GetByMaterialType(string materialType)
{
LogoConfig logoConfig = null;
logoConfig = _rep.GetFirst(x => x.MaterialType == materialType);
return logoConfig;
}
/// <summary>
///指定型号修改是否校验
/// </summary>
/// <returns></returns>
public bool updateByMaterialType(LogoConfig record)
{
bool result = _rep.Update(record);
return result;
}
/// <summary>
/// 批量插入型号
/// </summary>
/// <returns></returns>
public async Task<bool> InsertListAsync(List<LogoConfig> list)
{
bool result = await _rep.InsertRangeAsync(list);
return result;
}
}
}

@ -20,11 +20,10 @@ namespace SlnMesnac.Repository.service.Impl
_rep = rep;
}
public List<LogoIdentify> GetAllRecord()
public async Task<List<LogoIdentify>> GetAllRecordAsync()
{
List<LogoIdentify> list = null;
list = _rep.GetList();
list = await _rep.GetListAsync();
return list;
}
@ -43,14 +42,14 @@ namespace SlnMesnac.Repository.service.Impl
list = _rep.GetList();
}else if (time1 == null)
{
list = _rep.GetList().Where(x => DateTime.Parse(x.RecordTime) <= DateTime.Parse(time2)).ToList();
list = _rep.GetList().Where(x => x.RecordTime <= DateTime.Parse(time2)).ToList();
}else if (time2 == null)
{
list = _rep.GetList().Where(x => DateTime.Parse(x.RecordTime) >= DateTime.Parse(time1)).ToList();
list = _rep.GetList().Where(x => x.RecordTime >= DateTime.Parse(time1)).ToList();
}
else
{
list = _rep.GetList().Where(x=>DateTime.Parse(x.RecordTime) >= DateTime.Parse(time1) && DateTime.Parse(x.RecordTime) <= DateTime.Parse(time2)).ToList();
list = _rep.GetList().Where(x=>x.RecordTime >= DateTime.Parse(time1) && x.RecordTime <= DateTime.Parse(time2)).ToList();
}
return list;

@ -0,0 +1,31 @@
using SlnMesnac.WPF.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace SlnMesnac.WPF.ConvertTo
{
public class IsCheckedConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int isChecked)
{
return isChecked == 1 ? "是" : "否";
}
return string.Empty; // or handle unexpected value
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}

@ -0,0 +1,31 @@
using SlnMesnac.WPF.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace SlnMesnac.WPF.ConvertTo
{
public class IsSuccessConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int IsSuccess)
{
return IsSuccess == 1 ? "成功" : "失败";
}
return string.Empty; // or handle unexpected value
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}

@ -0,0 +1,206 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service;
using SlnMesnac.WPF.Models;
using SqlSugar;
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.Controls;
using System.Windows.Documents;
using System.Xml.Linq;
namespace SlnMesnac.WPF.ViewModel
{
public partial class ConfigPageViewModel : ObservableObject
{
private readonly ILogoConfigService? logoConfigService;
public ConfigPageViewModel() {
logoConfigService = App.ServiceProvider.GetService<ILogoConfigService>();
SyncCommand = new RelayCommand(SynchronizeLocal);
QueryCommand = new RelayCommand(Query);
UpdateCommand = new RelayCommand<object>(t=> Update(t));
// MainWindowViewModel.RefreDataGridEvent += LoadDataAsync;
LoadDataAsync();
}
#region 加载DataGrid数据
private async void LoadDataAsync()
{
List<LogoConfig> list = await logoConfigService.GetLocalAllRecordAsync();
if (list == null || list.Count == 0) return;
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
LogoConfigDataGrid.Clear();
foreach (LogoConfig verify in list)
{
LogoConfigDataGrid.Add(verify);
}
}));
}
#endregion
//修改
private void Update(object parameter)
{
string materialType = parameter as string;
if (!string.IsNullOrEmpty(materialType))
{
LogoConfig record = logoConfigService.GetByMaterialType(materialType);
if (record != null)
{
record.IsChecked = record.IsChecked == 1 ? 0 : 1;
logoConfigService.updateByMaterialType(record);
//LoadDataAsync();
}
}
}
/// <summary>
/// 从MES获取数据如果本地没有某个型号加入本地
/// </summary>
public async void SynchronizeLocal()
{
await Task.Run(async() =>
{
List<ProductModel> mesList = logoConfigService.GetMesAllRecord();
if (mesList == null || mesList.Count == 0) return;
List<LogoConfig> localList = await logoConfigService.GetLocalAllRecordAsync();
// 过滤后需要添加的型号
mesList = mesList.Where(m => !localList.Any(y => y.MaterialType == m.MaterialCode)).ToList();
if (mesList == null || mesList.Count == 0) return;
List<LogoConfig> newList = new List<LogoConfig>();
foreach (ProductModel item in mesList)
{
newList.Add(new LogoConfig()
{
MaterialType = item.MaterialCode,
MaterialName = item.MaterialName,
IsChecked = 0
});
}
bool result = await logoConfigService.InsertListAsync(newList);
Console.WriteLine(result);
LoadDataAsync();
});
}
/// <summary>
/// 查询方法
/// </summary>
private async void Query()
{
if(QueryCode == null && QueryIsCheck == null)
{
LoadDataAsync();
return;
}
var aa = QueryCode;
if(!string.IsNullOrEmpty(QueryCode))
{
List<LogoConfig> list = await logoConfigService.GetLikeByCode(QueryCode);
if (list == null || list.Count == 0) return;
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
LogoConfigDataGrid.Clear();
foreach (LogoConfig verify in list)
{
LogoConfigDataGrid.Add(verify);
}
}));
return;
}
if (QueryIsCheck != null)
{
if (QueryIsCheck.Content.Equals(""))
{
LoadDataAsync();
}
else
{
int check = QueryIsCheck.Content.ToString() == "是" ? 1 : 0;
List<LogoConfig> list = await logoConfigService.GetLocalAllRecordAsync();
if (list == null || list.Count == 0) return;
list = list.Where(x => x.IsChecked == check).ToList();
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
LogoConfigDataGrid.Clear();
foreach (LogoConfig verify in list)
{
LogoConfigDataGrid.Add(verify);
}
}));
}
}
}
/// <summary>
/// 查询条件
/// </summary>
private string _QueryCode;
public string QueryCode
{
get { return _QueryCode; }
set { _QueryCode = value; RaisePropertyChanged();}
}
private ComboBoxItem _QueryIsCheck;
public ComboBoxItem QueryIsCheck
{
get { return _QueryIsCheck; }
set { _QueryIsCheck = value; RaisePropertyChanged(); }
}
#region 初始化datagrid
private ObservableCollection<LogoConfig> _LogoConfigDataGrid = new ObservableCollection<LogoConfig>();
public ObservableCollection<LogoConfig> LogoConfigDataGrid
{
get { return _LogoConfigDataGrid; }
set
{
_LogoConfigDataGrid = value;
RaisePropertyChanged();//属性通知
}
}
#endregion
/// <summary>
/// 同步事件
/// </summary>
public RelayCommand SyncCommand { get; set; }
/// <summary>
/// 查询事件
/// </summary>
public RelayCommand QueryCommand { get; set; }
/// <summary>
/// 更新事件
/// </summary>
public RelayCommand<object> UpdateCommand { get; set; }
}
}

@ -64,14 +64,12 @@ namespace SlnMesnac.WPF.ViewModel
}
public async Task RefreshDataGrid()
public async void RefreshDataGrid()
{
await Task.Run(() =>
{
List<LogoIdentify> list = logoIdentifyService.GetAllRecord();
if (list == null || list.Count == 0) return;
App.Current.Dispatcher.BeginInvoke((Action)(() =>
List<LogoIdentify> list = await logoIdentifyService.GetAllRecordAsync();
if (list == null || list.Count == 0) return;
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
LogoIdentifyDataGrid.Clear();
list = list.OrderByDescending(x=>x.RecordTime).ToList();
@ -80,7 +78,7 @@ namespace SlnMesnac.WPF.ViewModel
LogoIdentifyDataGrid.Add(verify);
}
}));
});
}
#region 界面刷新
@ -229,12 +227,12 @@ namespace SlnMesnac.WPF.ViewModel
{
if (isSuccess)
{
ResultTxt = "成功";
ResultTxt = "OK";
ResultColor = System.Windows.Media.Brushes.LimeGreen;
}
else
{
ResultTxt = "失败";
ResultTxt = "NG";
ResultColor = System.Windows.Media.Brushes.Red;
}
}

@ -44,6 +44,7 @@ namespace SlnMesnac.WPF.ViewModel
private PlcPool plcPool = null;
private IndexPage indexPage = new IndexPage();
private StatisticsPageView statisticsPageView = new StatisticsPageView();
private ConfigPage configPage = new ConfigPage();
private DebugConfig config = DebugConfig.Instance;
public delegate void RefreDataGrid();
@ -281,8 +282,10 @@ namespace SlnMesnac.WPF.ViewModel
case "Index":
UserContent = indexPage; break;
case "List":
RefreDataGridEvent?.Invoke();
UserContent = statisticsPageView; break;
UserContent = statisticsPageView;
RefreDataGridEvent?.Invoke(); break;
case "Config":
UserContent = configPage; break;
default : break;
}

@ -32,31 +32,34 @@ namespace SlnMesnac.WPF.ViewModel
#region 加载DataGrid数据
private async void LoadData()
{
List<LogoIdentify> list = logoIdentifyService.GetAllRecord();
if (list == null || list.Count == 0) return;
list = list.OrderByDescending(x => x.RecordTime).ToList();
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
await Task.Run(async () =>
{
LogoIdentifyDataGrid.Clear();
foreach (LogoIdentify verify in list)
List<LogoIdentify> list = await logoIdentifyService.GetAllRecordAsync();
if (list == null || list.Count == 0) return;
list = list.OrderByDescending(x => x.RecordTime).ToList();
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
LogoIdentifyDataGrid.Add(verify);
}
}));
// 刷新型号统计
ModelList(list);
LogoIdentifyDataGrid.Clear();
foreach (LogoIdentify verify in list)
{
LogoIdentifyDataGrid.Add(verify);
}
}));
// 刷新型号统计
ModelList(list);
});
}
/// <summary>
/// 型号统计
/// </summary>
public void ModelList(List<LogoIdentify> list)
public void ModelList(List<LogoIdentify> list)
{
var ModelList = list.GroupBy(x => x.ProductModel).
Select(x => new { ProductModel = x.Key, Amount = x.Count() }).ToList();
App.Current.Dispatcher.BeginInvoke((Action)(() =>
var ModelList = list.GroupBy(x => x.MaterialName).
Select(x => new { ProductModel = x.Key, Amount = x.Count() }).ToList();
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
ModelDataGrid.Clear();
int index = 1;
@ -66,6 +69,7 @@ namespace SlnMesnac.WPF.ViewModel
}
}));
}
#endregion
@ -113,7 +117,8 @@ namespace SlnMesnac.WPF.ViewModel
List<LogoIdentify> list;
try
{
var result = (StatisticModel)obj;
LogoIdentifyDataGrid.Clear();
var result = (StatisticModel)obj;
if (string.IsNullOrEmpty(result.BeginTime) && string.IsNullOrEmpty(result.EndTime))
{
list = await logoIdentifyService.QueryAllByTime(null, null);
@ -142,7 +147,7 @@ namespace SlnMesnac.WPF.ViewModel
{
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
LogoIdentifyDataGrid.Clear();
list = list.OrderByDescending(x => x.RecordTime).ToList();
foreach (LogoIdentify verify in list)
{

@ -0,0 +1,142 @@
<UserControl x:Class="SlnMesnac.WPF.Views.ConfigPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SlnMesnac.WPF.Views"
xmlns:converters="clr-namespace:SlnMesnac.WPF.ConvertTo"
mc:Ignorable="d"
d:DesignHeight="900" d:DesignWidth="1620">
<UserControl.Resources>
<converters:IsCheckedConverter x:Key="IsCheckedConverter"/>
<Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="18"/>
</Style>
<Style TargetType="DataGrid">
<!--网格线颜色-->
<Setter Property="CanUserResizeColumns" Value="false"/>
<Setter Property="Background" Value="#1152AC" />
<Setter Property="BorderBrush" Value="#4285DE" />
<Setter Property="Foreground" Value="White"/>
<Setter Property="HorizontalGridLinesBrush">
<Setter.Value>
<SolidColorBrush Color="#4285DE"/>
</Setter.Value>
</Setter>
<Setter Property="VerticalGridLinesBrush">
<Setter.Value>
<SolidColorBrush Color="#1152AC"/>
</Setter.Value>
</Setter>
</Style>
<!--列头标题栏样式-->
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#dddddd" />
<Setter Property="Height" Value="40"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Background" Value="#4285DE"/>
<Setter Property="Foreground" Value="White"/>
</Style>
<!--单元格样式-->
<Style TargetType="DataGridCell">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="BorderBrush" Value="#4285DE" />
<Setter Property="Height" Value="40"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}" >
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#4285DE"/>
<Setter Property="Foreground" Value="#dddddd"/>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Border Grid.Row="1" Grid.Column="1" BorderBrush="#0288d1" BorderThickness="2" CornerRadius="5" Background="Transparent" Margin="5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.8*"/>
<RowDefinition Height="9*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="#0288d1" BorderThickness="0,0,0,1" CornerRadius="0" Background="#1157b9" Margin="1,1,5,5" >
<TextBlock Text="校验项配置" FontSize="25" FontWeight="Bold" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1" BorderBrush="Green" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="1,1,5,5">
<Grid Margin="10,5">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="8*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="horizontal" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Center">
<Label Content="型号:" FontSize="20" Foreground="White"/>
<TextBox Text="{Binding QueryCode,Mode=TwoWay}" Width="250" FontSize="20" Foreground="White" Margin="0 0 30 0" />
<Label Content="是否校验:" Width="100" FontSize="20" Foreground="White"/>
<ComboBox Width="70" Height="30" FontSize="20" SelectedItem="{Binding QueryIsCheck,Mode=TwoWay}" Margin="10,0,30,0" Foreground="White">
<ComboBoxItem Content="是" Background="White" Foreground="#4285DE"/>
<ComboBoxItem Content="否" Foreground="#4285DE"/>
<ComboBoxItem Content="" Foreground="#4285DE"/>
</ComboBox>
<Button
Content="查 询" Command="{Binding QueryCommand}"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="Green" Margin="0 0 140 0"/>
<Button
Content="同步型号" Command="{Binding SyncCommand}"
Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}" Background="#FF1CC57B"/>
</StackPanel>
<UniformGrid Grid.Row="1">
<DataGrid x:Name="listDataGrid" Grid.Row="0" ItemsSource="{Binding LogoConfigDataGrid}" Background="#00000000"
ColumnHeaderHeight="35" Height="{Binding Path=ActualHeight, ElementName=ScanPanel}"
RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0" FontSize="20"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto" LoadingRow="dgvMH_LoadingRow"
ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True"
Foreground="White" >
<!--修改选中字体颜色-->
<DataGrid.Columns>
<DataGridTemplateColumn Width="55" Header="序号" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}}, Path=Header}" FontSize="18" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"></TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding MaterialType}" Header="产品型号" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding MaterialName}" Header="产品名称" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding IsChecked, Converter={StaticResource IsCheckedConverter}}" Header="是否校验" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTemplateColumn Header="操作" Width="1.5*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="修改" Command="{Binding DataContext.UpdateCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
CommandParameter="{Binding MaterialType}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</UniformGrid>
</Grid>
</Border>
</Grid>
</Border>
</UserControl>

@ -0,0 +1,35 @@
using SlnMesnac.WPF.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SlnMesnac.WPF.Views
{
/// <summary>
/// Config.xaml 的交互逻辑
/// </summary>
public partial class ConfigPage : UserControl
{
public ConfigPage()
{
InitializeComponent();
this.DataContext = new ConfigPageViewModel();
}
private void dgvMH_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
}
}
}

@ -9,6 +9,9 @@
d:DesignHeight="1080" d:DesignWidth="1920">
<UserControl.Resources>
<converters:IsCheckedConverter x:Key="IsCheckedConverter"/>
<converters:IsSuccessConverter x:Key="IsSuccessConverter"/>
<converters:ByteArrayToImageConverter x:Key="ByteArrayToImageConverter"/>
<Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
@ -185,7 +188,7 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" ItemsSource="{Binding LogoIdentifyDataGrid}" Background="#00000000"
<DataGrid Grid.Row="0" ItemsSource="{Binding LogoIdentifyDataGrid}" Background="#00000000"
ColumnHeaderHeight="35" Height="{Binding Path=ActualHeight, ElementName=ScanPanel}"
RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0" FontSize="20"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto" LoadingRow="dgvMH_LoadingRow"
@ -200,9 +203,11 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding BoxCode}" Header="箱体码" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding ProductModel}" Header="产品型号" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding Result}" Header="检测结果" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding ProductCode}" Header="箱体码" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding MaterialType}" Header="产品型号" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding MaterialName}" Header="产品名称" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding isChecked, Converter={StaticResource IsCheckedConverter}}" Header="是否检测" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding Result, Converter={StaticResource IsSuccessConverter}}" Header="检测结果" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding RecordTime,StringFormat=\{0:yyyy-MM-dd HH:mm\}}" Header="扫描时间" Width="1.5*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
</DataGrid.Columns>

@ -9,7 +9,8 @@
mc:Ignorable="d"
d:DesignHeight="900" d:DesignWidth="1700">
<UserControl.Resources>
<cvt:IsCheckedConverter x:Key="IsCheckedConverter"/>
<cvt:IsSuccessConverter x:Key="IsSuccessConverter"/>
<cvt:MultiBindingConverter x:Key="QueryConvert"></cvt:MultiBindingConverter>
<Style x:Key="DataGridTextColumnCenterSytle" TargetType="{x:Type TextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
@ -160,10 +161,11 @@
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding BoxCode}" Header="箱体码" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding ProductModel}" Header="产品型号" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding Result}" Header="检测结果" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding ProductCode}" Header="箱体码" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding MaterialType}" Header="产品型号" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding MaterialName}" Header="产品名称" Width="2*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding isChecked, Converter={StaticResource IsCheckedConverter}}" Header="是否检测" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding Result, Converter={StaticResource IsSuccessConverter}}" Header="检测结果" Width="*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}" />
<DataGridTextColumn Binding="{Binding RecordTime,StringFormat=\{0:yyyy-MM-dd HH:mm\}}" Header="扫描时间" Width="1.5*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
</DataGrid.Columns>

@ -18,8 +18,7 @@
{
"configId": "AUCMA_MES",
"dbType": 3,
"connStr": ""
// "connStr": "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.100.72.20)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCLCDB)));User ID=c##aucma_mes;Password=aucma;"
"connStr": "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.100.70.11)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=NMES)));User ID=mesprd;Password=Mes2o23prd;"
}
],
"PlcConfig": [

Loading…
Cancel
Save