DealCloseViewModel.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/11/4 9:17:27
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using System.Windows;
  16. using GalaSoft.MvvmLight.Command;
  17. using GalaSoft.MvvmLight.Ioc;
  18. using Muchinfo.MTPClient.Data;
  19. using Muchinfo.MTPClient.Data.Enums;
  20. using Muchinfo.MTPClient.Data.Helper;
  21. using Muchinfo.MTPClient.Data.Model.Account;
  22. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  23. using Muchinfo.MTPClient.Infrastructure.Utilities;
  24. using Muchinfo.MTPClient.IService;
  25. namespace Muchinfo.MTPClient.Account.ViewModels
  26. {
  27. public class DealCloseViewModel : RegisterMessageBase
  28. {
  29. private IOrderService _iOrderService;
  30. public DealCloseViewModel()
  31. {
  32. _iOrderService = SimpleIoc.Default.GetInstance<IOrderService>();
  33. }
  34. private RelayCommand _comfrimCommand;
  35. public RelayCommand ComfrimCommand
  36. {
  37. get
  38. {
  39. if (_comfrimCommand != null)
  40. {
  41. return _comfrimCommand;
  42. }
  43. _comfrimCommand=new RelayCommand(() =>
  44. {
  45. if (SelectItem != null)
  46. {
  47. var titips = string.Format(Resources.Client_Resource.Content_DealClosedComfrim_Tips, SelectItem.DealNum, SelectItem.Direction.Discription());
  48. var message = MessageBoxHelper.ShowQuestion(titips, Resources.Client_Resource.Content_DealClosedComfrim);
  49. if (message == MessageBoxResult.Yes)
  50. {
  51. IsBusy = true;
  52. var dealCloseModel = new DealCloseOrder()
  53. {
  54. Direction = SelectItem.Direction,
  55. autoId = SelectItem.DealNum,
  56. AccountId = SelectItem.SelfAccountId,
  57. Status = ComfrimStatus.Comfrim
  58. };
  59. _iOrderService.DealCloseComfirm(dealCloseModel, ComfirmSuccessAction, ReceiveError);
  60. }
  61. }
  62. });
  63. return _comfrimCommand;
  64. }
  65. }
  66. private List<DealCloseModel> _dealCloseModels;
  67. /// <summary>
  68. /// 查询条件
  69. /// </summary>
  70. public List<DealCloseModel> DealCloseModels
  71. {
  72. get { return _dealCloseModels; }
  73. set { Set(() => DealCloseModels, ref _dealCloseModels, value); }
  74. }
  75. private DealCloseModel _selectItem;
  76. public DealCloseModel SelectItem
  77. {
  78. get { return _selectItem; }
  79. set { _selectItem = value; }
  80. }
  81. public override void RefreshContent()
  82. {
  83. IsBusy = true;
  84. var accountId = UserManager.CurrentTradeAccount.AccountId;
  85. //if (UserManager.CurrentTradeAccount.FundsAccounts != null &&
  86. // UserManager.CurrentTradeAccount.FundsAccounts.Any())
  87. //{
  88. // accountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  89. //}
  90. _iOrderService.QueryDealCloseSetting(accountId, QueryDealSuccess, ReceiveError);
  91. }
  92. #region 请求回应
  93. private void QueryDealSuccess(List<DealCloseModel> dealCloseModels)
  94. {
  95. IsBusy = false;
  96. var accountId = UserManager.CurrentTradeAccount.AccountId;
  97. //if (UserManager.CurrentTradeAccount.FundsAccounts != null &&
  98. // UserManager.CurrentTradeAccount.FundsAccounts.Any())
  99. //{
  100. // accountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  101. //}
  102. foreach (var dealCloseModel in dealCloseModels) ////设置己方账号
  103. {
  104. dealCloseModel.SelfAccountId = accountId;
  105. }
  106. DealCloseModels = dealCloseModels.FindAll(x => x.AuditStatus != eAuditStatus.AUDITSTATUS_REJECT);
  107. }
  108. private void ComfirmSuccessAction(DealCloseOrder dealClose)
  109. {
  110. IsBusy = false;
  111. ////确认成功后刷新
  112. RefreshContent();
  113. }
  114. private void ReceiveError(ErrorEntity errorEntity)
  115. {
  116. IsBusy = false;
  117. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  118. {
  119. ErrorManager.ShowReturnError(errorEntity, Resources.Client_Resource.MessageBox_Error_Title);
  120. }));
  121. }
  122. #endregion
  123. public override void RegisterMessage()
  124. {
  125. RefreshContent();
  126. }
  127. }
  128. }