You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Aucma.Core.BoxFoam/ViewModels/BeforeFoamingPageModelView.cs

213 lines
7.6 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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() {
_baseSpaceDetailServices = App.ServiceProvider.GetService<IBaseSpaceDetailServices>();
_baseSpaceInfoServices = App.ServiceProvider.GetService<IBaseSpaceInfoServices>();
this.LoadSpaceStoreMedthAsync();
}
#region 加载泡前库货道信息
/// <summary>
/// 加载泡前库货道信息
/// </summary>
private void LoadSpaceStoreMedthAsync()
{
string storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//泡前库code
var baseSpaceInfolist = _baseSpaceInfoServices.QueryAsync(d => d.StoreCode.Equals(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.unusualFlag = item.UnusualFlag == 2 ? "Red" : "White";
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<SpaceInfoModel> _shapes = new ObservableCollection<SpaceInfoModel>();
public ObservableCollection<SpaceInfoModel> Shapes
{
get => _shapes;
set => SetProperty(ref _shapes, value);
}
#endregion
#region 货道明细
[RelayCommand]
private void SpaceDetail(string info)
{
var storeCode = Appsettings.app("StoreInfo", "BeforeStoreCode");//内胆库号
List<BaseSpaceDetail> list = _baseSpaceDetailServices.GetSpaceDetailsBySpaceCode(storeCode, info).Result;
RefreshSpaceDetails(list);
}
/// <summary>
/// 刷新货道明细列表
/// </summary>
/// <param name="spaceDetails"></param>
private void RefreshSpaceDetails(List<BaseSpaceDetail> spaceDetails)
{
SpaceDetailDataGrid = new ObservableCollection<BaseSpaceDetail>();
if (spaceDetails != null)
{
spaceDetails.ForEach(
arg =>
{
SpaceDetailDataGrid.Add(arg);
});
}
}
private ObservableCollection<BaseSpaceDetail> spaceDetailDataGrid;
public ObservableCollection<BaseSpaceDetail> 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
/// <summary>
/// 货道入库标识设置
/// </summary>
/// <param name="obj"></param>
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);
}
}
/// <summary>
/// 修改货道入库标识
/// </summary>
/// <param name="storeCode"></param>
/// <param name="spaceCode"></param>
public async Task<bool> 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;
}
}
}