using System; using System.Collections.ObjectModel; using System.Linq; using System.Threading; using BPA.Message; using BPA.Message.Enum; using BPA.Helper; using BPASmartClient.Model; namespace BPASmartClient.ViewModel { public class OrderListDialogViewModel : NotifyBase { public static bool IsAutoClose = false; public OrderListDialogViewModel() { Init(); } private void Init() { CloseButton(); CancelButton(); ConfirmButton(); if (Json.Data.orderLists.Count > 0) { MessageLog.GetInstance.Show($"重启软件前订单剩余{Json.Data.orderLists.Count}个"); TaskManage.GetInstance.Start(new Action(() => { Thread.Sleep(10000); if (!IsAutoClose) ActionManage.GetInstance.Send("Close", false); }), "延时退出"); } } /// /// 关闭按钮 /// private void CloseButton() { CloseCommand = new BPARelayCommand(() => { Json.Data.orderLists.Clear(); ActionManage.GetInstance.Send("Close", false); Json.Save(); }); } /// /// 取消按钮 /// private void CancelButton() { CancelCommand = new BPARelayCommand(() => { Json.Data.orderLists.Clear(); ActionManage.GetInstance.Send("Close", false); Json.Save(); }); } /// /// 确定按钮 /// private void ConfirmButton() { ConfirmCommand = new BPARelayCommand(() => { Json.Data.orderLists.Clear(); //var res = orderStatusLists.Where(p => p.IsSelected == true).ToList(); var res = orderStatusLists.Where(p => p.morkOrderPushes.Where(s => s.IsSelected == true).ToList().Count > 0).ToList(); if (res != null) { Json.Data.orderLists.Clear(); foreach (var item in orderStatusLists) { ObservableCollection morkOrders = new ObservableCollection(); foreach (var mork in item.morkOrderPushes) { if (mork.IsSelected) morkOrders.Add(mork); } Json.Data.orderLists.Add(new OrderData() { DeviceId = item.DeviceId, IsAllSelect = item.IsAllSelect, morkOrderPushes = morkOrders, }); /* foreach (var mo in morkOrders) { DoOrderEvent de = new DoOrderEvent(); de.DeviceId = int.Parse(item.DeviceId); de.MorkOrder = mo.OrderPush; EventBus.GetInstance().Publish(de); }*/ } } ActionManage.GetInstance.Send("Close", true); }); } public BPARelayCommand CloseCommand { get; set; } public BPARelayCommand CancelCommand { get; set; } public BPARelayCommand ConfirmCommand { get; set; } public ObservableCollection orderStatusLists { get { return Json.Data.orderLists; } set { Json.Data.orderLists = value; } } } }