From 38e8396af20b032f1770b2da2c1a7955948acc25 Mon Sep 17 00:00:00 2001 From: taoye Date: Fri, 16 Sep 2022 16:29:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A4=A7=E9=85=8D=E6=96=99=E7=AB=99?= =?UTF-8?q?=E9=85=8D=E6=96=B9=E7=AE=A1=E7=90=86=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Model/Siemens/RemoteRecipeData.cs | 12 +- .../Model/Siemens/RemoteRecipeRawMaterial.cs | 11 +- .../View/RecipeInfosView.xaml | 244 +++++++++++- .../View/RecipeInfosView.xaml.cs | 17 +- .../View/RecipeReceiveView.xaml | 355 +++++++++++++++--- .../ViewModel/RecipeInfosViewModel.cs | 95 ++++- .../ViewModel/RecipeReceiveViewModel.cs | 24 +- DosingSystem/Model/DeviceInquire.cs | 2 +- DosingSystem/View/RecipeSettingsView.xaml | 6 +- 9 files changed, 686 insertions(+), 80 deletions(-) diff --git a/BPASmartClient.JXJFoodBigStation/Model/Siemens/RemoteRecipeData.cs b/BPASmartClient.JXJFoodBigStation/Model/Siemens/RemoteRecipeData.cs index 19d26ded..45b13638 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/Siemens/RemoteRecipeData.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/Siemens/RemoteRecipeData.cs @@ -1,4 +1,6 @@ -using System; + +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -7,24 +9,24 @@ using System.Threading.Tasks; namespace BPASmartClient.JXJFoodBigStation.Model { - public class RemoteRecipeData + public class RemoteRecipeData : ObservableObject { /// /// 配方名称 /// - public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; } } + public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } } private string _mRecipeName; /// /// 配方ID /// - public long RecipeCode { get { return _mRecipeCode; } set { _mRecipeCode = value; } } + public long RecipeCode { get { return _mRecipeCode; } set { _mRecipeCode = value; OnPropertyChanged(); } } private long _mRecipeCode; /// /// 托盘编号 /// - public int TrayCode { get { return _mTrayCode; } set { _mTrayCode = value; } } + public int TrayCode { get { return _mTrayCode; } set { _mTrayCode = value; OnPropertyChanged(); } } private int _mTrayCode; /// diff --git a/BPASmartClient.JXJFoodBigStation/Model/Siemens/RemoteRecipeRawMaterial.cs b/BPASmartClient.JXJFoodBigStation/Model/Siemens/RemoteRecipeRawMaterial.cs index 9a69a2c9..3f95a527 100644 --- a/BPASmartClient.JXJFoodBigStation/Model/Siemens/RemoteRecipeRawMaterial.cs +++ b/BPASmartClient.JXJFoodBigStation/Model/Siemens/RemoteRecipeRawMaterial.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,7 @@ using System.Threading.Tasks; namespace BPASmartClient.JXJFoodBigStation.Model { - public class RemoteRecipeRawMaterial + public class RemoteRecipeRawMaterial :ObservableObject { private int _mIp; public int DeviceIp { get { return _mIp; } set { _mIp = value; }} @@ -14,19 +15,19 @@ namespace BPASmartClient.JXJFoodBigStation.Model /// /// 原料对应的桶号 /// - public int RawMaterialBarrelNum { get { return _mRawMaterialBarrelNum; } set { _mRawMaterialBarrelNum = value; } } + public int RawMaterialBarrelNum { get { return _mRawMaterialBarrelNum; } set { _mRawMaterialBarrelNum = value;OnPropertyChanged(); } } private int _mRawMaterialBarrelNum; /// /// 需要原料重量 /// - public double RawMaterialWeight { get { return _mRawMaterialWeight; } set { _mRawMaterialWeight = value; } } + public double RawMaterialWeight { get { return _mRawMaterialWeight; } set { _mRawMaterialWeight = value; OnPropertyChanged(); } } private double _mRawMaterialWeight; /// /// 原料对应料仓的位置 /// - public int RawMaterialLocation { get { return _mRawMaterialLocation; } set { _mRawMaterialLocation = value; } } + public int RawMaterialLocation { get { return _mRawMaterialLocation; } set { _mRawMaterialLocation = value; OnPropertyChanged(); } } private int _mRawMaterialLocation; } } diff --git a/BPASmartClient.JXJFoodBigStation/View/RecipeInfosView.xaml b/BPASmartClient.JXJFoodBigStation/View/RecipeInfosView.xaml index 1ce7f330..124a23fb 100644 --- a/BPASmartClient.JXJFoodBigStation/View/RecipeInfosView.xaml +++ b/BPASmartClient.JXJFoodBigStation/View/RecipeInfosView.xaml @@ -7,8 +7,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="clr-namespace:BPASmartClient.JXJFoodBigStation.ViewModel" Title="RecipeInfosView" - Width="550" - Height="450" + Width="800" + Height="550" AllowsTransparency="True" Background="{x:Null}" Topmost="True" @@ -52,7 +52,7 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/BPASmartClient.JXJFoodBigStation/View/RecipeInfosView.xaml.cs b/BPASmartClient.JXJFoodBigStation/View/RecipeInfosView.xaml.cs index 5742f815..eb4e17c6 100644 --- a/BPASmartClient.JXJFoodBigStation/View/RecipeInfosView.xaml.cs +++ b/BPASmartClient.JXJFoodBigStation/View/RecipeInfosView.xaml.cs @@ -23,9 +23,24 @@ namespace BPASmartClient.JXJFoodBigStation.View public RecipeInfosView() { InitializeComponent(); - + this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); }; ActionManage.GetInstance.CancelRegister("CloseRecipeInfosView"); ActionManage.GetInstance.Register(new Action(() => { this.Close(); }), "CloseRecipeInfosView"); } + + private void Button_Click(object sender, RoutedEventArgs e) + { + this.Close(); + } + + private void ComboBox_KeyUp(object sender, KeyEventArgs e) + { + + } + + private void ComboBox_LostFocus(object sender, RoutedEventArgs e) + { + + } } } diff --git a/BPASmartClient.JXJFoodBigStation/View/RecipeReceiveView.xaml b/BPASmartClient.JXJFoodBigStation/View/RecipeReceiveView.xaml index 2713578d..9947abee 100644 --- a/BPASmartClient.JXJFoodBigStation/View/RecipeReceiveView.xaml +++ b/BPASmartClient.JXJFoodBigStation/View/RecipeReceiveView.xaml @@ -13,6 +13,9 @@ mc:Ignorable="d"> + + + @@ -37,6 +40,112 @@ + + + + + + @@ -49,6 +158,16 @@ + - - + + + HorizontalAlignment="Left" + VerticalAlignment="Top" + Columns="8" /> - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + - - + + diff --git a/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeInfosViewModel.cs b/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeInfosViewModel.cs index ad4390da..41f87b64 100644 --- a/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeInfosViewModel.cs +++ b/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeInfosViewModel.cs @@ -9,6 +9,8 @@ using Microsoft.Toolkit.Mvvm.Input; using BPASmartClient.Helper; using BPASmartClient.JXJFoodBigStation.Model; using BPASmartClient.CustomResource.Pages.Model; +using BPASmartClient.JXJFoodBigStation.Model.Siemens; +using System.Windows.Forms; namespace BPASmartClient.JXJFoodBigStation.ViewModel { @@ -33,10 +35,89 @@ namespace BPASmartClient.JXJFoodBigStation.ViewModel } }), "RecipeInfo"); - ReturnPage = new RelayCommand(() => + AddRecipe = new RelayCommand(() => { + RawMaterialsInfo.Add(new RemoteRecipeRawMaterial()); + }); + Comfirm = new RelayCommand(() => { - ActionManage.GetInstance.Send("CloseRecipeInfosView"); + var bom= Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == RecipeCode); + if (bom == null)//新配方 + { + var name= Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName); + if (name == null) + { + go: + long recipeCode = new Random().Next(10000, 99999); + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode); + if (res == null) + { + Json.Data.Recipes.Add(new RemoteRecipeData { RecipeCode = recipeCode, RawMaterial= RawMaterialsInfo,RecipeName=RecipeName,TrayCode=TrayCode}); + Json.Save(); + } + else + { + goto go; + } + ActionManage.GetInstance.Send("CloseRecipeInfosView"); + } + else + { + + MessageBox.Show("配方名称重复,请重命名!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + } + else//编辑已有配方 + { + + bom.RawMaterial.Clear(); + foreach (var item in RawMaterialsInfo) + { + bom.RawMaterial.Add(item); + } + bom.RecipeName = RecipeName; + Json.Save(); + ActionManage.GetInstance.Send("CloseRecipeInfosView"); + } + }); + + SaveAs = new RelayCommand(() => { + + var bom = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName); + var rec = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == RecipeCode); + if (bom == null && rec != null)//配方名称更改 + { + + prop: long recipeCode = new Random().Next(10000, 99999);//配方唯一ID,后期根据实际要求更改 + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode); + if (res == null) + { + Json.Data.Recipes.Add(new RemoteRecipeData { RecipeCode = recipeCode, RawMaterial = RawMaterialsInfo, RecipeName = RecipeName, TrayCode = TrayCode });//配方添加 + Json.Save(); + } + else + { + goto prop; + } + ActionManage.GetInstance.Send("CloseRecipeInfosView"); + } + else + { + MessageBox.Show("另存配方失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + ActionManage.GetInstance.Send("CloseNewRecipeView"); }); + + RemoveRecipe = new RelayCommand((materilaName) => { + + var res= RawMaterialsInfo.FirstOrDefault(p=>p.RawMaterialLocation==materilaName); + if (res != null) + RawMaterialsInfo.Remove(res); + }); + //ReturnPage = new RelayCommand(() => + //{ + // ActionManage.GetInstance.Send("CloseRecipeInfosView"); + //}); } public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } } @@ -50,6 +131,14 @@ namespace BPASmartClient.JXJFoodBigStation.ViewModel public RelayCommand ReturnPage { get; set; } - public ObservableCollection RawMaterialsInfo { get; set; } = new ObservableCollection(); + public RelayCommand AddRecipe { get; set; } + + public RelayCommand Comfirm { get; set; } + + public RelayCommand SaveAs { get; set; } + + public RelayCommand RemoveRecipe { get; set; } + + public ObservableCollection RawMaterialsInfo { get; set; } = new ObservableCollection() ; } } diff --git a/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeReceiveViewModel.cs b/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeReceiveViewModel.cs index 74fe86f7..4e1b5789 100644 --- a/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeReceiveViewModel.cs +++ b/BPASmartClient.JXJFoodBigStation/ViewModel/RecipeReceiveViewModel.cs @@ -23,10 +23,10 @@ namespace BPASmartClient.JXJFoodBigStation.ViewModel { public class RecipeReceiveViewModel : ObservableObject { - ObservableCollection RawMaterials { get; set; } = new ObservableCollection(); + public ObservableCollection RawMaterials { get; set; } = new ObservableCollection(); public RecipeReceiveViewModel() { - //Json.Read(); + Json.Read(); Recipes = Json.Data.Recipes; DetailsCommand = new RelayCommand((o) => { @@ -40,6 +40,12 @@ namespace BPASmartClient.JXJFoodBigStation.ViewModel MessageLog.GetInstance.ShowUserLog($"查看配方——{res.RecipeName}"); } }); + NewRecipe = new RelayCommand(() => { + + RecipeInfosView nrv = new RecipeInfosView(); + nrv.ShowDialog(); + }); + NewSimulateRecipe = new RelayCommand(() => { RawMaterials.Clear(); @@ -80,6 +86,14 @@ namespace BPASmartClient.JXJFoodBigStation.ViewModel ClearAllRecipe = new RelayCommand(() => { Json.Data.Recipes.Clear(); + Json.Save(); + }); + + RemoveCommand = new RelayCommand((recipeCode) => { + + var res = Recipes.FirstOrDefault(p=>p.RecipeCode==recipeCode); + if(res!=null) + Recipes.Remove(res); }); } @@ -88,6 +102,10 @@ namespace BPASmartClient.JXJFoodBigStation.ViewModel public RelayCommand NewSimulateRecipe { get; set; } public RelayCommand ClearAllRecipe { get; set; } - public ObservableCollection Recipes { get; set; } + public RelayCommand NewRecipe { get; set; } + + public RelayCommand RemoveCommand { get; set; } + + public ObservableCollection Recipes { get; set; } = new ObservableCollection(); } } diff --git a/DosingSystem/Model/DeviceInquire.cs b/DosingSystem/Model/DeviceInquire.cs index 4b21be78..40b697f6 100644 --- a/DosingSystem/Model/DeviceInquire.cs +++ b/DosingSystem/Model/DeviceInquire.cs @@ -98,7 +98,7 @@ namespace BPASmartClient.DosingSystem.Model public void Init() { - //TestData(); + TestData(); IpAddressLines(); DeviceDataInit(); ThreadManage.GetInstance().StartLong(new Action(() => diff --git a/DosingSystem/View/RecipeSettingsView.xaml b/DosingSystem/View/RecipeSettingsView.xaml index 5a751a2a..4f6f58a3 100644 --- a/DosingSystem/View/RecipeSettingsView.xaml +++ b/DosingSystem/View/RecipeSettingsView.xaml @@ -36,7 +36,7 @@ -