|
|
using Aucma.Scada.Business;
|
|
|
using Aucma.Scada.Model.domain;
|
|
|
using Aucma.Scada.UI.Page.InventoryInfo;
|
|
|
using GalaSoft.MvvmLight;
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
using HighWayIot.Config;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.Linq;
|
|
|
using System.Runtime.InteropServices;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
|
|
|
namespace Aucma.Scada.UI.viewModel.InventoryInfo
|
|
|
{
|
|
|
public class LinerInventoryViewModel : ViewModelBase
|
|
|
{
|
|
|
[DllImport("user32.dll")]
|
|
|
public static extern int MessageBoxTimeoutA(IntPtr hWnd, string msg, string Caps, int type, int Id, int time);
|
|
|
|
|
|
private ObservableCollection<BaseSpaceInfo> spaceItems = new ObservableCollection<BaseSpaceInfo>();
|
|
|
|
|
|
private InventoryInfoBusiness inventoryInfoBusiness = InventoryInfoBusiness.Instance;
|
|
|
|
|
|
private OutStoreBusiness outStoreBusiness = OutStoreBusiness.Instance;
|
|
|
|
|
|
private InStoreBusiness inStoreBusiness = InStoreBusiness.Instance;
|
|
|
|
|
|
private AppConfig appConfig = AppConfig.Instance;
|
|
|
|
|
|
private InStoreTaskHandle taskHandle = InStoreTaskHandle.Instance;
|
|
|
|
|
|
|
|
|
public LinerInventoryViewModel()
|
|
|
{
|
|
|
|
|
|
#region 事件绑定
|
|
|
|
|
|
// 设置型号
|
|
|
SubmitCommand = new RelayCommand<string>(obj => SubmitCommandExecute(obj));
|
|
|
|
|
|
UpdateInStoreFlagCommand = new RelayCommand<object>(obj => UpdateInStoreFlag(obj));
|
|
|
|
|
|
UpdateOutStoreFlagCommand = new RelayCommand<object>(obj => UpdateOutStoreFlag(obj));
|
|
|
|
|
|
UpdateUnusualFlagCommand = new RelayCommand<object>(obj => UpdateUnusualFlag(obj));
|
|
|
|
|
|
UpdateSpaceStatusCommand = new RelayCommand<object>(obj => UpdateSpaceStatus(obj));
|
|
|
|
|
|
SpaceDetailCommand = new RelayCommand<object>(obj => SpaceDetail(obj));
|
|
|
|
|
|
OutOnlyOneCommand = new RelayCommand<object>(obj => OutOnlyOne(obj));
|
|
|
#endregion
|
|
|
outStoreBusiness.RefreshStoreStockEvent += Query;
|
|
|
SelectTypeViewModel.RefreshLinerPageEvent += Query;
|
|
|
inStoreBusiness.RefreshInStoreTaskEvent += RefreshSpaceInfo;
|
|
|
taskHandle.RefreshLinerStockEvent += Query;
|
|
|
Query();
|
|
|
|
|
|
}
|
|
|
|
|
|
#region 参数定义
|
|
|
|
|
|
public RelayCommand<string> SubmitCommand { get; set; }
|
|
|
|
|
|
private void SubmitCommandExecute(string spaceCode)
|
|
|
{
|
|
|
|
|
|
SelectType type = new SelectType(1, spaceCode);
|
|
|
type.ShowDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public ObservableCollection<BaseSpaceInfo> _shapes;
|
|
|
|
|
|
public ObservableCollection<BaseSpaceInfo> Shapes
|
|
|
{
|
|
|
get { return _shapes; }
|
|
|
set { _shapes = value; RaisePropertyChanged(nameof(Shapes)); }
|
|
|
}
|
|
|
|
|
|
private ObservableCollection<BaseSpaceDetail> spaceDetailDataGrid;
|
|
|
|
|
|
public ObservableCollection<BaseSpaceDetail> SpaceDetailDataGrid
|
|
|
{
|
|
|
get { return spaceDetailDataGrid; }
|
|
|
set { spaceDetailDataGrid = value; RaisePropertyChanged(() => SpaceDetailDataGrid); }
|
|
|
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 事件定义
|
|
|
/// <summary>
|
|
|
/// 修改入库状态标识
|
|
|
/// </summary>
|
|
|
public RelayCommand<object> UpdateInStoreFlagCommand { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 修改出库状态标识
|
|
|
/// </summary>
|
|
|
public RelayCommand<object> UpdateOutStoreFlagCommand { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 修改异常状态标识
|
|
|
/// </summary>
|
|
|
public RelayCommand<object> UpdateUnusualFlagCommand { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 修改货道状态
|
|
|
/// </summary>
|
|
|
public RelayCommand<object> UpdateSpaceStatusCommand { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道明细
|
|
|
/// </summary>
|
|
|
public RelayCommand<object> SpaceDetailCommand { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 出一个
|
|
|
/// </summary>
|
|
|
public RelayCommand<object> OutOnlyOneCommand { get; set; }
|
|
|
#endregion
|
|
|
|
|
|
private async Task Query()
|
|
|
{
|
|
|
await Task.Run(() =>
|
|
|
{
|
|
|
App.Current.Dispatcher.BeginInvoke((Action)(() =>
|
|
|
{
|
|
|
var info = inventoryInfoBusiness.GetSpaceInfos(appConfig.linerStoreCode);
|
|
|
if (info != null)
|
|
|
{
|
|
|
if (spaceItems.Count > 0)
|
|
|
{
|
|
|
spaceItems.Clear();
|
|
|
}
|
|
|
|
|
|
foreach (var item in info)
|
|
|
{
|
|
|
// item.typeNameA = GetSubstringBetweenCommas(item.typeNameA);
|
|
|
spaceItems.Add(item);
|
|
|
}
|
|
|
Shapes = spaceItems;
|
|
|
}
|
|
|
}));
|
|
|
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 截取两个逗号之间的字符串
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
static string GetSubstringBetweenCommas(string input)
|
|
|
{
|
|
|
if (input == null) return null;
|
|
|
// 找到第一个逗号的位置
|
|
|
int firstCommaIndex = input.IndexOf(',');
|
|
|
if (firstCommaIndex != -1)
|
|
|
{
|
|
|
// 找到第二个逗号的位置
|
|
|
int secondCommaIndex = input.IndexOf(',', firstCommaIndex + 1);
|
|
|
if (secondCommaIndex != -1)
|
|
|
{
|
|
|
// 使用Substring截取第一个逗号和第二个逗号之间的字符
|
|
|
return input.Substring(firstCommaIndex + 1, secondCommaIndex - firstCommaIndex - 1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void RefreshSpaceInfo(object obj = null, bool isFinish = true)
|
|
|
{
|
|
|
Query();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道入库标识设置
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void UpdateInStoreFlag(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
bool result = 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道出库标识设置
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void UpdateOutStoreFlag(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
bool result = 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道异常标识设置
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void UpdateUnusualFlag(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
bool result = 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 修改货道状态
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void UpdateSpaceStatus(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
bool result = 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道明细
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void SpaceDetail(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
var list = inventoryInfoBusiness.GetBaseSpaceDetails(appConfig.linerStoreCode, info);
|
|
|
|
|
|
BaseSpaceInfo spaceInfo = inStoreBusiness.getSpaceBySpaceCode(appConfig.linerStoreCode, info);
|
|
|
if (spaceInfo == null) return;
|
|
|
|
|
|
list = list.OrderByDescending(x => x.createTime).Take(spaceInfo.spaceStock).ToList();
|
|
|
|
|
|
RefreshSpaceDetails(list);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新货道明细列表
|
|
|
/// </summary>
|
|
|
/// <param name="spaceDetails"></param>
|
|
|
private void RefreshSpaceDetails(List<BaseSpaceDetail> spaceDetails)
|
|
|
{
|
|
|
SpaceDetailDataGrid = new ObservableCollection<BaseSpaceDetail>();
|
|
|
if (spaceDetails != null)
|
|
|
{
|
|
|
spaceDetails.ForEach(
|
|
|
arg =>
|
|
|
{
|
|
|
arg.materialName = GetStringAfterFirstComma(arg.materialName);
|
|
|
SpaceDetailDataGrid.Add(arg);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 截取字符串第一个逗号之后的字符
|
|
|
/// </summary>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
public static string GetStringAfterFirstComma(string input)
|
|
|
{
|
|
|
|
|
|
int commaIndex = input.IndexOf(',');
|
|
|
|
|
|
if (commaIndex == -1)
|
|
|
return "";
|
|
|
string result = input.Substring(commaIndex + 1);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 手动出一个
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void OutOnlyOne(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
bool result = 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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} }
|