| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 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;
- /// <summary>
- /// 是否忙,显示等待控件
- /// </summary>
- //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<Announcement> _messageSource;
- /// <summary>
- /// 绑定数据源
- /// </summary>
- public ObservableCollection<Announcement> MessageSource
- {
- get { return _messageSource; }
- private set
- {
- _messageSource = value;
- RaisePropertyChanged(() => MessageSource);
- }
- }
- private MsgTypeEnum _msgTypeEnum;
- /// <summary>
- /// 消息类型
- /// </summary>
- 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<Announcement> 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<TradeAccount>(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()
- {
- }
- }
- }
|