using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.MorkCL.Model.DB; using BPASmartClient.MorkCL.Model.Json; using BPASmartClient.MorkCL.Server; namespace BPASmartClient.MorkCL.ViewModel { public class ItemStorageViewModel : NotifyBase { public ItemStorageViewModel() { //加载读取数据。 //AddTestData(); ActionManage.GetInstance.Register(() => { IngredientsItorage = new ObservableCollection(Json.Data.IngredientsStorage); AccessoriesItorage = new ObservableCollection(Json.Data.AccessoriesStorage); }, "RefreshItemStorage", true); ActionManage.GetInstance.Register((() => { Ingredients = new ObservableCollection(SqliteHelper.GetInstance.GetIngredients()); }), "RefreshIngredients", true); ActionManage.GetInstance.Register((object o) => { if (o != null && o is float f) { #if !FORMAL ScaleCurrentWeight = f; #else ScaleCurrentWeight = 1.23f; #endif } }, "SendCurrentWeight",true); //ActionManage.GetInstance.Register((object o) => //{ // CanItemStorage = (bool)o; //}, "RefreshCanItemStorage", true); //实例化时调用一次,更新数据。 ActionManage.GetInstance.Send("RefreshItemStorage"); ActionManage.GetInstance.Send("RefreshIngredients"); InStorageCommand = new BPARelayCommand((o) => { ActionManage.GetInstance.Send(NotifyTopic.ItemStorage, o); #region 暂时弃用 //if (!CanItemStorage) //{ // MessageNotify.GetInstance.ShowDialog("当前有炒菜任务正在排队,为避免影响菜品口味,不可入库,请稍后再试。", DialogType.Warning); // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料入库失败,当前正在制作菜品。"); // return; //} //TaskManage.GetInstance.Start(() => //{ // if (o != null && o is IngredientsTB ingredients) // { // foreach (ItemStorage item in Json.Data.IngredientsStorage) // { // if (item.IsEmploy == false) // { // item.MaterialID = ingredients.Id; // item.Name = ingredients.Name; // item.IsEmploy = true; // item.Weight = ScaleCurrentWeight; // ActionManage.GetInstance.Send("ItemStorage", IngredientsItorage.IndexOf(item) + // 1); Json.Save(); // IngredientsItorage = new ObservableCollection(Json.Data.IngredientsStorage); // Application.Current.Dispatcher.Invoke(() => { // NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, // Application.Current.MainWindow, "入库成功", $"物料{ingredients.Name}入库成功。"); // }); // return; // } // } // Application.Current.Dispatcher.Invoke(() => // { // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料库已满。"); // }); // } // else // { // Application.Current.Dispatcher.Invoke(() => // { // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "入库失败", $"物料入库失败。"); // }); // } //}, "ItemStorageTask"); #endregion 暂时弃用 }); InitialStorageCommand = new(() => { if (MessageNotify.GetInstance.ShowDialog($"确定清空所有仓位吗?")) { for (int i = 0; i < Json.Data.IngredientsStorage.Length; i++) { Json.Data.IngredientsStorage[i] = new(); } Json.Save(); ActionManage.GetInstance.Send("RefreshItemStorage"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", "清空仓位信息成功。"); } }); WeigherTareCommand = new(() => { if (MessageNotify.GetInstance.ShowDialog("请确认是否执行电子秤【除皮】操作?")) { Task.Run(() => { ActionManage.GetInstance.Send("WeighrTare"); }); } }); WeigherZeroCommand = new(() => { if (MessageNotify.GetInstance.ShowDialog("请确认是否执行电子秤【置零】操作?")) { Task.Run(() => { ActionManage.GetInstance.Send("WeighrZero"); }); } }); ModifySelectStorageCommand = new((o) => { if (o is not null && o is int index) { if (ActionManage.GetInstance.SendResult("SystemIsBusy") is bool isBusy) { if (isBusy == true) { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"当前还有配方任务在排队制作,请稍后后再试。"); return; } if (MessageNotify.GetInstance.ShowDialog($"确认修改库位【{index + 1}】的库位信息吗?")) { if (index >= 0 && index < Json.Data.IngredientsStorage.Length) { ManualSetItemStorageView view = new(); ActionManage.GetInstance.Send("SendItemStorageInfo", index); var result= view.ShowDialog(); ActionManage.GetInstance.Send("RefreshItemStorage"); if (result==true) { NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"修改库位【{index + 1}】信息成功。"); } } else { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"未找到库位【{index + 1}】,请确认后重试。"); } } } } }); ClearSelectStorageCommand = new((o) => { if (o is not null && o is int index) { if (ActionManage.GetInstance.SendResult("SystemIsBusy") is bool isBusy) { if (isBusy == true) { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"当前还有配方任务在排队制作,请稍后后再试。"); return; } if (MessageNotify.GetInstance.ShowDialog($"确认清除库位【{index + 1}】的库位信息吗?")) { if (index >= 0 && index < Json.Data.IngredientsStorage.Length) { Json.Data.IngredientsStorage[index] = new ItemStorage(); Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "成功", $"清除库位【{index+1}】信息成功。"); ActionManage.GetInstance.Send("RefreshItemStorage"); } else { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "失败", $"未找到库位【{index + 1}】,请确认后重试。"); } } } } }); } private void AddTestData() { ScaleCurrentWeight = 1.23f; //Materials.Clear(); //for (int i = 1; i < 13; i++) //{ // Materials.Add(new TempMaterial() { ID = 10000 + i, Loc = i.ToString(), Name = $"第{i}库位", Weight = new Random().NextSingle()*10000 }); //} //Seasonings.Clear(); //for (int i = 1; i < 9; i++) //{ // Seasonings.Add(new TempMaterial() { ID = 10000 + i, Loc = i.ToString(), Name = $"第{i}库位", Weight = new Random().NextSingle()*10000 }); //} } public BPARelayCommand InStorageCommand { get; set; } /// /// 初始化库位。 /// public BPARelayCommand InitialStorageCommand { get; set; } /// /// 电子秤除皮。 /// [Obsolete("除皮功能弃用,不会用这个功能。")] public BPARelayCommand WeigherTareCommand { get; set; } /// /// 电子秤置零。 /// public BPARelayCommand WeigherZeroCommand { get; set; } /// /// 修改指定库位信息。 /// public BPARelayCommand ModifySelectStorageCommand { get; set; } /// /// 清空指定库位信息。 /// public BPARelayCommand ClearSelectStorageCommand { get; set; } private float _ScaleCurrentWeight; public float ScaleCurrentWeight { get { return _ScaleCurrentWeight; } set { _ScaleCurrentWeight = value; OnPropertyChanged(); } } private IngredientsTB _SelectIngreditent; public IngredientsTB SelectIngreditent { get { return _SelectIngreditent; } set { _SelectIngreditent = value; OnPropertyChanged(); } } private ObservableCollection _IngredientsItorage; /// 主料库位。 public ObservableCollection IngredientsItorage { get { return _IngredientsItorage; } set { _IngredientsItorage = value; OnPropertyChanged(); } } private ObservableCollection _AccessoriesItorage; /// 辅料库位 public ObservableCollection AccessoriesItorage { get { return _AccessoriesItorage; } set { _AccessoriesItorage = value; OnPropertyChanged(); } } private ObservableCollection _Ingredients; /// 所有的主料数据。作为ComboBox的数据源。 public ObservableCollection Ingredients { get { return _Ingredients; } set { _Ingredients = value; OnPropertyChanged(); } } //private int _storageIndex; ///// ///// 库位选择的Index。 ///// //public int StorageIndex //{ // get { return _storageIndex; } // set { _storageIndex = value;OnPropertyChanged(); } //} } }