|
- using System;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Threading;
- using BPA.Message.Enum;
- using BPASmartClient.Helper;
- using BPASmartClient.Model;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using Microsoft.Toolkit.Mvvm.Messaging;
-
- namespace BPASmartClient.ViewModel
- {
- public class OrderListDialogViewModel : ObservableObject
- {
- public static bool IsAutoClose = false;
- public OrderListDialogViewModel()
- {
- Init();
- }
-
- private void Init()
- {
- CloseButton();
- CancelButton();
- ConfirmButton();
- if (Json<KeepDataBase>.Data.orderLists.Count > 0)
- {
- ThreadManage.GetInstance().Start(new Action(() =>
- {
- Thread.Sleep(10000);
- if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close");
- }), "延时退出");
- }
- AllSelected = true;
- }
-
- /// <summary>
- /// 关闭按钮
- /// </summary>
- private void CloseButton()
- {
- CloseCommand = new RelayCommand(() =>
- {
- Json<KeepDataBase>.Data.orderLists.Clear();
- WeakReferenceMessenger.Default.Send("false", "Close");
- Json<KeepDataBase>.Save();
- });
- }
-
- /// <summary>
- /// 取消按钮
- /// </summary>
- private void CancelButton()
- {
- CancelCommand = new RelayCommand(() =>
- {
- Json<KeepDataBase>.Data.orderLists.Clear();
- WeakReferenceMessenger.Default.Send("false", "Close");
- Json<KeepDataBase>.Save();
- });
- }
-
- /// <summary>
- /// 确定按钮
- /// </summary>
- private void ConfirmButton()
- {
- ConfirmCommand = new RelayCommand(() =>
- {
- var res = orderStatusLists.Where(p => p.IsSelected == true).ToList();
- if (res != null)
- {
- Json<KeepDataBase>.Data.orderLists.Clear();
- foreach (var item in res)
- {
- item.OrderStatus = ORDER_STATUS.WAIT;
- Json<KeepDataBase>.Data.orderLists.Add(item);
- }
- }
- WeakReferenceMessenger.Default.Send("true", "Close");
- });
- }
-
- /// <summary>
- /// 全选标志
- /// </summary>
- public bool AllSelected
- {
- get { return _mAllSelected; }
- set
- {
- _mAllSelected = value;
- OnPropertyChanged();
- for (int i = 0; i < orderStatusLists.Count; i++)
- {
- orderStatusLists.ElementAt(i).IsSelected = value;
- }
- }
- }
- private bool _mAllSelected = true;
-
- public RelayCommand CloseCommand { get; set; }
-
- public RelayCommand CancelCommand { get; set; }
-
- public RelayCommand ConfirmCommand { get; set; }
-
- public ObservableCollection<OrderData> orderStatusLists
- {
- get { return Json<KeepDataBase>.Data.orderLists; }
- set { Json<KeepDataBase>.Data.orderLists = value; }
- }
- }
- }
|