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.Extensions; using Muchinfo.MTPClient.Data.Model.Account; 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.Extensions; using Muchinfo.PC.Common.Helpers; using Muchinfo.WPF.Controls.Windows; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; namespace Muchinfo.MTPClient.Bank.ViewModels { public class BankTerminationViewModel : IdentifyCodeTimerViewModel { #region 变量成员 private IBankService _bankService; private BankTerminationView _view; private EncryptKey _encryptKey; private AreaAccount _areaAccount; //会员账号信息 private bool _isBusy; /// /// 是否忙,显示等待控件 /// public bool IsBusy { get { return _isBusy; } set { Set(() => IsBusy, ref _isBusy, value); } } private string _busyContent; public string BusyContent { get { return _busyContent; } set { Set(() => BusyContent, ref _busyContent, value); } } /// ///证件类型 /// public Dictionary ClientCardTypes { get { //var types = new Dictionary { { ClientCardType.Id, ClientCardType.Id.Discription() }, { ClientCardType.Driver, ClientCardType.Driver.Discription() } }; //return types; return EnumExtensions.ToDictionary(); } } //private List _cusBankList = new List(); ///// ///// 签约的托管银行 ///// //public List CusBankList //{ // get { return _cusBankList; } // set { Set(() => CusBankList, ref _cusBankList, value); } //} //private SigningBank _currentCusBank; ///// ///// 当前选中的托管银行 ///// //public SigningBank CurrentCusBank //{ // get { return _currentCusBank; } // set // { // Set(() => CurrentCusBank, ref _currentCusBank, value); // if (value != null) // { // CurrentSigningBank = SignBankList.FirstOrDefault(m => m.CusBankID == value.CusBankID); // } // } //} private ObservableCollection _signBankList; /// /// 客户签约银行列表 /// public ObservableCollection SignBankList { get { return _signBankList; } set { Set(() => SignBankList, ref _signBankList, value); } } private SigningBank _currentSigningBank; /// /// 当前选中签约银行 /// public SigningBank CurrentSigningBank { get { return _currentSigningBank; } set { Set(() => CurrentSigningBank, ref _currentSigningBank, value); //银行Id获取银行支行列表 //Dictionary BankBranchDictionary = _bankService.GetBankBranchList(value.Id); //支行Id获取支行名称 //BranchName = BankBranchDictionary[value.BranchId]; CredentialTypeName = ClientCardTypes[value.CredentialType]; SetCollapsed(); // SetSignBankInfo(); } } private string _credentialTypeName; /// /// 开户人证件类型名称 /// public string CredentialTypeName { get { return _credentialTypeName; } set { Set(() => CredentialTypeName, ref _credentialTypeName, value); } } private string _branchName; /// /// 开户银行支行名称 /// public string BranchName { get { return _branchName; } set { Set(() => BranchName, ref _branchName, value); } } /// /// 建行三方提示 /// private bool _branchMessage = false; /// /// 建行三方提示 /// public bool BranchMessage { get { return _branchMessage; } set { Set(() => BranchMessage, ref _branchMessage, value); } } /// /// 网银签约解约提示 /// private bool _netMessage = false; /// /// 网银签约解约提示 /// public bool NetMessage { get { return _netMessage; } set { Set(() => NetMessage, ref _netMessage, value); } } private string _netWorkSignTips; /// /// 网银端提示 /// public string NetWorkSignTips { get { return _netWorkSignTips; } set { Set(() => NetWorkSignTips, ref _netWorkSignTips, value); } } /// /// 是否可点确定 /// private bool _isOKEnable = true; /// /// 是否可点确定 /// public bool IsOKEnable { get { return _isOKEnable; } set { Set(() => IsOKEnable, ref _isOKEnable, value); } } /// ///银行列表 /// List AccoumtBankSignList; #endregion #region 构造函数 public BankTerminationViewModel(BankTerminationView bankTerminationView) { _view = bankTerminationView; IsBusy = true; temp_ankDealStatus = null; BusyContent = Muchinfo.MTPClient.Resources.Client_Resource.Bank_GetBankInfo_Waiting; _bankService = SimpleIoc.Default.GetInstance(); // _bankService.QueryBankInfo(QueryBankInfoCallback, ErrorCallback); //todo: QueryBankCustomerSign 未返回CusBankName 先查询QueryCusBankInfo返回匹配该字段 // SignBankList = //_bankService.QueryBankCustomerSign(QueryBankCustomerSignCallback, ErrorCallback); var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} _bankService.QueryBankCustomerSignInfo(accountid, SearchBankCustomerSignCallback, ErrorCallback); } /// /// 查询签约信息回应 /// /// private void SearchBankCustomerSignCallback(List list) { IsBusy = false; if (ApplicationParameter.NewBankPlatform == 1) ////新银行平台 { SignBankList = new ObservableCollection(list); } else { SignBankList = new ObservableCollection(list.Where((item) => item.ShowCancelSign == 0 && item.SignStatusType == SignStatus.SignStatus_Signed)); } System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { if (SignBankList == null || SignBankList.Count <= 0) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_NoSignWithBank, Muchinfo.MTPClient.Resources.Client_Resource.Bank_BankTerminationTips); // bankTerminationView.Close(); _view.Close(); return; } CurrentSigningBank = SignBankList.FirstOrDefault(); })); } private void QueryBankCustomerSignCallback(ObservableCollection list) { IsBusy = false; SignBankList = new ObservableCollection(list.Where((item) => item.ShowCancelSign == 0 && item.SignStatusType==SignStatus.SignStatus_Signed)); System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { if (SignBankList == null || SignBankList.Count <= 0) { MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_NoSignWithBank, Muchinfo.MTPClient.Resources.Client_Resource.Bank_BankTerminationTips); // bankTerminationView.Close(); _view.Close(); return; } if (null != AccoumtBankSignList && AccoumtBankSignList.Any()) { foreach (var item in SignBankList) { foreach (var k in AccoumtBankSignList) { if (item.BankId == k.BankId) { item.Name = k.BankName; // item.AccountName = UserManager.CurrentTradeAccount.CustomerName; } if (item.BranchId == k.BankId) { item.BranchBankName = k.BankName; } } } } CurrentSigningBank = SignBankList.FirstOrDefault(); })); } #endregion public RelayCommand OkCommand { get { temp_ankDealStatus = null; return new RelayCommand((win_BankTerminationView) => { if (CurrentSigningBank == null) { return; } var BandIDList = ApplicationParameter.CusBankNetSign.Split(','); if (this.CurrentSigningBank.CusBankID == 2) { MessageBoxHelper.ShowInfo( Muchinfo.MTPClient.Resources.Client_Resource.Bank_Termination_Message, Muchinfo.MTPClient.Resources.Client_Resource.APP_Tips); return; } else if (BandIDList.Contains(CurrentSigningBank.CusBankID + string.Empty)) { MessageBoxHelper.ShowInfo( ApplicationParameter.CusBankNetSignTipsInfo, Muchinfo.MTPClient.Resources.Client_Resource.APP_Tips); } win_BankTerminationView.bnt_OK.IsEnabled = false; IsBusy = true; BusyContent = Muchinfo.MTPClient.Resources.Client_Resource.Bank_SubmitingTerminData_Wait; CurrentSigningBank.CurrentTime = ApplicationParameter.ServerTimeNow; CurrentSigningBank.ExtOperatorID = UserManager.CurrentTradeAccount.AccountId; //CurrentSigningBank.AccountCode = UserManager.CurrentTradeAccount.AccountCode; //CurrentSigningBank.CustomerName = UserManager.CurrentTradeAccount.CustomerName; CurrentSigningBank.AccountType = UserManager.CurrentTradeAccount.AccountType; //if (UserManager.CurrentTradeAccount.AccountType == eLoginUserType.LOGINUSERTYPE_TRADER && // _areaAccount != null) //{ //CurrentSigningBank.AccountCode = CurrentSigningBank.AccountCode; //CurrentSigningBank.CustomerName = CurrentSigningBank.CustomerName; // } _bankService.BankCaneclSign(CurrentSigningBank, BankCaneclSignCallback, ErrorCallback); }); } } /// /// 取消 /// public RelayCommand CancelCommand { get { temp_ankDealStatus = null; return new RelayCommand((win_BankTerminationView) => { win_BankTerminationView.Close(); }); } } /// /// 获取手机验证码 /// public RelayCommand IdentifyCodeCommand { get { return new RelayCommand(() => { if (CurrentSigningBank == null) { return; } var IndentityReq = new IdentifyCodeReq() { AccountCode = CurrentSigningBank.AccountCode, CusBankID = CurrentSigningBank.CusBankID + string.Empty, CustomerSignId = CurrentSigningBank.CustomerSignId, CustomerName = CurrentSigningBank.CustomerName, BankCode = CurrentSigningBank.BankId, AccountType = CurrentSigningBank.AccountType, BankAccountNo = CurrentSigningBank.BankAccount, CardNum = CurrentSigningBank.CredentialNumber, CardType = CurrentSigningBank.CredentialType, MobilePhone = CurrentSigningBank.MobilePhone, Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any()) ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency, }; _bankService.BankGetIdentifyCode(IndentityReq, QueryIdentifyCodeSuccess, null); }); } } public void QueryIdentifyCodeSuccess(bool success) { } private string _identifyCode; public string IdentifyCode { get { return _identifyCode; } set { Set(() => IdentifyCode, ref _identifyCode, value); } } private void SetCollapsed() { this.CurrentSigningBank.PaymentNumberVisibility = false; this.CurrentSigningBank.ProtocolNumberVisibility = false; //this.CurrentSigningBank.CertIDVisibility = false; //this.CurrentSigningBank.BankVisibility = false; //this.CurrentSigningBank.BranchVisibility = false; //this.CurrentSigningBank.BankBankAccountNoVisibility = false; //this.CurrentSigningBank.AccountNameVisibility = false; this.CurrentSigningBank.AgentNameVisibility = false; this.CurrentSigningBank.AgentCIDNumberVisibility = false; this.CurrentSigningBank.BankPasswordVisibility = false; this.CurrentSigningBank.DrawIdentifyCodeVisibility = false; if (!string.IsNullOrEmpty(CurrentSigningBank.CancleSignShowField)) { bool isMemberTrade = UserManager.CurrentTradeAccount.AccountType != eUserType.USERTYPE_INVESTOR; //根据当前所选签约银行,配置输入字段 string[] CancleSignShowField = this.CurrentSigningBank.CancleSignShowField.Split(','); foreach (string item in CancleSignShowField) { switch (int.Parse(item)) { case (int)ShowFieldStatus.ShowField_PaymentNo: this.CurrentSigningBank.PaymentNumberVisibility = true; break; case (int)ShowFieldStatus.ShowField_ProtocolNo: this.CurrentSigningBank.ProtocolNumberVisibility = true; break; case (int)ShowFieldStatus.ShowField_AgentCertID: this.CurrentSigningBank.AgentCIDNumberVisibility = isMemberTrade; break; case (int)ShowFieldStatus.ShowField_AgentName: this.CurrentSigningBank.AgentNameVisibility = isMemberTrade; break; case (int)ShowFieldStatus.ShowField_BankAccountPWD: this.CurrentSigningBank.BankPasswordVisibility = true; //todo获取银行密钥 if (_encryptKey == null) { Task.Factory.TryStartNew(() => { IsBusy = true; var reqkey = new EncryptKeyRequest() { Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any()) ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency, CusBankId = CurrentSigningBank.CusBankID+string.Empty }; // _encryptKey = _bankService.QueryEncryptKey(reqkey, QueryEncryptKeyCallback_ShowField_BankAccountPWD, ErrorCallback); }, () => IsBusy = false); } break; case (int)ShowFieldStatus.ShowField_Draw_IdentifyCode: this.CurrentSigningBank.DrawIdentifyCodeVisibility = true; //todo获取银行密钥 if (_encryptKey == null) { Task.Factory.TryStartNew(() => { IsBusy = true; var reqkeyIC = new EncryptKeyRequest() { Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any()) ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency, CusBankId = CurrentSigningBank.CusBankID+string.Empty }; //_encryptKey = _bankService.QueryEncryptKey(reqkeyIC, QueryEncryptKeyCallback_ShowField_Draw_IdentifyCode, ErrorCallback); }, () => IsBusy = false); } break; } } } var BandIDList = ApplicationParameter.CusBankNetSign.Split(','); if (CurrentSigningBank.CusBankID == 2 ) { this.BranchMessage = true; IsOKEnable = false; } else if (BandIDList.Contains(CurrentSigningBank.CusBankID + string.Empty)) { this.NetMessage = true; this.NetWorkSignTips = ApplicationParameter.CusBankNetSignTipsInfo; IsOKEnable = false; } else { // this.BranchMessage = true; IsOKEnable = true; } } private void SetSignBankInfo() { IsBusy = true; BusyContent = Muchinfo.MTPClient.Resources.Client_Resource.Bank_GetBankInfomation_waiting; System.Threading.Tasks.Task.Factory.TryStartNew( () => System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { // SigningBank configInfo = // _bankService.QueryBankParamConfig(CurrentSigningBank.CusBankID, QueryBankparamConfigCallback, ErrorCallback); })), () => IsBusy = false); } private void QueryEncryptKeyCallback_ShowField_Draw_IdentifyCode(EncryptKey encryptKey) { if (String.IsNullOrEmpty(_encryptKey.SecretKey)) { MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Bank_NoGetIncryption, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error); } } private void QueryEncryptKeyCallback_ShowField_BankAccountPWD(EncryptKey encryptKey) { if (String.IsNullOrEmpty(_encryptKey.SecretKey)) { MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Bank_NoGetIncryption, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error); } } /// /// 临时结果 /// private BankSignResult temp_ankDealStatus; public void BankCaneclSignCallback(BankSignResult bankDealStatus) { IsBusy = false; //一般情况银行电话密码和银行取款密码只需要一个 bool isSendBankKey = (CurrentSigningBank.BankPasswordVisibility || CurrentSigningBank.DrawIdentifyCodeVisibility); temp_ankDealStatus = bankDealStatus; if (isSendBankKey && bankDealStatus.ReturnCode == 0) { var encryptHelper = new TasEncryptHelper(); if (_encryptKey == null) { var reqkey = new EncryptKeyRequest() { Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any()) ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency, CusBankId = CurrentSigningBank.CusBankID+string.Empty }; // _encryptKey = _bankService.QueryEncryptKey(reqkey, QueryEncryptKeyCallback, ErrorCallback); } else { string encryptPwd = ""; if (CurrentSigningBank.BankPasswordVisibility) { encryptPwd = encryptHelper.EncryptPassd(_encryptKey.SecretKey, CurrentSigningBank.BankPassword); } else if (CurrentSigningBank.DrawIdentifyCodeVisibility) { encryptPwd = encryptHelper.EncryptPassd(_encryptKey.SecretKey, CurrentSigningBank.DrawIdentifyCode); } var req = new SignBankPDW() { AccountCode = UserManager.CurrentTradeAccount.AccountCode, ExchTicket = bankDealStatus.ExchTicket, ExtOperatorID = bankDealStatus.ExtOperatorID, CusBankId = CurrentSigningBank.CusBankID + string.Empty, BankAccountPWD = encryptPwd, Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any()) ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency }; //errorCode =_bankService.SignBankPwd(req, UserManager.CurrentTradeAccount.LoginCode); _bankService.SignBankPwd(req, SignBankPwdCallback, ErrorCallback); } } SignBankPwdCallback(bankDealStatus.ReturnCode); } private void SignBankPwdCallback(int result) { var bankDealStatus = temp_ankDealStatus; bool isSendBankKey = (CurrentSigningBank.BankPasswordVisibility || CurrentSigningBank.DrawIdentifyCodeVisibility); System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { if (result == 0) { if (isSendBankKey) { MessageBoxHelper.ShowSuccess( Muchinfo.MTPClient.Resources.Client_Resource.Bank_TerminationSuccess, Muchinfo.MTPClient.Resources.Client_Resource.Bank_BankTerminationTips); if (bankDealStatus.Status == BankDealStatus.BankDealStatus__BankWebComfirm) { IPHelper.OpenWebAddress(bankDealStatus.WebAddress); var messageBox = new MsgAlter(bankDealStatus.WebAddress, Client_Resource.Tips_BankUnSignWebComfrim) { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; messageBox.ShowDialog(); } } else { // LogManager.WriteBankApplyLog(1, CurrentSigningBank, UserManager.CurrentTradeAccount); switch (bankDealStatus.Status) { case BankDealStatus.BankDealStatus__Succeed: MessageBoxHelper.ShowSuccess( Muchinfo.MTPClient.Resources.Client_Resource .Bank_TerminationSuccess, Muchinfo.MTPClient.Resources.Client_Resource .Bank_BankTerminationTips); break; case BankDealStatus.BankDealStatus__Pend: MessageBoxHelper.ShowSuccess( Muchinfo.MTPClient.Resources.Client_Resource .Bank_BankTerminationInfoSubmit_Wait, Muchinfo.MTPClient.Resources.Client_Resource .Bank_BankTerminationTips); break; case BankDealStatus.BankDealStatus__BankWebComfirm: try { IPHelper.OpenWebAddress(bankDealStatus.WebAddress); } catch (Exception) { throw new MuchinfoException(ExceptionManager.OpenIEError); } finally { var messageBox = new MsgAlter(bankDealStatus.WebAddress, Client_Resource.Tips_BankUnSignWebComfrim) { Owner = Application.Current.MainWindow, WindowStartupLocation = WindowStartupLocation.CenterOwner }; messageBox.ShowDialog(); } break; } } // win_BankTerminationView.DialogResult = true; _view.DialogResult = true; } else { ErrorManager.ShowReturnError(bankDealStatus.ReturnCode, Muchinfo.MTPClient.Resources.Client_Resource.Bank_ErrotTips); } //win_BankTerminationView.bnt_OK.IsEnabled = true; _view.bnt_OK.IsEnabled = true; })); } private void QueryEncryptKeyCallback(EncryptKey encryptKey) { var encryptHelper = new TasEncryptHelper(); var bankDealStatus = temp_ankDealStatus; string encryptPwd = ""; if (CurrentSigningBank.BankPasswordVisibility) { encryptPwd = encryptHelper.EncryptPassd(_encryptKey.SecretKey, CurrentSigningBank.BankPassword); } else if (CurrentSigningBank.DrawIdentifyCodeVisibility) { encryptPwd = encryptHelper.EncryptPassd(_encryptKey.SecretKey, CurrentSigningBank.DrawIdentifyCode); } var req = new SignBankPDW() { AccountCode = UserManager.CurrentTradeAccount.AccountCode, ExchTicket = bankDealStatus.ExchTicket, ExtOperatorID = bankDealStatus.ExtOperatorID, CusBankId = CurrentSigningBank.CusBankID + string.Empty, BankAccountPWD = encryptPwd, Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any()) ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency }; //errorCode =_bankService.SignBankPwd(req, UserManager.CurrentTradeAccount.LoginCode); _bankService.SignBankPwd(req, SignBankPwdCallback, ErrorCallback); SignBankPwdCallback(bankDealStatus.ReturnCode); } 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); })); } } }