OperateLogViewModel.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using GalaSoft.MvvmLight;
  4. using GalaSoft.MvvmLight.Command;
  5. using GalaSoft.MvvmLight.Messaging;
  6. using Muchinfo.MTPClient.Data.Enums;
  7. using Muchinfo.PC.Common.Extensions;
  8. using Muchinfo.MTPClient.Data;
  9. using Muchinfo.MTPClient.Data.Model.Account;
  10. using Muchinfo.MTPClient.Infrastructure.Utilities;
  11. using System.Collections.ObjectModel;
  12. using Muchinfo.MTPClient.Infrastructure.Helpers;
  13. namespace Muchinfo.MTPClient.Account.ViewModels
  14. {
  15. public class OperateLogViewModel : RegisterMessageBase
  16. {
  17. ObservableCollection<UserLog> _logs = new ObservableCollection<UserLog>();
  18. public ObservableCollection<UserLog> Logs
  19. {
  20. get
  21. {
  22. return _logs;
  23. }
  24. set
  25. {
  26. Set(() => Logs, ref _logs, value);
  27. }
  28. }
  29. #region 开始时间
  30. private DateTime startTime;
  31. /// <summary>
  32. /// 开始时间
  33. /// </summary>
  34. public DateTime StartTime
  35. {
  36. get { return startTime; }
  37. set { Set(() => StartTime, ref startTime, value); }
  38. }
  39. #endregion
  40. #region 结束时间
  41. private DateTime _endTime;
  42. /// <summary>
  43. /// 结束时间
  44. /// </summary>
  45. public DateTime EndTime
  46. {
  47. get { return _endTime; }
  48. set { Set(() => EndTime, ref _endTime, value); }
  49. }
  50. #endregion
  51. public OperateLogViewModel()
  52. {
  53. }
  54. public override void RegisterMessage()
  55. {
  56. EndTime = ApplicationParameter.ServerTimeNow;
  57. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  58. RefreshCommand.Execute(null);
  59. MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.OrderNotify);
  60. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.OrderNotify, (e) =>
  61. {
  62. //接收通知时,防止时间设置错误,弹出错误提示
  63. EndTime = ApplicationParameter.ServerTimeNow;
  64. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  65. RefreshCommand.Execute(null);
  66. });
  67. }
  68. #region 重置查询时间命令Command
  69. private RelayCommand _resetCommand;
  70. /// <summary>
  71. /// Gets the ResetCommand.
  72. /// </summary>
  73. public RelayCommand ResetCommand
  74. {
  75. get
  76. {
  77. return _resetCommand
  78. ?? (_resetCommand = new RelayCommand(
  79. () =>
  80. {
  81. EndTime = ApplicationParameter.ServerTimeNow;
  82. StartTime = ApplicationParameter.ServerTimeNow.AddDays(-30);
  83. }));
  84. }
  85. }
  86. #endregion
  87. /// <summary>
  88. /// 查询持仓成功回调
  89. /// </summary>
  90. /// <param name="holdOrders">持仓内容</param>
  91. private void QueryHoldOrderCallBack(List<UserLog> userLogs)
  92. {
  93. ////获取当前的持仓
  94. IsBusy = false;
  95. Logs = new ObservableCollection<UserLog>(userLogs);
  96. }
  97. /// <summary>
  98. ///
  99. /// </summary>
  100. /// <param name="errorEntity"></param>
  101. public override void QueryErrorCallback(ErrorEntity errorEntity)
  102. {
  103. IsBusy = false;
  104. //var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态
  105. //MessengerHelper.DefaultSend(errorMsg, MessengerTokens.ErrorMessage);
  106. // base.QueryErrorCallback();
  107. }
  108. public override void RefreshContent()
  109. {
  110. IsBusy = true;
  111. var queryCommons = new List<QueryCommonParam>();
  112. queryCommons.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = UserManager.CurrentTradeAccount.AccountId + string.Empty });
  113. queryCommons.Add(new QueryCommonParam() { ParamKey = "startDate", ParamValue = StartTime.ToString("yyyy-MM-dd HH:mm:ss") });
  114. queryCommons.Add(new QueryCommonParam() { ParamKey = "endDate", ParamValue = EndTime.ToString("yyyy-MM-dd HH:mm:ss") });
  115. _orderService.QueryUserLogs(QueryStatement.SearchSysLog, queryCommons, QueryHoldOrderCallBack, QueryErrorCallback);
  116. }
  117. }
  118. }