using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.ViewModels;
using Admin.Core.Service;
using Aucma.Core.PalletizCX1.Business;
using Aucma.Core.PalletizCX1.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Elasticsearch.Net.Specification.MachineLearningApi;
using log4net;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace Aucma.Core.PalletizCX1.ViewModels
{
public partial class HandPalletizViewModel : ObservableObject
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(HandPalletizViewModel));
public static StackInfoModel tempStackInfo = new StackInfoModel();
private readonly IBaseSpaceInfoServices _baseSpaceInfoServices;
private readonly IRecordInStoreServices _recordInstoreServices;
private readonly ICodeBindingRecordServices? _codeBindingRecordServices;
///
/// 手动入库委托
///
public delegate void HandSend(string spaceArea, string asciiStr);
public static event HandSend? HandSendEvent;
public HandPalletizViewModel()
{
_codeBindingRecordServices = App.ServiceProvider.GetService();
init();
}
public void init()
{
List list = _codeBindingRecordServices.GetAllProductModel();
if (list == null || list.Count == 0) return;
list = list.OrderBy(x => x.ProductMasterModel).ToList();
MaterialDataGrid.Clear();
Application.Current.Dispatcher.Invoke(() =>
{
foreach (ProductAllModel info in list)
{
MaterialDataGrid.Add(info);
}
});
}
#region 鼠标双击事件
///
/// 鼠标双击事件
///
///
public void MouseClick(object obj)
{
var info = SelectedDataItem;
if (info != null)
{
ProductCode = info.ProductCode;
ProductModel = info.ProductModel;
}
}
#endregion
#region 初始化下拉列表
///
/// 初始化下拉列表
///
private ProductAllModel selectedDataItem;
public ProductAllModel SelectedDataItem
{
get { return selectedDataItem; }
set => SetProperty(ref selectedDataItem, value);
}
#endregion
#region 分垛信息下传
///
/// 分垛信息下传
///
[RelayCommand]
public void Save(Window window)
{
if (Area == null)
{
MessageBox.Show("请先选择区域");
return;
}
if (string.IsNullOrEmpty(ProductCode))
{
MessageBox.Show("请先选择产品型号");
return;
}
HandSendEvent?.Invoke(Area.Content.ToString(), productCode);
MessageBox.Show("手动入库成功");
window.Close();
// 入库
}
///
/// 分垛信息下传
///
[RelayCommand]
public void Cancel(Window window)
{
window.Close();
}
#endregion
#region 初始化datagrid产品信息
///
/// 初始化物料信息
///
private ObservableCollection materialDataGrid = new ObservableCollection();
public ObservableCollection MaterialDataGrid
{
get { return materialDataGrid; }
set => SetProperty(ref materialDataGrid, value);
}
#endregion
#region 选中条码
private string productCode;
public string ProductCode
{
get => productCode;
set => SetProperty(ref productCode, value);
}
#endregion
///
/// 区域
///
private ComboBoxItem area;
public ComboBoxItem Area
{
get { return area; }
set => SetProperty(ref area, value);
}
#region 选中型号
private string productModel;
public string ProductModel
{
get => productModel;
set => SetProperty(ref productModel, value);
}
#endregion
}
}