TaAmountLogViewModel.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //----------------------------------------------------------------
  6. //Module Name: $safeprojectname$
  7. //Purpose:
  8. //CopyRight: Muchinfo
  9. //History:
  10. //----------------------------------------------------------------
  11. //DateTime 2016/10/25 15:25:09
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using GalaSoft.MvvmLight.Command;
  16. using GalaSoft.MvvmLight.Ioc;
  17. using Muchinfo.MTPClient.Data;
  18. using Muchinfo.MTPClient.Data.Enums;
  19. using Muchinfo.MTPClient.Data.Model.Account;
  20. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  21. using Muchinfo.MTPClient.Infrastructure.Helpers;
  22. using Muchinfo.MTPClient.Infrastructure.Utilities;
  23. using Muchinfo.MTPClient.IService;
  24. using Muchinfo.MTPClient.Resources;
  25. namespace Muchinfo.MTPClient.Account.ViewModels
  26. {
  27. public class TaAmountLogViewModel : RegisterMessageBase
  28. {
  29. public bool IsQueryHistory
  30. {
  31. get;set;
  32. }
  33. /// 查询开始时间
  34. private DateTime _startDateTime;
  35. /// <summary>
  36. /// 查询开始时间
  37. /// </summary>
  38. public DateTime StartDateTime
  39. {
  40. get { return _startDateTime; }
  41. set
  42. {
  43. Set(() => StartDateTime, ref _startDateTime, new DateTime(value.Year, value.Month, value.Day, 0, 0, 0));
  44. }
  45. }
  46. /// 查询结束时间
  47. private DateTime _endDateTime;
  48. /// <summary>
  49. /// 查询结束时间
  50. /// </summary>
  51. public DateTime EndDateTime
  52. {
  53. get { return _endDateTime; }
  54. set
  55. {
  56. Set(() => EndDateTime, ref _endDateTime, new DateTime(value.Year, value.Month, value.Day, 23, 59, 59));
  57. }
  58. }
  59. private List<AccountAmountLog> _amountLogList;
  60. public List<AccountAmountLog> AmountLogList
  61. {
  62. get { return _amountLogList; }
  63. set { Set(() => AmountLogList, ref _amountLogList, value); }
  64. }
  65. public TaAmountLogViewModel()
  66. {
  67. _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
  68. DateTime time = ApplicationParameter.ServerTimeNow;
  69. //this.StartDateTime = time.AddDays(1 - time.Day);
  70. this.StartDateTime = time.AddDays(-7);
  71. this.EndDateTime = time;
  72. MessengerHelper.DefaultUnregister<ulong>(this, MessengerTokens.ShowTaAmountLogByCapitalAccount);
  73. MessengerHelper.DefaultRegister<ulong>(this, MessengerTokens.ShowTaAmountLogByCapitalAccount, (e) =>
  74. {
  75. //显示对应资金账户的数据信息
  76. QueryAmountLog(e);
  77. });
  78. }
  79. public RelayCommand QueryCommand
  80. {
  81. get
  82. {
  83. return new RelayCommand(() =>
  84. {
  85. if (Vailed())
  86. {
  87. QueryAmountLog(UserManager.CurrentTradeAccount.FundsAccountId, IsQueryHistory);
  88. }
  89. });
  90. }
  91. }
  92. /// <summary>
  93. /// Queries the amount log.
  94. /// </summary>
  95. /// <param name="accountid">The accountid.</param>
  96. /// <param name="isHistory">if set to <c>true</c> [is history].</param>
  97. public void QueryAmountLog(ulong accountid, bool isHistory = false)
  98. {
  99. if (IsBusy) return;
  100. IsBusy = true;
  101. var queryCommons = new List<QueryCommonParam>();
  102. queryCommons.Add(new QueryCommonParam()
  103. {
  104. ParamKey = "accountId",
  105. ParamValue = accountid + string.Empty
  106. });
  107. if (isHistory)
  108. {
  109. queryCommons.Add(new QueryCommonParam()
  110. {
  111. ParamKey = "startDate",
  112. ParamValue = StartDateTime.ToString("yyyy-MM-dd")
  113. });
  114. queryCommons.Add(new QueryCommonParam()
  115. {
  116. ParamKey = "endDate",
  117. ParamValue = EndDateTime.ToString("yyyy-MM-dd HH:mm:ss")
  118. });
  119. }
  120. queryCommons.Add(new QueryCommonParam() // 90926 2.资金流水记录中,仅保留出入金记录,其他类型的流水都不显示;
  121. {
  122. ParamKey = "operatetype",
  123. ParamValue = "101,103",
  124. });
  125. _orderService.QueryTaAmountLog(isHistory, queryCommons, QueryAmountLogCallBack,
  126. QueryErrorCallback);
  127. }
  128. private void QueryAmountLogCallBack(List<AccountAmountLog> amountQueryList)
  129. {
  130. IsBusy = false;
  131. this.AmountLogList = amountQueryList;
  132. }
  133. public override void QueryErrorCallback(ErrorEntity errorEntity)
  134. {
  135. IsBusy = false;
  136. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  137. {
  138. ErrorManager.ShowReturnError(errorEntity, Client_Resource.APP_Tips, false);
  139. }));
  140. }
  141. //注册消息
  142. public override void RegisterMessage()
  143. {
  144. RefreshContent();
  145. }
  146. public override void RefreshContent()
  147. {
  148. QueryCommand.Execute(null);
  149. }
  150. /// <summary>
  151. /// 数据验证
  152. /// </summary>
  153. /// <returns></returns>
  154. private bool Vailed()
  155. {
  156. if (StartDateTime > EndDateTime)
  157. {
  158. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_StartEnd, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  159. return false;
  160. }
  161. else if ((EndDateTime - StartDateTime).Days > 30)
  162. {
  163. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.DateTimeVaided_Over30days, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  164. return false;
  165. }
  166. return true;
  167. }
  168. }
  169. }