MotifyPhoneViewModel.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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/14 17:28:31
  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.Data;
  20. using Muchinfo.MTPClient.Data.Model.Bank;
  21. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  22. using Muchinfo.MTPClient.Infrastructure.Utilities;
  23. using Muchinfo.MTPClient.IService;
  24. namespace Muchinfo.MTPClient.Bank.ViewModels
  25. {
  26. public class MotifyPhoneViewModel : IdentifyCodeTimerViewModel
  27. {
  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. public MotifyPhoneViewModel(SigningBank bankSign)
  39. {
  40. CurrentSigningBank = bankSign;
  41. MobilePhone = bankSign.BankMobile;
  42. _bankService = SimpleIoc.Default.GetInstance<IBankService>();
  43. }
  44. private string _mobilePhone;
  45. /// <summary>
  46. /// 手机号码
  47. /// </summary>
  48. public string MobilePhone
  49. {
  50. get { return _mobilePhone; }
  51. set { Set(() => MobilePhone, ref _mobilePhone, value); }
  52. }
  53. private SigningBank _currentSigningBank;
  54. public SigningBank CurrentSigningBank
  55. {
  56. get { return _currentSigningBank; }
  57. set { _currentSigningBank = value; }
  58. }
  59. private Window _window;
  60. public RelayCommand<Window> OKCommand
  61. {
  62. get
  63. {
  64. return new RelayCommand<Window>((view) =>
  65. {
  66. if (CurrentSigningBank == null)
  67. {
  68. return;
  69. }
  70. IsBusy = true;
  71. if (Validate())
  72. {
  73. _window = view;
  74. CurrentSigningBank.MobilePhone = MobilePhone;
  75. CurrentSigningBank.ExtOperatorID = UserManager.CurrentTradeAccount.AccountId;
  76. CurrentSigningBank.AccountType = UserManager.CurrentTradeAccount.AccountType;
  77. _bankService.SignUpdate(CurrentSigningBank, SignUpdateCallback, ErrorCallback);
  78. }
  79. });
  80. }
  81. }
  82. private void SignUpdateCallback(int result)
  83. {
  84. IsBusy = false;
  85. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  86. {
  87. if (result == 0)
  88. {
  89. MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Bank_ChangeBankInfoSuccess_Wait, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  90. if (_window != null)
  91. {
  92. _window.Close();
  93. }
  94. }
  95. else
  96. {
  97. ErrorManager.ShowReturnError(result, Muchinfo.MTPClient.Resources.Client_Resource.Bank_ErrotTips);
  98. }
  99. }));
  100. }
  101. public void ErrorCallback(ErrorEntity error)
  102. {
  103. IsBusy = false;
  104. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  105. {
  106. ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true);
  107. }));
  108. }
  109. /// <summary>
  110. /// 验证
  111. /// </summary>
  112. /// <returns>是否通过</returns>
  113. private bool Validate()
  114. {
  115. if (string.IsNullOrWhiteSpace(MobilePhone))
  116. {
  117. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputMobilePhone, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  118. return false;
  119. }
  120. if (string.IsNullOrEmpty(CurrentSigningBank.IdentifyCode))
  121. {
  122. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputIdentifyCode, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  123. return false;
  124. }
  125. //if (this.NewBankAccount.Trim() == this.BankAccount.Trim())
  126. //{
  127. // MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_NewAndOldAccountSame, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  128. // return false;
  129. //}
  130. return true;
  131. }
  132. /// <summary>
  133. /// 获取手机验证码
  134. /// </summary>
  135. public RelayCommand IdentifyCodeCommand
  136. {
  137. get
  138. {
  139. return new RelayCommand(() =>
  140. {
  141. if (CurrentSigningBank == null)
  142. {
  143. return;
  144. }
  145. if (string.IsNullOrWhiteSpace(MobilePhone))
  146. {
  147. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputMobilePhone, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  148. return ;
  149. }
  150. var IndentityReq = new IdentifyCodeReq()
  151. {
  152. AccountCode = CurrentSigningBank.AccountCode,
  153. CusBankID = CurrentSigningBank.CusBankID + string.Empty,
  154. TradeType = BankTradeType.UpdateSign,
  155. Amount = 0,
  156. CustomerSignId = CurrentSigningBank.CustomerSignId,
  157. CustomerName = CurrentSigningBank.CustomerName,
  158. BankCode = CurrentSigningBank.BankId,
  159. AccountType = CurrentSigningBank.AccountType,
  160. BankAccountNo = CurrentSigningBank.BankAccount,
  161. CardNum = CurrentSigningBank.CredentialNumber,
  162. CardType = CurrentSigningBank.CredentialType,
  163. MobilePhone = MobilePhone,
  164. Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any())
  165. ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency,
  166. };
  167. _bankService.BankGetIdentifyCode(IndentityReq, null, ErrorCallback);
  168. this.Start();
  169. }, (() => IsGetIdentifyCodeEnable()));
  170. }
  171. }
  172. private bool IsGetIdentifyCodeEnable()
  173. {
  174. if (string.IsNullOrWhiteSpace(MobilePhone))
  175. {
  176. return false;
  177. }
  178. if (!IsNumberString(MobilePhone))
  179. {
  180. return false;
  181. }
  182. if (MobilePhone.Length!=11)
  183. {
  184. return false;
  185. }
  186. return true;
  187. }
  188. /// <summary>
  189. /// /字符串是否只包括数字
  190. /// </summary>
  191. /// <param name="str"></param>
  192. /// <returns></returns>
  193. private bool IsNumberString(string str)
  194. {
  195. char[] chArr = str.ToCharArray();
  196. foreach (var ch in chArr)
  197. {
  198. if (!char.IsDigit(ch))
  199. {
  200. return false;
  201. }
  202. }
  203. return true;
  204. }
  205. }
  206. }