using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2017/3/14 17:28:31 //Author //Description Create //---------------------------------------------------------------- using System.Windows; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Model.Bank; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; namespace Muchinfo.MTPClient.Bank.ViewModels { public class MotifyPhoneViewModel : IdentifyCodeTimerViewModel { private IBankService _bankService; private bool _isBusy; /// /// 是否忙,显示等待控件 /// public bool IsBusy { get { return _isBusy; } set { Set(() => IsBusy, ref _isBusy, value); } } public MotifyPhoneViewModel(SigningBank bankSign) { CurrentSigningBank = bankSign; MobilePhone = bankSign.BankMobile; _bankService = SimpleIoc.Default.GetInstance(); } private string _mobilePhone; /// /// 手机号码 /// public string MobilePhone { get { return _mobilePhone; } set { Set(() => MobilePhone, ref _mobilePhone, value); } } private SigningBank _currentSigningBank; public SigningBank CurrentSigningBank { get { return _currentSigningBank; } set { _currentSigningBank = value; } } private Window _window; public RelayCommand OKCommand { get { return new RelayCommand((view) => { if (CurrentSigningBank == null) { return; } IsBusy = true; if (Validate()) { _window = view; CurrentSigningBank.MobilePhone = MobilePhone; CurrentSigningBank.ExtOperatorID = UserManager.CurrentTradeAccount.AccountId; CurrentSigningBank.AccountType = UserManager.CurrentTradeAccount.AccountType; _bankService.SignUpdate(CurrentSigningBank, SignUpdateCallback, ErrorCallback); } }); } } private void SignUpdateCallback(int result) { IsBusy = false; System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { if (result == 0) { MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Bank_ChangeBankInfoSuccess_Wait, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips); if (_window != null) { _window.Close(); } } else { ErrorManager.ShowReturnError(result, Muchinfo.MTPClient.Resources.Client_Resource.Bank_ErrotTips); } })); } public void ErrorCallback(ErrorEntity error) { IsBusy = false; System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true); })); } /// /// 验证 /// /// 是否通过 private bool Validate() { if (string.IsNullOrWhiteSpace(MobilePhone)) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputMobilePhone, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips); return false; } if (string.IsNullOrEmpty(CurrentSigningBank.IdentifyCode)) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputIdentifyCode, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips); return false; } //if (this.NewBankAccount.Trim() == this.BankAccount.Trim()) //{ // MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_NewAndOldAccountSame, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips); // return false; //} return true; } /// /// 获取手机验证码 /// public RelayCommand IdentifyCodeCommand { get { return new RelayCommand(() => { if (CurrentSigningBank == null) { return; } if (string.IsNullOrWhiteSpace(MobilePhone)) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputMobilePhone, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips); return ; } var IndentityReq = new IdentifyCodeReq() { AccountCode = CurrentSigningBank.AccountCode, CusBankID = CurrentSigningBank.CusBankID + string.Empty, TradeType = BankTradeType.UpdateSign, Amount = 0, CustomerSignId = CurrentSigningBank.CustomerSignId, CustomerName = CurrentSigningBank.CustomerName, BankCode = CurrentSigningBank.BankId, AccountType = CurrentSigningBank.AccountType, BankAccountNo = CurrentSigningBank.BankAccount, CardNum = CurrentSigningBank.CredentialNumber, CardType = CurrentSigningBank.CredentialType, MobilePhone = MobilePhone, Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any()) ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency, }; _bankService.BankGetIdentifyCode(IndentityReq, null, ErrorCallback); this.Start(); }, (() => IsGetIdentifyCodeEnable())); } } private bool IsGetIdentifyCodeEnable() { if (string.IsNullOrWhiteSpace(MobilePhone)) { return false; } if (!IsNumberString(MobilePhone)) { return false; } if (MobilePhone.Length!=11) { return false; } return true; } /// /// /字符串是否只包括数字 /// /// /// private bool IsNumberString(string str) { char[] chArr = str.ToCharArray(); foreach (var ch in chArr) { if (!char.IsDigit(ch)) { return false; } } return true; } } }