using BPA.Helper;
using BPA.Message;
using BPA.Message.Enum;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace BPASmartClient.ScreenLib
{
public class ScreenMinWokControlViewModel : NotifyBase
{
#region 变量
///
/// 广告地址
///
public Uri GgAdder { get { return _GgAdder; } set { _GgAdder = value; OnPropertyChanged(); } }
private Uri _GgAdder = new Uri(System.Configuration.ConfigurationManager.AppSettings["GgAdder"].ToString());
///
/// 界面数据绑定
///
public ScreenModelMinWok ViewData
{
get { return _ViewData; }
set
{
_ViewData = value;
OnPropertyChanged();
}
}
private ScreenModelMinWok _ViewData = new ScreenModelMinWok();
///
/// 1号炒锅流程
///
public ObservableCollection ProcessModel1
{
get { return _ProcessModel1; }
set
{
_ProcessModel1 = value;
OnPropertyChanged();
}
}
private ObservableCollection _ProcessModel1 = new ObservableCollection();
///
/// 2号炒锅流程
///
public ObservableCollection ProcessModel2
{
get { return _ProcessModel2; }
set
{
_ProcessModel2 = value;
OnPropertyChanged();
}
}
private ObservableCollection _ProcessModel2 = new ObservableCollection();
///
/// 当前刷新数据类型
///
public ScreenDeviceType type = ScreenDeviceType.小炒;
///
/// 订单总数
///
public int OrderCount
{
get { return _OrderCount; }
set
{
_OrderCount = value;
OnPropertyChanged();
}
}
private int _OrderCount = 0;
#endregion
public ScreenMinWokControlViewModel()
{
TaskManage.GetInstance.StartLong(new Action(() =>
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
if (Main.GetInstance.mqttDatasDic.ContainsKey(type))
{
ScreenModelMinWok modelMaxWok = Main.GetInstance.mqttDatasDic[type] as ScreenModelMinWok;
if (modelMaxWok != null && modelMaxWok.Alarm != null)
modelMaxWok.Alarm = modelMaxWok.Alarm?.OrderByDescending(k => DateTime.Parse(k.AlarmTime)).ToList();
ProcessModel1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(modelMaxWok.MinWok_Process_1));
ProcessModel2 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(modelMaxWok.MinWok_Process_2));
ProcessModel1?.ToList().ForEach(par => { if (par.Id + 1 == ProcessModel1.Count) { par.IsLast = 1; } else { par.IsLast = 0; } });
ProcessModel2?.ToList().ForEach(par => { if (par.Id + 1 == ProcessModel2.Count) { par.IsLast = 1; } else { par.IsLast = 0; } });
ViewData = modelMaxWok;
OrderCount = modelMaxWok.MinWok_OrderCount_1 + modelMaxWok.MinWok_OrderCount_2;
}
}));
Thread.Sleep(1000);
}), $"{DateTime.Now},线程服务");
}
}
}