using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//----------------------------------------------------------------
//Module Name: $safeprojectname$
//Purpose:
//CopyRight: Muchinfo
//History:
//----------------------------------------------------------------
//DateTime 2017/3/14 18:33:26
//Author
//Description Create
//----------------------------------------------------------------
using System.Windows;
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.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 TerminationSignViewModel : IdentifyCodeTimerViewModel
{
private IBankService _bankService;
private bool _isBusy;
///
/// 是否忙,显示等待控件
///
public bool IsBusy
{
get { return _isBusy; }
set { Set(() => IsBusy, ref _isBusy, value); }
}
private SigningBank _currentSigningBank;
///
/// 当前选中签约银行
///
public SigningBank CurrentSigningBank
{
get
{
return _currentSigningBank;
}
set
{
Set(() => CurrentSigningBank, ref _currentSigningBank, value);
}
}
private EncryptKey _encryptKey; ////银行密钥
private string _password;
///
/// 密码
///
public string Password
{
get { return _password; }
set { Set(() => Password, ref _password, value); }
}
public string[] ShowFielNo { get; set; }
public TerminationSignViewModel(SigningBank SigningBank, string[] fieldNo)
{
CurrentSigningBank = SigningBank;
ShowFielNo = fieldNo;
_bankService = SimpleIoc.Default.GetInstance();
if (IsBandPassWordVisible)
{
var reqkey = new EncryptKeyRequest()
{
Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null
|| !UserManager.CurrentTradeAccount.FundsAccounts.Any())
? "RMB"
: UserManager.CurrentTradeAccount.FundsAccounts[0].Currency,
CusBankId = CurrentSigningBank.CusBankID + string.Empty,
};
IsBusy = true;
// _encryptKey =
_bankService.QueryEncryptKey(reqkey, QueryEncryptKeyCallback_ShowField_BankAccountPWD,
QueryErrorCallback);
}
}
public bool IsBandPassWordVisible
{
get
{
if (ShowFielNo == null || !ShowFielNo.Any()) return false;
return ShowFielNo.Contains(((int)ShowFieldStatus.ShowField_Draw_IdentifyCode) + string.Empty) || ShowFielNo.Contains(((int)ShowFieldStatus.ShowField_BankAccountPWD) + string.Empty);
}
}
public bool IsMobileCodeVisible
{
get
{
if (ShowFielNo == null || !ShowFielNo.Any()) return false;
return ShowFielNo.Contains(((int) ShowFieldStatus.ShowField_IdentifyCode) + string.Empty);
}
}
private void QueryEncryptKeyCallback_ShowField_BankAccountPWD(EncryptKey encryptKey)
{
IsBusy = false;
_encryptKey = encryptKey;
if (String.IsNullOrEmpty(encryptKey.SecretKey))
{
MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Bank_NoGetIncryption, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error);
}
}
public virtual void QueryErrorCallback(ErrorEntity errorEntity)
{
IsBusy = false;
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
ErrorManager.ShowReturnError(errorEntity, Client_Resource.APP_Tips, false);
}));
}
public RelayCommand OkCommand
{
get
{
return new RelayCommand((view) =>
{
if (CurrentSigningBank == null)
{
return;
}
if (!Vailed())
{
return;
}
_view = view;
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);
}
IsBusy = true;
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);
});
}
}
private Window _view;
///
/// 临时结果
///
private BankSignResult temp_ankDealStatus;
public void BankCaneclSignCallback(BankSignResult bankDealStatus)
{
temp_ankDealStatus = bankDealStatus;
IsBusy = false;
//一般情况银行电话密码和银行取款密码只需要一个
bool isSendBankKey = (IsBandPassWordVisible);
temp_ankDealStatus = bankDealStatus;
if (isSendBankKey && bankDealStatus.ReturnCode == 0)
{
var encryptHelper = new TasEncryptHelper();
string encryptPwd = "";
encryptPwd = encryptHelper.EncryptPassd(_encryptKey.SecretKey,Password);
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);
return;
}
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);
}
}));
}
///
/// 取消
///
public RelayCommand CancelCommand
{
get
{
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,
TradeType = BankTradeType.UpdateSign,
Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any())
? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency,
};
_bankService.BankGetIdentifyCode(IndentityReq, QueryIdentifyCodeSuccess, ErrorCallback);
this.Start();
});
}
}
public void QueryIdentifyCodeSuccess(bool success)
{
}
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 Vailed()
{
if (IsMobileCodeVisible && string.IsNullOrEmpty(CurrentSigningBank.IdentifyCode))
{
MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputIdentifyCode, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
return false;
}
if (IsBandPassWordVisible && string.IsNullOrEmpty(Password))
{
MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputBankPassword, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
return false;
}
return true;
}
}
}