using BPA.Helper; using BPASmartClient.Model; using BPASmartClient.MorkM.Model; using BPASmartClient.MorkM.View; using BPA.Helper; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.MorkM.ViewModel { internal class DebugViewModel : NotifyBase { public DebugViewModel() { AddSimDataCommand = new BPARelayCommand(() => { SimOrderConfitView simOrderConfitView = new SimOrderConfitView(); simOrderConfitView.Show(); }); SimOrderCommand = new BPARelayCommand(() => { List locs = new List(); foreach (var item in simOrderConfig) { if (item.IsSelected) locs.Add((ushort)(new Random().Next(item.MinValue, item.MaxValue + 1))); else locs.Add(item.Loc); } if (locs.Count == 0) { locs.Add((ushort)(new Random().Next(1, 5))); locs.Add(10); } ActionManage.GetInstance.Send(locs, "SimOrder"); //下发模拟订单 Trace.WriteLine("下发模拟订单。。。"); }); InitCommand = new BPARelayCommand(() => { ActionManage.GetInstance.Send("InitDevice"); //初始化按钮 Trace.WriteLine("已点击初始化按钮。。。"); }); LoopSimOrderCommand = new BPARelayCommand(() => { if (LoopOrderButtonContent == "循环跑单") ActionManage.GetInstance.Send("EnableForOrder"); if (LoopOrderButtonContent == "停止跑单") ActionManage.GetInstance.Send("StopForOrder"); LoopOrderButtonContent = LoopOrderButtonContent == "循环跑单" ? "停止跑单" : "循环跑单"; }); EditCommand = new BPARelayCommand((o) => { if (o != null) { var res = Json.Data.simOrderConfig.FirstOrDefault(p => p.Text == o.ToString()); if (res != null) { SimOrderConfitView simOrderConfitView = new SimOrderConfitView(); simOrderConfitView.Show(); ActionManage.GetInstance.Send(res, "SendSimData"); } } }); RemoveCommand = new BPARelayCommand((o) => { if (o != null) { var res = Json.Data.simOrderConfig.FirstOrDefault(p => p.Text == o.ToString()); if (res != null) Json.Data.simOrderConfig.Remove(res); } }); } public static bool EnableLocalSimOrder { get { return GeneralConfig.EnableLocalSimOrder; } set { GeneralConfig.EnableLocalSimOrder = value; OnStaticPropertyChanged(); } } public ObservableCollection simOrderConfig { get { return Json.Data.simOrderConfig; } set { Json.Data.simOrderConfig = value; } } public BPARelayCommand AddSimDataCommand { get; set; } public BPARelayCommand SimOrderCommand { get; set; } public BPARelayCommand InitCommand { get; set; } public BPARelayCommand LoopSimOrderCommand { get; set; } public BPARelayCommand EditCommand { get; set; } public BPARelayCommand RemoveCommand { get; set; } public static event EventHandler StaticPropertyChanged; public static void OnStaticPropertyChanged([CallerMemberName] string PropName = "") { StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(PropName)); } public static string LoopOrderButtonContent { get { return _mLoopOrderButtonContent; } set { _mLoopOrderButtonContent = value; OnStaticPropertyChanged(); } } private static string _mLoopOrderButtonContent = "循环跑单"; } }