终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

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