|
- using BPASmart.Model;
- using BPASmartClient.Helper;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmart.RecipeManagement.ViewModel
- {
- public class PropertySettingViewModel : ObservableObject
- {
- public ObservableCollection<Property> properties { get; set; } = Json<LocalMaterails>.Data.PorpertyCollections;
-
- public string PropertyName { get { return _propertyName; } set { _propertyName = value; OnPropertyChanged(); } }
- private string _propertyName;
-
- public string PropertyDescription { get { return _propertyDescription; } set { _propertyDescription = value; OnPropertyChanged(); } }
- private string _propertyDescription;
-
- public string ErrorName { get { return _errorName; } set { _errorName = value; OnPropertyChanged(); } }
- private string _errorName;
-
- public RelayCommand SaveCommand { get; set; }
-
- public RelayCommand<object> DeleteCommand { get; set; }
-
- private void Delete(object o)
- {
- if (o == null) return;
- if (o is string id)
- {
- var res = properties.FirstOrDefault(p => p.PropertyId == id);
- if (res != null)
- {
- properties.Remove(res);
- }
- }
- }
-
- public PropertySettingViewModel()
- {
- SaveCommand = new RelayCommand(() =>
- {
- if (PropertyName == null)
- {
- ErrorName = "属性名称不能为空";
- return;
- }
- if (PropertyDescription == null)
- {
- ErrorName = "请添加属性说明";
- return;
- }
- if (properties.FirstOrDefault(p => p.PropertyName == PropertyName) != null)
- {
- ErrorName = "属性名重复";
- return;
- }
-
- properties.Add(new Property
- {
- PropertyId = Guid.NewGuid().ToString(),
- PropertyDescription = PropertyDescription,
- PropertyName = PropertyName
- });
- Json<LocalMaterails>.Save();
- ErrorName = String.Empty;
- });
- DeleteCommand = new RelayCommand<object>(Delete);
- }
- }
- }
|