using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Service; using Aucma.Core.Palletiz.Business; using Aucma.Core.Palletiz.Models; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using log4net; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Aucma.Core.Palletiz.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; public HandPalletizViewModel() { _baseSpaceInfoServices = App.ServiceProvider.GetService(); _recordInstoreServices = App.ServiceProvider.GetService(); Range = 1; SpaceNo ="001"; InstoreBusiness.LogInStoreInfoDelegateEvent += PromptInfo; PromptInfo("请选择信息下传......", "White"); } #region 分垛信息下传 /// /// 分垛信息下传 /// [RelayCommand] public void Save() { try { DialogResult cr = MessageBox.Show("是否确认下传分垛信息?", "系统提醒", MessageBoxButtons.OKCancel); if (cr != DialogResult.OK) { return; } PromptInfo("分垛信息下传中......", "White"); int range = Range; int spaceNo =Convert.ToInt32(SpaceNo); if (spaceNo==0) { MessageBox.Show("请选择目的货道!","系统提醒"); return; } string hh = "FD01_" + SpaceNo; Admin.Core.Model.BaseSpaceInfo spaceInfo = _baseSpaceInfoServices.FirstAsync(X => X.StoreCode.Contains("FD") && X.SpaceCode == "FD01_"+SpaceNo).Result; if (spaceInfo == null) { MessageBox.Show("货道未创建!", "系统提醒"); return; } bool backResult = InstoreBusiness.TempWritePlc(spaceNo, range); if (backResult) { #region 手动入库没有扫码 默认为"0000000000" 添加入库记录 RecordInStore recordInstore = new RecordInStore();// 入库记录 recordInstore.SpaceCode = spaceInfo.SpaceCode; recordInstore.StoreCode = spaceInfo.StoreCode; recordInstore.MaterialType = "0000000000"; recordInstore.MaterialCode = "0000000000"; recordInstore.MaterialName = "0000000000"; recordInstore.BarCodeCode= "0000000000"; recordInstore.InStoreAmount = 1; recordInstore.InStoreTime = DateTime.Now; recordInstore.InStoreTime = DateTime.Now; recordInstore.CreatedTime = DateTime.Now; recordInstore.UpdateTime = DateTime.Now; int r= _recordInstoreServices.AddAsync(recordInstore).Result; if (r>0) { PromptInfo("分垛信息下传成功!", "White"); } else { PromptInfo("分垛信息下传成功!入库明细保存失败!", "Red"); } #endregion } else { PromptInfo("分垛信息下传失败!", "Red"); } } catch (Exception ex) { PromptInfo($"分垛信息下传失败:{ex.Message}", "Red"); } } #endregion #region 提示信息 private string? msgTxt; public string? MsgTxt { get => msgTxt; set => SetProperty(ref msgTxt, value); } #endregion #region 字体颜色 private string? msgColor; public string? MsgColor { get => msgColor; set => SetProperty(ref msgColor, value); } #endregion #region 提示信息 /// /// 提示信息 /// /// 提示信息 /// 提示信息颜色 public void PromptInfo(string mesg, string color) { System.Windows.Application.Current.Dispatcher.Invoke((Action)(() => { MsgTxt = mesg; MsgColor = color; })); } #endregion #region 目的货道 private string spaceNo; public string SpaceNo { get => spaceNo; set => SetProperty(ref spaceNo, value); } #endregion #region 方向 private int range; public int Range { get => range; set => SetProperty(ref range, value); } #endregion } }