using Aucma.Scada.Business; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HighWayIot.Config; using HighWayIot.Log4net; using HighWayIot.Repository.domain; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Aucma.Scada.UI.viewModel.OutStoreInfo { public class OutStoreInfoViewModel : ViewModelBase { private LogHelper logHelper = LogHelper.Instance; private ObservableCollection listItems = new ObservableCollection(); private ObservableCollection taskItems = new ObservableCollection(); private OutStoreBusiness outStoreBusiness = OutStoreBusiness.Instance; private AppConfig appConfig = AppConfig.Instance; public OutStoreInfoViewModel() { outStoreBusiness.RefreshOutStoreTaskEvent += RefreshOutStoreTask; outStoreBusiness.RefreshScanMateriaCodeEvent += RefreshScanInfo; outStoreBusiness.RefreshLogMessageEvent += PrintMessageToListBox; } #region 参数定义 /// /// 箱壳物料条码 /// private string shellMaterialCode = string.Empty; public string ShellMaterialCode { get { return shellMaterialCode; } set { shellMaterialCode = value; RaisePropertyChanged(nameof(ShellMaterialCode)); } } /// /// 箱壳物料名称 /// private string shellMaterialName = string.Empty; public string ShellMaterialName { get { return shellMaterialName; } set { shellMaterialName = value; RaisePropertyChanged(nameof(ShellMaterialName)); } } /// /// 箱壳入库货道 /// private string shellSpaceName = string.Empty; public string ShellSpaceName { get { return shellSpaceName; } set { shellSpaceName = value; RaisePropertyChanged(nameof(ShellSpaceName)); } } /// /// 内胆物料条码 /// private string linerMaterialCode = string.Empty; public string LinerMaterialCode { get { return linerMaterialCode; } set { linerMaterialCode = value; RaisePropertyChanged(nameof(LinerMaterialCode)); } } /// /// 内胆物料名称 /// private string linerMaterialName = string.Empty; public string LinerMaterialName { get { return linerMaterialName; } set { linerMaterialName = value; RaisePropertyChanged(nameof(LinerMaterialName)); } } /// /// 内胆入库货道 /// private string linerSpaceName = string.Empty; public string LinerSpaceName { get { return linerSpaceName; } set { linerSpaceName = value; RaisePropertyChanged(nameof(LinerSpaceName)); } } /// /// LisBox数据模板 /// private IEnumerable logInfoListBox; public IEnumerable LogInfoListBox { get { return logInfoListBox; } set { logInfoListBox = value; RaisePropertyChanged(() => LogInfoListBox); } } /// /// 出库任务DataGrid /// private IEnumerable instoreTask; public IEnumerable InstoreTask { get { return instoreTask; } set { instoreTask = value; RaisePropertyChanged(() => InstoreTask); } } #endregion #region 事件定义 #endregion /// /// listBox绑定日志 /// /// private void PrintMessageToListBox(string message) { try { listItems.Add($"{DateTime.Now.ToString("HH:mm:ss")}==>{message}"); LogInfoListBox = listItems.OrderByDescending(x => x); } catch (Exception ex) { logHelper.Error("日志数据绑定异常", ex); } } /// /// 刷新入库任务列表 /// /// private void RefreshOutStoreTask(RealTaskInfo taskInfo) { try { App.Current.Dispatcher.Invoke((Action)(() => { taskItems.Add(taskInfo); InstoreTask = taskItems; })); } catch (Exception ex) { logHelper.Error("入库任务列表刷新异常", ex); } } /// /// 刷新扫码信息 /// /// /// /// /// private void RefreshScanInfo(string materialCode, string materialName, string spaceName, string materialType) { if (materialType == appConfig.shellStoreCode) { ShellMaterialCode = materialCode; ShellMaterialName = materialName; ShellSpaceName = spaceName; } else if (materialType == appConfig.linerStoreCode) { LinerMaterialCode = materialCode; LinerMaterialName = materialName; LinerSpaceName = spaceName; } } } }