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.
AUCMA_SCADA/Aucma.Core.SheetMetal/ViewModels/QuantityIssuedViewModel.cs

189 lines
6.5 KiB
C#

using Admin.Core.Common;
using Admin.Core.IService;
1 year ago
using Admin.Core.Model;
using Admin.Core.Service;
1 year ago
using Aucma.Core.HwPLc;
1 year ago
using Aucma.Core.SheetMetal.Business;
1 year ago
using Aucma.Core.SheetMetal.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
1 year ago
using CommunityToolkit.Mvvm.Messaging;
1 year ago
using log4net;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Logging;
1 year ago
using System;
using System.Collections.Generic;
using System.Linq;
1 year ago
using System.Reflection.Metadata;
1 year ago
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Aucma.Core.SheetMetal.ViewModels
{
public partial class QuantityIssuedViewModel : ObservableObject
{
#region 刷新创建计划
/// <summary>
/// 刷新创建计划
/// </summary>
public delegate Task RefreshCretaePlanInfo();
public static event RefreshCretaePlanInfo RefreshCretaePlanInfoEvent;
#endregion
1 year ago
private static readonly log4net.ILog logHelper = LogManager.GetLogger(typeof(QuantityIssuedViewModel));
private IBaseBomInfoServices _bomInfoServices;
private IBaseSpaceDetailServices _spaceDetailServices;
1 year ago
protected readonly IExecutePlanInfoServices? _executePlanInfoServices;
1 year ago
#region 构造函数
public QuantityIssuedViewModel(ProductPlanInfoModel productPlanInfo)
{
_bomInfoServices = App.ServiceProvider.GetService<IBaseBomInfoServices>();
_spaceDetailServices = App.ServiceProvider.GetService<IBaseSpaceDetailServices>();
1 year ago
_executePlanInfoServices = App.ServiceProvider.GetService<IExecutePlanInfoServices>();
1 year ago
PlanInfo = productPlanInfo;
1 year ago
}
#endregion
1 year ago
1 year ago
#region 属性
1 year ago
private ProductPlanInfoModel _PlanInfo = new ProductPlanInfoModel();
public ProductPlanInfoModel PlanInfo
{
get => _PlanInfo;
set => SetProperty(ref _PlanInfo, value);
}
private string _TransmitAmount = string.Empty;
public string TransmitAmount
{
get => _TransmitAmount;
set => SetProperty(ref _TransmitAmount, value);
}
1 year ago
#endregion
1 year ago
1 year ago
#region 下传计划
/// <summary>
/// 下传计划,前后板联动计划创建两条分别为前后板计划
1 year ago
/// </summary>
1 year ago
[RelayCommand]
1 year ago
private async Task PlanInfoTransmit()
1 year ago
{
var productPlanInfo = _PlanInfo;
1 year ago
if (productPlanInfo != null)
{
//下传到PLC
string stationCode = "1001";
var list = await _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(stationCode));
1 year ago
1 year ago
ExecutePlanInfo task = new ExecutePlanInfo();
task.ExecutePlanCode = Guid.NewGuid().ToString();
task.ProductPlanCode = PlanInfo.PlanCode;
task.OrderCode = PlanInfo.OrderCode;
task.ProductLineCode = stationCode;//计划工位
//task.TaskCode = GetMaxCodeAsync();
task.TaskCode = System.Guid.NewGuid().ToString("N").Substring(0,16);
1 year ago
task.MaterialCode = PlanInfo.MaterialCode;
task.MaterialName = PlanInfo.MaterialName;
if (list.Count == 0)
task.ExecuteOrder = 1;
if (list.Count != 0)
task.ExecuteOrder = list.Max(d => d.ExecuteOrder) + 1;
1 year ago
1 year ago
task.ExecuteMethod = 2;//不做要求,系统自动确定
1 year ago
task.PlanAmount = Convert.ToInt32(TransmitAmount);
task.CompleteAmount = 0;
1 year ago
task.CreatedTime = DateTime.Now;
1 year ago
task.BeginTime = DateTime.Now;
task.ExecuteStatus = 1;
task.PlanType = productPlanInfo.PlanType;
1 year ago
var result = await _executePlanInfoServices.AddAsync(task);
if (result > 0)
{
MessageBox.Show("计划拆分成功!", "系统提醒");
//WeakReferenceMessenger.Default.Send<string>("Refresh");//刷新窗口
RefreshCretaePlanInfoEvent?.Invoke();
1 year ago
}
else
{
MessageBox.Show("计划拆分失败,请检查后重试!", "系统提醒");
}
1 year ago
}
else
{
MessageBox.Show("生产计划获取失败,加载为空", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
return;
}
1 year ago
}
1 year ago
#endregion
#region 清除
/// <summary>
/// 清除
/// </summary>
1 year ago
[RelayCommand]
private void ClearTransmitAmount()
{
string amount = _TransmitAmount.ToString();
if (amount.Length > 0)
{
TransmitAmount = amount.Substring(0, amount.Length - 1);
}
}
1 year ago
#endregion
1 year ago
1 year ago
#region KeypadButton
1 year ago
[RelayCommand]
private void KeypadButton(object obj)
{
var info = obj as string;
TransmitAmount += info;
}
1 year ago
#endregion
1 year ago
1 year ago
#region 关闭
/// <summary>
/// 关闭
/// </summary>
/// <param name="parameter"></param>
1 year ago
[RelayCommand]
private void CloseWindow(object parameter)
{
var window = parameter as Window;
if (window != null)
{
window.Close();
}
1 year ago
}
1 year ago
#endregion
1 year ago
public string GetMaxCodeAsync()
1 year ago
{
string stationCode = Appsettings.app("StoreInfo", "StationCode");
string today = DateTime.Now.ToString("yyyyMMdd");
var maxCode = _executePlanInfoServices.QueryAsync(d => d.ProductLineCode.Equals(stationCode)).Result.Max(d => d.TaskCode);
if (maxCode.IsNotEmptyOrNull())
1 year ago
{
string date = maxCode.Substring(0, 8);
string max = maxCode.Substring(maxCode.Length - 4, maxCode.Length);
if (today.Equals(date))
{
return date + (int.Parse(max) + 1);
}
else
1 year ago
{
return today + "00001";
1 year ago
}
}
else
{
return today + "00001";
}
1 year ago
}
1 year ago
}
}