|
- using BPASmartClient.CustomResource.Pages.Model;
- using BPA.Helper;
- using BPASmartClient.Model;
- using BPA.Helper;
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.DosingSystem.ViewModel;
-
- public class NewMaterialViewModel : ViewModelBase
- {
- 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 BPARelayCommand<object> RemoveCommand { get; set; }
-
- //public BPARelayCommand 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();
- MessageNotify.GetInstance.ShowUserLog($"删除原料--{res.RawMaterialName}");
- }
- }
-
- public NewMaterialViewModel()
- {
- RemoveCommand = new BPARelayCommand<object>(Remove);
-
- SaveCommand = new BPARelayCommand(() =>
- {
- 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();
- MessageNotify.GetInstance.ShowUserLog($"添加原料--{MaterialName}");
- });
- }
- }
|