终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

59 行
2.3 KiB

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