From 463d50f5b64ba1ab94b28cb8e9ba1ed6f30f837f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Thu, 6 Oct 2022 18:31:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E9=85=8D=E6=96=99=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{ => Interfaces}/IRecipeMaterials.cs | 0 .../ViewModel/RecipeManagerViewModel.cs | 5 +- BPASmart.Server/CommunicationServer.cs | 8 +- .../App.xaml.cs | 36 +- .../Models/ConfigInfoModel.cs | 18 + .../Models/OutletInfoModel.cs | 6 +- .../Models/PlcDataModel.cs | 14 + .../Models/RecipeInfo.cs | 19 + .../Models/RecipeRawMaterialInfo.cs | 24 + .../Models/SiloInfoModel.cs | 2 +- .../Services/Control.cs | 115 ++++ .../Services/PlcServer.cs | 22 +- .../Services/SiloServer.cs | 14 +- .../ViewModels/NewOutletViewModel.cs | 78 +++ .../ViewModels/NewRecipeViewModel.cs | 60 ++ .../ViewModels/OutletManagementViewModel.cs | 45 ++ .../ViewModels/RecipeControlViewModel.cs | 37 + .../ViewModels/RecipeViewModel.cs | 72 ++ .../ViewModels/SiloManagementViewModel.cs | 21 +- .../Views/NewOutletView.xaml | 94 ++- .../Views/NewOutletView.xaml.cs | 6 +- .../Views/NewRecipeView.xaml | 290 ++++++++ .../Views/NewRecipeView.xaml.cs | 62 ++ .../Views/NewSiloView.xaml | 4 + .../Views/NewSiloView.xaml.cs | 16 + .../Views/OutletManagementView.xaml | 515 +++++++++++++- .../Views/RecipeControlView.xaml | 638 ++++++++++++++++++ .../Views/RecipeControlView.xaml.cs | 28 + .../Views/RecipeView.xaml | 359 ++++++++++ .../Views/RecipeView.xaml.cs | 28 + .../Views/SiloManagementView.xaml | 32 +- DosingSystem/View/RecipeSettingsView.xaml | 2 +- 32 files changed, 2576 insertions(+), 94 deletions(-) rename BPASmart.Model/{ => Interfaces}/IRecipeMaterials.cs (100%) create mode 100644 BPASmartClient.SmallBatchingSystem/Models/ConfigInfoModel.cs create mode 100644 BPASmartClient.SmallBatchingSystem/Models/PlcDataModel.cs create mode 100644 BPASmartClient.SmallBatchingSystem/Models/RecipeInfo.cs create mode 100644 BPASmartClient.SmallBatchingSystem/Models/RecipeRawMaterialInfo.cs create mode 100644 BPASmartClient.SmallBatchingSystem/Services/Control.cs create mode 100644 BPASmartClient.SmallBatchingSystem/ViewModels/NewRecipeViewModel.cs create mode 100644 BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs create mode 100644 BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs create mode 100644 BPASmartClient.SmallBatchingSystem/Views/NewRecipeView.xaml create mode 100644 BPASmartClient.SmallBatchingSystem/Views/NewRecipeView.xaml.cs create mode 100644 BPASmartClient.SmallBatchingSystem/Views/RecipeControlView.xaml create mode 100644 BPASmartClient.SmallBatchingSystem/Views/RecipeControlView.xaml.cs create mode 100644 BPASmartClient.SmallBatchingSystem/Views/RecipeView.xaml create mode 100644 BPASmartClient.SmallBatchingSystem/Views/RecipeView.xaml.cs diff --git a/BPASmart.Model/IRecipeMaterials.cs b/BPASmart.Model/Interfaces/IRecipeMaterials.cs similarity index 100% rename from BPASmart.Model/IRecipeMaterials.cs rename to BPASmart.Model/Interfaces/IRecipeMaterials.cs diff --git a/BPASmart.RecipeManagement/ViewModel/RecipeManagerViewModel.cs b/BPASmart.RecipeManagement/ViewModel/RecipeManagerViewModel.cs index f6cf1d6d..5c9c8a77 100644 --- a/BPASmart.RecipeManagement/ViewModel/RecipeManagerViewModel.cs +++ b/BPASmart.RecipeManagement/ViewModel/RecipeManagerViewModel.cs @@ -31,7 +31,7 @@ namespace BPASmart.RecipeManagement.ViewModel /// /// 配方下发 /// - public RelayCommand PecipeStartCommand { get; set; } + public RelayCommand PecipeStartCommand { get; set; } private void EditRecipe(object o) { @@ -74,14 +74,13 @@ namespace BPASmart.RecipeManagement.ViewModel private void PecipeStart(object o) { - if (o == null) return; if (o is string id) { var res = Json.Data.locaRecipes.FirstOrDefault(p => p.ID == id); if (res != null) { - //下发配方 + //下发配方 } } diff --git a/BPASmart.Server/CommunicationServer.cs b/BPASmart.Server/CommunicationServer.cs index 58de4bd1..42e706a7 100644 --- a/BPASmart.Server/CommunicationServer.cs +++ b/BPASmart.Server/CommunicationServer.cs @@ -122,11 +122,6 @@ namespace BPASmart.Server private void DeviceControl(PublishInfo publishInfo) { - //if (msg.TryDequeue(out string s)) - //{ - // var res = JsonConvert.DeserializeObject(s); - // if (res != null) - // { publishInfo.PublishModels.ForEach(item => { if (CommunicationDevices.ContainsKey(item.DeviceName)) @@ -171,8 +166,7 @@ namespace BPASmart.Server } }); - //} - //} + } private void SetValue(Array arrays, string DeviceName, ReadDataModel readDataModel, EDataType eDataType) diff --git a/BPASmartClient.SmallBatchingSystem/App.xaml.cs b/BPASmartClient.SmallBatchingSystem/App.xaml.cs index 2f483dea..395b45c8 100644 --- a/BPASmartClient.SmallBatchingSystem/App.xaml.cs +++ b/BPASmartClient.SmallBatchingSystem/App.xaml.cs @@ -6,9 +6,11 @@ using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; +using BPA.Helper; using BPASmartClient.CustomResource.Pages.Enums; using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.Pages.View; +using BPASmartClient.SmallBatchingSystem.Models; using BPASmartClient.SmallBatchingSystem.Services; namespace BPASmartClient.SmallBatchingSystem @@ -22,8 +24,10 @@ namespace BPASmartClient.SmallBatchingSystem protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); + Json.Read(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; MenuInit(); + Control.GetInstance.Init(); SiloServer siloServer = new SiloServer(); MainView mv = new MainView(); //LoginView lv = new LoginView(); @@ -31,7 +35,7 @@ namespace BPASmartClient.SmallBatchingSystem //if (res != null && res == true) //{ // MessageLog.GetInstance.ShowUserLog("用户登录"); - mv.Show(); + mv.Show(); //} //else // mv.Close(); @@ -42,22 +46,40 @@ namespace BPASmartClient.SmallBatchingSystem { #region 配方管理菜单 ObservableCollection RecipeManage = new ObservableCollection(); + RecipeManage.Add(new SubMenumodel() + { + SubMenuName = "料仓管理", + SubMenuVisibility = Visibility.Visible, + AssemblyName = "BPASmartClient.SmallBatchingSystem", + ToggleWindowPath = "Views.SiloManagementView" + }); + + RecipeManage.Add(new SubMenumodel() + { + SubMenuName = "出料口管理", + AssemblyName = "BPASmartClient.SmallBatchingSystem", + SubMenuVisibility = Visibility.Visible, + ToggleWindowPath = "Views.OutletManagementView" + }); + RecipeManage.Add(new SubMenumodel() { SubMenuName = "配方管理", - SubMenuPermission = new Permission[] { Permission.管理员 }, - AssemblyName = "BPASmartClient.DosingSystem", - ToggleWindowPath = "View.RecipeSettingsView" + AssemblyName = "BPASmartClient.SmallBatchingSystem", + SubMenuVisibility = Visibility.Visible, + ToggleWindowPath = "Views.RecipeView" }); RecipeManage.Add(new SubMenumodel() { SubMenuName = "配方下发", - SubMenuPermission = new Permission[] { Permission.操作员, Permission.管理员 }, - AssemblyName = "BPASmartClient.DosingSystem", - ToggleWindowPath = "View.RecipeControlView" + AssemblyName = "BPASmartClient.SmallBatchingSystem", + SubMenuVisibility = Visibility.Visible, + ToggleWindowPath = "Views.RecipeControlView" }); + + MenuManage.GetInstance.menuModels.Add(new MenuModel() { MainMenuIcon = "", diff --git a/BPASmartClient.SmallBatchingSystem/Models/ConfigInfoModel.cs b/BPASmartClient.SmallBatchingSystem/Models/ConfigInfoModel.cs new file mode 100644 index 00000000..5bc0dbf1 --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/Models/ConfigInfoModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.ObjectModel; + +namespace BPASmartClient.SmallBatchingSystem.Models +{ + public class ConfigInfoModel + { + public ObservableCollection SiloInfoModels { get; set; } = new ObservableCollection(); + + public ObservableCollection OutletInfoModels { get; set; } = new ObservableCollection(); + + public ObservableCollection Recipes { get; set; } = new ObservableCollection(); + } +} diff --git a/BPASmartClient.SmallBatchingSystem/Models/OutletInfoModel.cs b/BPASmartClient.SmallBatchingSystem/Models/OutletInfoModel.cs index e2018e94..4a3ab337 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/OutletInfoModel.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/OutletInfoModel.cs @@ -20,7 +20,7 @@ namespace BPASmartClient.SmallBatchingSystem.Models private string _mOutletName; /// - /// 出来哦口位置 + /// 出料口位置 /// public int OutletLoc { get { return _mOutletLoc; } set { _mOutletLoc = value; OnPropertyChanged(); } } private int _mOutletLoc; @@ -28,9 +28,7 @@ namespace BPASmartClient.SmallBatchingSystem.Models /// /// 出料口对应的料仓信息 /// - public ObservableCollection SiloInfos { get { return _mSiloInfos; } set { _mSiloInfos = value; OnPropertyChanged(); } } - private ObservableCollection _mSiloInfos; - + public ObservableCollection SiloInfos { get; set; } = new ObservableCollection(); } } diff --git a/BPASmartClient.SmallBatchingSystem/Models/PlcDataModel.cs b/BPASmartClient.SmallBatchingSystem/Models/PlcDataModel.cs new file mode 100644 index 00000000..a891a24f --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/Models/PlcDataModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.SmallBatchingSystem.Models +{ + public class PlcDataModel + { + public static bool[] TargetLocFeedback { get; set; } = new bool[16]; + public static bool BatchingCompleted { get; set; } + } +} diff --git a/BPASmartClient.SmallBatchingSystem/Models/RecipeInfo.cs b/BPASmartClient.SmallBatchingSystem/Models/RecipeInfo.cs new file mode 100644 index 00000000..b3ee08f4 --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/Models/RecipeInfo.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System.Collections.ObjectModel; +namespace BPASmartClient.SmallBatchingSystem.Models +{ + public class RecipeInfo : ObservableObject + { + + public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } } + private string _mRecipeName; + + public ObservableCollection SiloInfoModels { get; set; } = new ObservableCollection(); + + } +} diff --git a/BPASmartClient.SmallBatchingSystem/Models/RecipeRawMaterialInfo.cs b/BPASmartClient.SmallBatchingSystem/Models/RecipeRawMaterialInfo.cs new file mode 100644 index 00000000..7e30ce52 --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/Models/RecipeRawMaterialInfo.cs @@ -0,0 +1,24 @@ +using Microsoft.Toolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.SmallBatchingSystem.Models +{ + public class RecipeRawMaterialInfo : ObservableObject + { + /// + /// 原料名称 + /// + public string SiloName { get { return _mSiloName; } set { _mSiloName = value; OnPropertyChanged(); } } + private string _mSiloName; + + /// + /// 原料重量 + /// + public int SiloWeight { get { return _mSiloWeight; } set { _mSiloWeight = value; OnPropertyChanged(); } } + private int _mSiloWeight; + } +} diff --git a/BPASmartClient.SmallBatchingSystem/Models/SiloInfoModel.cs b/BPASmartClient.SmallBatchingSystem/Models/SiloInfoModel.cs index 8e8e35ce..ab822258 100644 --- a/BPASmartClient.SmallBatchingSystem/Models/SiloInfoModel.cs +++ b/BPASmartClient.SmallBatchingSystem/Models/SiloInfoModel.cs @@ -13,7 +13,7 @@ namespace BPASmartClient.SmallBatchingSystem.Models public class SiloInfoModel : ObservableObject { /// - /// 料仓原料名称 + /// 原料名称 /// public string SiloName { get { return _mSiloName; } set { _mSiloName = value; OnPropertyChanged(); } } private string _mSiloName; diff --git a/BPASmartClient.SmallBatchingSystem/Services/Control.cs b/BPASmartClient.SmallBatchingSystem/Services/Control.cs new file mode 100644 index 00000000..07556efd --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/Services/Control.cs @@ -0,0 +1,115 @@ +using BPA.Helper; +using BPASmartClient.SmallBatchingSystem.Models; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace BPASmartClient.SmallBatchingSystem.Services +{ + public class Control + { + private volatile static Control _Instance; + public static Control GetInstance => _Instance ?? (_Instance = new Control()); + private Control() { } + public ConcurrentQueue MakeOrderQueue { get; set; } = new ConcurrentQueue(); + + public void Init() + { + ThreadManage.GetInstance().Start(new Action(() => + { + PlcServer.GetInstance.Connect(); + + }), "设备初始化"); + + ThreadManage.GetInstance().StartLong(new Action(() => + { + while (MakeOrderQueue.Count > 0) + { + if (MakeOrderQueue.TryDequeue(out RecipeInfo recipeInfo)) + { + List OutletInfo = new List(); + recipeInfo.SiloInfoModels.ToList()?.ForEach(item => + { + var res = Json.Data.OutletInfoModels.FirstOrDefault(p => p.SiloInfos.FirstOrDefault(s => s.Contains(item.SiloName)) != null); + if (res != null) if (!OutletInfo.Contains(res.OutletLoc)) OutletInfo.Add(res.OutletLoc); + }); + + OutletInfo.ForEach(temp => + { + PlcServer.GetInstance.WriteData("VW302", (ushort)temp);//设置出料口位置 + PlcServer.GetInstance.WriteData("M10.0", true);//定位启动 + int index = temp - 1; + if (index >= 0 && index < PlcDataModel.TargetLocFeedback.Length) + { + while (!PlcDataModel.TargetLocFeedback[index]) Thread.Sleep(1);//等待定位反馈 + recipeInfo.SiloInfoModels.ToList()?.ForEach(temp1 => + { + var res = Json.Data.SiloInfoModels.FirstOrDefault(p => p.SiloName == temp1.SiloName); + if (res != null) + { + PlcServer.GetInstance.WriteData(GetWeightAdd(res.SiloLoc), (ushort)temp1.SiloWeight); + PlcServer.GetInstance.WriteData(GetStartSingleAdd(res.SiloLoc), true); + while (!PlcDataModel.BatchingCompleted) Thread.Sleep(1);//等待出料完成 + PlcServer.GetInstance.WriteData("M4.0", false);//复位出料完成信号 + while (PlcDataModel.BatchingCompleted) Thread.Sleep(1);//等待出料完成信号复位成功 + } + }); + } + + }); + PlcServer.GetInstance.WriteData("M10.4", true); + } + } + Thread.Sleep(10); + }), "配方流程控制"); + } + + + + /// + /// 获取重量设置地址 + /// + /// + /// + private string GetWeightAdd(int num) + { + if (num > 0) + { + var s = 100 + (num - 1) * 2; + return $"VW{s}"; + } + return default; + } + + /// + /// 获取启动信号地址 + /// + /// + /// + private string GetStartSingleAdd(int num) + { + if (num > 0) + { + string Add = string.Empty; + var t = num / 8; + var c = (num % 8); + if (c == 0) + { + t--; + c = 7; + } + else c--; + + Add = $"M{ t}.{c}"; + return Add; + } + return default; + } + + } +} diff --git a/BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs b/BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs index 420505bd..9b03eba5 100644 --- a/BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs +++ b/BPASmartClient.SmallBatchingSystem/Services/PlcServer.cs @@ -16,7 +16,7 @@ namespace BPASmartClient.SmallBatchingSystem.Services public static PlcServer GetInstance => _Instance ?? (_Instance = new PlcServer()); private PlcServer() { } - public ModbusTcp Communication = new ModbusTcp(); + public ModbusTcp Communication = new ModbusTcp(); public void Connect() { @@ -26,6 +26,20 @@ namespace BPASmartClient.SmallBatchingSystem.Services MessageLog.GetInstance.Show("设备连接成功"); ThreadManage.GetInstance().StartLong(new Action(() => { + var res = ReadData("M20.0", 16);//到达目标位置信号 + if (res != null && res is bool[] bools && bools.Length == 16) + { + for (int i = 0; i < bools.Length; i++) + { + PlcDataModel.TargetLocFeedback[i] = bools[i]; + } + } + + var res1 = ReadData("M4.0", 1);//通道出料完成 + if (res1 != null && res1 is bool[] bools1 && bools1.Length == 1) + { + PlcDataModel.BatchingCompleted = bools1[0]; + } Thread.Sleep(10); }), "PLC 数据监听"); @@ -39,11 +53,11 @@ namespace BPASmartClient.SmallBatchingSystem.Services Communication.Write(address, value); } - public object ReadData(string address,int length) + public object ReadData(string address, int length) { - object res=null; + object res = null; if (address != null) - res= Communication.Read(address,(ushort)length); + res = Communication.Read(address, (ushort)length); return res; } } diff --git a/BPASmartClient.SmallBatchingSystem/Services/SiloServer.cs b/BPASmartClient.SmallBatchingSystem/Services/SiloServer.cs index a02514b4..3e6dea82 100644 --- a/BPASmartClient.SmallBatchingSystem/Services/SiloServer.cs +++ b/BPASmartClient.SmallBatchingSystem/Services/SiloServer.cs @@ -35,7 +35,7 @@ namespace BPASmartClient.SmallBatchingSystem.Services #endregion #region 订单管理 - public ConcurrentQueue MakeOrderQueue { get; set; }=new ConcurrentQueue(); + public ConcurrentQueue MakeOrderQueue { get; set; } = new ConcurrentQueue(); #endregion #region 业务 @@ -44,7 +44,7 @@ namespace BPASmartClient.SmallBatchingSystem.Services /// public void BusinessThread() { - + ThreadManage.GetInstance().Start(new Action(() => { PlcServer.GetInstance.Connect(); @@ -76,7 +76,8 @@ namespace BPASmartClient.SmallBatchingSystem.Services Json.Read(); RecipeMaterialsDic = Json.Data.locaMaterails; RecipesDic = Json.Data.locaRecipes; - RecipesDic?.ToList().ForEach(par => { + RecipesDic?.ToList().ForEach(par => + { par.recipeMaterials?.ToList().ForEach((recipeMaterial) => { RecipeMaterials recipe = RecipeMaterialsDic?.ToList().Find(k => k.ID == recipeMaterial.ID); @@ -129,9 +130,12 @@ namespace BPASmartClient.SmallBatchingSystem.Services recipes?.recipeMaterials?.ToList().ForEach(recipe => { //料仓位置 - int recipesLoc = 1; int.TryParse(recipe.PropertyCollections?.First()?.PropertyValue, out recipesLoc); + int recipesLoc = 1; + int.TryParse(recipe.PropertyCollections?.First()?.PropertyValue, out recipesLoc); + //原料位置 int storeLoc = 1; int.TryParse(recipe.MaterialPosion, out recipesLoc); + //原料需求(g)数 int storeWeight = recipe.MaterialWeight; @@ -144,7 +148,7 @@ namespace BPASmartClient.SmallBatchingSystem.Services if (storeWeight > 0) { WriteData("VW302", recipesLoc); - WriteData("M10.0",true); + WriteData("M10.0", true); #region 读取是否到达目标位置,超时10秒 bool IsOver = false; diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/NewOutletViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/NewOutletViewModel.cs index 74b28236..9e2b4b9c 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/NewOutletViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/NewOutletViewModel.cs @@ -1,17 +1,95 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using BPA.Helper; +using BPASmartClient.SmallBatchingSystem.Models; +using BPASmartClient.SmallBatchingSystem.Views; using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; namespace BPASmartClient.SmallBatchingSystem.ViewModels { public class NewOutletViewModel : ObservableObject { + int index = -1; public NewOutletViewModel() { + ActionManage.GetInstance.Register(new Action((o) => + { + if (o != null && o is OutletInfoModel tempOutletInfo) + { + OutletName = tempOutletInfo.OutletName; + OutletLoc = tempOutletInfo.OutletLoc; + tempOutletInfo.SiloInfos?.ToList()?.ForEach((item => + { + SiloInfos.Add(new RawMaterialInfo() { RawMaterialName = item }); + })); + index = Array.FindIndex(Json.Data.OutletInfoModels.ToArray(), p => p.OutletName == tempOutletInfo.OutletName); + } + }), "OpenNewOutlet", true); + AddRawMaterialCommand = new RelayCommand(() => { SiloInfos.Add(new RawMaterialInfo()); }); + CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("NewOutletViewClose"); }); + SaveCommand = new RelayCommand(() => + { + ObservableCollection SileNames = new ObservableCollection(); + SiloInfos.ToList()?.ForEach(item => { SileNames.Add(item.RawMaterialName); }); + if (index >= 0 && index < Json.Data.OutletInfoModels.Count) + { + Json.Data.OutletInfoModels.ElementAt(index).OutletName = OutletName; + Json.Data.OutletInfoModels.ElementAt(index).OutletLoc = OutletLoc; + Json.Data.OutletInfoModels.ElementAt(index).SiloInfos = SileNames; + } + else + { + Json.Data.OutletInfoModels.Add(new OutletInfoModel() + { + OutletLoc = OutletLoc, + OutletName = OutletName, + SiloInfos = SileNames + }); + } + ActionManage.GetInstance.Send("NewOutletViewClose"); + }); + RemoveCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) + { + var res = SiloInfos.FirstOrDefault(p => p.RawMaterialName == o.ToString()); + if (res != null) SiloInfos.Remove(res); + } + }); + Json.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add(item.SiloName); }); } + + + + + public RelayCommand AddRawMaterialCommand { get; set; } + public RelayCommand CancelCommand { get; set; } + public RelayCommand SaveCommand { get; set; } + + public RelayCommand RemoveCommand { get; set; } + + public string OutletName { get { return _mOutletName; } set { _mOutletName = value; OnPropertyChanged(); } } + private string _mOutletName; + + public int OutletLoc { get { return _mOutletLoc; } set { _mOutletLoc = value; OnPropertyChanged(); } } + private int _mOutletLoc; + + public ObservableCollection SiloInfos { get; set; } = new ObservableCollection(); + + public ObservableCollection SileName { get; set; } = new ObservableCollection(); + } + + public class RawMaterialInfo : ObservableObject + { + + public string RawMaterialName { get { return _mRawMaterialName; } set { _mRawMaterialName = value; OnPropertyChanged(); } } + private string _mRawMaterialName; + } } diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/NewRecipeViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/NewRecipeViewModel.cs new file mode 100644 index 00000000..67f7ae69 --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/NewRecipeViewModel.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using System.Collections.ObjectModel; +using BPA.Helper; +using BPASmartClient.SmallBatchingSystem.Models; + +namespace BPASmartClient.SmallBatchingSystem.ViewModels +{ + public class NewRecipeViewModel : ObservableObject + { + public NewRecipeViewModel() + { + AddRawMaterialCommand = new RelayCommand(() => { SiloInfos.Add(new RecipeRawMaterialInfo()); }); + CnacelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("NewRecipeViewModelClose"); }); + SaveCommand = new RelayCommand(() => + { + //ObservableCollection SileNames = new ObservableCollection(); + //SiloInfos.ToList()?.ForEach(item => { SileNames.Add(item.RawMaterialName); }); + Json.Data.Recipes.Add(new RecipeInfo() + { + RecipeName = RecipeName, + SiloInfoModels = SiloInfos + }); + ActionManage.GetInstance.Send("NewRecipeViewModelClose"); + }); + + RemoveCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) + { + var res = SiloInfos.FirstOrDefault(p => p.SiloName == o.ToString()); + if (res != null) SiloInfos.Remove(res); + } + }); + + Json.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add(item.SiloName); }); + } + + public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } } + private string _mRecipeName; + + public RelayCommand AddRawMaterialCommand { get; set; } + + public RelayCommand CnacelCommand { get; set; } + + public RelayCommand SaveCommand { get; set; } + + public RelayCommand RemoveCommand { get; set; } + + public ObservableCollection SiloInfos { get; set; } = new ObservableCollection(); + + public ObservableCollection SileName { get; set; } = new ObservableCollection(); + + } +} diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs index 45fc86b7..b6b10491 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/OutletManagementViewModel.cs @@ -1,9 +1,14 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using BPA.Helper; +using BPASmartClient.SmallBatchingSystem.Models; +using BPASmartClient.SmallBatchingSystem.Views; using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; namespace BPASmartClient.SmallBatchingSystem.ViewModels { @@ -11,7 +16,47 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels { public OutletManagementViewModel() { + AddSiloCommand = new RelayCommand(() => + { + NewOutletView newOutletView = new NewOutletView(); + newOutletView.ShowDialog(); + }); + SaveCommand = new RelayCommand(() => { Json.Save(); }); + OutletInfoModels = Json.Data.OutletInfoModels; + RemoveCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) + { + var res = Json.Data.OutletInfoModels.FirstOrDefault(p => p.OutletName == o.ToString()); + if (res != null) Json.Data.OutletInfoModels.Remove(res); + } + }); + DetailsCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) + { + var res = Json.Data.OutletInfoModels.FirstOrDefault(p => p.OutletName == o.ToString()); + if (res != null) + { + NewOutletView newOutletView = new NewOutletView(); + ActionManage.GetInstance.Send("OpenNewOutlet", res); + newOutletView.ShowDialog(); + } + } + }); } + + public RelayCommand AddSiloCommand { get; set; } + + public RelayCommand SaveCommand { get; set; } + + public RelayCommand RemoveCommand { get; set; } + + public RelayCommand DetailsCommand { get; set; } + + public ObservableCollection OutletInfoModels { get; set; } + + } } diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs new file mode 100644 index 00000000..5b27c78e --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeControlViewModel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.Helper; +using BPASmartClient.SmallBatchingSystem.Models; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using BPASmartClient.SmallBatchingSystem.Services; + +namespace BPASmartClient.SmallBatchingSystem.ViewModels +{ + public class RecipeControlViewModel : ObservableObject + { + public RecipeControlViewModel() + { + Recipes = Json.Data.Recipes; + StartCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) + { + int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeName == o.ToString()); + if (index >= 0 && index < Json.Data.Recipes.Count) + { + Control.GetInstance.MakeOrderQueue.Enqueue(Json.Data.Recipes.ElementAt(index)); + } + } + }); + } + public ObservableCollection Recipes { get; set; } + + public RelayCommand StartCommand { get; set; } + + } +} diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs new file mode 100644 index 00000000..ab203f7e --- /dev/null +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/RecipeViewModel.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BPA.Helper; +using BPASmartClient.SmallBatchingSystem.Models; +using BPASmartClient.SmallBatchingSystem.Views; +using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; + +namespace BPASmartClient.SmallBatchingSystem.ViewModels +{ + public class RecipeViewModel : ObservableObject + { + public RecipeViewModel() + { + NewRecipeCommand = new RelayCommand(() => + { + NewRecipeView newOutletView = new NewRecipeView(); + newOutletView.ShowDialog(); + }); + SaveCommand = new RelayCommand(() => { Json.Save(); }); + RecipeInfoModels = Json.Data.Recipes; + RemoveCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) + { + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString()); + if (res != null) Json.Data.Recipes.Remove(res); + } + }); + + DetailsCommand = new RelayCommand((o) => + { + if (!string.IsNullOrEmpty(o?.ToString())) + { + var res = Json.Data.Recipes.FirstOrDefault(p => p.RecipeName == o.ToString()); + if (res != null) + { + NewRecipeView newOutletView = new NewRecipeView(); + newOutletView.outName.Text = o.ToString(); + //res.SiloInfoModels?.ToList()?.ForEach(item => { NewRecipeViewModel.SiloInfoModels.Add(item); }); + //int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeName == o.ToString()); + //if (index >= 0 && index < Json.Data.Recipes.Count) + //{ + // NewRecipeViewModel.SiloInfoModels = Json.Data.Recipes.ElementAt(index).SiloInfoModels; + //} + newOutletView.ShowDialog(); + //int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeName == o.ToString()); + //if (index >= 0 && index < Json.Data.Recipes.Count) + //{ + // NewRecipeViewModel.SiloInfoModels = Json.Data.Recipes.ElementAt(index).SiloInfoModels; + //} + + } + } + }); + } + + public RelayCommand NewRecipeCommand { get; set; } + + public RelayCommand SaveCommand { get; set; } + + public RelayCommand RemoveCommand { get; set; } + + public RelayCommand DetailsCommand { get; set; } + + public ObservableCollection RecipeInfoModels { get; set; } + } +} diff --git a/BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs b/BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs index 6b5f8147..e124fbdd 100644 --- a/BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs +++ b/BPASmartClient.SmallBatchingSystem/ViewModels/SiloManagementViewModel.cs @@ -4,6 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; +using Microsoft.Toolkit.Mvvm.Input; +using BPASmartClient.SmallBatchingSystem.Views; +using BPASmartClient.SmallBatchingSystem.Models; +using System.Collections.ObjectModel; +using BPA.Helper; namespace BPASmartClient.SmallBatchingSystem.ViewModels { @@ -11,9 +16,23 @@ namespace BPASmartClient.SmallBatchingSystem.ViewModels { public SiloManagementViewModel() { - + AddSilo = new RelayCommand(() => + { + NewSiloView newSiloView = new NewSiloView(); + if (newSiloView.ShowDialog() == true) + { + //if (newSiloView.Tag!=null && newSiloView.Tag is ) + } + }); + SaveData = new RelayCommand(() => { Json.Save(); }); + SiloInfoModels = Json.Data.SiloInfoModels; } + public RelayCommand AddSilo { get; set; } + + public RelayCommand SaveData { get; set; } + + public ObservableCollection SiloInfoModels { get; set; } } } diff --git a/BPASmartClient.SmallBatchingSystem/Views/NewOutletView.xaml b/BPASmartClient.SmallBatchingSystem/Views/NewOutletView.xaml index fa53b1c0..e5c26338 100644 --- a/BPASmartClient.SmallBatchingSystem/Views/NewOutletView.xaml +++ b/BPASmartClient.SmallBatchingSystem/Views/NewOutletView.xaml @@ -6,14 +6,20 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:BPASmartClient.SmallBatchingSystem.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:vm="clr-namespace:BPASmartClient.SmallBatchingSystem.ViewModels" Title="NewOutletView" - Width="500" - Height="300" + Width="600" + Height="400" AllowsTransparency="True" Background="{x:Null}" WindowStartupLocation="CenterScreen" WindowStyle="None" mc:Ignorable="d"> + + + + + @@ -122,31 +128,62 @@ - + + + + + + + + + + + + - + Style="{StaticResource TextBoxStyle}" />-->