using Aucma.Scada.Business; using Aucma.Scada.Model.domain; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HighWayIot.Config; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; namespace Aucma.Scada.UI.viewModel.AssemblyPlan { public class QuantityIssuedViewModel : ViewModelBase { private AssemblyPlanBusiness assemblyPlanBusiness = AssemblyPlanBusiness.Instance; private AppConfig appConfig = AppConfig.Instance; public QuantityIssuedViewModel(ProductPlanInfo productPlanInfo) { PlanInfoTransmitCommand = new RelayCommand(PlanInfoTransmit); ClearTransmitAmountCommand = new RelayCommand(ClearTransmitAmount); KeypadButtonCommand = new RelayCommand(obj => KeypadButton(obj)); CloseWindowCommand = new RelayCommand(t => CloseWindow(t)); PlanInfo = productPlanInfo; } private ProductPlanInfo _PlanInfo = new ProductPlanInfo(); public ProductPlanInfo PlanInfo { get { return _PlanInfo; } set { _PlanInfo = value; RaisePropertyChanged(nameof(PlanInfo)); } } private string _TransmitAmount = string.Empty; public string TransmitAmount { get { return _TransmitAmount; } set { _TransmitAmount = value; RaisePropertyChanged(nameof(TransmitAmount)); } } public RelayCommand PlanInfoTransmitCommand { get; set; } public RelayCommand ClearTransmitAmountCommand { get; set; } public RelayCommand KeypadButtonCommand { get;set; } public RelayCommand CloseWindowCommand { get; set; } private void PlanInfoTransmit() { var productPlanInfo = _PlanInfo; if (productPlanInfo != null) { var materialType = productPlanInfo.materialCode; bool shellResult = assemblyPlanBusiness.JudgmentStock(productPlanInfo, Convert.ToInt32(_TransmitAmount), appConfig.foamMaterialType, appConfig.foamStoreCode); if (!shellResult) { MessageBox.Show("计划下达失败,箱体物料库存不足","提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); return; } } else { MessageBox.Show("生产计划获取失败,加载为空", "提示", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); return; } bool result = assemblyPlanBusiness.PlanTransmitByProductPlan(_PlanInfo.planCode, Convert.ToInt32(_TransmitAmount)); if (result) { MessageBox.Show("执行计划维护成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } } private void ClearTransmitAmount() { string amount = _TransmitAmount.ToString(); if(amount.Length > 0) { TransmitAmount = amount.Substring(0, amount.Length - 1); } } private void KeypadButton(object obj) { var info = obj as string; TransmitAmount += info; } private void CloseWindow(object parameter) { var window = parameter as Window; if (window != null) { window.Close(); } } } }