BindCardViewModel.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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/4/28 11:37:40
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using System.Windows;
  16. using GalaSoft.MvvmLight;
  17. using GalaSoft.MvvmLight.Command;
  18. using GalaSoft.MvvmLight.Ioc;
  19. using Muchinfo.MTPClient.Bank.Views;
  20. using Muchinfo.MTPClient.CustomException;
  21. using Muchinfo.MTPClient.Data;
  22. using Muchinfo.MTPClient.Data.Enums;
  23. using Muchinfo.MTPClient.Data.Helper;
  24. using Muchinfo.MTPClient.Data.Model.Bank;
  25. using Muchinfo.MTPClient.Infrastructure.Helpers;
  26. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  27. using Muchinfo.MTPClient.Infrastructure.Utilities;
  28. using Muchinfo.MTPClient.IService;
  29. using Muchinfo.MTPClient.Resources;
  30. using Muchinfo.PC.Common.Helpers;
  31. namespace Muchinfo.MTPClient.Bank.ViewModels
  32. {
  33. public class BindCardViewModel : ViewModelBase
  34. {
  35. /// <summary>
  36. /// 银行接口
  37. /// </summary>
  38. private IBankService _bankService;
  39. /// <summary>
  40. /// 签约信息
  41. /// </summary>
  42. private SigningBank _signingBank;
  43. #region 属性
  44. private string _bankAccountName;
  45. /// <summary>
  46. /// 银行账号名称
  47. /// </summary>
  48. public string BankAccountName
  49. {
  50. get { return _bankAccountName; }
  51. set { Set(() => BankAccountName, ref _bankAccountName, value); }
  52. }
  53. private string _bankCardNum;
  54. /// <summary>
  55. /// 银行卡号
  56. /// </summary>
  57. public string BankCardNum
  58. {
  59. get { return _bankCardNum; }
  60. set { Set(() => BankCardNum, ref _bankCardNum, value); }
  61. }
  62. public Dictionary<BankAccountType, string> AccountDictionary
  63. {
  64. get
  65. {
  66. var dicType = new Dictionary<BankAccountType, string>();
  67. dicType.Add(BankAccountType.PrivateAccount, BankAccountType.PrivateAccount.Discription());
  68. dicType.Add(BankAccountType.PublicAccount, BankAccountType.PublicAccount.Discription());
  69. return dicType;
  70. }
  71. }
  72. private Banks _selectBankItem;
  73. /// <summary>
  74. /// 选择银行
  75. /// </summary>
  76. public Banks SelectBankItem
  77. {
  78. get
  79. {
  80. return _selectBankItem;
  81. }
  82. set
  83. {
  84. Set(() => SelectBankItem, ref _selectBankItem, value);
  85. }
  86. }
  87. private bool _isBusy;
  88. public bool IsBusy
  89. {
  90. get { return _isBusy; }
  91. set { Set(() => IsBusy, ref _isBusy, value); }
  92. }
  93. private List<Banks> _bankList;
  94. /// <summary>
  95. /// 开户银行列表
  96. /// </summary>
  97. /// <value>The bank branch dictionary.</value>
  98. public List<Banks> BankList
  99. {
  100. get
  101. {
  102. return _bankList;
  103. }
  104. set
  105. {
  106. Set(() => BankList, ref _bankList, value);
  107. }
  108. }
  109. private BankAccountType _BankAccountType;
  110. /// <summary>
  111. /// 对公对私方式
  112. /// </summary>
  113. public BankAccountType BankAccountType
  114. {
  115. get { return _BankAccountType; }
  116. set { Set(() => BankAccountType, ref _BankAccountType, value); }
  117. }
  118. #endregion
  119. public BindCardViewModel(SigningBank signingBank)
  120. {
  121. _signingBank = signingBank;
  122. _bankService = SimpleIoc.Default.GetInstance<IBankService>();
  123. var accountid = UserManager.CurrentTradeAccount.AccountId;
  124. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  125. //{
  126. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  127. //}
  128. _bankService.QueryCusBankParamConfig(accountid, QueryBankCusBankParamConfig, QueryErrorCallback);
  129. BankAccountName = signingBank.AccountName;
  130. BankAccountType = UserManager.CurrentTradeAccount.AccountType == eUserType.USERTYPE_INVESTOR
  131. ? BankAccountType.PrivateAccount
  132. : BankAccountType.PrivateAccount;
  133. }
  134. /// <summary>
  135. /// 查询托管银行信息配置
  136. /// </summary>
  137. /// <param name="list"></param>
  138. private void QueryBankCusBankParamConfig(List<CusBankInfo> list)
  139. {
  140. IsBusy = false;
  141. var cusBank= list.FirstOrDefault((item) => item.CusBankId == _signingBank.CusBankID);
  142. var queryCommons = new List<QueryCommonParam>();
  143. if (cusBank != null)
  144. {
  145. queryCommons.Add(new QueryCommonParam() { ParamKey = "bankid", ParamValue = cusBank.BankListId });
  146. }
  147. _bankService.QueryCommonBankInfo(queryCommons,QueryBankInfoCallback, QueryErrorCallback);
  148. }
  149. public void QueryBankInfoCallback(List<Banks> list)
  150. {
  151. IsBusy = false;
  152. BankList = list;
  153. if (list != null)
  154. {
  155. SelectBankItem = list.FirstOrDefault((item) => item.BankId == _signingBank.BankId);
  156. }
  157. }
  158. public void QueryErrorCallback(ErrorEntity error)
  159. {
  160. IsBusy = false;
  161. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  162. {
  163. ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true);
  164. }));
  165. }
  166. private Window _view = null;
  167. public RelayCommand<Window> OKCommand
  168. {
  169. get
  170. {
  171. return new RelayCommand<Window>(
  172. (view) =>
  173. {
  174. if (Validate())
  175. {
  176. _view = view;
  177. IsBusy = true;
  178. _signingBank.RebindToNewBankCardNo = BankCardNum;
  179. _signingBank.RebindToNewBankCardNoAccName = BankAccountName;
  180. _signingBank.RebindToNewBankNo = SelectBankItem.BankId;
  181. _signingBank.BankAccountType = BankAccountType;
  182. _signingBank.ExtOperatorID = UserManager.CurrentTradeAccount.AccountId;
  183. _signingBank.AppDateTime = ApplicationParameter.ServerTimeNow.ToString("yyyy-MM-dd HH:mm");
  184. _signingBank.ExchId = UserManager.CurrentTradeAccount.ExchAreaId+string.Empty;
  185. _bankService.BankBindingBankCard(_signingBank, BankBindingCardSuccess, QueryErrorCallback);
  186. }
  187. });
  188. }
  189. }
  190. private void BankBindingCardSuccess(BankSignResult bankDealStatus)
  191. {
  192. IsBusy = false;
  193. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  194. {
  195. //switch (bankDealStatus.Status)
  196. //{
  197. // case BankDealStatus.BankDealStatus__Succeed:
  198. if (string.IsNullOrWhiteSpace(bankDealStatus.WebAddress))
  199. {
  200. MessageBoxHelper.ShowSuccess(
  201. Muchinfo.MTPClient.Resources.Client_Resource
  202. .Tips_BankReBindCardSuccess,
  203. Muchinfo.MTPClient.Resources.Client_Resource
  204. .APP_Tips);
  205. }
  206. // break;
  207. // case BankDealStatus.BankDealStatus__BankWebComfirm:
  208. else
  209. {
  210. try
  211. {
  212. IPHelper.OpenWebAddress(bankDealStatus.WebAddress);
  213. }
  214. catch (Exception ex)
  215. {
  216. throw new MuchinfoException(ExceptionManager.OpenIEError);
  217. }
  218. finally
  219. {
  220. var messageBox = new MsgAlter(bankDealStatus.WebAddress, Client_Resource.Tips_BankBindCardWebComfrim)
  221. {
  222. Owner = Application.Current.MainWindow,
  223. WindowStartupLocation = WindowStartupLocation.CenterOwner
  224. };
  225. messageBox.ShowDialog();
  226. }
  227. }
  228. // break;
  229. // }
  230. }));
  231. }
  232. private bool Validate()
  233. {
  234. if (SelectBankItem == null)
  235. {
  236. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_SelectBankAccount,
  237. Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  238. return false;
  239. }
  240. if (string.IsNullOrWhiteSpace(BankAccountName))
  241. {
  242. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputAccountName, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  243. return false;
  244. }
  245. if (string.IsNullOrWhiteSpace(BankCardNum)||!ValidationHelper.IsNumber(BankCardNum))
  246. {
  247. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputBankAccount, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  248. return false;
  249. }
  250. return true;
  251. }
  252. }
  253. }