|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.DosingHKProject.Model;
- using BPASmartClient.Helper;
- using BPASmartClient.Model;
- 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 BPASmartClient.DosingHKProject.ViewModel;
-
- public class NewMaterialViewModel:ObservableObject
- {
- public ObservableCollection<RawMaterialModel> Materials { get; set; } = Json<LocaMaterial>.Data.LocalMaterails;
-
- public string MaterialName { get { return _materialName; } set { _materialName = value; OnPropertyChanged(); } }
- private string _materialName = string.Empty;
-
- public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
- private string _mErrorInfo;
-
- public RelayCommand<object> RemoveCommand { get; set; }
-
- public RelayCommand SaveCommand { get; set; }
-
-
-
- private void Remove(object o)
- {
- if (o == null) return;
- if(o is string id)
- {
- var res = Materials.FirstOrDefault(p=>p.RawMaterialId == id);
- Materials.Remove(res);
- Json<LocaMaterial>.Save();
- MessageLog.GetInstance.ShowUserLog($"删除原料--{res.RawMaterialName}");
- }
- }
-
- public NewMaterialViewModel()
- {
- RemoveCommand = new RelayCommand<object>(Remove);
-
- SaveCommand = new RelayCommand(() =>
- {
- if(MaterialName == String.Empty) { ErrorInfo = "原料名称不能为空";return; }
- if(Global.DeviceRawMaterials.FirstOrDefault(p=>p.RawMaterialName == MaterialName) != null) { ErrorInfo = "设备中已存在该原料名称";return;}
- if(Json<LocaMaterial>.Data.LocalMaterails.FirstOrDefault(p=>p.RawMaterialName == MaterialName) != null) { ErrorInfo = "本地原料名称重复";return ;}
- Json<LocaMaterial>.Data.LocalMaterails.Add(new RawMaterialModel { RawMaterialName = MaterialName, RawMaterialId = Guid.NewGuid().ToString() , RawMaterialSource = 0 });
- Json<LocaMaterial>.Save();
- MessageLog.GetInstance.ShowUserLog($"添加原料--{MaterialName}");
- });
- }
- }
|