/// <summary> /// 初始化数据 /// </summary> public override void Initialize() { if (IsBusy) { return; } IsBusy = true; Action action = () => { CommunicateManager.Invoke <ITPosService>(service => { //获取帐户信息 AccountStatData = service.GetAccountStat(); //获取客服电话 var tempService = CommunicationProxy.GetCustomerService(); var serviceMode = tempService.HotlinePhone.FirstOrDefault(m => m.Key != null && m.Key.ToLower().Contains("pos")); if (serviceMode != null) { ServiceHotline = serviceMode.Value; } //获取统计数据 int totalDays = 7;//统计的天数 var tempServerData = service.GainStat(DateTime.Today.AddDays(-totalDays), DateTime.Now); if (tempServerData == null) { return; } Collection <TradeStatDataObject> tempCollection = new Collection <TradeStatDataObject>(); for (int i = 0; i < totalDays; i++) { var tempDate = DateTime.Today.AddDays(-totalDays + i + 1); var serverModel = tempServerData.FirstOrDefault(m => m.Date.Year == tempDate.Year && m.Date.DayOfYear == tempDate.DayOfYear); var displayModel = new TradeStatDataObject(); displayModel.Date = tempDate; if (serverModel != null) { displayModel.TradeGain = serverModel.TradeGain; displayModel.TradeMoney = serverModel.TradeMoney; displayModel.TradeTimes = serverModel.TradeTimes; } tempCollection.Add(displayModel); } TradeStatData = tempCollection; }, UIManager.ShowErr); }; Task.Factory.StartNew(action).ContinueWith((task) => { Action setAction = () => { IsBusy = false; }; DispatcherHelper.UIDispatcher.Invoke(setAction); }); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceCenterViewModel"/> class. /// </summary> public ServiceCenterViewModel() { if (IsInDesignMode) { return; } IsBusy = true; Action action = () => { Customer = CommunicationProxy.GetCustomerService(); if (Customer == null) { UIManager.ShowMessage("获取信息失败"); return; } if (Customer.AdvisoryQQ == null) { return; } Parallel.For(0, Customer.AdvisoryQQ.Count, delegate(int i) { var model = new Usher() { Name = Customer.AdvisoryQQ[i].Key, QQ = Customer.AdvisoryQQ[i].Value }; var uri = GetImageUri(Customer.AdvisoryQQ[i].Value); model.QQStateImage = uri; DispatcherHelper.UIDispatcher.Invoke(new Action(() => Ushers.Add(model))); }); }; Task.Factory.StartNew(action).ContinueWith(task => { Action setBusyAction = () => { IsBusy = false; }; DispatcherHelper.UIDispatcher.Invoke(setBusyAction); }); }