TerminationSignViewModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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 18:33:26
  12. //Author
  13. //Description Create
  14. //----------------------------------------------------------------
  15. using System.Windows;
  16. using GalaSoft.MvvmLight.Command;
  17. using GalaSoft.MvvmLight.Ioc;
  18. using Muchinfo.MTPClient.Bank.Views;
  19. using Muchinfo.MTPClient.CustomException;
  20. using Muchinfo.MTPClient.Data;
  21. using Muchinfo.MTPClient.Data.Enums;
  22. using Muchinfo.MTPClient.Data.Model.Bank;
  23. using Muchinfo.MTPClient.Infrastructure.Helpers;
  24. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  25. using Muchinfo.MTPClient.Infrastructure.Utilities;
  26. using Muchinfo.MTPClient.IService;
  27. using Muchinfo.MTPClient.Resources;
  28. using Muchinfo.PC.Common.Helpers;
  29. namespace Muchinfo.MTPClient.Bank.ViewModels
  30. {
  31. public class TerminationSignViewModel : IdentifyCodeTimerViewModel
  32. {
  33. private IBankService _bankService;
  34. private bool _isBusy;
  35. /// <summary>
  36. /// 是否忙,显示等待控件
  37. /// </summary>
  38. public bool IsBusy
  39. {
  40. get { return _isBusy; }
  41. set { Set(() => IsBusy, ref _isBusy, value); }
  42. }
  43. private SigningBank _currentSigningBank;
  44. /// <summary>
  45. /// 当前选中签约银行
  46. /// </summary>
  47. public SigningBank CurrentSigningBank
  48. {
  49. get
  50. {
  51. return _currentSigningBank;
  52. }
  53. set
  54. {
  55. Set(() => CurrentSigningBank, ref _currentSigningBank, value);
  56. }
  57. }
  58. private EncryptKey _encryptKey; ////银行密钥
  59. private string _password;
  60. /// <summary>
  61. /// 密码
  62. /// </summary>
  63. public string Password
  64. {
  65. get { return _password; }
  66. set { Set(() => Password, ref _password, value); }
  67. }
  68. public string[] ShowFielNo { get; set; }
  69. public TerminationSignViewModel(SigningBank SigningBank, string[] fieldNo)
  70. {
  71. CurrentSigningBank = SigningBank;
  72. ShowFielNo = fieldNo;
  73. _bankService = SimpleIoc.Default.GetInstance<IBankService>();
  74. if (IsBandPassWordVisible)
  75. {
  76. var reqkey = new EncryptKeyRequest()
  77. {
  78. Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null
  79. || !UserManager.CurrentTradeAccount.FundsAccounts.Any())
  80. ? "RMB"
  81. : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency,
  82. CusBankId = CurrentSigningBank.CusBankID + string.Empty,
  83. };
  84. IsBusy = true;
  85. // _encryptKey =
  86. _bankService.QueryEncryptKey(reqkey, QueryEncryptKeyCallback_ShowField_BankAccountPWD,
  87. QueryErrorCallback);
  88. }
  89. }
  90. public bool IsBandPassWordVisible
  91. {
  92. get
  93. {
  94. if (ShowFielNo == null || !ShowFielNo.Any()) return false;
  95. return ShowFielNo.Contains(((int)ShowFieldStatus.ShowField_Draw_IdentifyCode) + string.Empty) || ShowFielNo.Contains(((int)ShowFieldStatus.ShowField_BankAccountPWD) + string.Empty);
  96. }
  97. }
  98. public bool IsMobileCodeVisible
  99. {
  100. get
  101. {
  102. if (ShowFielNo == null || !ShowFielNo.Any()) return false;
  103. return ShowFielNo.Contains(((int) ShowFieldStatus.ShowField_IdentifyCode) + string.Empty);
  104. }
  105. }
  106. private void QueryEncryptKeyCallback_ShowField_BankAccountPWD(EncryptKey encryptKey)
  107. {
  108. IsBusy = false;
  109. _encryptKey = encryptKey;
  110. if (String.IsNullOrEmpty(encryptKey.SecretKey))
  111. {
  112. MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Bank_NoGetIncryption, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error);
  113. }
  114. }
  115. public virtual void QueryErrorCallback(ErrorEntity errorEntity)
  116. {
  117. IsBusy = false;
  118. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  119. {
  120. ErrorManager.ShowReturnError(errorEntity, Client_Resource.APP_Tips, false);
  121. }));
  122. }
  123. public RelayCommand<Window> OkCommand
  124. {
  125. get
  126. {
  127. return new RelayCommand<Window>((view) =>
  128. {
  129. if (CurrentSigningBank == null)
  130. {
  131. return;
  132. }
  133. if (!Vailed())
  134. {
  135. return;
  136. }
  137. _view = view;
  138. var BandIDList = ApplicationParameter.CusBankNetSign.Split(',');
  139. if (this.CurrentSigningBank.CusBankID == 2)
  140. {
  141. MessageBoxHelper.ShowInfo(
  142. Muchinfo.MTPClient.Resources.Client_Resource.Bank_Termination_Message,
  143. Muchinfo.MTPClient.Resources.Client_Resource.APP_Tips);
  144. return;
  145. }
  146. else if (BandIDList.Contains(CurrentSigningBank.CusBankID + string.Empty))
  147. {
  148. MessageBoxHelper.ShowInfo(
  149. ApplicationParameter.CusBankNetSignTipsInfo,
  150. Muchinfo.MTPClient.Resources.Client_Resource.APP_Tips);
  151. }
  152. IsBusy = true;
  153. CurrentSigningBank.CurrentTime = ApplicationParameter.ServerTimeNow;
  154. CurrentSigningBank.ExtOperatorID = UserManager.CurrentTradeAccount.AccountId;
  155. //CurrentSigningBank.AccountCode = UserManager.CurrentTradeAccount.AccountCode;
  156. //CurrentSigningBank.CustomerName = UserManager.CurrentTradeAccount.CustomerName;
  157. CurrentSigningBank.AccountType = UserManager.CurrentTradeAccount.AccountType;
  158. //if (UserManager.CurrentTradeAccount.AccountType == eLoginUserType.LOGINUSERTYPE_TRADER &&
  159. // _areaAccount != null)
  160. //{
  161. //CurrentSigningBank.AccountCode = CurrentSigningBank.AccountCode;
  162. //CurrentSigningBank.CustomerName = CurrentSigningBank.CustomerName;
  163. // }
  164. _bankService.BankCaneclSign(CurrentSigningBank, BankCaneclSignCallback, ErrorCallback);
  165. });
  166. }
  167. }
  168. private Window _view;
  169. /// <summary>
  170. /// 临时结果
  171. /// </summary>
  172. private BankSignResult temp_ankDealStatus;
  173. public void BankCaneclSignCallback(BankSignResult bankDealStatus)
  174. {
  175. temp_ankDealStatus = bankDealStatus;
  176. IsBusy = false;
  177. //一般情况银行电话密码和银行取款密码只需要一个
  178. bool isSendBankKey = (IsBandPassWordVisible);
  179. temp_ankDealStatus = bankDealStatus;
  180. if (isSendBankKey && bankDealStatus.ReturnCode == 0)
  181. {
  182. var encryptHelper = new TasEncryptHelper();
  183. string encryptPwd = "";
  184. encryptPwd = encryptHelper.EncryptPassd(_encryptKey.SecretKey,Password);
  185. var req = new SignBankPDW()
  186. {
  187. AccountCode = UserManager.CurrentTradeAccount.AccountCode,
  188. ExchTicket = bankDealStatus.ExchTicket,
  189. ExtOperatorID = bankDealStatus.ExtOperatorID,
  190. CusBankId = CurrentSigningBank.CusBankID + string.Empty,
  191. BankAccountPWD = encryptPwd,
  192. Currency =
  193. (UserManager.CurrentTradeAccount.FundsAccounts == null ||
  194. !UserManager.CurrentTradeAccount.FundsAccounts.Any())
  195. ? "RMB"
  196. : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency
  197. };
  198. //errorCode =_bankService.SignBankPwd(req, UserManager.CurrentTradeAccount.LoginCode);
  199. _bankService.SignBankPwd(req, SignBankPwdCallback, ErrorCallback);
  200. return;
  201. }
  202. SignBankPwdCallback(bankDealStatus.ReturnCode);
  203. }
  204. private void SignBankPwdCallback(int result)
  205. {
  206. var bankDealStatus = temp_ankDealStatus;
  207. bool isSendBankKey = (CurrentSigningBank.BankPasswordVisibility || CurrentSigningBank.DrawIdentifyCodeVisibility);
  208. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  209. {
  210. if (result == 0)
  211. {
  212. if (isSendBankKey)
  213. {
  214. MessageBoxHelper.ShowSuccess(
  215. Muchinfo.MTPClient.Resources.Client_Resource.Bank_TerminationSuccess,
  216. Muchinfo.MTPClient.Resources.Client_Resource.Bank_BankTerminationTips);
  217. if (bankDealStatus.Status == BankDealStatus.BankDealStatus__BankWebComfirm)
  218. {
  219. IPHelper.OpenWebAddress(bankDealStatus.WebAddress);
  220. var messageBox = new MsgAlter(bankDealStatus.WebAddress, Client_Resource.Tips_BankUnSignWebComfrim)
  221. {
  222. Owner = Application.Current.MainWindow,
  223. WindowStartupLocation = WindowStartupLocation.CenterOwner
  224. };
  225. messageBox.ShowDialog();
  226. }
  227. }
  228. else
  229. {
  230. // LogManager.WriteBankApplyLog(1, CurrentSigningBank, UserManager.CurrentTradeAccount);
  231. switch (bankDealStatus.Status)
  232. {
  233. case BankDealStatus.BankDealStatus__Succeed:
  234. MessageBoxHelper.ShowSuccess(
  235. Muchinfo.MTPClient.Resources.Client_Resource
  236. .Bank_TerminationSuccess,
  237. Muchinfo.MTPClient.Resources.Client_Resource
  238. .Bank_BankTerminationTips);
  239. break;
  240. case BankDealStatus.BankDealStatus__Pend:
  241. MessageBoxHelper.ShowSuccess(
  242. Muchinfo.MTPClient.Resources.Client_Resource
  243. .Bank_BankTerminationInfoSubmit_Wait,
  244. Muchinfo.MTPClient.Resources.Client_Resource
  245. .Bank_BankTerminationTips);
  246. break;
  247. case BankDealStatus.BankDealStatus__BankWebComfirm:
  248. try
  249. {
  250. IPHelper.OpenWebAddress(bankDealStatus.WebAddress);
  251. }
  252. catch (Exception)
  253. {
  254. throw new MuchinfoException(ExceptionManager.OpenIEError);
  255. }
  256. finally
  257. {
  258. var messageBox = new MsgAlter(bankDealStatus.WebAddress, Client_Resource.Tips_BankUnSignWebComfrim)
  259. {
  260. Owner = Application.Current.MainWindow,
  261. WindowStartupLocation = WindowStartupLocation.CenterOwner
  262. };
  263. messageBox.ShowDialog();
  264. }
  265. break;
  266. }
  267. }
  268. // win_BankTerminationView.DialogResult = true;
  269. _view.DialogResult = true;
  270. }
  271. else
  272. {
  273. ErrorManager.ShowReturnError(bankDealStatus.ReturnCode, Muchinfo.MTPClient.Resources.Client_Resource.Bank_ErrotTips);
  274. }
  275. }));
  276. }
  277. /// <summary>
  278. /// 取消
  279. /// </summary>
  280. public RelayCommand<Window> CancelCommand
  281. {
  282. get
  283. {
  284. return new RelayCommand<Window>((win_BankTerminationView) =>
  285. {
  286. win_BankTerminationView.Close();
  287. });
  288. }
  289. }
  290. /// <summary>
  291. /// 获取手机验证码
  292. /// </summary>
  293. public RelayCommand IdentifyCodeCommand
  294. {
  295. get
  296. {
  297. return new RelayCommand(() =>
  298. {
  299. if (CurrentSigningBank == null)
  300. {
  301. return;
  302. }
  303. var IndentityReq = new IdentifyCodeReq()
  304. {
  305. AccountCode = CurrentSigningBank.AccountCode,
  306. CusBankID = CurrentSigningBank.CusBankID + string.Empty,
  307. CustomerSignId = CurrentSigningBank.CustomerSignId,
  308. CustomerName = CurrentSigningBank.CustomerName,
  309. BankCode = CurrentSigningBank.BankId,
  310. AccountType = CurrentSigningBank.AccountType,
  311. BankAccountNo = CurrentSigningBank.BankAccount,
  312. CardNum = CurrentSigningBank.CredentialNumber,
  313. CardType = CurrentSigningBank.CredentialType,
  314. MobilePhone = CurrentSigningBank.MobilePhone,
  315. TradeType = BankTradeType.UpdateSign,
  316. Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any())
  317. ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency,
  318. };
  319. _bankService.BankGetIdentifyCode(IndentityReq, QueryIdentifyCodeSuccess, ErrorCallback);
  320. this.Start();
  321. });
  322. }
  323. }
  324. public void QueryIdentifyCodeSuccess(bool success)
  325. {
  326. }
  327. public void ErrorCallback(ErrorEntity error)
  328. {
  329. IsBusy = false;
  330. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  331. {
  332. ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true);
  333. }));
  334. }
  335. private bool Vailed()
  336. {
  337. if (IsMobileCodeVisible && string.IsNullOrEmpty(CurrentSigningBank.IdentifyCode))
  338. {
  339. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputIdentifyCode, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  340. return false;
  341. }
  342. if (IsBandPassWordVisible && string.IsNullOrEmpty(Password))
  343. {
  344. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputBankPassword, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Tips);
  345. return false;
  346. }
  347. return true;
  348. }
  349. }
  350. }