| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/1/16 10:22:14
- //Author
- //Description Create
- //----------------------------------------------------------------
- using System.Windows;
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.MTPClient.Service;
- using Muchinfo.WPF.Controls.Windows;
- using GalaSoft.MvvmLight.Ioc;
- using GalaSoft.MvvmLight.Messaging;
- namespace Muchinfo.MTPClient.Trade.ViewModels
- {
- /// <summary>
- /// Class OpenFrameViewModel.
- /// </summary>
- public class OpenFrameViewModel : ViewModelBase
- {
- private IGoodsService _goodsService;
- private OrderType _orderType; ////打开口时默认订单类型
- private Window _openWindow; ////服务成功关闭窗口
- /// <summary>
- /// 是否忙,显示等待控件
- /// </summary>
- private bool _isBusy;
- /// <summary>
- /// 是否忙,显示等待控件
- /// </summary>
- public bool IsBusy
- {
- get
- {
- return _isBusy;
- }
- set
- {
- Set(() => IsBusy, ref _isBusy, value);
- }
- }
- private string _busyTips;
- /// <summary>
- /// 服务忙提示
- /// </summary>
- public string BusyTips
- {
- get
- {
- return _busyTips;
- }
- set
- {
- Set(() => BusyTips, ref _busyTips, value);
- }
- }
- /// <summary>
- /// 账号信息
- /// </summary>
- public uint AccountId { get; set; }
-
- private List<QuoteGoods> _goodsList;
- /// <summary>
- /// 商品列表
- /// </summary>
- public List<QuoteGoods> GoodsList
- {
- get
- {
- return _goodsList;
- }
- set
- {
- Set(() => GoodsList, ref _goodsList, value);
- }
- }
- private QuoteGoods _currentGoods;
- /// <summary>
- /// 当前商品
- /// </summary>
- public QuoteGoods CurrentGoods
- {
- get { return _currentGoods; }
- set
- {
- Set(() => CurrentGoods, ref _currentGoods, value);
- SetQuoteGoods();
- }
- }
-
- private TradeOrderBase _tradeOrderBase;
- /// <summary>
- /// 做市竞价类型
- /// </summary>
- public TradeOrderBase TradeOrderBase
- {
- get
- {
- return _tradeOrderBase;
- }
- set
- {
- Set(() => TradeOrderBase, ref _tradeOrderBase, value);
- }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="OpenFrameViewModel" /> class.
- /// </summary>
- /// <param name="quoteGoods">The quote goods.</param>
- /// <param name="orderType">建仓类型使用OTC市价或限价参数</param>
- public OpenFrameViewModel(QuoteGoods quoteGoods, OrderType orderType = OrderType.MarketOpenOrder)
- {
- _goodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
- GoodsList = CacheManager.CacheGoodsBaseInfos; //_goodsService.GetGoodsInfoListByExchangeId(UserManager.CurrentTradeAccount.ExchangeId).ToList();
- _orderType = orderType;
- //todo:取可交易的商品,不一定是一个交易所的
- if (quoteGoods != null)
- {
- CurrentGoods = GoodsList.FirstOrDefault((item) => item.GoodsCode == quoteGoods.GoodsCode);
- }
- ////找不到商品取默认的
- if (CurrentGoods == null)
- {
- CurrentGoods = GoodsList.FirstOrDefault();
- }
- AccountId = UserManager.CurrentTradeAccount.AccountId;
- }
- /// <summary>
- /// Sets the quote goods.
- /// </summary>
- private void SetQuoteGoods()
- {
- if (_currentGoods != null)
- {
- if (_currentGoods.GoodsParameters != null && _currentGoods.GoodsParameters.TradeMode == eTradeMode.TRADEMODE_BIDDING)
- {
- OrderType orderType = _orderType == OrderType.MarketOpenOrder
- ? OrderType.BidMarketOpen
- : OrderType.BidLimitOpen;
- TradeOrderBase = new BidOpenOrderViewModel(_currentGoods, orderType);
-
- }
- else
- {
- TradeOrderBase = new MakeOrderViewModel(_currentGoods, _orderType);
- }
- }
- }
- /// <summary>
- /// 快速下单窗口取消
- /// </summary>
- public RelayCommand<Window> CancelCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- dialog.DialogResult = false;
- });
- }
- }
- private bool _oKButtonEnabled = true;
- /// <summary>
- ///设置按键不可用
- /// </summary>
- public bool OKButtonEnabled
- {
- get
- {
- return _oKButtonEnabled;
- }
- set
- {
- Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
- }
- }
- /// <summary>
- /// 下单确定
- /// </summary>
- public RelayCommand<Window> OKCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- OKButtonEnabled = false;
- string errorMsg = string.Empty;
- bool validateBool = _tradeOrderBase.Validated(); ////内容验证
- if (validateBool)
- {
- _openWindow = dialog;
- IsBusy = true;
- BusyTips = Muchinfo_Resource.Window_Wait;
- _tradeOrderBase.PostOrder(EntrurstSuccessCallBack, EntrurstErrorCallBack); ////获取表单内容
- }
- else
- {
- MessageBoxHelper.ShowInfo(errorMsg, Muchinfo_Resource.MessageBox_Error_Title);
- OKButtonEnabled = true;
- }
- });
- }
- }
- /// <summary>
- /// 提交成功返回
- /// </summary>
- /// <param name="order"></param>
- private void EntrurstSuccessCallBack(OrderDetail order)
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- MessageBoxHelper.ShowSuccess(Muchinfo_Resource.Order_Success_Result,
- Muchinfo_Resource.Open_MessageBox_Title);
- IsBusy = false;
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- }));
- Messenger.Default.Send(UserManager.CurrentTradeAccount, MessengerTokens.OrderNotify);
- }
- /// <summary>
- /// 委托失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void EntrurstErrorCallBack(ErrorEntity errorEntity)
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ErrorManager.ShowReturnError(errorEntity, Muchinfo_Resource.UI2014_Tips, true);
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- IsBusy = false;
- }));
- }
- }
- }
|