| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- 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
- {
- /// <summary>
- /// 交易参数设置业务逻辑
- /// </summary>
- 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;
- /// <summary>
- /// 是否自动选择
- /// </summary>
- public bool IsAutoChoose
- {
- get { return _isAutoChoose; }
- set
- {
- Set(() => IsAutoChoose, ref _isAutoChoose, value);
- }
- }
- private bool _isDefineGoods;
- /// <summary>
- /// 是否选中自定义商品
- /// </summary>
- public bool IsDefineGoods
- {
- get { return _isDefineGoods; }
- set
- {
- Set(() => IsDefineGoods, ref _isDefineGoods, value);
- }
- }
- private bool _isBuy;
- /// <summary>
- /// 是否选中买入
- /// </summary>
- public bool IsBuy
- {
- get { return _isBuy; }
- set
- {
- Set(() => IsBuy, ref _isBuy, value);
- }
- }
- private bool _isSell;
- /// <summary>
- /// 是否选中卖出
- /// </summary>
- public bool IsSell
- {
- get { return _isSell; }
- set
- {
- Set(() => IsSell, ref _isSell, value);
- }
- }
- /// <summary>
- /// 是否显示忙
- /// </summary>
- private bool _isBusy;
- /// <summary>
- /// 是否忙,显示等待控件
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- /// <summary>
- /// 商品列表
- /// </summary>
- public ObservableCollection<Goods> Goods { get; set; }
- /// <summary>
- /// 选中商品
- /// </summary>
- public Goods ChooseGoods { get; set; }
- /// <summary>
- /// 最大手数
- /// </summary>
- public decimal MaxHands { get; set; }
- /// <summary>
- /// 最小手数
- /// </summary>
- public decimal MinHands { get; set; }
- /// <summary>
- /// 手数
- /// </summary>
- public decimal Hands { get; set; }
- /// <summary>
- /// 最大点差
- /// </summary>
- public decimal MaxSpreed { get; set; }
- /// <summary>
- /// 最小点差
- /// </summary>
- public decimal MinSpreed { get; set; }
- /// <summary>
- /// 点差
- /// </summary>
- public decimal Spreed { get; set; }
- #endregion Properties
- #region Command
- /// <summary>
- /// 取消
- /// </summary>
- public RelayCommand<TradeParamerSetView> CancelCommand
- {
- get
- {
- return new RelayCommand<TradeParamerSetView>((w) =>
- {
- w.DialogResult = false;
- });
- }
- }
- /// <summary>
- /// 确定
- /// </summary>
- public RelayCommand<TradeParamerSetView> OKCommand
- {
- get
- {
- return new RelayCommand<TradeParamerSetView>((w) =>
- {
- ////debug注释验证
- if (!ValidData())
- {
- return;
- }
- w.DialogResult = false;
- });
- }
- }
- #endregion
- #region Methods
- /// <summary>
- /// 客户端验证登录数据
- /// </summary>
- /// <returns></returns>
- 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
- }
- }
|