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

53 lines
2.1 KiB

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