AmountQueryViewModel.cs 6.3 KB

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