终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

59 rader
2.2 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.Model;
  4. using Microsoft.Toolkit.Mvvm.ComponentModel;
  5. using Microsoft.Toolkit.Mvvm.Input;
  6. using System;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. namespace BPASmartClient.FoodStationTest.ViewModel;
  10. public class NewMaterialViewModel : ObservableObject
  11. {
  12. public ObservableCollection<RawMaterialModel> Materials { get; set; } = Json<LocaMaterial>.Data.LocalMaterails;
  13. public string MaterialName { get { return _materialName; } set { _materialName = value; OnPropertyChanged(); } }
  14. private string _materialName = string.Empty;
  15. public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
  16. private string _mErrorInfo;
  17. public RelayCommand<object> RemoveCommand { get; set; }
  18. public RelayCommand SaveCommand { get; set; }
  19. private void Remove(object o)
  20. {
  21. if (o == null)
  22. return;
  23. if (o is string id)
  24. {
  25. var res = Materials.FirstOrDefault(p => p.RawMaterialId == id);
  26. Materials.Remove(res);
  27. Json<LocaMaterial>.Save();
  28. MessageNotify.GetInstance.ShowUserLog($"删除原料--{res.RawMaterialName}");
  29. }
  30. }
  31. public NewMaterialViewModel()
  32. {
  33. RemoveCommand = new RelayCommand<object>(Remove);
  34. SaveCommand = new RelayCommand(() =>
  35. {
  36. if (MaterialName == String.Empty)
  37. { ErrorInfo = "原料名称不能为空"; return; }
  38. if (Global.DeviceRawMaterials.FirstOrDefault(p => p.RawMaterialName == MaterialName) != null)
  39. { ErrorInfo = "设备中已存在该原料名称"; return; }
  40. if (Json<LocaMaterial>.Data.LocalMaterails.FirstOrDefault(p => p.RawMaterialName == MaterialName) != null)
  41. { ErrorInfo = "本地原料名称重复"; return; }
  42. Json<LocaMaterial>.Data.LocalMaterails.Add(new RawMaterialModel { RawMaterialName = MaterialName, RawMaterialId = Guid.NewGuid().ToString(), RawMaterialSource = 0 });
  43. Json<LocaMaterial>.Save();
  44. MessageNotify.GetInstance.ShowUserLog($"添加原料--{MaterialName}");
  45. });
  46. }
  47. }