using GalaSoft.MvvmLight;
using Muchinfo.MTPClient.Data.Enums;
using Muchinfo.MTPClient.Data.Helper;
using Muchinfo.MTPClient.Resources;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace Muchinfo.MTPClient.Data.Model.Account
{
///
/// 交易帐户类
///
public class TradeAccount : ObservableObject
{
#region Fields
private const decimal c_DefautAgreeAmount = 1000000m;
private decimal _balance;
private ObservableCollection _fundsAccounts;
private List _memberPositions; //会员头寸
//资金账号密码
private string _tradePassword;
#endregion Fields
#region Properties
#region Public Properties
///
/// 余额
///
public decimal Balance
{
get { return _balance; }
set { Set(() => Balance, ref _balance, value); }
}
///
/// md5方式加密后的加密密码
///
public string _md5Password;
public string Md5Password
{
get { return _md5Password; }
set
{
Set(() => Md5Password, ref _md5Password, value);
}
}
///
/// 风险率
///
public string FundsUsageRate
{
get
{
if (this.AccountType != eUserType.USERTYPE_INVESTOR)
{
if (MemberAccountInfo != null)
{
return MemberAccountInfo.Rate.ToString("p2");
}
}
else
{
if (FundsAccounts != null && FundsAccounts.Any() && FundsAccounts[0].CurrentNetWorth > 0)
{
////暂时使用第一个账户信息
return FundsAccounts[0].RiskRatioDisplay;
}
}
return "0%";
}
}
///
/// 交易账号
///
public ObservableCollection FundsAccounts
{
get
{
return _fundsAccounts;
}
set
{
if (_fundsAccounts != null && _fundsAccounts.Any())
{
_fundsAccounts[0].PropertyChanged -= TradeAccount_PropertyChanged;
}
Set(() => FundsAccounts, ref _fundsAccounts, value);
if (_fundsAccounts != null && _fundsAccounts.Any())
{
_fundsAccounts[0].PropertyChanged += TradeAccount_PropertyChanged;
}
}
}
void TradeAccount_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
//throw new System.NotImplementedException();
if (e.PropertyName == "CurrentNetWorth")
{
RaisePropertyChanged(() => FundsUsageRate);
RaisePropertyChanged(() => UsableFunds);
}
}
///
/// 会员头寸
///
public List MemberPositions
{
get
{
return _memberPositions;
}
set
{
Set(() => MemberPositions, ref _memberPositions, value);
RaisePropertyChanged(() => FundsUsageRate);
}
}
///
/// 会员账号风险率配置
///
public List RiskRateParams { get; set; }
///
/// 会员账号风险率配置参数
///
public RiskRateParam AccountRiskRate
{
get
{
if (RiskRateParams != null && RiskRateParams.Any())
{
return RiskRateParams[0];
}
return new RiskRateParam();
}
}
///
/// 资金账号密码
///
public string TradePassword
{
get { return _tradePassword; }
set { _tradePassword = value; }
}
///
/// 获取可用资金
///
public decimal UsableFunds
{
get
{
if (FundsAccounts != null && FundsAccounts.Any())
{ //暂时使用第一个账户信息
return FundsAccounts[0].AvailMargin;
}
return 0m;
}
}
///
/// 允许最大持仓金额
///
public decimal MaxAgreeAmount
{
get
{
if (FundsAccounts != null && FundsAccounts.Any())
{
////暂时使用第一个账户信息
return FundsAccounts[0].MaxAgreeAmount;
////.UsedMargin / FundsAccounts[0].CurrentNetWorth * 100;
}
return c_DefautAgreeAmount;
}
}
private MemberAccountInfo _memberAccountInfo;
///
/// 会员账户信息
///
public MemberAccountInfo MemberAccountInfo
{
get { return _memberAccountInfo; }
set { Set(() => MemberAccountInfo, ref _memberAccountInfo, value); }
}
///
/// 交易所代码
///
public uint ExchAreaId { get; set; }
///
/// 账户是否已锁定
///
public bool AccountIsLock { get; set; }
///
/// 内部资金账号
///
public string TaAccountCode { get; set; }
///
/// 证件类型
///
public eCardType CardType { get; set; }
///
/// 证件号码
///
public string CardNum { get; set; }
///
/// 会员证件类型
///
public eCardType MemberCardType { get; set; }
///
/// 会员证件号码
///
public string MemberCardNum { get; set; }
///
///
///
public SexType Sex { get; set; }
#endregion Public Properties
#endregion Properties
#region 业务服务属性
///
/// 机构名称
///
public string AreaName { get; set; }
///
/// 会员名称
///
public string MemberName { get; set; }
///
/// 用户名
///
public string CustomerName { get; set; }
///
/// 用户状态
///
public eAccountStatus AccountStatus { get; set; }
///
/// 显示用户状态
///
public string AccountStatusDisplay
{
get
{
return AccountStatus.Discription();
}
}
///
/// 是否显示上面的资金信息
///
public bool IsShowHeaderFundInfo
{
get
{
if (AccountType != eUserType.USERTYPE_INVESTOR)
return false;
if (FundsAccounts != null && FundsAccounts.Count == 1)
return true;
else
return false;
}
}
public bool IsShowHeaderFundInfoEx
{
get
{
if (AccountType == eUserType.USERTYPE_INVESTOR)
return false;
if (FundsAccounts != null && FundsAccounts.Count == 1)
return true;
else
return false;
}
}
///
/// 账户类型
///
public eUserType AccountType { get; set; }
///
/// 所属机构代码
///
public string AreaCode { get; set; }
///
/// 机构ID
///
public uint AreaId { get; set; }
///
/// 所属经纪人id
///
public uint BrokerAccountId { get; set; }
///
/// 风险率类型ID
///
public uint RiskRatioId { get; set; }
///
/// 风险率计算方法
///
public eRiskRateMode RiskRatioCalcMode { get; set; }
///
/// 类型名称
///
public string RiskRatioName { get; set; }
///
/// 服务端系统时间
///
public ulong SystemTime { get; set; }
///
/// 内容权限组编号
///
public int ContRightCode { get; set; }
///
/// 用户编号
///
public uint CustomerId { get; set; }
///
/// 用户ID
///
public ulong AccountId { get; set; }
///
/// 资金账号ID
/// add by dk
///
public ulong FundsAccountId { get; set; }
///
/// 当前账号下有权限的资金账户ID列表
///
public List FundsAccountIds { get; set; }
///
/// 会员机构ID
///
public uint MemberAreaId { get; set; }
///
/// 功能权限组编号
///
public int FuncRightCode { get; set; }
///
/// 登录账号
///
public ulong LoginID { get; set; }
///
/// 登录密码修改状态
///
public int LoginPasswordModType { get; set; }
///
/// 所属会员代码
///
public string MemberCode { get; set; }
///
/// 对手资金账号
///
public string OtherTradeCode { get; set; }
///
/// 风险率类型编号
///
public uint RiskRateId { get; set; }
///
/// 账户
///
public string AccountCode { get; set; }
///
/// 连接令牌
///
public string Token { get; set; }
///
/// 通信公钥
///
public string PublicKey { get; set; }
///
/// 是否已修改密码
///
/// The has updated password.
public uint HasUpdatedPwd { get; set; }
///
/// 当前密码输入错误次数
///
/// The password wrong count.
public uint PwdWrongCnt { get; set; }
///
/// 登陆账号锁定密码输入错误次数
///
/// The password wrong lock count.
public uint PwdWrongLockCnt { get; set; }
///
/// 登陆账号锁定时长(小时)
///
/// The login lock hour number.
public uint LoginLockHourNum { get; set; }
///
/// 终端系统信息
///
public byte[] ClientSystemInfo { get; set; }
///
/// 终端ID(登陆服务分配,用于通道交易关联链路)
///
public ulong ClientId { get; set; }
#endregion
#region 用户设置
/////
///// 登录系统时间
/////
//public DateTime LoginTime { get; set; }
/////
///// 登录系统时间
/////
//public bool IsRememberSave { get; set; }
///
/// 内容权限类型
///
public string ContentRightType { get; set; }
#endregion
#region Methods
#region Public Methods
///
/// Returns a that represents this instance.
///
/// A that represents this instance.
public override string ToString()
{
return Client_Resource.Domain_AccountH + AccountCode + Client_Resource.Domain_AvailableFunds + UsableFunds + Client_Resource.Domain_FundUseRate + FundsUsageRate;
}
#endregion Public Methods
///
/// 更新的风险率
///
public void UpdataFundsUsageRate()
{
RaisePropertyChanged(() => FundsUsageRate);
}
private string _accountTitle;
///
/// 账号标题
///
public string AccountTitle
{
get
{
return this.ToString();
}
}
///
/// 当前资金账号信息--用于计算风险率
///
/// The current funds account.
public FundsAccount CurrentFundsAccount
{
get {
if (FundsAccounts != null)
{
return FundsAccounts.FirstOrDefault(z => z.AccountId == FundsAccountId);
}
return null;
}
}
#endregion Methods
}
}