终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

59 righe
2.2 KiB

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