AmountManagerViewModel.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. using System.Threading;
  2. using GalaSoft.MvvmLight;
  3. using GalaSoft.MvvmLight.Command;
  4. using GalaSoft.MvvmLight.Ioc;
  5. using Microsoft.Practices.ServiceLocation;
  6. using Muchinfo.MTPClient.Bank.Views;
  7. using Muchinfo.MTPClient.CustomException;
  8. using Muchinfo.MTPClient.Data;
  9. using Muchinfo.MTPClient.Data.Enums;
  10. using Muchinfo.MTPClient.Data.Helper;
  11. using Muchinfo.MTPClient.Data.Model;
  12. using Muchinfo.MTPClient.Data.Model.Account;
  13. using Muchinfo.MTPClient.Data.Model.Bank;
  14. using Muchinfo.MTPClient.Infrastructure.Cache;
  15. using Muchinfo.MTPClient.Infrastructure.Helpers;
  16. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  17. using Muchinfo.MTPClient.Infrastructure.Utilities;
  18. using Muchinfo.MTPClient.IService;
  19. using Muchinfo.MTPClient.Resources;
  20. using Muchinfo.PC.Common.Extensions;
  21. using Muchinfo.PC.Common.Helpers;
  22. using Muchinfo.WPF.Controls.Keyboard;
  23. using System;
  24. using System.Collections.Generic;
  25. using System.Collections.ObjectModel;
  26. using System.Linq;
  27. using System.Threading.Tasks;
  28. using System.Windows;
  29. using System.Windows.Controls;
  30. namespace Muchinfo.MTPClient.Bank.ViewModels
  31. {
  32. public class AmountManagerViewModel : IdentifyCodeTimerViewModel
  33. {
  34. #region Fields
  35. private FundsApplyType _currentApplyType;
  36. private TradeAccount _currentTradeAccount;
  37. private IBankService _bankService;
  38. private EncryptKey _encryptKey;
  39. private Window _OKCommandTemp;
  40. private AreaAccount _areaAccount; //会员账号信息
  41. private ILoginService _loginService; ////
  42. private bool _isGetIdentifyCode=false; ////是否取验证码
  43. private ObservableCollection<SigningBank> _signBankList = new ObservableCollection<SigningBank>();
  44. private List<OutMoneyThresholdRatio> _moneyThresholdRatios; ////出金阈值比率
  45. /// <summary>
  46. /// 当前选中的交易账号
  47. /// </summary>
  48. public TradeAccount CurrentTradeAccount
  49. {
  50. get
  51. {
  52. return _currentTradeAccount;
  53. }
  54. set
  55. {
  56. Set(() => CurrentTradeAccount, ref _currentTradeAccount, value);
  57. }
  58. }
  59. /// <summary>
  60. /// 签约银行列表
  61. /// </summary>
  62. public ObservableCollection<SigningBank> SignBankList
  63. {
  64. get { return _signBankList; }
  65. set { Set(() => SignBankList, ref _signBankList, value); }
  66. }
  67. private SigningBank _currentSigningBank = new SigningBank();
  68. /// <summary>
  69. /// 当前选中签约银行
  70. /// </summary>
  71. public SigningBank CurrentSigningBank
  72. {
  73. get
  74. {
  75. return _currentSigningBank;
  76. }
  77. set
  78. {
  79. Set(() => CurrentSigningBank, ref _currentSigningBank, value);
  80. this.PhoneBankPassword = string.Empty;
  81. if (value != null)
  82. {
  83. SetSignBankInfo();
  84. }
  85. RaisePropertyChanged(() => IsShowInTips);
  86. }
  87. }
  88. public string InAmountTips
  89. {
  90. get
  91. {
  92. if (CurrentSigningBank != null)
  93. {
  94. return string.Format(Client_Resource.text_inWindow_ShowInGuideTips, CurrentSigningBank.card_Acct);
  95. }
  96. return string.Empty;
  97. }
  98. }
  99. /// <summary>
  100. /// 是否显示入金提示
  101. /// </summary>
  102. public bool IsShowInTips
  103. {
  104. get
  105. {
  106. if (CurrentSigningBank == null)
  107. {
  108. return false;
  109. }
  110. return _fundsApplyType == FundsApplyType.Deposit && CurrentSigningBank.CusBankID==3; ////中信银行入金显示提示
  111. }
  112. }
  113. /// <summary>
  114. ///银行列表
  115. /// </summary>
  116. List<Banks> AccoumtBankSignList;
  117. private FundsApplyType _fundsApplyType;
  118. #endregion Fields
  119. #region Constructors
  120. public AmountManagerViewModel(FundsApplyType applyType)
  121. {
  122. _fundsApplyType = applyType;
  123. _bankService = ServiceLocator.Current.GetInstance<IBankService>();
  124. IsBusy = true;
  125. CurrentTradeAccount = UserManager.CurrentTradeAccount;
  126. _loginService = SimpleIoc.Default.GetInstance<ILoginService>();
  127. CurrentApplyType = ApplyTypes.FirstOrDefault(z => z.Key == applyType).Key;
  128. // _bankService.QueryBankInfo(QueryBankInfoCallback, QueryErrorCallback);
  129. // var signBankList = _bankService.QueryBankCustomerSign(UserManager.CurrentTradeAccount);
  130. var accountid = UserManager.CurrentTradeAccount.AccountId;
  131. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  132. //{
  133. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  134. //}
  135. _bankService.QueryBankCustomerSignInfo(accountid, SearchBankCustomerSignCallback, ErrorCallback);
  136. ////计算浮动盈亏
  137. MessengerHelper.QuoteRegister<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTimeQuote, (quoteList) =>
  138. {
  139. UseAmount = FloatPLExpressions.SetUseAmount(_moneyThresholdRatios);
  140. });
  141. }
  142. public void QueryBankInfoCallback(List<Banks> list)
  143. {
  144. AccoumtBankSignList = list;
  145. if (UserManager.CurrentTradeAccount.AccountType == eUserType.USERTYPE_INVESTOR)
  146. {
  147. _bankService.QueryBankCustomerSign(UserManager.CurrentTradeAccount.AccountCode, QueryBankCustomerSignCallback, QueryErrorCallback);
  148. }
  149. else
  150. {
  151. ///查询会员账号信息
  152. _bankService.QueryMemberAccountInfo(UserManager.CurrentTradeAccount.AccountId, QueryAreaAccountCallback, QueryErrorCallback);
  153. }
  154. }
  155. private void SearchBankCustomerSignCallback(List<SigningBank> list)
  156. {
  157. IsBusy = false;
  158. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  159. {
  160. if (list != null && list.Any())
  161. {
  162. // list = list.Where((item) => item.SignStatusType == SignStatus.SignStatus_Signed).ToList();
  163. foreach (var item in list)
  164. {
  165. switch (CurrentApplyType)
  166. {
  167. case FundsApplyType.Deposit:
  168. if (item.IsAllowInMoney == 1)
  169. {
  170. SignBankList.Add(item);
  171. }
  172. break;
  173. case FundsApplyType.Withdraw:
  174. if (item.IsAllowOutMoney == 1)
  175. {
  176. SignBankList.Add(item);
  177. }
  178. break;
  179. }
  180. }
  181. if (SignBankList.Any())
  182. {
  183. CurrentSigningBank = SignBankList.FirstOrDefault();
  184. }
  185. }
  186. // if (applyType == FundsApplyType.Withdraw)
  187. if (CurrentApplyType == FundsApplyType.Withdraw)
  188. {
  189. Task.Factory.TryStartNew(() =>
  190. {
  191. // var useAmount =
  192. CalcUseAmount();
  193. // UseAmount = Math.Round(useAmount, 2, MidpointRounding.AwayFromZero);
  194. }, () => IsBusy = false);
  195. }
  196. }));
  197. }
  198. private void QueryAreaAccountCallback(List<AreaAccount> areaAccounts)
  199. {
  200. if (areaAccounts != null && areaAccounts.Any())
  201. {
  202. _areaAccount = areaAccounts[0];
  203. _bankService.QueryBankCustomerSign(_areaAccount.AccountCode, QueryBankCustomerSignCallback, QueryErrorCallback);
  204. }
  205. }
  206. private void QueryBankCustomerSignCallback(ObservableCollection<SigningBank> signBankList)
  207. {
  208. IsBusy = false;
  209. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  210. {
  211. if (signBankList != null && signBankList.Any())
  212. {
  213. foreach (var item in signBankList)
  214. {
  215. switch (CurrentApplyType)
  216. {
  217. case FundsApplyType.Deposit:
  218. //if (item.IsAllowinMoney == 1) todo:银行联调忽略状态
  219. //{
  220. SignBankList.Add(item);
  221. //}
  222. break;
  223. case FundsApplyType.Withdraw:
  224. // if (item.IsAllowoutMoney == 1) todo:银行联调忽略状态
  225. //{
  226. SignBankList.Add(item);
  227. //}
  228. break;
  229. }
  230. }
  231. if (null != AccoumtBankSignList && AccoumtBankSignList.Any())
  232. {
  233. foreach (var item in SignBankList)
  234. {
  235. foreach (var k in AccoumtBankSignList)
  236. {
  237. if (item.BankId == k.BankId)
  238. {
  239. item.CusBankName = k.BankName;
  240. item.Name = k.BankName;
  241. // item.AccountName = UserManager.CurrentTradeAccount.CustomerName;
  242. }
  243. if (item.BranchId == k.BankId)
  244. {
  245. item.BranchBankName = k.BankName;
  246. }
  247. }
  248. }
  249. }
  250. if (SignBankList.Any())
  251. {
  252. CurrentSigningBank = SignBankList.FirstOrDefault();
  253. }
  254. }
  255. // if (applyType == FundsApplyType.Withdraw)
  256. if (CurrentApplyType == FundsApplyType.Withdraw)
  257. {
  258. Task.Factory.TryStartNew(() =>
  259. {
  260. // var useAmount =
  261. CalcUseAmount();
  262. // UseAmount = Math.Round(useAmount, 2, MidpointRounding.AwayFromZero);
  263. }, () => IsBusy = false);
  264. }
  265. }));
  266. }
  267. #endregion Constructors
  268. #region Public Properties
  269. private string _titleName;
  270. public string TitleName
  271. {
  272. get
  273. {
  274. return this._titleName;
  275. }
  276. set
  277. {
  278. Set(() => TitleName, ref this._titleName, value);
  279. }
  280. }
  281. public Dictionary<FundsApplyType, string> ApplyTypes
  282. {
  283. get
  284. {
  285. return new Dictionary<FundsApplyType, string>
  286. {
  287. {FundsApplyType.Deposit, FundsApplyType.Deposit.Discription()},
  288. {FundsApplyType.Withdraw, FundsApplyType.Withdraw.Discription()}
  289. };
  290. }
  291. }
  292. public FundsApplyType CurrentApplyType
  293. {
  294. get
  295. {
  296. return this._currentApplyType;
  297. }
  298. set
  299. {
  300. Set(() => CurrentApplyType, ref this._currentApplyType, value);
  301. if (CurrentApplyType == FundsApplyType.Deposit)
  302. {
  303. OutVisibility = Visibility.Collapsed;
  304. InVisibility = Visibility.Visible;
  305. this.TitleName = Muchinfo.MTPClient.Resources.Client_Resource.TradeTreeMenu_AmountInApply;
  306. }
  307. else
  308. {
  309. OutVisibility = Visibility.Visible;
  310. InVisibility = Visibility.Collapsed;
  311. this.TitleName = Muchinfo.MTPClient.Resources.Client_Resource.TradeTreeMenu_AmountOutApply;
  312. }
  313. }
  314. }
  315. private decimal _useAmount;
  316. /// <summary>
  317. ///可取资金
  318. /// </summary>
  319. public decimal UseAmount
  320. {
  321. get
  322. {
  323. return _useAmount;
  324. }
  325. set
  326. {
  327. value = value < 0 ? 0 : value; //出金不显示负数
  328. Set(() => UseAmount, ref _useAmount, value);
  329. }
  330. }
  331. /// <summary>
  332. /// 计算可出金额
  333. /// </summary>
  334. /// <returns></returns>
  335. private void CalcUseAmount()
  336. {
  337. // 可出资金1 = 期末余额 - 交易占用 - 交易冻结 - 出金冻结 - 交割冻结 - 发售冻结 - 摘牌冻结 - 托管冻结 - 浮动亏损
  338. //可出资金2 = 期初余额 - 当日出金 - 出金冻结 [(如果当日入金可出的话) + 当日入金]
  339. //可出资金3 = min(可出资金1, 可出资金2) - max(期末余额阀值, 人工冻结, 出金阀值, 净值阀值)
  340. IsBusy = true;
  341. var accountid = UserManager.CurrentTradeAccount.AccountId;
  342. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  343. //{
  344. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  345. //}
  346. _loginService.QueryOutMoneyThresholdRatio(accountid, QueryOutMoneyThresholdSuccess, QueryOutMoneyError);
  347. }
  348. private void QueryTaAccountSuccess(List<FundsAccount> fundsAccounts)
  349. {
  350. //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  351. //{
  352. MessengerHelper.DefaultSend(string.Empty, MessengerTokens.UpdateAccountCommand); ////计算浮动盈亏
  353. Thread.Sleep(500);////等待计划浮动盈亏完成
  354. UseAmount = FloatPLExpressions.SetUseAmount(_moneyThresholdRatios);
  355. //}));
  356. }
  357. /// <summary>
  358. /// 获取手机验证码
  359. /// </summary>
  360. public RelayCommand IdentifyCodeCommand
  361. {
  362. get
  363. {
  364. return new RelayCommand(() =>
  365. {
  366. if (CurrentSigningBank == null)
  367. {
  368. return;
  369. }
  370. var IndentityReq = new IdentifyCodeReq()
  371. {
  372. AccountCode = CurrentSigningBank.AccountCode,
  373. CusBankID = CurrentSigningBank.CusBankID + string.Empty,
  374. Amount = Money,
  375. CustomerSignId = CurrentSigningBank.CustomerSignId,
  376. CustomerName = CurrentSigningBank.CustomerName,
  377. BankCode = CurrentSigningBank.BankId,
  378. AccountType = CurrentSigningBank.AccountType,
  379. BankAccountNo = CurrentSigningBank.BankAccount,
  380. CardNum = CurrentSigningBank.CredentialNumber,
  381. CardType = CurrentSigningBank.CredentialType,
  382. MobilePhone = CurrentSigningBank.MobilePhone,
  383. Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null || !UserManager.CurrentTradeAccount.FundsAccounts.Any())
  384. ? "RMB" : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency,
  385. };
  386. IndentityReq.TradeType = CurrentApplyType == FundsApplyType.Deposit
  387. ? BankTradeType.inAmount
  388. : BankTradeType.OutAmount;
  389. _bankService.BankGetIdentifyCode(IndentityReq, QueryIdentifyCodeSuccess, QueryErrorCallback);
  390. IsMoneyBoxEnable = false;
  391. this.Start();
  392. },(()=>Money>0));
  393. }
  394. }
  395. public void QueryIdentifyCodeSuccess(bool success)
  396. {
  397. _isGetIdentifyCode = true;
  398. }
  399. private string _identifyCode;
  400. public string IdentifyCode
  401. {
  402. get { return _identifyCode; }
  403. set { Set(() => IdentifyCode, ref _identifyCode, value); }
  404. }
  405. /// <summary>
  406. /// 查询
  407. /// </summary>
  408. /// <param name="ratios"></param>
  409. private void QueryOutMoneyThresholdSuccess(List<OutMoneyThresholdRatio> ratios)
  410. {
  411. _moneyThresholdRatios = ratios;
  412. var accountid = UserManager.CurrentTradeAccount.AccountId;
  413. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  414. //{
  415. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  416. //}
  417. _loginService.QueryTaAccount(accountid, QueryTaAccountSuccess, QueryErrorCallback);
  418. }
  419. /// <summary>
  420. ///
  421. /// </summary>
  422. private void QueryOutMoneyError(ErrorEntity errorEntity)
  423. {
  424. var errorMsg = string.Format("{0}:{1}", errorEntity.RequestFunc, ErrorManager.FormatErrorMsg(errorEntity)); //错误信息显示到状态
  425. LogInfoHelper.WriteInfo(errorMsg);
  426. var accountid = UserManager.CurrentTradeAccount.AccountId;
  427. //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
  428. //{
  429. // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  430. //}
  431. _loginService.QueryTaAccount(accountid, QueryTaAccountSuccess, QueryErrorCallback);
  432. }
  433. /// <summary>
  434. /// 打开键盘命令
  435. /// </summary>
  436. public RelayCommand<Control> OpenKeyboardCommand
  437. {
  438. get
  439. {
  440. return new RelayCommand<Control>((control) =>
  441. {
  442. PassWordKeyBoard.SetTouchScreenKeyboard(control, true);
  443. control.Focus();
  444. });
  445. }
  446. }
  447. private Visibility _outVisibility;
  448. /// <summary>
  449. /// 显示出金申请
  450. /// </summary>
  451. public Visibility OutVisibility
  452. {
  453. get
  454. {
  455. return _outVisibility;
  456. }
  457. set
  458. {
  459. Set(() => OutVisibility, ref _outVisibility, value);
  460. }
  461. }
  462. private Visibility _inVisibility;
  463. /// <summary>
  464. /// 显示入金申请
  465. /// </summary>
  466. public Visibility InVisibility
  467. {
  468. get
  469. {
  470. return _inVisibility;
  471. }
  472. set
  473. {
  474. Set(() => InVisibility, ref _inVisibility, value);
  475. }
  476. }
  477. private string _remark;
  478. /// <summary>
  479. /// 备注
  480. /// </summary>
  481. public string Remark
  482. {
  483. get
  484. {
  485. return _remark;
  486. }
  487. set
  488. {
  489. Set(() => Remark, ref _remark, value);
  490. }
  491. }
  492. private decimal _money;
  493. /// <summary>
  494. /// 出入金金额
  495. /// </summary>
  496. public decimal Money
  497. {
  498. get
  499. {
  500. ChineseNumber = FormatHelper.ConvertToChinese(_money); //设置大小写
  501. if (_money.Equals(0) || _money < 0)
  502. {
  503. return 0;
  504. }
  505. return _money;
  506. }
  507. set
  508. {
  509. Set(() => Money, ref _money, value);
  510. if (_isGetIdentifyCode)
  511. {
  512. IsShowModifyTips = true;
  513. }
  514. }
  515. }
  516. private bool _isShowModifyTips;
  517. /// <summary>
  518. /// 是否显示修改金额提示
  519. /// </summary>
  520. public bool IsShowModifyTips
  521. {
  522. get { return _isShowModifyTips; }
  523. set { Set(() => IsShowModifyTips, ref _isShowModifyTips, value);}
  524. }
  525. private string _password;
  526. /// <summary>
  527. /// 账户密码
  528. /// </summary>
  529. public string Password
  530. {
  531. get { return _password; }
  532. set { Set(() => Password, ref _password, value); }
  533. }
  534. private string _chineseNumber;
  535. /// <summary>
  536. /// 转换成大写数字
  537. /// </summary>
  538. public string ChineseNumber
  539. {
  540. get { return _chineseNumber; }
  541. set { Set(() => ChineseNumber, ref _chineseNumber, value); }
  542. }
  543. private bool _isBusy;
  544. /// <summary>
  545. /// 是否在忙
  546. /// </summary>
  547. public bool IsBusy
  548. {
  549. get { return _isBusy; }
  550. set { Set(() => IsBusy, ref _isBusy, value); }
  551. }
  552. private string _busyContent;
  553. public string BusyContent
  554. {
  555. get { return _busyContent; }
  556. set { Set(() => BusyContent, ref _busyContent, value); }
  557. }
  558. //private BankAccountInfo _bankAccountInfo = new BankAccountInfo();
  559. ///// <summary>
  560. ///// 银行信息
  561. ///// </summary>
  562. //public BankAccountInfo BankAccountInfo
  563. //{
  564. // get { return _bankAccountInfo; }
  565. // set
  566. // {
  567. // Set(() => BankAccountInfo, ref _bankAccountInfo, value);
  568. // }
  569. //}
  570. private bool _phoneBankPassIsEnabled;
  571. /// <summary>
  572. /// 是否输入电话银行密码
  573. /// </summary>
  574. public bool PhoneBankPassIsEnabled
  575. {
  576. get { return _phoneBankPassIsEnabled; }
  577. set { Set(() => PhoneBankPassIsEnabled, ref _phoneBankPassIsEnabled, value); }
  578. }
  579. private bool _BankPassIsEnabled;
  580. /// <summary>
  581. /// 是否输入 银行取款密码
  582. /// </summary>
  583. public bool BankPassIsEnabled
  584. {
  585. get { return _BankPassIsEnabled; }
  586. set { Set(() => BankPassIsEnabled, ref _BankPassIsEnabled, value); }
  587. }
  588. /// <summary>
  589. /// 是否显示密码
  590. /// </summary>
  591. public bool IsPassWordEnabled
  592. {
  593. get
  594. {
  595. return BankPassIsEnabled || PhoneBankPassIsEnabled;
  596. }
  597. }
  598. private bool _isShowIdentifyCode;
  599. /// <summary>
  600. /// 是否显示验证码
  601. /// </summary>
  602. public bool IsShowIdentifyCode
  603. {
  604. get { return _isShowIdentifyCode; }
  605. set { Set(() => IsShowIdentifyCode, ref _isShowIdentifyCode, value); }
  606. }
  607. private bool _isMoneyBoxEnable=true;
  608. /// <summary>
  609. /// 是否可输入金额
  610. /// </summary>
  611. public bool IsMoneyBoxEnable
  612. {
  613. get { return _isMoneyBoxEnable; }
  614. set { Set(() => IsMoneyBoxEnable, ref _isMoneyBoxEnable, value); }
  615. }
  616. private string _phoneBankPassword;
  617. /// <summary>
  618. /// 电话银行密码
  619. /// </summary>
  620. public string PhoneBankPassword
  621. {
  622. get
  623. {
  624. return _phoneBankPassword;
  625. }
  626. set
  627. {
  628. Set(() => PhoneBankPassword, ref _phoneBankPassword, value);
  629. }
  630. }
  631. #endregion Public Properties
  632. /// <summary>
  633. /// 确定
  634. /// </summary>
  635. public RelayCommand<AmountManagerView> OKCommand
  636. {
  637. get
  638. {
  639. return new RelayCommand<AmountManagerView>((view) =>
  640. {
  641. var caption = CurrentApplyType == FundsApplyType.Deposit ? Muchinfo.MTPClient.Resources.Client_Resource.Bank_InCashTips : Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCashTips;
  642. var successMessage = CurrentApplyType == FundsApplyType.Deposit ? Muchinfo.MTPClient.Resources.Client_Resource.Bank_InCash : Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCash;
  643. if (Money <= 0)
  644. {
  645. MessageBoxHelper.ShowInfo(string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Bank_CashGreatThanZero, successMessage), caption);
  646. return;
  647. }
  648. if (string.IsNullOrEmpty(Password))
  649. {
  650. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputCashPassword, caption);
  651. return;
  652. }
  653. if (Password.Length < 6)
  654. {
  655. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_CashPasswordNotLess6Bit, caption);
  656. return;
  657. }
  658. if (CurrentApplyType == FundsApplyType.Withdraw && Money > UseAmount)
  659. {
  660. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCashNotGreatAvailable, caption);
  661. return;
  662. }
  663. if (IsPassWordEnabled)
  664. {
  665. if (string.IsNullOrEmpty(PhoneBankPassword))
  666. {
  667. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_InputBankPassword, caption);
  668. return;
  669. }
  670. if (PhoneBankPassword.Length < 6)
  671. {
  672. MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.Bank_TelephoPasswordNotLess6Bit, caption);
  673. return;
  674. }
  675. }
  676. _OKCommandTemp = view;
  677. //验证账号信息,出入金交互。
  678. IsBusy = true;
  679. BusyContent = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Bank_SubmitInfo_Waiting, successMessage);
  680. // BankSignResult bankDealStatus;
  681. Amount amount = new Amount()
  682. {
  683. FundsApplyType = CurrentApplyType,
  684. Money = Money,
  685. Password = Password,
  686. Remark = Remark
  687. };
  688. amount.AccountId = UserManager.CurrentTradeAccount.AccountId;// 操作账号
  689. amount.AccountType = UserManager.CurrentTradeAccount.AccountType;
  690. amount.AccountCode = CurrentSigningBank.AccountCode;
  691. _bankService.OutInMoney(amount, this.CurrentSigningBank, OutInMoneyCallback, ErrorCallback);
  692. //LogManager.WriteFundApplyLog(CurrentApplyType,
  693. // UserManager.CurrentTradeAccount,
  694. // Money,this.CurrentSigningBank);
  695. });
  696. }
  697. }
  698. private BankSignResult temp_bankDealStatus;
  699. private void OutInMoneyCallback(BankSignResult bankDealStatus)
  700. {
  701. var caption = CurrentApplyType == FundsApplyType.Deposit ? Muchinfo.MTPClient.Resources.Client_Resource.Bank_InCashTips : Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCashTips;
  702. var successMessage = CurrentApplyType == FundsApplyType.Deposit ? Muchinfo.MTPClient.Resources.Client_Resource.Bank_InCash : Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCash;
  703. temp_bankDealStatus = bankDealStatus;
  704. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  705. {
  706. //IsBusy = false;
  707. if (bankDealStatus.ReturnCode == 0)
  708. {
  709. if (IsPassWordEnabled)
  710. {
  711. if (_encryptKey == null)
  712. {
  713. var reqKey = new EncryptKeyRequest()
  714. {
  715. Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null
  716. || !UserManager.CurrentTradeAccount.FundsAccounts.Any())
  717. ? "RMB"
  718. : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency,
  719. CusBankId = CurrentSigningBank.CusBankID+string.Empty,
  720. };
  721. // _encryptKey =
  722. _bankService.QueryEncryptKey(reqKey, QueryEncryptKeyCallback, QueryErrorCallback);
  723. }
  724. }
  725. else
  726. {
  727. IsBusy = false;
  728. if (bankDealStatus.Status == BankDealStatus.BankDealStatus__Succeed)
  729. {
  730. MessageBoxHelper.ShowSuccess(
  731. string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Bank_ApplaySuccess, successMessage),
  732. caption);
  733. }
  734. else if (bankDealStatus.Status == BankDealStatus.BankDealStatus__Pend)
  735. {
  736. MessageBoxHelper.ShowSuccess(
  737. string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Bank_ApplaySubmit, successMessage), caption);
  738. }
  739. else if (bankDealStatus.Status == BankDealStatus.BankDealStatus__BankWebComfirm)
  740. {
  741. try
  742. {
  743. IPHelper.OpenWebAddress(bankDealStatus.WebAddress);
  744. }
  745. catch (Exception ex)
  746. {
  747. throw new MuchinfoException(ExceptionManager.OpenIEError);
  748. }
  749. finally
  750. {
  751. string tips = string.Format(Client_Resource.Tips_BankDepositWebComfrim,
  752. CurrentApplyType.Discription());
  753. var messageBox = new MsgAlter(bankDealStatus.WebAddress, tips)
  754. {
  755. Owner = Application.Current.MainWindow,
  756. WindowStartupLocation = WindowStartupLocation.CenterOwner
  757. };
  758. messageBox.ShowDialog();
  759. }
  760. }
  761. if (_OKCommandTemp != null)
  762. _OKCommandTemp.DialogResult = true;
  763. }
  764. }
  765. else
  766. {
  767. ErrorManager.ShowReturnError(bankDealStatus.ReturnCode, caption);
  768. }
  769. }));
  770. }
  771. private void QueryEncryptKeyCallback(EncryptKey encryptKey)
  772. {
  773. _encryptKey = encryptKey;
  774. var encryptHelper = new TasEncryptHelper();
  775. string encryptPWD = encryptHelper.EncryptPassd(_encryptKey.SecretKey, PhoneBankPassword);
  776. var bankDealStatus = temp_bankDealStatus;
  777. var req = new SignBankPDW()
  778. {
  779. AccountCode = CurrentSigningBank.AccountCode,
  780. ExchTicket = bankDealStatus.ExchTicket,
  781. ExtOperatorID = bankDealStatus.ExtOperatorID,
  782. CusBankId = CurrentSigningBank.CusBankID + string.Empty,
  783. BankAccountPWD = encryptPWD,
  784. Currency = (UserManager.CurrentTradeAccount.FundsAccounts == null
  785. || !UserManager.CurrentTradeAccount.FundsAccounts.Any())
  786. ? "RMB"
  787. : UserManager.CurrentTradeAccount.FundsAccounts[0].Currency,
  788. };
  789. //if (UserManager.CurrentTradeAccount.AccountType == eLoginUserType.LOGINUSERTYPE_TRADER && _areaAccount != null)
  790. //{
  791. // req.AccountCode = _areaAccount.AccountCode;
  792. //}
  793. // var result = _bankService.SignBankPwd(req, UserManager.CurrentTradeAccount.LoginCode);
  794. _bankService.SignBankPwd(req, SignBankPwdCallback, ErrorCallback);
  795. }
  796. private void SignBankPwdCallback(int result)
  797. {
  798. IsBusy = false;
  799. var caption = CurrentApplyType == FundsApplyType.Deposit ? Muchinfo.MTPClient.Resources.Client_Resource.Bank_InCashTips : Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCashTips;
  800. var successMessage = CurrentApplyType == FundsApplyType.Deposit ? Muchinfo.MTPClient.Resources.Client_Resource.Bank_InCash : Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCash;
  801. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  802. {
  803. if (result != 0) //密码
  804. {
  805. ErrorManager.ShowReturnError(result, caption);
  806. }
  807. else
  808. {
  809. MessageBoxHelper.ShowSuccess(
  810. string.Format(
  811. Muchinfo.MTPClient.Resources.Client_Resource.Bank_ApplaySuccess,
  812. successMessage),
  813. caption);
  814. if (_OKCommandTemp != null)
  815. _OKCommandTemp.DialogResult = true;
  816. }
  817. }));
  818. }
  819. public void ErrorCallback(ErrorEntity error)
  820. {
  821. IsBusy = false;
  822. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  823. {
  824. var caption = CurrentApplyType == FundsApplyType.Deposit ? Muchinfo.MTPClient.Resources.Client_Resource.Bank_InCashTips : Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCashTips;
  825. ErrorManager.ShowReturnError(error, caption);
  826. }));
  827. }
  828. public void QueryErrorCallback(ErrorEntity error)
  829. {
  830. IsBusy = false;
  831. if (!_isClose)
  832. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  833. {
  834. var caption = CurrentApplyType == FundsApplyType.Deposit ? Muchinfo.MTPClient.Resources.Client_Resource.Bank_InCashTips : Muchinfo.MTPClient.Resources.Client_Resource.Bank_OutCashTips;
  835. ErrorManager.ShowReturnError(error, caption);
  836. }));
  837. }
  838. /// <summary>
  839. /// 取消命令
  840. /// </summary>
  841. public RelayCommand<AmountManagerView> CancelCommand
  842. {
  843. get
  844. {
  845. return new RelayCommand<AmountManagerView>((view) =>
  846. {
  847. view.DialogResult = false;
  848. });
  849. }
  850. }
  851. /// <summary>
  852. /// 刷新可出资金
  853. /// </summary>
  854. public RelayCommand RefreshCommand
  855. {
  856. get
  857. {
  858. return new RelayCommand(() =>
  859. {
  860. //todo:更新可出资金
  861. Task.Factory.TryStartNew(() =>
  862. {
  863. // var useAmount =
  864. CalcUseAmount();
  865. // UseAmount = Math.Round(useAmount, 2, MidpointRounding.AwayFromZero);
  866. }, () => IsBusy = false);
  867. });
  868. }
  869. }
  870. private void SetSignBankInfo()
  871. {
  872. string inOutshowfield = string.Empty;
  873. if (CurrentApplyType == FundsApplyType.Deposit)
  874. {
  875. inOutshowfield = CurrentSigningBank.InShowField;
  876. }
  877. else
  878. {
  879. inOutshowfield = CurrentSigningBank.OutShowField;
  880. }
  881. if (inOutshowfield != null)
  882. {
  883. string[] showField = inOutshowfield.Split(',');
  884. PhoneBankPassIsEnabled = showField.Any(m => m == ((int)ShowFieldStatus.ShowField_BankAccountPWD) + string.Empty );
  885. BankPassIsEnabled = showField.Any(m => m == ((int)ShowFieldStatus.ShowField_Draw_IdentifyCode) + string.Empty);
  886. RaisePropertyChanged(() => IsPassWordEnabled);
  887. IsShowIdentifyCode =
  888. showField.Any(m => m == ((int) ShowFieldStatus.ShowField_IdentifyCode) + string.Empty);
  889. //this.PhoneBankPassIsEnabled = value != null ? true : false;
  890. }
  891. // IsBusy = true;
  892. //BusyContent = Muchinfo.MTPClient.Resources.Client_Resource.Bank_GetBankInfomation_waiting;
  893. //System.Threading.Tasks.Task.Factory.TryStartNew(
  894. //() =>
  895. //{
  896. // // SigningBank configInfo =
  897. // _bankService.QueryBankParamConfig(CurrentSigningBank.CusBankID + string.Empty, QueryBankParamConfigCallback, QueryErrorCallback);
  898. //}, () => IsBusy = false);
  899. }
  900. private void QueryBankParamConfigCallback(List<SigningBank> signingBank)
  901. {
  902. System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  903. {
  904. if (signingBank != null)
  905. {
  906. foreach (var sb in signingBank)
  907. {
  908. if (CurrentSigningBank.CusBankID != sb.CusBankID)
  909. {
  910. continue;
  911. }
  912. string inOutshowfield = string.Empty;
  913. if (CurrentApplyType == FundsApplyType.Deposit)
  914. {
  915. inOutshowfield = sb.InShowField;
  916. }
  917. else
  918. {
  919. inOutshowfield = sb.OutShowField;
  920. }
  921. if (inOutshowfield != null)
  922. {
  923. string[] showField = inOutshowfield.Split(',');
  924. string value = showField.FirstOrDefault(m => m == "8");
  925. this.PhoneBankPassIsEnabled = value != null ? true : false;
  926. }
  927. }
  928. }
  929. //this.PhoneBankPassIsEnabled = (CurrentSigningBank != null && CurrentSigningBank.CusBankID == "10") ? true : false;
  930. }));
  931. }
  932. private bool _isClose = false;
  933. public override void Cleanup()
  934. {
  935. MessengerHelper.QuoteUnregister< List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTimeQuote);
  936. base.Cleanup();
  937. _isClose = true;
  938. }
  939. }
  940. }