using Admin.Core.Common; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Service; using Aucma.Core.BoxFoam.Models; using Aucma.Core.BoxFoam.Views.UserPage; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using log4net; using MaterialDesignThemes.Wpf; using Microsoft.Extensions.DependencyInjection; using Microsoft.IdentityModel.Logging; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Windows; using static NPOI.SS.Formula.PTG.AttrPtg; namespace Aucma.Core.BoxFoam.ViewModels { public partial class BeforeFoamingPageModelView : ObservableObject { private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel)); private readonly IBaseSpaceDetailServices? _baseSpaceDetailServices; private readonly IBaseSpaceInfoServices? _baseSpaceInfoServices; public BeforeFoamingPageModelView() { // 设置型号 SubmitCommand = new RelayCommand(obj => SubmitCommandExecute(obj)); SubmitCommand2 = new RelayCommand(obj => SubmitCommandExecute2(obj)); SubmitCommand3 = new RelayCommand(obj => SubmitCommandExecute3(obj)); SetBoxTypeCommand = new RelayCommand(obj => SetBoxTypeCommandExecute(obj)); _baseSpaceDetailServices = App.ServiceProvider.GetService(); _baseSpaceInfoServices = App.ServiceProvider.GetService(); SetBoxTypeViewModel.RefreshPageEvent += LoadSpaceStoreMedthAsync; SelectTypeViewModel.RefreshPageEvent += LoadSpaceStoreMedthAsync; this.LoadSpaceStoreMedthAsync(); } #region 参数定义 /// /// 设置型号 /// public RelayCommand SubmitCommand { get; set; } private void SubmitCommandExecute(string spaceCode) { SelectType type = new SelectType(1, spaceCode); type.ShowDialog(); } public RelayCommand SubmitCommand2 { get; set; } private void SubmitCommandExecute2(string spaceCode) { SelectType type = new SelectType(2, spaceCode); type.ShowDialog(); } public RelayCommand SubmitCommand3 { get; set; } private void SubmitCommandExecute3(string spaceCode) { SelectType type = new SelectType(3, spaceCode); type.ShowDialog(); } /// /// 设置夹具型号 /// public RelayCommand SetBoxTypeCommand { get; set; } private void SetBoxTypeCommandExecute(string spaceCode) { SetBoxType boxTypePage = new SetBoxType(spaceCode); boxTypePage.ShowDialog(); Console.WriteLine(spaceCode); } #endregion #region 加载泡前库货道信息 /// /// 加载泡前库货道信息 /// private void LoadSpaceStoreMedthAsync() { string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code var baseSpaceInfolist = _baseSpaceInfoServices.QueryAsync(d => d.StoreCode==storeCode).Result;//仓库 if (baseSpaceInfolist == null) return; Shapes.Clear(); foreach (var item in baseSpaceInfolist) { SpaceInfoModel model=new SpaceInfoModel(); model.spaceCode = item.SpaceCode; model.spaceStock = item.SpaceStock; model.onTheWay = item.OnRouteAmount; model.totalAmount = item.SpaceStock + item.OnRouteAmount; model.materialType = item.MaterialType; model.typeCodeB = item.typeCodeB; model.typeCodeC = item.typeCodeC; model.unusualFlag = item.UnusualFlag == 2 ? "Red" : "White"; // 夹具型号 model.boxType = item.BoxType; if (item.SpaceStatus == 2) { model.setEnable = "False"; model.inStoreFlag = "Red"; model.isFlag = "Red"; } else { model.isFlag = item.IsFlag.ToString(); //禁用状态 model.inStoreFlag ="White"; } model.onlyOne = 1; model.spaceType = item.SpaceType; Shapes.Add(model); } } #endregion #region 初始化 private ObservableCollection _shapes = new ObservableCollection(); public ObservableCollection Shapes { get => _shapes; set => SetProperty(ref _shapes, value); } #endregion #region 货道明细 [RelayCommand] private void SpaceDetail(string info) { var storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//内胆库号 List list = _baseSpaceDetailServices.GetSpaceDetailsBySpaceCode(storeCode, info).Result; RefreshSpaceDetails(list); } /// /// 刷新货道明细列表 /// /// private void RefreshSpaceDetails(List spaceDetails) { SpaceDetailDataGrid = new ObservableCollection(); if (spaceDetails != null) { spaceDetails.ForEach( arg => { SpaceDetailDataGrid.Add(arg); }); } } private ObservableCollection spaceDetailDataGrid; public ObservableCollection SpaceDetailDataGrid { get => spaceDetailDataGrid; set => SetProperty(ref spaceDetailDataGrid, value); } #endregion #region 禁用货道 [RelayCommand] private async Task IsEnableSpace(string spaceCode) { string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code var list= await _baseSpaceInfoServices.QueryAsync(d => d.StoreCode.Equals(storeCode) && d.SpaceCode.Equals(spaceCode)); list.ForEach(d => { d.SpaceStatus = 2; }); var result= await _baseSpaceInfoServices.UpdateAsync(list); if (result) { MessageBox.Show($"禁用货道[{spaceCode}] 成功!"); LoadSpaceStoreMedthAsync(); } else { MessageBox.Show($"禁用货道[{spaceCode}] 失败!"); } } #endregion #region 入库 [RelayCommand] private void EnterSpace(string spaceCode) { string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code //SpaceDetailPageView page = new SpaceDetailPageView(storeCode, spaceCode); //page.ShowDialog(); } #endregion #region 出库 [RelayCommand] private void OutSpace(string spaceCode) { //string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code //SpaceDetailPageView page = new SpaceDetailPageView(storeCode, spaceCode); //page.ShowDialog(); } #endregion /// /// 货道入库标识设置 /// /// private async void UpdateInStoreFlag(object obj) { string info = obj as string; string shellStoreCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code bool result =await UpdateInStoreFlag(shellStoreCode, info); if (result) { //Query(); //MessageBoxTimeoutA((IntPtr)0, $"货道入库状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000); } else { MessageBox.Show("货道入库状态修改失败", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } /// /// 修改货道入库标识 /// /// /// public async Task UpdateInStoreFlag(string storeCode, string spaceCode) { bool result = false; try { BaseSpaceInfo spaceInfo =await _baseSpaceInfoServices.GetSpaceInfoBySpaceCode(storeCode, spaceCode); if (spaceInfo != null) { spaceInfo.InStoreFlag = spaceInfo.InStoreFlag == 1 ? 2 : 1; result =await _baseSpaceInfoServices.UpdateSpaceInfo(spaceInfo); //logHelper.Info($"修改仓库:{storeCode};货道:{spaceCode};入库标识:{spaceInfo.inStoreFlag};修改{(result == true ? "成功" : "失败")}"); } } catch (Exception ex) { //logHelper.Error("修改货道入库标识异常", ex); } return result; } } }