using System; using System.Collections.Generic; using System.Linq; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2017/4/28 11:37:40 //Author //Description Create //---------------------------------------------------------------- using System.Windows; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Bank.Views; using Muchinfo.MTPClient.CustomException; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Helper; using Muchinfo.MTPClient.Data.Model.Bank; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Resources; using Muchinfo.PC.Common.Helpers; namespace Muchinfo.MTPClient.Bank.ViewModels { public class BindCardViewModel : ViewModelBase { /// /// 银行接口 /// private IBankService _bankService; /// /// 签约信息 /// private SigningBank _signingBank; #region 属性 private string _bankAccountName; /// /// 银行账号名称 /// public string BankAccountName { get { return _bankAccountName; } set { Set(() => BankAccountName, ref _bankAccountName, value); } } private string _bankCardNum; /// /// 银行卡号 /// public string BankCardNum { get { return _bankCardNum; } set { Set(() => BankCardNum, ref _bankCardNum, value); } } public Dictionary AccountDictionary { get { var dicType = new Dictionary(); dicType.Add(BankAccountType.PrivateAccount, BankAccountType.PrivateAccount.Discription()); dicType.Add(BankAccountType.PublicAccount, BankAccountType.PublicAccount.Discription()); return dicType; } } private Banks _selectBankItem; /// /// 选择银行 /// public Banks SelectBankItem { get { return _selectBankItem; } set { Set(() => SelectBankItem, ref _selectBankItem, value); } } private bool _isBusy; public bool IsBusy { get { return _isBusy; } set { Set(() => IsBusy, ref _isBusy, value); } } private List _bankList; /// /// 开户银行列表 /// /// The bank branch dictionary. public List BankList { get { return _bankList; } set { Set(() => BankList, ref _bankList, value); } } private BankAccountType _BankAccountType; /// /// 对公对私方式 /// public BankAccountType BankAccountType { get { return _BankAccountType; } set { Set(() => BankAccountType, ref _BankAccountType, value); } } #endregion public BindCardViewModel(SigningBank signingBank) { _signingBank = signingBank; _bankService = SimpleIoc.Default.GetInstance(); var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} _bankService.QueryCusBankParamConfig(accountid, QueryBankCusBankParamConfig, QueryErrorCallback); BankAccountName = signingBank.AccountName; BankAccountType = UserManager.CurrentTradeAccount.AccountType == eUserType.USERTYPE_INVESTOR ? BankAccountType.PrivateAccount : BankAccountType.PrivateAccount; } /// /// 查询托管银行信息配置 /// /// private void QueryBankCusBankParamConfig(List list) { IsBusy = false; var cusBank= list.FirstOrDefault((item) => item.CusBankId == _signingBank.CusBankID); var queryCommons = new List(); if (cusBank != null) { queryCommons.Add(new QueryCommonParam() { ParamKey = "bankid", ParamValue = cusBank.BankListId }); } _bankService.QueryCommonBankInfo(queryCommons,QueryBankInfoCallback, QueryErrorCallback); } public void QueryBankInfoCallback(List list) { IsBusy = false; BankList = list; if (list != null) { SelectBankItem = list.FirstOrDefault((item) => item.BankId == _signingBank.BankId); } } public void QueryErrorCallback(ErrorEntity error) { IsBusy = false; System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true); })); } private Window _view = null; public RelayCommand OKCommand { get { return new RelayCommand( (view) => { if (Validate()) { _view = view; IsBusy = true; _signingBank.RebindToNewBankCardNo = BankCardNum; _signingBank.RebindToNewBankCardNoAccName = BankAccountName; _signingBank.RebindToNewBankNo = SelectBankItem.BankId; _signingBank.BankAccountType = BankAccountType; _signingBank.ExtOperatorID = UserManager.CurrentTradeAccount.AccountId; _signingBank.AppDateTime = ApplicationParameter.ServerTimeNow.ToString("yyyy-MM-dd HH:mm"); _signingBank.ExchId = UserManager.CurrentTradeAccount.ExchAreaId+string.Empty; _bankService.BankBindingBankCard(_signingBank, BankBindingCardSuccess, QueryErrorCallback); } }); } } private void BankBindingCardSuccess(BankSignResult bankDealStatus) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { //switch (bankDealStatus.Status) //{ // case BankDealStatus.BankDealStatus__Succeed: if (string.IsNullOrWhiteSpace(bankDealStatus.WebAddress)) { MessageBoxHelper.ShowSuccess( Muchinfo.MTPClient.Resources.Client_Resource .Tips_BankReBindCardSuccess, Muchinfo.MTPClient.Resources.Client_Resource .APP_Tips); } // break; // case BankDealStatus.BankDealStatus__BankWebComfirm: else { try { IPHelper.OpenWebAddress(bankDealStatus.WebAddress); } catch (Exception ex) { throw new MuchinfoException(ExceptionManager.OpenIEError); } finally { var messageBox = new MsgAlter(bankDealStatus.WebAddress, Client_Resource.Tips_BankBindCardWebComfrim) { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; messageBox.ShowDialog(); } } // break; // } })); } private bool Validate() { if (SelectBankItem == null) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_SelectBankAccount, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips); return false; } if (string.IsNullOrWhiteSpace(BankAccountName)) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputAccountName, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips); return false; } if (string.IsNullOrWhiteSpace(BankCardNum)||!ValidationHelper.IsNumber(BankCardNum)) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputBankAccount, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips); return false; } return true; } } }