终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
2.1 KiB

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