using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.MorkCL.Model.DB; using BPASmartClient.MorkCL.Model.Json; using BPASmartClient.MorkCL.Server; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.MorkCL.ViewModel { public class ManualSetItemStorageViewModel : NotifyBase { public ManualSetItemStorageViewModel() { ActionManage.GetInstance.Register((object o) => { if (o is not null && o is int storageIndex) { if (storageIndex >= 0 && storageIndex <= 11) { var storage = Json.Data.IngredientsStorage[storageIndex]; if (storage is not null) { Storage = new(); StorageIndex = storageIndex; Storage.Weight = storage.Weight; Storage.Name = storage.Name; Storage.IsEmploy = storage.IsEmploy; Storage.MaterialID = storage.MaterialID; } } } }, "SendItemStorageInfo", true); //获取所有主料。 Ingredients = new ObservableCollection(SqliteHelper.GetInstance.GetIngredients()); SaveCommand = new(() => { if (Storage.Weight is float f) { if (f > 0) { if (StorageIndex >= 0 && StorageIndex <= 11) { var storage = Json.Data.IngredientsStorage[StorageIndex]; storage.Name = Storage.Name; storage.Weight = Storage.Weight; storage.MaterialID = Ingredients.FirstOrDefault(material => material.Name == Storage.Name).Id; storage.IsEmploy = true; Json.Save(); ActionManage.GetInstance.Send(true, "CloseManualSetStorageView"); } else { } } else MessageNotify.GetInstance.ShowDialog("重量不应小于零,请确认后再试。"); } else MessageNotify.GetInstance.ShowDialog("重量因为数字,请确认后再试。"); }); } private ItemStorage _storage; /// /// 仓位信息 /// public ItemStorage Storage { get { return _storage; } set { _storage = value; OnPropertyChanged(); } } private int _storageIndex; /// /// 仓位索引。 /// public int StorageIndex { get { return _storageIndex; } set { _storageIndex = value; OnPropertyChanged(); } } private ObservableCollection _Ingredients; /// 所有的主料数据。作为ComboBox的数据源。 public ObservableCollection Ingredients { get { return _Ingredients; } set { _Ingredients = value; OnPropertyChanged(); } } public BPARelayCommand SaveCommand { get; set; } } }