MessageViewModel.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using GalaSoft.MvvmLight.Command;
  2. using Muchinfo.MTPClient.Account.Views;
  3. using Muchinfo.MTPClient.Data;
  4. using Muchinfo.MTPClient.Data.Enums;
  5. using Muchinfo.MTPClient.Data.Model;
  6. using Muchinfo.MTPClient.Data.Model.Account;
  7. using Muchinfo.MTPClient.Infrastructure.Helpers;
  8. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  9. using Muchinfo.MTPClient.Infrastructure.Utilities;
  10. using Muchinfo.MTPClient.IService;
  11. using Muchinfo.MTPClient.Resources;
  12. using Muchinfo.PC.Common.Extensions;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Collections.ObjectModel;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. namespace Muchinfo.MTPClient.Account.ViewModels
  19. {
  20. public class MessageViewModel : RegisterMessageBase
  21. {
  22. private IAnnouncementService _announcementService;
  23. private bool _isBusy;
  24. /// <summary>
  25. /// 是否忙,显示等待控件
  26. /// </summary>
  27. //public bool IsBusy
  28. //{
  29. // get { return _isBusy; }
  30. // set { Set(() => IsBusy, ref _isBusy, value); }
  31. //}
  32. private Announcement _selectedItemMessage;
  33. public Announcement SelectedItemMessage
  34. {
  35. get { return _selectedItemMessage; }
  36. set { Set(() => SelectedItemMessage, ref _selectedItemMessage, value); }
  37. }
  38. private DateTime _startDateTime;
  39. public DateTime StartDateTime
  40. {
  41. get { return _startDateTime; }
  42. set { Set(() => StartDateTime, ref _startDateTime, new DateTime(value.Year, value.Month, value.Day)); }
  43. }
  44. private DateTime _endDateTime;
  45. public DateTime EndDateTime
  46. {
  47. get { return _endDateTime; }
  48. set { Set(() => EndDateTime, ref _endDateTime, new DateTime(value.Year, value.Month, value.Day)); }
  49. }
  50. private string _selectWhere;
  51. public string SelectWhere
  52. {
  53. get { return _selectWhere; }
  54. set { Set(() => SelectWhere, ref _selectWhere, value); }
  55. }
  56. private ObservableCollection<Announcement> _messageSource;
  57. /// <summary>
  58. /// 绑定数据源
  59. /// </summary>
  60. public ObservableCollection<Announcement> MessageSource
  61. {
  62. get { return _messageSource; }
  63. private set
  64. {
  65. _messageSource = value;
  66. RaisePropertyChanged(() => MessageSource);
  67. }
  68. }
  69. private MsgTypeEnum _msgTypeEnum;
  70. /// <summary>
  71. /// 消息类型
  72. /// </summary>
  73. public MsgTypeEnum MsgTypeEnum
  74. {
  75. get { return _msgTypeEnum; }
  76. set { _msgTypeEnum = value; }
  77. }
  78. public MessageViewModel(IAnnouncementService announcementService)
  79. {
  80. this._announcementService = announcementService;
  81. DateTime serverTimeNow = ApplicationParameter.ServerTimeNow;
  82. DateTime startDate = serverTimeNow.Date.AddDays(-30);
  83. DateTime endDate = new DateTime(serverTimeNow.Year, serverTimeNow.Month, serverTimeNow.Day);
  84. this.StartDateTime = startDate;
  85. this.EndDateTime = endDate;
  86. }
  87. public RelayCommand ShowCommand
  88. {
  89. get
  90. {
  91. return new RelayCommand(() =>
  92. {
  93. if (this.SelectedItemMessage != null)
  94. {
  95. MessageInfoView _messageInfoView = new MessageInfoView() { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner };
  96. MessageInfoViewModel _messageInfoViewModel = new MessageInfoViewModel();
  97. _messageInfoView.DataContext = _messageInfoViewModel;
  98. _messageInfoViewModel.MsgTypeEnum = this.MsgTypeEnum;
  99. _messageInfoViewModel.MessageOrders = this.MessageSource;
  100. _messageInfoViewModel.CurrentAnnouncement = this.SelectedItemMessage;
  101. _messageInfoView.ShowDialog();
  102. }
  103. });
  104. }
  105. }
  106. public RelayCommand QuetyCommand
  107. {
  108. get
  109. {
  110. return new RelayCommand(() =>
  111. {
  112. if (this.EndDateTime < this.StartDateTime)
  113. {
  114. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_EndDateLessBegin, Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_Tips, true);
  115. return;
  116. }
  117. IsBusy = true;
  118. Task.Factory.TryStartNew(() =>
  119. {
  120. // this.MessageSource = _announcementService.QueryClientBM(this.StartDateTime, this.EndDateTime,
  121. //this.SelectWhere, this.MsgTypeEnum, UserManager.CurrentTradeAccount);
  122. QueryClientBMParam clientBMPar = new QueryClientBMParam()
  123. {
  124. StartDate = this.StartDateTime,
  125. EndDate = this.EndDateTime,
  126. MsgTypeEnum = this.MsgTypeEnum,
  127. Title = this.SelectWhere,
  128. TradeAccount = UserManager.CurrentTradeAccount,
  129. };
  130. _announcementService.QueryClientBM(clientBMPar, QueryClientBMCallBack,
  131. QueryClientBMCallBack);
  132. //UserManager.IsRead(this.MsgTypeEnum, this.MessageSource);
  133. //IsBusy = false;
  134. }, () => IsBusy = false);
  135. });
  136. }
  137. }
  138. private void QueryClientBMCallBack(List<Announcement> successAction)
  139. {
  140. this.MessageSource = successAction.ToObservableCollection();
  141. }
  142. private void QueryClientBMCallBack(ErrorEntity error)
  143. {
  144. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  145. {
  146. ErrorManager.ShowReturnError(error, Muchinfo_Resource.UI2014_Tips, true);
  147. }));
  148. }
  149. public override void RegisterMessage()
  150. {
  151. var tradeCacheData = UserManager.GetTradeCacheData((UserManager.CurrentTradeAccount.AccountId));
  152. IsBusy = true;
  153. //当选择时刷新
  154. Task.Factory.TryStartNew(() =>
  155. {
  156. if (this.MsgTypeEnum == MsgTypeEnum.Bulletin)
  157. {
  158. //MessageSource = UserManager.GetMessageAnnouncementOrders(UserManager.CurrentTradeAccount); //_orderService.GetCloseOrdersByTradeAccount(UserManager.CurrentTradeAccount);
  159. MessageSource = tradeCacheData.MessageAnnouncementOrders;
  160. }
  161. if (this.MsgTypeEnum == MsgTypeEnum.NTF)
  162. {
  163. // MessageSource = UserManager.GetMessageNoticeOrders(UserManager.CurrentTradeAccount); //_orderService.GetCloseOrdersByTradeAccount(UserManager.CurrentTradeAccount);
  164. MessageSource = tradeCacheData.MessageNoticeOrders;
  165. }
  166. //IsBusy = false;
  167. }, () => IsBusy = false);
  168. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.OrderNotify, (e) =>
  169. {
  170. Task.Factory.TryStartNew(() =>
  171. {
  172. if (this.MsgTypeEnum == MsgTypeEnum.Bulletin)
  173. {
  174. //MessageSource = UserManager.GetMessageAnnouncementOrders(e, true); //_orderService.GetCloseOrdersByTradeAccount(UserManager.CurrentTradeAccount);
  175. MessageSource = tradeCacheData.MessageAnnouncementOrders;
  176. }
  177. if (this.MsgTypeEnum == MsgTypeEnum.NTF)
  178. {
  179. //MessageSource = UserManager.GetMessageNoticeOrders(e, true); //_orderService.GetCloseOrdersByTradeAccount(UserManager.CurrentTradeAccount);
  180. MessageSource = tradeCacheData.MessageNoticeOrders;
  181. }
  182. //IsBusy = false;
  183. }, () => IsBusy = false);
  184. });
  185. }
  186. public override void RefreshContent()
  187. {
  188. }
  189. }
  190. }