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.

172 lines
4.8 KiB
C#

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business;
using SlnMesnac.Model.dto;
using SlnMesnac.Model.enums;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.WPF.ViewModel
* 7b8b1dd3-c235-4b39-9df0-2c086246b206
*
* WenJY
* wenjy@mesnac.com
* 2024-04-10 10:31:47
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel
{
public class ManualDeliveryViewModel : ViewModelBase
{
private readonly ProdMgmtBusiness? _prodMgmtBusiness;
public ManualDeliveryViewModel()
{
_prodMgmtBusiness = App.ServiceProvider.GetService<ProdMgmtBusiness>();
QueryStringCommand = new RelayCommand<string>(Query);
this.Query(string.Empty);
ConfirmCommand = new RelayCommand<object>(Confirm);
CancelCommand = new RelayCommand<object>(Cancel);
}
#region 参数定义
/// <summary>
/// 计划列表DataGrid
/// </summary>
private ObservableCollection<MesProductPlanDto> planInfoDataGrid;
public ObservableCollection<MesProductPlanDto> PlanInfoDataGrid
{
get { return planInfoDataGrid; }
set { planInfoDataGrid = value; RaisePropertyChanged(() => PlanInfoDataGrid); }
}
/// <summary>
/// 选中计划列表信息
/// </summary>
private MesProductPlanDto selectedCells;
public MesProductPlanDto SelectedCells
{
get { return selectedCells; }
set
{
selectedCells = value;
RaisePropertyChanged(() => SelectedCells);
}
}
#endregion
#region 事件定义
public RelayCommand<string> QueryStringCommand { get; set; }
/// <summary>
/// 确认事件
/// </summary>
public RelayCommand<object> ConfirmCommand { get; set; }
/// <summary>
/// 关闭事件
/// </summary>
public RelayCommand<object> CancelCommand { get; set; }
#endregion
/// <summary>
/// 查询事件
/// </summary>
/// <param name="queryStr"></param>
private void Query(string queryStr)
{
try
{
PlanInfoDataGrid = new ObservableCollection<MesProductPlanDto>();
var list = _prodMgmtBusiness._mesProductPlanService.GetPlanDtos();
if (list != null)
{
list.OrderByDescending(x => x.PlanStatus);
list.ForEach(
arg =>
{
PlanInfoDataGrid.Add(arg);
});
}
}
catch (Exception ex)
{
//_logger.LogError($"生产计划刷新异常:{ex.Message}");
}
}
/// <summary>
/// 确认
/// </summary>
/// <param name="parameter"></param>
private void Confirm(object parameter)
{
try
{
if (selectedCells != null)
{
if (_prodMgmtBusiness.ApplyDeliveryHandle(selectedCells.MaterialId.ToString()))
{
_prodMgmtBusiness.RefreshMessage("手动叫料成功");
}
else
{
_prodMgmtBusiness.RefreshMessage("手动叫料失败");
}
}
}catch (Exception ex)
{
_prodMgmtBusiness.RefreshMessage($"手动叫料处理异常:{ex.Message}");
}
var window = parameter as Window;
if (window != null)
{
window.Close();
}
}
/// <summary>
/// 取消
/// </summary>
private void Cancel(object parameter)
{
var window = parameter as Window;
if (window != null)
{
window.Close();
}
}
}
}