diff --git a/SlnMesnac.Business/LogoBusiness.cs b/SlnMesnac.Business/LogoBusiness.cs index 4961380..0dc72c2 100644 --- a/SlnMesnac.Business/LogoBusiness.cs +++ b/SlnMesnac.Business/LogoBusiness.cs @@ -51,7 +51,8 @@ namespace SlnMesnac.Business this.logoIdentifyService = logoIdentifyService; 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 , 传入照片 diff --git a/SlnMesnac.Common/GunHelper.cs b/SlnMesnac.Common/GunHelper.cs index 9563362..0640305 100644 --- a/SlnMesnac.Common/GunHelper.cs +++ b/SlnMesnac.Common/GunHelper.cs @@ -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 serialPorts = new List(); -// // 扫码枪绑定模型 -// public static List gunBindModels = new List(); -// #region 单例实现 -// private static readonly GunHelper lazy = new GunHelper(); - - - -// /// -// /// 扫码委托 ,箱壳码1,内胆码2 -// /// -// /// -// /// -// 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 + + /// + /// 扫码委托 + /// + /// + /// + 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()); + } + } + + + /// + /// 接收数据 + /// + /// + /// + 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(); + } + + /// + /// 发送数据方法 + /// + /// + 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}"); + } + } + + } +} diff --git a/SlnMesnac.Model/domain/LogoConfig.cs b/SlnMesnac.Model/domain/LogoConfig.cs new file mode 100644 index 0000000..40446a0 --- /dev/null +++ b/SlnMesnac.Model/domain/LogoConfig.cs @@ -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 +{ + /// + /// 从MES同步过来信息 + /// + [SugarTable("LOGO_CONFIG"), TenantAttribute("AUCMA_MES")] + public class LogoConfig + { + /// + /// 主键标识 + /// + [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, IsIdentity = true,OracleSequenceName ="SEQ_LOGO_CONFIG")] + public int Id { get; set; } + + /// + /// 型号 + /// + [SugarColumn(ColumnName = "MATERIAL_TYPE")] + public string MaterialType { get; set; } + + /// + /// 成品名称 + /// + [SugarColumn(ColumnName = "MATERIAL_NAME")] + public string MaterialName { get; set; } + + /// + /// 是否需要检测;0不需要;1需要 + /// + [SugarColumn(ColumnName = "IS_CHECKED")] + public int IsChecked { get; set; } + + + } +} diff --git a/SlnMesnac.Model/domain/LogoIdentify.cs b/SlnMesnac.Model/domain/LogoIdentify.cs index 98eb6c7..1d3af5b 100644 --- a/SlnMesnac.Model/domain/LogoIdentify.cs +++ b/SlnMesnac.Model/domain/LogoIdentify.cs @@ -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 { /// /// 主键标识 /// - [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, IsIdentity = true)] + [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, IsIdentity = true,OracleSequenceName ="SEQ_LOGO_IDENTIFY")] public int Id { get; set; } /// /// 箱体码 /// - [SugarColumn(ColumnName = "BOX_CODE")] - public string BoxCode { get; set; } + [SugarColumn(ColumnName = "PRODUCT_CODE")] + public string ProductCode { get; set; } /// - /// 箱体型号 + /// 型号 /// - [SugarColumn(ColumnName = "PRODUCT_MODEL")] - public string ProductModel { get; set; } + [SugarColumn(ColumnName = "MATERIAL_TYPE")] + public string MaterialType { get; set; } + + /// + /// 成品名称 + /// + [SugarColumn(ColumnName = "MATERIAL_NAME")] + public string MaterialName { get; set; } + + /// + /// 是否需要检测;0不需要;1需要 + /// + [SugarColumn(ColumnName = "IS_CHECKED")] + public int isChecked { get; set; } + /// - /// 结果 + /// 检测结果,0-失败;1-成功 /// [SugarColumn(ColumnName = "RESULT")] - public string Result { get; set; } + public int Result { get; set; } /// /// 记录时间 /// [SugarColumn(ColumnName = "RECORD_TIME")] - public string RecordTime { get; set; } + public DateTime RecordTime { get; set; } diff --git a/SlnMesnac.Model/domain/ProductModel.cs b/SlnMesnac.Model/domain/ProductModel.cs new file mode 100644 index 0000000..91bf762 --- /dev/null +++ b/SlnMesnac.Model/domain/ProductModel.cs @@ -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 +{ + /// + /// 从MES同步过来的型号实体 + /// + + public class ProductModel + { + + /// + /// 型号 + /// + [SugarColumn(ColumnName = "MATERIAL_CODE")] + public string MaterialCode { get; set; } + + /// + /// 成品名称 + /// + [SugarColumn(ColumnName = "MATERIAL_NAME")] + public string MaterialName { get; set; } + + + + } +} diff --git a/SlnMesnac.Repository/SqlsugarSetup.cs b/SlnMesnac.Repository/SqlsugarSetup.cs index 55c7f07..77a9323 100644 --- a/SlnMesnac.Repository/SqlsugarSetup.cs +++ b/SlnMesnac.Repository/SqlsugarSetup.cs @@ -63,6 +63,7 @@ namespace SlnMesnac.Repository services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); } } } diff --git a/SlnMesnac.Repository/service/ILogoConfigService.cs b/SlnMesnac.Repository/service/ILogoConfigService.cs new file mode 100644 index 0000000..7c8c16a --- /dev/null +++ b/SlnMesnac.Repository/service/ILogoConfigService.cs @@ -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 + { + /// + /// 模糊查询,从本地查询某个型号 + /// + /// + Task> GetLikeByCode(string code); + + /// + /// 从MES查询所有型号 + /// + /// + List GetMesAllRecord(); + + + /// + /// 从本地查询所有型号用来展示 + /// + /// + Task> GetLocalAllRecordAsync(); + + /// + ///指定型号查询 + /// + /// + LogoConfig GetByMaterialType(string materialType); + + /// + ///指定型号修改是否校验 + /// + /// + bool updateByMaterialType(LogoConfig record); + + /// + /// 批量插入型号 + /// + /// + Task InsertListAsync(List list); + } +} diff --git a/SlnMesnac.Repository/service/ILogoIdentifyService.cs b/SlnMesnac.Repository/service/ILogoIdentifyService.cs index 157311b..9acc504 100644 --- a/SlnMesnac.Repository/service/ILogoIdentifyService.cs +++ b/SlnMesnac.Repository/service/ILogoIdentifyService.cs @@ -13,7 +13,7 @@ namespace SlnMesnac.Repository.service /// 查询所有数据 /// /// - List GetAllRecord(); + Task> GetAllRecordAsync(); diff --git a/SlnMesnac.Repository/service/Impl/LogoConfigImpl.cs b/SlnMesnac.Repository/service/Impl/LogoConfigImpl.cs new file mode 100644 index 0000000..9e89050 --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/LogoConfigImpl.cs @@ -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 _logger; + + private readonly Repository _rep; + + public LogoConfigImpl(ILogger logger, Repository rep) + { + _logger = logger; + _rep = rep; + } + + + /// + /// 从MES查询所有型号 + /// + /// + public List GetMesAllRecord() + { + List list = null; + try + { + // 查询MES所有型号 + list = _rep.Context.SqlQueryable(@"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; + } + + /// + /// 模糊查询,从本地查询某个型号 + /// + /// + public async Task> GetLikeByCode(string code) + { + List list = null; + list = await _rep.GetListAsync(x=>x.MaterialType.Contains(code) || x.MaterialName.Contains(code)); + return list; + } + + /// + /// 从本地查询所有型号用来展示 + /// + /// + public async Task> GetLocalAllRecordAsync() + { + List list = null; + list =await _rep.GetListAsync(); + return list; + + } + + /// + ///指定型号查询 + /// + /// + public LogoConfig GetByMaterialType(string materialType) + { + LogoConfig logoConfig = null; + logoConfig = _rep.GetFirst(x => x.MaterialType == materialType); + return logoConfig; + } + + /// + ///指定型号修改是否校验 + /// + /// + public bool updateByMaterialType(LogoConfig record) + { + bool result = _rep.Update(record); + return result; + } + + + + + /// + /// 批量插入型号 + /// + /// + public async Task InsertListAsync(List list) + { + bool result = await _rep.InsertRangeAsync(list); + return result; + } + } +} diff --git a/SlnMesnac.Repository/service/Impl/LogoIdentifyImpl.cs b/SlnMesnac.Repository/service/Impl/LogoIdentifyImpl.cs index 2041e9d..89f2cf0 100644 --- a/SlnMesnac.Repository/service/Impl/LogoIdentifyImpl.cs +++ b/SlnMesnac.Repository/service/Impl/LogoIdentifyImpl.cs @@ -20,11 +20,10 @@ namespace SlnMesnac.Repository.service.Impl _rep = rep; } - public List GetAllRecord() - { - + public async Task> GetAllRecordAsync() + { List 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; diff --git a/SlnMesnac.WPF/ConvertTo/ByteArrayToImageConverter .cs b/SlnMesnac.WPF/ConvertTo/ByteArrayToImageConverter.cs similarity index 100% rename from SlnMesnac.WPF/ConvertTo/ByteArrayToImageConverter .cs rename to SlnMesnac.WPF/ConvertTo/ByteArrayToImageConverter.cs diff --git a/SlnMesnac.WPF/ConvertTo/IsCheckedConverter.cs b/SlnMesnac.WPF/ConvertTo/IsCheckedConverter.cs new file mode 100644 index 0000000..d639524 --- /dev/null +++ b/SlnMesnac.WPF/ConvertTo/IsCheckedConverter.cs @@ -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(); + } + } + +} diff --git a/SlnMesnac.WPF/ConvertTo/IsSuccessConverter.cs b/SlnMesnac.WPF/ConvertTo/IsSuccessConverter.cs new file mode 100644 index 0000000..4ee4640 --- /dev/null +++ b/SlnMesnac.WPF/ConvertTo/IsSuccessConverter.cs @@ -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(); + } + } + +} diff --git a/SlnMesnac.WPF/ViewModel/ConfigPageViewModel.cs b/SlnMesnac.WPF/ViewModel/ConfigPageViewModel.cs new file mode 100644 index 0000000..ecfe1cc --- /dev/null +++ b/SlnMesnac.WPF/ViewModel/ConfigPageViewModel.cs @@ -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(); + SyncCommand = new RelayCommand(SynchronizeLocal); + QueryCommand = new RelayCommand(Query); + UpdateCommand = new RelayCommand(t=> Update(t)); + // MainWindowViewModel.RefreDataGridEvent += LoadDataAsync; + LoadDataAsync(); + } + + + #region 加载DataGrid数据 + private async void LoadDataAsync() + { + List 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(); + } + } + + } + + + /// + /// 从MES获取数据,如果本地没有某个型号,加入本地 + /// + public async void SynchronizeLocal() + { + await Task.Run(async() => + { + List mesList = logoConfigService.GetMesAllRecord(); + if (mesList == null || mesList.Count == 0) return; + List localList = await logoConfigService.GetLocalAllRecordAsync(); + + // 过滤后需要添加的型号 + mesList = mesList.Where(m => !localList.Any(y => y.MaterialType == m.MaterialCode)).ToList(); + if (mesList == null || mesList.Count == 0) return; + List newList = new List(); + + 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(); + }); + } + + /// + /// 查询方法 + /// + private async void Query() + { + if(QueryCode == null && QueryIsCheck == null) + { + LoadDataAsync(); + return; + } + var aa = QueryCode; + if(!string.IsNullOrEmpty(QueryCode)) + { + + List 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 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); + } + })); + + } + } + + } + + /// + /// 查询条件 + /// + 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 _LogoConfigDataGrid = new ObservableCollection(); + public ObservableCollection LogoConfigDataGrid + { + get { return _LogoConfigDataGrid; } + set + { + _LogoConfigDataGrid = value; + RaisePropertyChanged();//属性通知 + } + } + #endregion + + + + /// + /// 同步事件 + /// + public RelayCommand SyncCommand { get; set; } + + + /// + /// 查询事件 + /// + public RelayCommand QueryCommand { get; set; } + + /// + /// 更新事件 + /// + public RelayCommand UpdateCommand { get; set; } + + + } +} \ No newline at end of file diff --git a/SlnMesnac.WPF/ViewModel/IndexViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexViewModel.cs index 839c11b..c936dd5 100644 --- a/SlnMesnac.WPF/ViewModel/IndexViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexViewModel.cs @@ -64,14 +64,12 @@ namespace SlnMesnac.WPF.ViewModel } - public async Task RefreshDataGrid() + public async void RefreshDataGrid() { - await Task.Run(() => - { - List list = logoIdentifyService.GetAllRecord(); + + List list = await logoIdentifyService.GetAllRecordAsync(); if (list == null || list.Count == 0) return; - - App.Current.Dispatcher.BeginInvoke((Action)(() => + 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; } } diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 9504496..b88035e 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -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(); @@ -280,9 +281,11 @@ namespace SlnMesnac.WPF.ViewModel switch (info) { case "Index": UserContent = indexPage; break; - case "List": - RefreDataGridEvent?.Invoke(); - UserContent = statisticsPageView; break; + case "List": + UserContent = statisticsPageView; + RefreDataGridEvent?.Invoke(); break; + case "Config": + UserContent = configPage; break; default : break; } diff --git a/SlnMesnac.WPF/ViewModel/StatisticsPageViewModel.cs b/SlnMesnac.WPF/ViewModel/StatisticsPageViewModel.cs index 5c01c90..2f13234 100644 --- a/SlnMesnac.WPF/ViewModel/StatisticsPageViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/StatisticsPageViewModel.cs @@ -32,31 +32,34 @@ namespace SlnMesnac.WPF.ViewModel #region 加载DataGrid数据 private async void LoadData() { - List 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 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); + }); } /// /// 型号统计 /// - public void ModelList(List list) + public void ModelList(List 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; @@ -65,6 +68,7 @@ namespace SlnMesnac.WPF.ViewModel ModelDataGrid.Add(new ModelCount() { No = index++, ProductName = item.ProductModel, Amount = item.Amount }); } })); + } @@ -113,7 +117,8 @@ namespace SlnMesnac.WPF.ViewModel List 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) { diff --git a/SlnMesnac.WPF/Views/ConfigPage.xaml b/SlnMesnac.WPF/Views/ConfigPage.xaml new file mode 100644 index 0000000..f82580e --- /dev/null +++ b/SlnMesnac.WPF/Views/ConfigPage.xaml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +