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.

251 lines
8.5 KiB
C#

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using SlnMesnac.Model.enums;
using SlnMesnac.Plc;
using SlnMesnac.Repository.service;
using SlnMesnac.WPF.MessageTips;
using SqlSugar;
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 IWmsRawPreferredOutService? wmsRawPreferredOutService;
private readonly ISqlSugarClient? sqlSugarClient;
public ManualDeliveryViewModel()
{
wmsRawPreferredOutService = App.ServiceProvider.GetService<IWmsRawPreferredOutService>();
sqlSugarClient = App.ServiceProvider.GetService<ISqlSugarClient>();
QueryStringCommand = new RelayCommand<string>(Query);
Init();
// ConfirmCommand = new RelayCommand<object>(Confirm);
DeleteCommand = new RelayCommand<object>(Delete);
}
private void Init()
{
WmsRawPreferredOutDataGrid.Clear();
List<WmsRawPreferredOut> list = wmsRawPreferredOutService.Query();
if(list!= null && list.Count > 0)
{
foreach (var item in list)
{
WmsRawPreferredOutDataGrid.Add(item);
}
}
}
#region 参数定义
/// <summary>
/// 计划列表DataGrid
/// </summary>
private ObservableCollection<WmsRawPreferredOut> wmsRawPreferredOutDataGrid = new ObservableCollection<WmsRawPreferredOut>();
public ObservableCollection<WmsRawPreferredOut> WmsRawPreferredOutDataGrid
{
get { return wmsRawPreferredOutDataGrid; }
set { wmsRawPreferredOutDataGrid = value; RaisePropertyChanged(() => WmsRawPreferredOutDataGrid); }
}
/// <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> DeleteCommand { get; set; }
#endregion
/// <summary>
/// 查询库位能否优先投料,可以的话保存
/// </summary>
/// <param name="queryStr"></param>
private void Query(string queryStr)
{
try
{
WmsBaseLocation? targetLocation = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<WmsBaseLocation>().Where(it => it.LocationCode == queryStr && it.WarehouseId ==311).First();
WmsRawStock? wmsRawStock = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<WmsRawStock>().Where(it => it.LocationCode == queryStr).First();
if(targetLocation != null)
{
if (string.IsNullOrEmpty(targetLocation.ContainerCode) || wmsRawStock==null)
{
Application.Current.Dispatcher.Invoke(() =>
{
Msg.MsgShow("该库位没有库存,请重新输入", 2, 5);
});
return;
}
if (targetLocation.LocationStatus != "1")
{
Application.Current.Dispatcher.Invoke(() =>
{
Msg.MsgShow("该库位状态异常,禁止出", 2, 5);
});
return;
}
if (targetLocation.LocDeep == 1)
{
int? row = targetLocation.LocRow %2==0? targetLocation.LocRow - 1 : targetLocation.LocRow +1;
WmsBaseLocation? shallowLocation = sqlSugarClient.AsTenant().GetConnection("mes").Queryable<WmsBaseLocation>().Where(it => it.WarehouseId == 311 && it.LocRow==row && it.LocColumn==targetLocation.LocColumn).First();
if (shallowLocation != null && shallowLocation.LocationStatus != "1")
{
Msg.MsgShow("当前库位对应的浅库位状态异常,禁止出库", 2, 5);
return;
}
}
WmsRawPreferredOut wmsRawPreferredOut = new WmsRawPreferredOut();
wmsRawPreferredOut.WarehouseId = wmsRawStock.WarehouseId;
wmsRawPreferredOut.WarehouseFloor = targetLocation.WarehouseFloor;
wmsRawPreferredOut.LocationCode = targetLocation.LocationCode;
wmsRawPreferredOut.StockType = "1";
wmsRawPreferredOut.MaterialId = wmsRawStock.MaterialId;
wmsRawPreferredOut.CreateBy = "PRD";
wmsRawPreferredOut.CreateDate = DateTime.Now;
wmsRawPreferredOut.UpdateBy = "PRD";
wmsRawPreferredOut.UpdateDate = DateTime.Now;
wmsRawPreferredOut.UseFlag = "1";
wmsRawPreferredOutService.Insert(wmsRawPreferredOut);
Init();
Msg.MsgShow("保存成功", 0, 5);
}
else
{
Msg.MsgShow("输入的库位有误,请重新输入", 2, 5);
return;
}
}
catch (Exception ex)
{
Msg.MsgShow($"保存异常:{ex.Message}", 2, 5);
}
}
///// <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 Delete(object parameter)
{
string locationCode = parameter as string;
if (!string.IsNullOrEmpty(locationCode))
{
var item = wmsRawPreferredOutService.Query(x => x.LocationCode == locationCode).FirstOrDefault();
bool isSuccess = wmsRawPreferredOutService.DeleteById(item.RawPreferredOutId);
Init();
}
}
}
}