25개 이상의 토픽을 선택하실 수 없습니다.
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- using BPA.Helper;
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Model;
- using System;
- using System.Collections.ObjectModel;
- using System.Linq;
-
- namespace BPASmartClient.Academy.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() });
- Json<LocaMaterial>.Save();
- MessageNotify.GetInstance.ShowUserLog($"添加原料--{MaterialName}");
- });
- }
- }
|