终端一体化运控平台
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 line
2.2 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.DosingHKProject.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.DosingHKProject.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. }