diff --git a/SlnMesnac.Model/domain/LogoFormula.cs b/SlnMesnac.Model/domain/LogoFormula.cs new file mode 100644 index 0000000..d563ee0 --- /dev/null +++ b/SlnMesnac.Model/domain/LogoFormula.cs @@ -0,0 +1,36 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; +using System.Xml.Linq; + +namespace SlnMesnac.Model.domain +{ + /// + /// 海康配方 + /// + [SugarTable("LOGO_FORMULA"), TenantAttribute("AUCMA_MES")] + public class LogoFormula + { + /// + /// 主键标识 + /// + [SugarColumn(ColumnName = "ID", IsPrimaryKey = true, IsIdentity = true, OracleSequenceName = "SEQ_LOGO_FORMULA")] + public int Id { get; set; } + + /// + /// 存储1-2-3-4这种发给海康的型号 + /// + [SugarColumn(ColumnName = "KEY")] + public int Key { get; set; } + + /// + /// 存储人工选择的特征-如白色冰柜大LOGO;黑色冰柜小LOGO + /// + [SugarColumn(ColumnName = "VALUE")] + public string Value { get; set; } + + + } +} diff --git a/SlnMesnac.Repository/SqlsugarSetup.cs b/SlnMesnac.Repository/SqlsugarSetup.cs index 77a9323..9daf205 100644 --- a/SlnMesnac.Repository/SqlsugarSetup.cs +++ b/SlnMesnac.Repository/SqlsugarSetup.cs @@ -64,6 +64,7 @@ namespace SlnMesnac.Repository services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); } } } diff --git a/SlnMesnac.Repository/service/ILogoFormulaService.cs b/SlnMesnac.Repository/service/ILogoFormulaService.cs new file mode 100644 index 0000000..004d978 --- /dev/null +++ b/SlnMesnac.Repository/service/ILogoFormulaService.cs @@ -0,0 +1,43 @@ +using SlnMesnac.Model.domain; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace SlnMesnac.Repository.service +{ + public interface ILogoFormulaService + { + + /// + /// 从本地查询所有型号用来展示 + /// + /// + Task> GetListAsync(); + + + //TODO 修改、删除 + + /// + /// 新增 + /// + /// + /// + Task InsertAsync(LogoFormula record); + + /// + /// 删除 + /// + /// + /// + Task DeleteAsync(LogoFormula record); + + /// + /// 修改 + /// + /// + /// + Task UpdateAsync(LogoFormula record); + + } +} diff --git a/SlnMesnac.Repository/service/Impl/LogoFormulaImpl.cs b/SlnMesnac.Repository/service/Impl/LogoFormulaImpl.cs new file mode 100644 index 0000000..038b1d2 --- /dev/null +++ b/SlnMesnac.Repository/service/Impl/LogoFormulaImpl.cs @@ -0,0 +1,64 @@ +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 LogoFormulaImpl : ILogoFormulaService + { + private readonly ILogger _logger; + + private readonly Repository _rep; + + public LogoFormulaImpl(ILogger logger, Repository rep) + { + _logger = logger; + _rep = rep; + } + + public async Task> GetListAsync() + { + List list = null; + list = await _rep.GetListAsync(); + return list; + } + + /// + /// 修改 + /// + /// + /// + public async Task UpdateAsync(LogoFormula record) + { + bool result = await _rep.UpdateAsync(record); + return result; + } + + /// + /// 删除 + /// + /// + /// + public async Task DeleteAsync(LogoFormula record) + { + bool result = await _rep.DeleteAsync(record); + return result; + } + + /// + /// 新增 + /// + /// + /// + public async Task InsertAsync(LogoFormula record) + { + bool result = await _rep.InsertAsync(record); + return result; + } + + } +} diff --git a/SlnMesnac.WPF/ViewModel/ConfigPageViewModel.cs b/SlnMesnac.WPF/ViewModel/ConfigPageViewModel.cs index e8e5bba..bc527ca 100644 --- a/SlnMesnac.WPF/ViewModel/ConfigPageViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ConfigPageViewModel.cs @@ -29,6 +29,7 @@ namespace SlnMesnac.WPF.ViewModel SyncCommand = new RelayCommand(SynchronizeLocal); QueryCommand = new RelayCommand(Query); UpdateCommand = new RelayCommand(t=> Update(t)); + MangerCommand = new RelayCommand(Manger); // MainWindowViewModel.RefreDataGridEvent += LoadDataAsync; LoadDataAsync(); } @@ -73,6 +74,13 @@ namespace SlnMesnac.WPF.ViewModel } + + private void Manger() + { + FormulaWindow window = new FormulaWindow(); + window.ShowDialog(); + + } /// /// 从MES获取数据,如果本地没有某个型号,加入本地 @@ -202,10 +210,14 @@ namespace SlnMesnac.WPF.ViewModel public RelayCommand QueryCommand { get; set; } /// - /// 更新事件 + /// 更新检测类型事件 /// public RelayCommand UpdateCommand { get; set; } + /// + /// 管理配方 + /// + public RelayCommand MangerCommand { get; set; } } } \ No newline at end of file diff --git a/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs new file mode 100644 index 0000000..3e56b82 --- /dev/null +++ b/SlnMesnac.WPF/ViewModel/FormulaWindowViewModel.cs @@ -0,0 +1,162 @@ +using GalaSoft.MvvmLight; +using GalaSoft.MvvmLight.Command; +using Microsoft.Extensions.DependencyInjection; +using SlnMesnac.Model.domain; +using SlnMesnac.Repository.service; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Documents; + +namespace SlnMesnac.WPF.ViewModel +{ + public class FormulaWindowViewModel : ObservableObject + { + private ILogoFormulaService? formulaService; + + public FormulaWindowViewModel() + { + formulaService = App.ServiceProvider.GetService(); + AddCommand = new RelayCommand(AddRecord); + DeleteCommand = new RelayCommand(t => DeleteRecord(t)); + + LoadDataAsync(); + } + + + + + #region 加载DataGrid数据 + private async void LoadDataAsync() + { + List list = await formulaService.GetListAsync(); + if (list == null || list.Count == 0) return; + list = list.OrderBy(x => x.Key).ToList(); + await App.Current.Dispatcher.BeginInvoke((Action)(() => + { + LogoFormulaDataGrid.Clear(); + foreach (LogoFormula verify in list) + { + LogoFormulaDataGrid.Add(verify); + } + })); + + } + #endregion + + private async void DeleteRecord(int key) + { + if (key>=0) + { + List list = await formulaService.GetListAsync(); + if (list == null || list.Count == 0) return; + LogoFormula formula = list.FirstOrDefault(t => t.Key == key); + if (formula != null) + { + bool result = await formulaService.DeleteAsync(formula); + if (result) + { + MessageBox.Show("删除成功"); + LoadDataAsync(); + } + } + } + } + + private async void AddRecord() + { + string key = KeyTxt; + string value = ValueTxt; + if(string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)){ + MessageBox.Show("两个值都不能为空"); + return; + } + List list = await formulaService.GetListAsync(); + if (list == null || list.Count == 0) return; + + try + { + int result = int.Parse(key); + Console.WriteLine("转换成功,结果是:" + result); + } + catch (FormatException) + { + MessageBox.Show("Key必须为数字"); + return; + } + + LogoFormula formula = list.FirstOrDefault(t => t.Key == int.Parse(key)); + if (formula != null) + { + MessageBox.Show("Key已经存在"); + return; + } + else + { + bool result = await formulaService.InsertAsync(new LogoFormula() { Key = int.Parse(key), Value = value }); + if (result) + { + MessageBox.Show("添加成功"); + LoadDataAsync(); + } + } + + + } + + #region 属性 + + /// + /// Key + /// + private string _KeyTxt; + public string KeyTxt + { + get { return _KeyTxt; } + set { _KeyTxt = value; RaisePropertyChanged(); } + } + + /// + /// Value + /// + private string _ValueTxt; + public string ValueTxt + { + get { return _ValueTxt; } + set { _ValueTxt = value; RaisePropertyChanged(); } + } + + #region 初始化datagrid + private ObservableCollection _LogoFormulaDataGrid = new ObservableCollection(); + public ObservableCollection LogoFormulaDataGrid + { + get { return _LogoFormulaDataGrid; } + set + { + _LogoFormulaDataGrid = value; + RaisePropertyChanged();//属性通知 + } + } + #endregion + + + #endregion + + /// + /// 查询事件 + /// + public RelayCommand AddCommand { get; set; } + + /// + /// 更新检测类型事件 + /// + public RelayCommand DeleteCommand { get; set; } + + + } +} diff --git a/SlnMesnac.WPF/ViewModel/IndexViewModel.cs b/SlnMesnac.WPF/ViewModel/IndexViewModel.cs index 7c40ece..b151ea4 100644 --- a/SlnMesnac.WPF/ViewModel/IndexViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/IndexViewModel.cs @@ -25,6 +25,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; +using static System.Net.Mime.MediaTypeNames; namespace SlnMesnac.WPF.ViewModel { @@ -41,6 +42,7 @@ namespace SlnMesnac.WPF.ViewModel private IBaseMaterialService? baseMaterialService; private ILogoIdentifyService? ocrVerfiyService; private ILogoConfigService? logoConfigService; + private TcpServer? tcpServer; private PlcPool plcPool = null; @@ -59,6 +61,7 @@ namespace SlnMesnac.WPF.ViewModel ocrVerfiyService = App.ServiceProvider.GetService(); baseMaterialService = App.ServiceProvider.GetService(); logoConfigService = App.ServiceProvider.GetService(); + _logger2 = App.ServiceProvider.GetService>(); logoBusiness = LogoBusiness.GetInstance(_logger2, logoConfigService, baseMaterialService, ocrVerfiyService, plcPool, tcpServer); @@ -75,9 +78,11 @@ namespace SlnMesnac.WPF.ViewModel /// private void Reset() { + logoBusiness.Pass(); } + /// /// 测试方法 /// diff --git a/SlnMesnac.WPF/Views/FormulaWindow.xaml b/SlnMesnac.WPF/Views/FormulaWindow.xaml index 9bbb283..eae59f5 100644 --- a/SlnMesnac.WPF/Views/FormulaWindow.xaml +++ b/SlnMesnac.WPF/Views/FormulaWindow.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:SlnMesnac.WPF.Views" WindowStartupLocation="CenterScreen" xmlns:converters="clr-namespace:SlnMesnac.WPF.ConvertTo" mc:Ignorable="d" Background="#1157b9" - Title="配方管理" Height="500" Width="500"> + Title="配方管理" Height="1000" Width="1200">