BankBalanceViewModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 2017/3/23 15:03:32
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using GalaSoft.MvvmLight;
  16. using GalaSoft.MvvmLight.Ioc;
  17. using Muchinfo.MTPClient.Data;
  18. using Muchinfo.MTPClient.Data.Model.Bank;
  19. using Muchinfo.MTPClient.Infrastructure.Utilities;
  20. using Muchinfo.MTPClient.IService;
  21. namespace Muchinfo.MTPClient.Bank.ViewModels
  22. {
  23. public class BankBalanceViewModel : ViewModelBase
  24. {
  25. /// <summary>
  26. /// 银行接口
  27. /// </summary>
  28. private IBankService _bankService;
  29. private bool _isBusy;
  30. /// <summary>
  31. /// 是否忙,显示等待控件
  32. /// </summary>
  33. public bool IsBusy
  34. {
  35. get { return _isBusy; }
  36. set { Set(() => IsBusy, ref _isBusy, value); }
  37. }
  38. private SigningBank _currentSigningBank;
  39. /// <summary>
  40. /// 当前选中签约银行
  41. /// </summary>
  42. public SigningBank CurrentSigningBank
  43. {
  44. get
  45. {
  46. return _currentSigningBank;
  47. }
  48. set
  49. {
  50. Set(() => CurrentSigningBank, ref _currentSigningBank, value);
  51. }
  52. }
  53. private List<BankBalanceModel> _balanceModels;
  54. /// <summary>
  55. /// 查询银行余额
  56. /// </summary>
  57. public List<BankBalanceModel> BalanceModels
  58. {
  59. get { return _balanceModels; }
  60. set { Set(() => BalanceModels, ref _balanceModels, value); }
  61. }
  62. private BankBalanceModel _selectItem;
  63. /// <summary>
  64. /// 选择的项
  65. /// </summary>
  66. public BankBalanceModel SelectItem
  67. {
  68. get { return _selectItem; }
  69. set { Set(() => SelectItem, ref _selectItem, value); }
  70. }
  71. public BankBalanceViewModel(SigningBank signingBank)
  72. {
  73. _bankService = SimpleIoc.Default.GetInstance<IBankService>();
  74. CurrentSigningBank = signingBank;
  75. IsBusy = true;
  76. _bankService.GetBankBalace(signingBank, QueryBalanceCallBack, ErrorCallback);
  77. }
  78. private void QueryBalanceCallBack(List<BankBalanceModel> balanceModels)
  79. {
  80. IsBusy = false;
  81. BalanceModels = balanceModels;
  82. SelectItem = BalanceModels != null ? BalanceModels.FirstOrDefault() : null;
  83. #if DEBUG
  84. var balances = new List<BankBalanceModel>();
  85. balances.Add(new BankBalanceModel() { AccountCode = 12315555 + string.Empty, PlatBalance = 254542, Cusbankid = "fdaddd" });
  86. balances.Add(new BankBalanceModel() { AccountCode = 12315532455 + string.Empty, PlatBalance = 25432542, Cusbankid = "fda323ddd" });
  87. BalanceModels = balances;
  88. SelectItem = BalanceModels != null ? BalanceModels.FirstOrDefault() : null;
  89. #endif
  90. }
  91. public void ErrorCallback(ErrorEntity error)
  92. {
  93. #if DEBUG
  94. var balances = new List<BankBalanceModel>();
  95. balances.Add(new BankBalanceModel(){AccountCode = 12315555+string.Empty,PlatBalance = 254542,Cusbankid = "fdaddd"});
  96. balances.Add(new BankBalanceModel() { AccountCode = 12315532455 + string.Empty, PlatBalance = 25432542, Cusbankid = "fda323ddd" });
  97. BalanceModels = balances;
  98. SelectItem = BalanceModels != null ? BalanceModels.FirstOrDefault() : null;
  99. #endif
  100. IsBusy = false;
  101. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  102. {
  103. ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true);
  104. }));
  105. }
  106. }
  107. }