|
- 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<ItemStorage>(Json<ItemStorageInfo>.Data.IngredientsStorage);
- AccessoriesItorage = new ObservableCollection<ItemStorage>(Json<ItemStorageInfo>.Data.AccessoriesStorage);
- }, "RefreshItemStorage", true);
-
- ActionManage.GetInstance.Register((() =>
- {
- Ingredients = new ObservableCollection<IngredientsTB>(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<object>((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<ItemStorageInfo>.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<ItemStorageInfo>.Save();
-
- // IngredientsItorage = new ObservableCollection<ItemStorage>(Json<ItemStorageInfo>.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<ItemStorageInfo>.Data.IngredientsStorage.Length; i++)
- {
- Json<ItemStorageInfo>.Data.IngredientsStorage[i] = new();
- }
- Json<ItemStorageInfo>.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<ItemStorageInfo>.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<ItemStorageInfo>.Data.IngredientsStorage.Length)
- {
- Json<ItemStorageInfo>.Data.IngredientsStorage[index] = new ItemStorage();
- Json<ItemStorageInfo>.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<object> InStorageCommand { get; set; }
- /// <summary>
- /// 初始化库位。
- /// </summary>
- public BPARelayCommand InitialStorageCommand { get; set; }
- /// <summary>
- /// 电子秤除皮。
- /// </summary>
- [Obsolete("除皮功能弃用,不会用这个功能。")]
- public BPARelayCommand WeigherTareCommand { get; set; }
- /// <summary>
- /// 电子秤置零。
- /// </summary>
- public BPARelayCommand WeigherZeroCommand { get; set; }
- /// <summary>
- /// 修改指定库位信息。
- /// </summary>
- public BPARelayCommand<object> ModifySelectStorageCommand { get; set; }
- /// <summary>
- /// 清空指定库位信息。
- /// </summary>
- public BPARelayCommand<object> 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<ItemStorage> _IngredientsItorage;
-
- /// <summary>主料库位。</summary>
- public ObservableCollection<ItemStorage> IngredientsItorage
- {
- get { return _IngredientsItorage; }
- set { _IngredientsItorage = value; OnPropertyChanged(); }
- }
-
- private ObservableCollection<ItemStorage> _AccessoriesItorage;
-
- /// <summary>辅料库位</summary>
- public ObservableCollection<ItemStorage> AccessoriesItorage
- {
- get { return _AccessoriesItorage; }
- set { _AccessoriesItorage = value; OnPropertyChanged(); }
- }
-
- private ObservableCollection<IngredientsTB> _Ingredients;
-
- /// <summary>所有的主料数据。作为ComboBox的数据源。</summary>
- public ObservableCollection<IngredientsTB> Ingredients
- {
- get { return _Ingredients; }
- set { _Ingredients = value; OnPropertyChanged(); }
- }
-
- //private int _storageIndex;
- ///// <summary>
- ///// 库位选择的Index。
- ///// </summary>
- //public int StorageIndex
- //{
- // get { return _storageIndex; }
- // set { _storageIndex = value;OnPropertyChanged(); }
- //}
-
- }
- }
|