using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//----------------------------------------------------------------
//Module Name: $safeprojectname$
//Purpose:
//CopyRight: Muchinfo
//History:
//----------------------------------------------------------------
//DateTime 2017/3/23 15:03:32
//Author
//Description Create
//----------------------------------------------------------------
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Muchinfo.MTPClient.Data;
using Muchinfo.MTPClient.Data.Model.Bank;
using Muchinfo.MTPClient.Infrastructure.Utilities;
using Muchinfo.MTPClient.IService;
namespace Muchinfo.MTPClient.Bank.ViewModels
{
public class BankBalanceViewModel : ViewModelBase
{
///
/// 银行接口
///
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 List _balanceModels;
///
/// 查询银行余额
///
public List BalanceModels
{
get { return _balanceModels; }
set { Set(() => BalanceModels, ref _balanceModels, value); }
}
private BankBalanceModel _selectItem;
///
/// 选择的项
///
public BankBalanceModel SelectItem
{
get { return _selectItem; }
set { Set(() => SelectItem, ref _selectItem, value); }
}
public BankBalanceViewModel(SigningBank signingBank)
{
_bankService = SimpleIoc.Default.GetInstance();
CurrentSigningBank = signingBank;
IsBusy = true;
_bankService.GetBankBalace(signingBank, QueryBalanceCallBack, ErrorCallback);
}
private void QueryBalanceCallBack(List balanceModels)
{
IsBusy = false;
BalanceModels = balanceModels;
SelectItem = BalanceModels != null ? BalanceModels.FirstOrDefault() : null;
#if DEBUG
var balances = new List();
balances.Add(new BankBalanceModel() { AccountCode = 12315555 + string.Empty, PlatBalance = 254542, Cusbankid = "fdaddd" });
balances.Add(new BankBalanceModel() { AccountCode = 12315532455 + string.Empty, PlatBalance = 25432542, Cusbankid = "fda323ddd" });
BalanceModels = balances;
SelectItem = BalanceModels != null ? BalanceModels.FirstOrDefault() : null;
#endif
}
public void ErrorCallback(ErrorEntity error)
{
#if DEBUG
var balances = new List();
balances.Add(new BankBalanceModel(){AccountCode = 12315555+string.Empty,PlatBalance = 254542,Cusbankid = "fdaddd"});
balances.Add(new BankBalanceModel() { AccountCode = 12315532455 + string.Empty, PlatBalance = 25432542, Cusbankid = "fda323ddd" });
BalanceModels = balances;
SelectItem = BalanceModels != null ? BalanceModels.FirstOrDefault() : null;
#endif
IsBusy = false;
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
ErrorManager.ShowReturnError(error, Muchinfo.MTPClient.Resources.Client_Resource.Bank_Error, true);
}));
}
}
}