using Admin.Core.Model; using Aucma.Scada.UI; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; namespace Aucma.Scada.UI.ViewModel.InventoryInfo { public partial class SpaceDetailViewModel : ObservableObject { private InventoryInfoBusiness inventoryInfoBusiness = new InventoryInfoBusiness();// InventoryInfoBusiness.Instance; private string storeCode = string.Empty; private string spaceCode = string.Empty; public SpaceDetailViewModel(string storeCode, string spaceCode) { inventoryInfoBusiness.RefreshSpaceDetailsEvent += RefreshSpaceDetails; this.storeCode = storeCode; this.spaceCode = spaceCode; TitleName = "货道明细信息"; } #region 参数定义 /// /// 物料编号 /// private string materialCodeSearch; public string MaterialCodeSearch { get => materialCodeSearch; set => SetProperty(ref materialCodeSearch, value); } /// /// 物料名称 /// private string materialNameSearch; public string MaterialNameSearch { get => materialNameSearch; set => SetProperty(ref materialNameSearch, value); } private string titleName; public string TitleName { get => titleName; set => SetProperty(ref titleName, value); } /// /// 计划列表DataGrid /// private ObservableCollection spaceDetailDataGrid; public ObservableCollection SpaceDetailDataGrid { get => spaceDetailDataGrid; set => SetProperty(ref spaceDetailDataGrid, value); } #endregion [RelayCommand] private void CloseWindow(object parameter) { var window = parameter as Window; if (window != null) { window.Close(); } } /// /// 查询 /// [RelayCommand] private async void Query() { var list =await inventoryInfoBusiness.GetBaseSpaceDetails(this.storeCode, this.spaceCode); if (!string.IsNullOrEmpty(materialCodeSearch)) { list = list.Where(x => x.MaterialCode == materialCodeSearch).ToList(); } else if (!string.IsNullOrEmpty(materialNameSearch)) { list = list.Where(x => x.MaterialName == materialNameSearch).ToList(); } RefreshSpaceDetails(list); } [RelayCommand] public void Reset() { MaterialCodeSearch = string.Empty; MaterialNameSearch = string.Empty; this.Query(); } /// /// 刷新货道明细列表 /// /// [RelayCommand] private void RefreshSpaceDetails(List spaceDetails) { SpaceDetailDataGrid = new ObservableCollection(); if (spaceDetails != null) { spaceDetails.ForEach( arg => { SpaceDetailDataGrid.Add(arg); }); } } } }