using Admin.Core.Model; using Aucma.Scada.UI.Common; using Aucma.Scada.UI; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.InteropServices; using System.Windows; namespace Aucma.Scada.UI.ViewModel.InventoryInfo { public partial class LinerInventoryViewModel : ObservableObject { [DllImport("user32.dll")] public static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time); private ObservableCollection spaceItems = new ObservableCollection(); private InventoryInfoBusiness inventoryInfoBusiness = new InventoryInfoBusiness();// InventoryInfoBusiness.Instance; private OutStoreBusiness outStoreBusiness = new OutStoreBusiness();// OutStoreBusiness.Instance; private InStoreBusiness inStoreBusiness = new InStoreBusiness();// InStoreBusiness.Instance; private AppConfig appConfig = new AppConfig();//AppConfig.Instance; public LinerInventoryViewModel() { outStoreBusiness.RefreshStoreStockEvent += Query; inStoreBusiness.RefreshInStoreTaskEvent += RefreshSpaceInfo; Query(); } #region 参数定义 public ObservableCollection _shapes; public ObservableCollection Shapes { get => _shapes; set => SetProperty(ref _shapes, value); } private ObservableCollection spaceDetailDataGrid; public ObservableCollection SpaceDetailDataGrid { get => spaceDetailDataGrid; set => SetProperty(ref spaceDetailDataGrid, value); } #endregion private void Query() { App.Current.Dispatcher.BeginInvoke((Action)(async () => { var info =await inventoryInfoBusiness.GetSpaceInfos(appConfig.linerStoreCode); if (info != null) { if (spaceItems.Count > 0) { spaceItems.Clear(); } foreach (var item in info) { spaceItems.Add(item); } Shapes = spaceItems; } })); } private void RefreshSpaceInfo(object obj = null, bool isFinish = true) { Query(); } /// /// 货道入库标识设置 /// /// [RelayCommand] private async void UpdateInStoreFlag(string info) { bool result =await inventoryInfoBusiness.UpdateInStoreFlag(appConfig.linerStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"货道入库状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道入库状态修改失败", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } /// /// 货道出库标识设置 /// /// [RelayCommand] private async void UpdateOutStoreFlag(object obj) { string info = obj as string; bool result =await inventoryInfoBusiness.UpdateOutStoreFlag(appConfig.linerStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"货道出库状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道出库状态修改失败", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } /// /// 货道异常标识设置 /// /// [RelayCommand] private async void UpdateUnusualFlag(object obj) { string info = obj as string; bool result =await inventoryInfoBusiness.UpdateUnusualFlag(appConfig.linerStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"货道异常标识修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道异常标识修改失败", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } /// /// 修改货道状态 /// /// [RelayCommand] private async void UpdateSpaceStatus(object obj) { string info = obj as string; bool result =await inventoryInfoBusiness.UpdateSpaceStatus(appConfig.linerStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"货道状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道状态修改失败", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } /// /// 货道明细 /// /// [RelayCommand] private async void SpaceDetail(object obj) { string info = obj as string; var list =await inventoryInfoBusiness.GetBaseSpaceDetails(appConfig.linerStoreCode, info); RefreshSpaceDetails(list); } /// /// 刷新货道明细列表 /// /// private void RefreshSpaceDetails(List spaceDetails) { SpaceDetailDataGrid = new ObservableCollection(); if (spaceDetails != null) { spaceDetails.ForEach( arg => { SpaceDetailDataGrid.Add(arg); }); } } /// /// 手动出一个 /// /// [RelayCommand] private async void OutOnlyOne(object obj) { string info = obj as string; bool result =await outStoreBusiness.OutOnlyOneBySpaceCode(appConfig.linerStoreCode, info); if (result) { Query(); MessageBoxTimeoutA((IntPtr)0, $"出库任务创建成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("出库任务创建失败", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } } }