using GalaSoft.MvvmLight.Command; using Muchinfo.MTPClient.Account.Views; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Model.Account; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Resources; using Muchinfo.PC.Common.Extensions; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; using System.Windows; namespace Muchinfo.MTPClient.Account.ViewModels { public class MessageViewModel : RegisterMessageBase { private IAnnouncementService _announcementService; private bool _isBusy; /// /// 是否忙,显示等待控件 /// //public bool IsBusy //{ // get { return _isBusy; } // set { Set(() => IsBusy, ref _isBusy, value); } //} private Announcement _selectedItemMessage; public Announcement SelectedItemMessage { get { return _selectedItemMessage; } set { Set(() => SelectedItemMessage, ref _selectedItemMessage, value); } } private DateTime _startDateTime; public DateTime StartDateTime { get { return _startDateTime; } set { Set(() => StartDateTime, ref _startDateTime, new DateTime(value.Year, value.Month, value.Day)); } } private DateTime _endDateTime; public DateTime EndDateTime { get { return _endDateTime; } set { Set(() => EndDateTime, ref _endDateTime, new DateTime(value.Year, value.Month, value.Day)); } } private string _selectWhere; public string SelectWhere { get { return _selectWhere; } set { Set(() => SelectWhere, ref _selectWhere, value); } } private ObservableCollection _messageSource; /// /// 绑定数据源 /// public ObservableCollection MessageSource { get { return _messageSource; } private set { _messageSource = value; RaisePropertyChanged(() => MessageSource); } } private MsgTypeEnum _msgTypeEnum; /// /// 消息类型 /// public MsgTypeEnum MsgTypeEnum { get { return _msgTypeEnum; } set { _msgTypeEnum = value; } } public MessageViewModel(IAnnouncementService announcementService) { this._announcementService = announcementService; DateTime serverTimeNow = ApplicationParameter.ServerTimeNow; DateTime startDate = serverTimeNow.Date.AddDays(-30); DateTime endDate = new DateTime(serverTimeNow.Year, serverTimeNow.Month, serverTimeNow.Day); this.StartDateTime = startDate; this.EndDateTime = endDate; } public RelayCommand ShowCommand { get { return new RelayCommand(() => { if (this.SelectedItemMessage != null) { MessageInfoView _messageInfoView = new MessageInfoView() { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; MessageInfoViewModel _messageInfoViewModel = new MessageInfoViewModel(); _messageInfoView.DataContext = _messageInfoViewModel; _messageInfoViewModel.MsgTypeEnum = this.MsgTypeEnum; _messageInfoViewModel.MessageOrders = this.MessageSource; _messageInfoViewModel.CurrentAnnouncement = this.SelectedItemMessage; _messageInfoView.ShowDialog(); } }); } } public RelayCommand QuetyCommand { get { return new RelayCommand(() => { if (this.EndDateTime < this.StartDateTime) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_EndDateLessBegin, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_Tips, true); return; } IsBusy = true; Task.Factory.TryStartNew(() => { // this.MessageSource = _announcementService.QueryClientBM(this.StartDateTime, this.EndDateTime, //this.SelectWhere, this.MsgTypeEnum, UserManager.CurrentTradeAccount); QueryClientBMParam clientBMPar = new QueryClientBMParam() { StartDate = this.StartDateTime, EndDate = this.EndDateTime, MsgTypeEnum = this.MsgTypeEnum, Title = this.SelectWhere, TradeAccount = UserManager.CurrentTradeAccount, }; _announcementService.QueryClientBM(clientBMPar, QueryClientBMCallBack, QueryClientBMCallBack); //UserManager.IsRead(this.MsgTypeEnum, this.MessageSource); //IsBusy = false; }, () => IsBusy = false); }); } } private void QueryClientBMCallBack(List successAction) { this.MessageSource = successAction.ToObservableCollection(); } private void QueryClientBMCallBack(ErrorEntity error) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { ErrorManager.ShowReturnError(error, Muchinfo_Resource.UI2014_Tips, true); })); } public override void RegisterMessage() { var tradeCacheData = UserManager.GetTradeCacheData((UserManager.CurrentTradeAccount.AccountId)); IsBusy = true; //当选择时刷新 Task.Factory.TryStartNew(() => { if (this.MsgTypeEnum == MsgTypeEnum.Bulletin) { //MessageSource = UserManager.GetMessageAnnouncementOrders(UserManager.CurrentTradeAccount); //_orderService.GetCloseOrdersByTradeAccount(UserManager.CurrentTradeAccount); MessageSource = tradeCacheData.MessageAnnouncementOrders; } if (this.MsgTypeEnum == MsgTypeEnum.NTF) { // MessageSource = UserManager.GetMessageNoticeOrders(UserManager.CurrentTradeAccount); //_orderService.GetCloseOrdersByTradeAccount(UserManager.CurrentTradeAccount); MessageSource = tradeCacheData.MessageNoticeOrders; } //IsBusy = false; }, () => IsBusy = false); MessengerHelper.DefaultRegister(this, MessengerTokens.OrderNotify, (e) => { Task.Factory.TryStartNew(() => { if (this.MsgTypeEnum == MsgTypeEnum.Bulletin) { //MessageSource = UserManager.GetMessageAnnouncementOrders(e, true); //_orderService.GetCloseOrdersByTradeAccount(UserManager.CurrentTradeAccount); MessageSource = tradeCacheData.MessageAnnouncementOrders; } if (this.MsgTypeEnum == MsgTypeEnum.NTF) { //MessageSource = UserManager.GetMessageNoticeOrders(e, true); //_orderService.GetCloseOrdersByTradeAccount(UserManager.CurrentTradeAccount); MessageSource = tradeCacheData.MessageNoticeOrders; } //IsBusy = false; }, () => IsBusy = false); }); } public override void RefreshContent() { } } }