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

77 line
2.5 KiB

  1. using BPASmart.Model;
  2. using BPASmartClient.Helper;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  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 BPASmart.RecipeManagement.ViewModel
  12. {
  13. public class PropertySettingViewModel : ObservableObject
  14. {
  15. public ObservableCollection<Property> properties { get; set; } = Json<LocalMaterails>.Data.PorpertyCollections;
  16. public string PropertyName { get { return _propertyName; } set { _propertyName = value; OnPropertyChanged(); } }
  17. private string _propertyName;
  18. public string PropertyDescription { get { return _propertyDescription; } set { _propertyDescription = value; OnPropertyChanged(); } }
  19. private string _propertyDescription;
  20. public string ErrorName { get { return _errorName; } set { _errorName = value; OnPropertyChanged(); } }
  21. private string _errorName;
  22. public RelayCommand SaveCommand { get; set; }
  23. public RelayCommand<object> DeleteCommand { get; set; }
  24. private void Delete(object o)
  25. {
  26. if (o == null) return;
  27. if (o is string id)
  28. {
  29. var res = properties.FirstOrDefault(p => p.PropertyId == id);
  30. if (res != null)
  31. {
  32. properties.Remove(res);
  33. }
  34. }
  35. }
  36. public PropertySettingViewModel()
  37. {
  38. SaveCommand = new RelayCommand(() =>
  39. {
  40. if (PropertyName == null)
  41. {
  42. ErrorName = "属性名称不能为空";
  43. return;
  44. }
  45. if (PropertyDescription == null)
  46. {
  47. ErrorName = "请添加属性说明";
  48. return;
  49. }
  50. if (properties.FirstOrDefault(p => p.PropertyName == PropertyName) != null)
  51. {
  52. ErrorName = "属性名重复";
  53. return;
  54. }
  55. properties.Add(new Property
  56. {
  57. PropertyId = Guid.NewGuid().ToString(),
  58. PropertyDescription = PropertyDescription,
  59. PropertyName = PropertyName
  60. });
  61. Json<LocalMaterails>.Save();
  62. ErrorName = String.Empty;
  63. });
  64. DeleteCommand = new RelayCommand<object>(Delete);
  65. }
  66. }
  67. }