|
|
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.Windows;
|
|
|
|
|
|
namespace Aucma.Scada.UI.viewModel.InventoryInfo
|
|
|
{
|
|
|
public class BoxFoamRearInventoryViewModel : 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 InStoreTaskHandle taskHandle = InStoreTaskHandle.Instance;
|
|
|
|
|
|
private AppConfig appConfig = AppConfig.Instance;
|
|
|
|
|
|
private AssemblyPlanBusiness assemblyPlanBusiness = AssemblyPlanBusiness.Instance;
|
|
|
|
|
|
public BoxFoamRearInventoryViewModel()
|
|
|
{
|
|
|
|
|
|
#region 事件绑定
|
|
|
// 设置型号
|
|
|
SubmitCommand = new RelayCommand<string>(obj => SubmitCommandExecute(obj));
|
|
|
SubmitCommand2 = new RelayCommand<string>(obj => SubmitCommandExecute2(obj));
|
|
|
SubmitCommand3 = new RelayCommand<string>(obj => SubmitCommandExecute3(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));
|
|
|
|
|
|
OutAllCommand = new RelayCommand<object>(obj => OutAll(obj));
|
|
|
#endregion
|
|
|
|
|
|
outStoreBusiness.RefreshStoreStockEvent += Query;
|
|
|
|
|
|
inStoreBusiness.RefreshInStoreTaskEvent += RefreshSpaceInfo;
|
|
|
taskHandle.RefreshFoamStockEvent += Query;
|
|
|
SelectTypeViewModel.RefreshPageEvent += Query;
|
|
|
Query();
|
|
|
|
|
|
}
|
|
|
|
|
|
#region 参数定义
|
|
|
public RelayCommand<string> SubmitCommand { get; set; }
|
|
|
|
|
|
private void SubmitCommandExecute(string spaceCode)
|
|
|
{
|
|
|
|
|
|
SelectType type = new SelectType(1, spaceCode);
|
|
|
type.ShowDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
public RelayCommand<string> SubmitCommand2 { get; set; }
|
|
|
|
|
|
private void SubmitCommandExecute2(string spaceCode)
|
|
|
{
|
|
|
|
|
|
SelectType type = new SelectType(2, spaceCode);
|
|
|
type.ShowDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
public RelayCommand<string> SubmitCommand3 { get; set; }
|
|
|
|
|
|
private void SubmitCommandExecute3(string spaceCode)
|
|
|
{
|
|
|
|
|
|
SelectType type = new SelectType(3, 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; }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 整条道出
|
|
|
/// </summary>
|
|
|
public RelayCommand<object> OutAllCommand { get; set; }
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新货道信息,入库完成委托事件
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
/// <param name="isFinish"></param>
|
|
|
private void RefreshSpaceInfo(object obj = null, bool isFinish = true)
|
|
|
{
|
|
|
Query();
|
|
|
}
|
|
|
|
|
|
private void Query()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var info = inventoryInfoBusiness.GetSpaceInfos(appConfig.foamStoreCode);
|
|
|
if (info != null)
|
|
|
{
|
|
|
info = info.OrderBy(x => x.objId).ToList();
|
|
|
|
|
|
App.Current.Dispatcher.Invoke((Action)(() =>
|
|
|
{
|
|
|
if (spaceItems.Count > 0)
|
|
|
{
|
|
|
spaceItems.Clear();
|
|
|
}
|
|
|
|
|
|
foreach (var item in info)
|
|
|
{
|
|
|
// item.typeNameA = GetSubstringAfterFirstDelimiter(item);
|
|
|
spaceItems.Add(item);
|
|
|
}
|
|
|
|
|
|
Shapes = spaceItems; // 创建新的 ObservableCollection
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
Console.WriteLine(ex.ToString());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 截取第一个逗号以后的内容
|
|
|
/// </summary>
|
|
|
/// <param name="originalString"></param>
|
|
|
/// <returns></returns>
|
|
|
//public static string GetSubstringAfterFirstDelimiter(BaseSpaceInfo space)
|
|
|
//{
|
|
|
// if (string.IsNullOrEmpty(space.typeNameA))
|
|
|
// {
|
|
|
// return "";
|
|
|
// }
|
|
|
// int index = space.typeNameA.IndexOf(",");
|
|
|
// if (index != -1 && index < space.typeNameA.Length - 1)
|
|
|
// {
|
|
|
// return space.typeNameA.Substring(index + 1);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// return space.typeNameA;
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道入库标识设置
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void UpdateInStoreFlag(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
MessageBoxResult result1 = MessageBox.Show("确认修改入库状态吗", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
if (result1 == MessageBoxResult.Yes)
|
|
|
{
|
|
|
bool result = inventoryInfoBusiness.UpdateInStoreFlag(appConfig.foamStoreCode, info);
|
|
|
if (result)
|
|
|
{
|
|
|
Query();
|
|
|
MessageBoxTimeoutA((IntPtr)0, $"货道入库状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("货道入库状态修改失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道出库标识设置
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void UpdateOutStoreFlag(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
MessageBoxResult result1 = MessageBox.Show("确认修改出库状态吗", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
if (result1 == MessageBoxResult.Yes)
|
|
|
{
|
|
|
bool result = inventoryInfoBusiness.UpdateOutStoreFlag(appConfig.foamStoreCode, info);
|
|
|
if (result)
|
|
|
{
|
|
|
Query();
|
|
|
MessageBoxTimeoutA((IntPtr)0, $"货道出库状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("货道出库状态修改失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道异常标识设置
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void UpdateUnusualFlag(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
MessageBoxResult result1 = MessageBox.Show("确认修改货道状态吗", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
if (result1 == MessageBoxResult.Yes)
|
|
|
{
|
|
|
bool result = inventoryInfoBusiness.UpdateUnusualFlag(appConfig.foamStoreCode, info);
|
|
|
if (result)
|
|
|
{
|
|
|
Query();
|
|
|
MessageBoxTimeoutA((IntPtr)0, $"货道异常标识修改成功,3秒后关闭提示", "提示", 0, 0, 3000);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("货道异常标识修改失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 修改货道状态
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void UpdateSpaceStatus(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
MessageBoxResult result1 = MessageBox.Show("确认修改货道状态吗", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
if (result1 == MessageBoxResult.Yes)
|
|
|
{
|
|
|
bool result = inventoryInfoBusiness.UpdateSpaceStatus(appConfig.foamStoreCode, info);
|
|
|
if (result)
|
|
|
{
|
|
|
Query();
|
|
|
MessageBoxTimeoutA((IntPtr)0, $"货道状态修改成功,3秒后关闭提示", "提示", 0, 0, 3000);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("货道状态修改失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 货道明细
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void SpaceDetail(object obj)
|
|
|
{
|
|
|
|
|
|
string info = obj as string;
|
|
|
//SpaceDetailWindow spaceDetailWindow = new SpaceDetailWindow(appConfig.shellStoreCode, info);
|
|
|
//spaceDetailWindow.Show();
|
|
|
|
|
|
//inventoryInfoBusiness.RefreshBaseSpaceDetails(appConfig.shellStoreCode, info);
|
|
|
BaseSpaceInfo space = inStoreBusiness.GetSpaceInfo(info);
|
|
|
|
|
|
List<BaseSpaceDetail> list = inventoryInfoBusiness.GetBaseSpaceDetails(appConfig.foamStoreCode, info);
|
|
|
if (list != null && list.Count > 0)
|
|
|
{
|
|
|
list = list.OrderByDescending(x => x.createTime).Take(Math.Min(list.Count, space.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 = GetSubstringBetweenCommas(arg.materialName);
|
|
|
SpaceDetailDataGrid.Add(arg);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static string GetSubstringBetweenCommas(string input)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(input)) return input;
|
|
|
// 找到第一个逗号的位置
|
|
|
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 "";
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 手动出一个
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void OutOnlyOne(object obj)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
MessageBoxResult result1 = MessageBox.Show("确认出一个吗", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
if (result1 == MessageBoxResult.Yes)
|
|
|
{
|
|
|
bool result = outStoreBusiness.OutOnlyOneBySpaceCode(appConfig.foamStoreCode, info);
|
|
|
if (result)
|
|
|
{
|
|
|
Query();
|
|
|
MessageBoxTimeoutA((IntPtr)0, $"出库任务创建成功,3秒后关闭提示", "提示", 0, 0, 3000);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("出库任务创建失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 整条道出
|
|
|
/// </summary>
|
|
|
/// <param name="obj"></param>
|
|
|
private void OutAll(object obj)
|
|
|
{
|
|
|
|
|
|
MessageBoxResult result1 = MessageBox.Show("确认整道出吗", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
if (result1 == MessageBoxResult.Yes)
|
|
|
{
|
|
|
string info = obj as string;
|
|
|
bool result = outStoreBusiness.OutAllBySpaceCode(appConfig.foamStoreCode, info);
|
|
|
if (result)
|
|
|
{
|
|
|
Query();
|
|
|
MessageBoxTimeoutA((IntPtr)0, $"出库任务创建成功,3秒后关闭提示", "提示", 0, 0, 3000);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageBox.Show("出库任务创建失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
///// 手动出一个
|
|
|
///// </summary>
|
|
|
///// <param name="obj"></param>
|
|
|
//private void OutOnlyOne(object obj)
|
|
|
//{
|
|
|
// string info = obj as string;
|
|
|
// bool result = outStoreBusiness.OutOnlyOneBySpaceCode(appConfig.foamStoreCode, info);
|
|
|
// if (result)
|
|
|
// {
|
|
|
// Query();
|
|
|
// MessageBoxTimeoutA((IntPtr)0, $"出库任务创建成功,3秒后关闭提示", "提示", 0, 0, 3000);
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// MessageBox.Show("出库任务创建失败");
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
///// <summary>
|
|
|
///// 整条道出
|
|
|
///// </summary>
|
|
|
///// <param name="obj"></param>
|
|
|
//private void OutAll(object obj)
|
|
|
//{
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
} |