using Aucma.Scada.Business; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HighWayIot.Repository.domain; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace Aucma.Scada.UI.viewModel.InventoryInfo { public class SpaceDetailViewModel : ViewModelBase { private InventoryInfoBusiness inventoryInfoBusiness = InventoryInfoBusiness.Instance; private string storeCode = string.Empty; private string spaceCode = string.Empty; public SpaceDetailViewModel(string storeCode, string spaceCode) { CloseWindowCommand = new RelayCommand(t => CloseWindow(t)); QueryCommand = new RelayCommand(Query); ResetCommand = new RelayCommand(Reset); inventoryInfoBusiness.RefreshSpaceDetailsEvent += RefreshSpaceDetails; this.storeCode = storeCode; this.spaceCode = spaceCode; TitleName = "货道明细信息"; } #region 参数定义 /// /// 物料编号 /// private string materialCodeSearch; public string MaterialCodeSearch { get { return materialCodeSearch; } set { materialCodeSearch = value; RaisePropertyChanged(nameof(MaterialCodeSearch)); } } /// /// 物料名称 /// private string materialNameSearch; public string MaterialNameSearch { get { return materialNameSearch; } set { materialNameSearch = value; RaisePropertyChanged(nameof(MaterialNameSearch)); } } private string titleName; public string TitleName { get { return titleName; } set { titleName = value; RaisePropertyChanged(nameof(TitleName)); } } /// /// 计划列表DataGrid /// private ObservableCollection spaceDetailDataGrid; public ObservableCollection SpaceDetailDataGrid { get { return spaceDetailDataGrid; } set { spaceDetailDataGrid = value; RaisePropertyChanged(() => SpaceDetailDataGrid); } } #endregion #region 事件定义 /// /// 关闭事件 /// public RelayCommand CloseWindowCommand { get; set; } /// /// 查询事件 /// public RelayCommand QueryCommand { get; set; } /// /// 重置事件 /// public RelayCommand ResetCommand { get; set; } #endregion private void CloseWindow(object parameter) { var window = parameter as Window; if (window != null) { window.Close(); } } /// /// 查询 /// private void Query() { var list = 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); } public void Reset() { MaterialCodeSearch = string.Empty; MaterialNameSearch = string.Empty; this.Query(); } /// /// 刷新货道明细列表 /// /// private void RefreshSpaceDetails(List spaceDetails) { SpaceDetailDataGrid = new ObservableCollection(); if (spaceDetails != null) { spaceDetails.ForEach( arg => { SpaceDetailDataGrid.Add(arg); }); } } } }