AmountQueryViewModel.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using GalaSoft.MvvmLight.Command;
  2. using GalaSoft.MvvmLight.Ioc;
  3. using Muchinfo.MTPClient.Data;
  4. using Muchinfo.MTPClient.Data.Model.Bank;
  5. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  6. using Muchinfo.MTPClient.Infrastructure.Utilities;
  7. using Muchinfo.MTPClient.IService;
  8. using Muchinfo.MTPClient.Resources;
  9. using Muchinfo.WPF.Controls.Windows;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. namespace Muchinfo.MTPClient.Account.ViewModels
  14. {
  15. public class AmountQueryViewModel : RegisterMessageBase
  16. {
  17. /// 查询开始时间
  18. private DateTime _startDateTime;
  19. /// <summary>
  20. /// 查询开始时间
  21. /// </summary>
  22. public DateTime StartDateTime
  23. {
  24. get { return _startDateTime; }
  25. set
  26. {
  27. Set(() => StartDateTime, ref _startDateTime, new DateTime(value.Year, value.Month, value.Day, 0, 0, 0));
  28. }
  29. }
  30. /// 查询结束时间
  31. private DateTime _endDateTime;
  32. /// <summary>
  33. /// 查询结束时间
  34. /// </summary>
  35. public DateTime EndDateTime
  36. {
  37. get { return _endDateTime; }
  38. set
  39. {
  40. Set(() => EndDateTime, ref _endDateTime, new DateTime(value.Year, value.Month, value.Day, 23, 59, 59));
  41. }
  42. }
  43. private List<AmountQuery> _amountQueryList;
  44. public List<AmountQuery> AmountQueryList
  45. {
  46. get { return _amountQueryList; }
  47. set { Set(() => AmountQueryList, ref _amountQueryList, value); }
  48. }
  49. private IBankService _bankService;
  50. public AmountQueryViewModel()
  51. {
  52. _bankService = SimpleIoc.Default.GetInstance<IBankService>();
  53. DateTime time = ApplicationParameter.ServerTimeNow;
  54. //this.StartDateTime = time.AddDays(1 - time.Day);
  55. this.StartDateTime = time.AddDays(-7);
  56. this.EndDateTime = time;
  57. SelectBankOutIn();
  58. }
  59. public RelayCommand QuetyCommand
  60. {
  61. get
  62. {
  63. return new RelayCommand(() =>
  64. {
  65. if (this.EndDateTime < this.StartDateTime)
  66. {
  67. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Models_EndDateLessBegin, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  68. return;
  69. }
  70. int number = (StartDateTime.Year - EndDateTime.Year) * 12 + StartDateTime.Month - EndDateTime.Month;
  71. if (number < -3)
  72. {
  73. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Models_CanNotGreatThan3Month, Muchinfo.MTPClient.Resources.Client_Resource.Models_Tips, true);
  74. return;
  75. }
  76. SelectBankOutIn();
  77. });
  78. }
  79. }
  80. public void SelectBankOutIn()
  81. {
  82. var queryCommons = new List<QueryCommonParam>();
  83. var accountid = UserManager.CurrentTradeAccount.AccountId;
  84. //if (UserManager.CurrentTradeAccount.FundsAccounts!=null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  85. //{
  86. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  87. //}
  88. queryCommons.Add(new QueryCommonParam()
  89. {
  90. ParamKey = "accountId",
  91. ParamValue = accountid + string.Empty
  92. });
  93. queryCommons.Add(new QueryCommonParam()
  94. {
  95. ParamKey = "beginDate",
  96. ParamValue = StartDateTime.ToString("yyyy-MM-dd")
  97. });
  98. queryCommons.Add(new QueryCommonParam()
  99. {
  100. ParamKey = "endDate",
  101. ParamValue = EndDateTime.Date.AddHours(24).ToString("yyyy-MM-dd HH:mm:ss")
  102. });
  103. //
  104. IsBusy = true;
  105. //this.AmountQueryList = _bankService.QueryBankOutIn(this.StartDateTime, this.EndDateTime, UserManager.CurrentTradeAccount);
  106. _bankService.QueryBankOutIn(QueryStatement.SearchClientMoneyOutIn, queryCommons, QueryBankOutInCallBack,
  107. QueryErrorCallback);
  108. }
  109. private void QueryBankOutInCallBack(List<AmountQuery> amountQueryList)
  110. {
  111. IsBusy = false;
  112. this.AmountQueryList = amountQueryList;
  113. }
  114. public virtual void QueryErrorCallback(ErrorEntity errorEntity)
  115. {
  116. IsBusy = false;
  117. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  118. {
  119. ErrorManager.ShowReturnError(errorEntity, Client_Resource.APP_Tips, false);
  120. }));
  121. }
  122. //注册消息
  123. public override void RegisterMessage()
  124. {
  125. SelectBankOutIn();
  126. }
  127. public override void RefreshContent()
  128. {
  129. QuetyCommand.Execute(null);
  130. }
  131. }
  132. }