using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Muchinfo.MTPClient.Account.Views;
using Muchinfo.MTPClient.Data.Model;
using Muchinfo.MTPClient.Data.Model.Account;
using Muchinfo.MTPClient.Infrastructure.Utilities;
using System.Collections.ObjectModel;
using System.Linq;
namespace Muchinfo.MTPClient.Account.ViewModels
{
///
/// 交易参数设置业务逻辑
///
public class TradeParamerSetViewModel : ViewModelBase
{
#region Constructors
public TradeParamerSetViewModel()
{
var temp = UserManager.GetTradeAccounts();
if (temp == null || temp.Count <= 0)
{
IsBuy = true;
IsSell = false;
Hands = 1;
}
else
{
UserInfo userInfo = new UserInfo();
foreach (var info in temp)
{
if (info.UserName.Equals(UserManager.CurrentTradeAccount.LoginCode))
{
userInfo = info;
break;
}
}
if (string.IsNullOrEmpty(userInfo.UserName))
{
userInfo = temp.FirstOrDefault();
}
if (userInfo.TradeParamer == null)
{
IsBuy = true;
IsSell = false;
Hands = 1;
}
else
{
IsBuy = userInfo.TradeParamer.DefaultBuy;
IsSell = !userInfo.TradeParamer.DefaultBuy;
Hands = userInfo.TradeParamer.DefaultHands;
}
}
// var temp=UserManager.GetTradeAccounts().FirstOrDefault((t)=>t.UserName.Equals(UserManager.CurrentTradeAccount.TradeCode));
//todo:从服务端获取
MaxHands = 1000;
MinHands = 1;
//Hands = 100;
MaxSpreed = 100;
MinSpreed = 1;
Spreed = 50;
}
#endregion Constructors
#region Properties
private bool _isAutoChoose;
///
/// 是否自动选择
///
public bool IsAutoChoose
{
get { return _isAutoChoose; }
set
{
Set(() => IsAutoChoose, ref _isAutoChoose, value);
}
}
private bool _isDefineGoods;
///
/// 是否选中自定义商品
///
public bool IsDefineGoods
{
get { return _isDefineGoods; }
set
{
Set(() => IsDefineGoods, ref _isDefineGoods, value);
}
}
private bool _isBuy;
///
/// 是否选中买入
///
public bool IsBuy
{
get { return _isBuy; }
set
{
Set(() => IsBuy, ref _isBuy, value);
}
}
private bool _isSell;
///
/// 是否选中卖出
///
public bool IsSell
{
get { return _isSell; }
set
{
Set(() => IsSell, ref _isSell, value);
}
}
///
/// 是否显示忙
///
private bool _isBusy;
///
/// 是否忙,显示等待控件
///
public bool IsBusy
{
get { return _isBusy; }
set { Set(() => IsBusy, ref _isBusy, value); }
}
///
/// 商品列表
///
public ObservableCollection Goods { get; set; }
///
/// 选中商品
///
public Goods ChooseGoods { get; set; }
///
/// 最大手数
///
public decimal MaxHands { get; set; }
///
/// 最小手数
///
public decimal MinHands { get; set; }
///
/// 手数
///
public decimal Hands { get; set; }
///
/// 最大点差
///
public decimal MaxSpreed { get; set; }
///
/// 最小点差
///
public decimal MinSpreed { get; set; }
///
/// 点差
///
public decimal Spreed { get; set; }
#endregion Properties
#region Command
///
/// 取消
///
public RelayCommand CancelCommand
{
get
{
return new RelayCommand((w) =>
{
w.DialogResult = false;
});
}
}
///
/// 确定
///
public RelayCommand OKCommand
{
get
{
return new RelayCommand((w) =>
{
////debug注释验证
if (!ValidData())
{
return;
}
w.DialogResult = false;
});
}
}
#endregion
#region Methods
///
/// 客户端验证登录数据
///
///
private bool ValidData()
{
var lsUserInfo = UserManager.GetTradeAccounts();
UserInfo userInfo = new UserInfo();
if (lsUserInfo != null && lsUserInfo.Count > 0)
{
userInfo = lsUserInfo.FirstOrDefault();
}
userInfo.TradeParamer = new TradeParamer { DefaultHands = Hands, DefaultBuy = IsBuy };
UserManager.SaveTradeAccount(userInfo);
return true;
}
#endregion Methods
}
}