|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using System.Collections.ObjectModel;
- using BPASmartClient.JXJFoodSmallStation.Model;
- using BPASmartClient.Helper;
- using Microsoft.Toolkit.Mvvm.Input;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.CustomResource.UserControls;
- using System.Diagnostics;
-
- namespace BPASmartClient.JXJFoodSmallStation.ViewModel
- {
- public class DeviceMaterialParViewModel : ObservableObject
- {
- public DeviceMaterialParViewModel()
- {
- deviceParModels = Json<DevicePar>.Data.deviceParModels;
- RemoveCommand = new RelayCommand<object>((o) =>
- {
- var res = deviceParModels.FirstOrDefault(p => p.MaterialName == o?.ToString());
- if (res != null) deviceParModels.Remove(res);
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{o.ToString()}:原料删除成功!");
- });
-
- AddCommand = new RelayCommand(() => { deviceParModels.Add(new DeviceParModel()); });
- SaveCommand = new RelayCommand(() =>
- {
- if (deviceParModels == null || deviceParModels.Count <= 0)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"没有可保存的参数!");
- return;
- }
-
- for (int i = 0; i < deviceParModels.Count; i++)
- {
- if (deviceParModels.Where(p => p.MaterialName == deviceParModels.ElementAt(i).MaterialName)?.ToList()?.Count >= 2)
- deviceParModels.ElementAt(i).IsRedundant = true;
- else
- deviceParModels.ElementAt(i).IsRedundant = false;
- }
-
- if (deviceParModels.FirstOrDefault(p => p.IsRedundant == true) != null)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"原料名称冲突,请检查后重试!");
- return;
- }
-
- deviceParModels.Where(P => P.MaterialName.Length <= 0)?.ToList()?.ForEach(item =>
- {
- Json<DevicePar>.Data.deviceParModels.Remove(item);
- });
- Json<DevicePar>.Save();
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"原料参数保存成功!");
- });
- }
-
- public ObservableCollection<DeviceParModel> deviceParModels { get; set; }
-
- public RelayCommand<object> RemoveCommand { get; set; }
-
- public RelayCommand AddCommand { get; set; }
- public RelayCommand SaveCommand { get; set; }
-
- }
- }
|