| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/7/22 16:03:12
- //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.Helpers;
- using Muchinfo.MTPClient.Infrastructure.MessageBox;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.Resources;
- using System.Collections.ObjectModel;
- using System.Windows.Media;
- using Muchinfo.MTPClient.Data.Model.Delivery;
- using Muchinfo.MTPClient.IService;
- using GalaSoft.MvvmLight.Ioc;
- namespace Muchinfo.MTPClient.Trade.ViewModels
- {
- public class TradeOrderViewModel : ViewModelBase
- {
- private Window _openWindow; ///下单窗口
- private bool _isBusy;
- private bool _isDefautClose; //是否从平仓入口进入
- private IDeliveryService _deliveryService;
- private OrderModel _orderModel = OrderModel.Normal;
- // 风管云平台
- public OrderModel OrderModel
- {
- get { return _orderModel; }
- }
- /// <summary>
- /// 选择商品后的入口
- /// </summary>
- /// <param name="goods"></param>
- /// <param name="tradeDirection"></param>
- public TradeOrderViewModel(QuoteGoods goods, Direction tradeDirection)
- {
- _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
- GoodsList =
- CacheManager.CacheGoodsBaseInfos.Where((item) => (item.ContainsGoodsSrc & (int)GoodsFromScr.Trade) == (int)GoodsFromScr.Trade)
- .ToList(); ////交易的商品
- GoodsList = GoodsList.Where((item) => ((item.TradeMode != eTradeMode.TRADEMODE_SALE))).ToList();//|| (item.TradeMode == eTradeMode.TRADEMODE_SALE && item.GoodsParameters.RunSteps == eRunStep.RUNSTEP_ISSUE_SUBSCRIPTING)
- if (goods == null || GoodsList.FirstOrDefault(item => item.GoodsId == goods.GoodsId) == null)
- {
- _currentGoods = GoodsList.FirstOrDefault();
- }
- else
- {
- _currentGoods = GoodsList.FirstOrDefault(item => item.GoodsId == goods.GoodsId);
- }
- _direction = tradeDirection;
- TradeViewModel = CreateTradeModeViewModel(_currentGoods, tradeDirection);
- ShowTradeArea();
- //绑定Popup关联交割商品信息
- SelectGoodsOfPAndX_ItemSource(_currentGoods);
- ShowLockGoods();
- }
- /// <summary>
- /// 选择单据的入口
- /// </summary>
- /// <param name="orderBase"></param>
- /// <param name="priceMode"></param>
- /// <param name="orderModel"></param>
- public TradeOrderViewModel(OrderBase orderBase, ePriceMode priceMode, OrderModel orderModel = OrderModel.Normal)
- {
- this._orderModel = orderModel;
- _isDefautClose = true;
- _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
- GoodsList =
- CacheManager.CacheGoodsBaseInfos.Where((item) => (item.ContainsGoodsSrc & (int)GoodsFromScr.Trade) == (int)GoodsFromScr.Trade)
- .ToList(); ////交易的商品
- GoodsList = GoodsList.Where((item) => ((item.TradeMode != eTradeMode.TRADEMODE_SALE) || (item.TradeMode == eTradeMode.TRADEMODE_SALE && item.GoodsParameters.RunSteps == eRunStep.RUNSTEP_BIDDINGCONTINUOUS))).ToList();
- if (orderBase == null || GoodsList.FirstOrDefault(item => item.GoodsId == orderBase.GoodsId) == null)
- {
- _currentGoods = GoodsList.FirstOrDefault();
- }
- else
- {
- _currentGoods = GoodsList.FirstOrDefault(item => item.GoodsId == orderBase.GoodsId);
- }
- TradeViewModel = CreateCloseViewModel(_currentGoods, orderBase, priceMode, orderModel);
- ShowTradeArea();
- //绑定Popup关联交割商品信息
- SelectGoodsOfPAndX_ItemSource(_currentGoods);
- ShowLockGoods();
- TradeViewModel.ChangeBuySellBackground(orderBase.Direction);
- }
- private void ShowTradeArea()
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- // 没有商品界面是没有办法知道自己显示成什么样子的,所以
- MessengerHelper.DefaultSend(_currentGoods != null, MessengerTokens.TradeLoadGoods);
- }));
- }
- #region 只有传统模式的下单界面,才需要锁商品,除此之外就不需要了,因为其他的模式都是弹出框的下单界面。
- /// <summary>
- /// 判断传统下单方式下的锁商品按钮显示
- /// </summary>
- private void ShowLockGoods()
- {
- if (UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition)
- {
- ShowGoodsLock = true;
- }
- else
- {
- ShowGoodsLock = false;
- }
- LockType = LockType.UnLock;
- }
- /// <summary>
- /// 是否显示锁商品按钮
- /// </summary>
- private bool _showGoodsLock = true;
- public bool ShowGoodsLock
- {
- get { return _showGoodsLock; }
- set { Set(() => ShowGoodsLock, ref _showGoodsLock, value); }
- }
- #endregion
- #region 当前资金账号,用户
- /// <summary>
- /// 当前资金账号
- /// </summary>
- public string CurrentFunAccount
- {
- get
- {
- ulong _currentFunAccount;
- //交易员账号和资金账号不一致
- if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
- UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
- {
- _currentFunAccount = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- }
- else
- {
- //投资者账号和资金账号一致
- _currentFunAccount = UserManager.CurrentTradeAccount.AccountId;
- }
- //string CustomerName = UserManager.CurrentTradeAccount.CustomerName;
- //if (CustomerName.Length > 10)
- //{
- // CustomerName = UserManager.CurrentTradeAccount.CustomerName.Substring(0, 10)+"...";
- //}
- return _currentFunAccount.ToString();
- }
- //set { _currentFunAccount = value; }
- }
- public string CurrentFunAccountNameFormat
- {
- get
- {
- string CustomerName = UserManager.CurrentTradeAccount.CustomerName;
- if (CustomerName.Length > 10)
- {
- CustomerName = UserManager.CurrentTradeAccount.CustomerName.Substring(0, 10) + "...";
- }
- return CustomerName;
- }
- }
- public string CurrentFunAccountName
- {
- get
- {
- string CustomerName = UserManager.CurrentTradeAccount.CustomerName;
- return CustomerName;
- }
- }
- #endregion
- #region 商品列表
- private List<QuoteGoods> _goodsList; //商品列表
- /// <summary>
- /// 商品列表
- /// </summary>
- public List<QuoteGoods> GoodsList
- {
- get { return _goodsList; }
- set
- {
- Set(() => GoodsList, ref _goodsList, value);
- }
- }
- #endregion
- #region 当前选择商品/所属市场【[混合]竞价/即期/竞价全额】
- private QuoteGoods _currentGoods;
- /// <summary>
- /// 当前选择商品
- /// </summary>
- public QuoteGoods CurrentGoods
- {
- get { return _currentGoods; }
- set
- {
- Set(() => CurrentGoods, ref _currentGoods, value);
- if (value != null)
- {
- if (_isDefautClose)
- {
- var holders = UserManager.GetCacheOrders<HoldingOrder>();
- if (holders != null)
- {
- var defaultHolder = holders.FirstOrDefault((item => item.GoodsId == value.GoodsId));
- if (defaultHolder != null)
- {
- TradeViewModel = CreateCloseViewModel(value, defaultHolder);
- return;
- }
- }
- }
- TradeViewModel = CreateTradeModeViewModel(CurrentGoods, _direction);
- //绑定Popup关联交割商品信息
- SelectGoodsOfPAndX_ItemSource(_currentGoods);
- if (!IsVisibilityGoodsOfPAndX)
- {
- IsChecked_IsPopupOpen = false;
- }
- //订阅当前交易选中的商品
- UserManager.CurrentGoodsId = (int) value.GoodsId;
- QuoteProxyHelper.QuoteSubscribe(GoodsFromScr.Trade);
- SelectGoods();
- }
- }
- }
- /// <summary>
- /// 选择商品,报价牌和图表也要联动
- /// </summary>
- private void SelectGoods()
- {
- if (_currentGoods == null) return;
- QuoteGoods quoteGoods = CacheManager.CacheGoodsBaseInfos.Find(g => _currentGoods.GoodsId == g.GoodsId);
- QuoteGoodsForSelectOrder quoteGoodsForSelectOrder = new QuoteGoodsForSelectOrder()
- {
- IsSelect = true,
- QuoteGoods = quoteGoods,
- };
- MessengerHelper.DefaultSend<QuoteGoodsForSelectOrder>(quoteGoodsForSelectOrder, MessengerTokens.SelectGoodsOrderChange);
- }
- private bool _hasGoods = false;
- public bool HasGoods
- {
- get { return _hasGoods; }
- set { Set(() => HasGoods, ref _hasGoods, value); }
- }
- #endregion
- #region 关联P+X配置列表
- private List<RelationperformConfigModel> _relationPerformConfigList = null;
- /// <summary>
- /// 关联P+X配置列表
- /// </summary>
- public List<RelationperformConfigModel> RelationPerformConfigList
- {
- get
- {
- return _relationPerformConfigList;
- }
- set
- {
- Set(() => RelationPerformConfigList, ref _relationPerformConfigList, value);
- }
- }
- #endregion
- #region 隐藏商品配比信息提示
- private Visibility _isVisibility_GoodsScale = Visibility.Visible;
- /// <summary>
- /// 隐藏商品配比信息提示
- /// </summary>
- public Visibility IsVisibility_GoodsScale
- {
- get
- {
- return _isVisibility_GoodsScale;
- }
- set
- {
- Set(() => IsVisibility_GoodsScale, ref _isVisibility_GoodsScale, value);
- }
- }
- #endregion
- #region Popup关联交割商品信息
- private ObservableCollection<GoodsOfPAndX> _goodsOfPAndXInfoList = new ObservableCollection<GoodsOfPAndX>();
- /// <summary>
- /// 选择商品的P+X商品数据源
- /// </summary>
- public ObservableCollection<GoodsOfPAndX> GoodsOfPandXInfoList
- {
- get
- {
- return _goodsOfPAndXInfoList;
- }
- set
- {
- Set(() => GoodsOfPandXInfoList, ref _goodsOfPAndXInfoList, value);
- }
- }
- #endregion
- #region 交易类型
- private TradeBaseViewModel _tradeViewModel;
- public TradeBaseViewModel TradeViewModel
- {
- get { return _tradeViewModel; }
- set
- {
- if (_tradeViewModel != null)
- {
- _tradeViewModel.Cleanup();
- }
- Set(() => TradeViewModel, ref _tradeViewModel, value);
- }
- }
- #endregion
- /// <summary>
- /// 打开窗口时的买卖方向
- /// </summary>
- private Direction _direction;
- public LockType LockType
- {
- get { return ApplicationParameter._LockType; }
- set { Set(() => LockType, ref ApplicationParameter._LockType, value); }
- }
- public RelayCommand LockImageCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- LockType = LockType == LockType.UnLock ? LockType.Lock : LockType.UnLock;
- });
- }
- }
- private TradeBaseViewModel CreateTradeModeViewModel(QuoteGoods goods, Direction direction)
- {
- if (goods != null)
- {
- #region switch goods.GoodsParameters.TradeMode
- switch (goods.TradeMode)
- {
- case eTradeMode.TRADEMODE_MARKETMAKE:
- return new MarketTradeViewModel(goods, direction);
- //case eTradeMode.Full_Transfer:
- // return new BidPayTradeViewModel(goods, direction);
- case eTradeMode.TRADEMODE_BIDDING://竞价
- if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名前=保证金】
- {
- return new BidTradeViewModel(goods, direction);
- }
- else
- {
- return new BidPayTradeViewModel(goods, direction);//所有权
- }
- case eTradeMode.TRADEMODE_LISTING_SELECT://挂牌点选
- goods.formType = eOrderFormType.Listting;
- if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名前=保证金】
- {
- return new TradeListingViewModel(goods, direction);
- }
- else
- {
- return new TradeListingFullViewModel(goods, direction); //所有权不能建空,只能买(建),卖(平)-》有头寸
- }
- //case eTradeMode.TRADEMODE_SALE:
- // return new SaleTradeViewModel(goods, direction);
- //case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
- // //if (goods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN)
- // if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名后】=保证金
- // {
- // return new MixTradeViewModel(goods, direction);
- // }
- // else
- // {
- // return new MixPayTradeViewModel(goods, direction);
- // }
- case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
- //通道交易市场
- return new ChannelTradeViewMode(goods, direction);
- default:
- return new MarketTradeViewModel(goods, direction);
- }
- #endregion
- }
- else
- {
- return null;
- }
- }
- /// <summary>
- /// 持仓汇总平仓调用
- /// </summary>
- /// <param name="goods"></param>
- /// <param name="orderBase"></param>
- /// <param name="priceMode"></param>
- /// <returns></returns>
- private TradeBaseViewModel CreateCloseViewModel(QuoteGoods goods, OrderBase orderBase, ePriceMode priceMode = ePriceMode.PRICEMODE_MARKET, OrderModel orderModel = OrderModel.Normal)
- {
- switch (goods.TradeMode)
- {
- case eTradeMode.TRADEMODE_MARKETMAKE:
- return new MarketTradeViewModel(goods, orderBase);
- //case eTradeMode.Full_Transfer:
- // return new BidPayTradeViewModel(goods, orderBase);
- case eTradeMode.TRADEMODE_BIDDING://无报价商竞价
- if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名前=保证金】
- {
- return new BidTradeViewModel(goods, orderBase);
- }
- else
- {
- return new BidPayTradeViewModel(goods, orderBase);//所有权
- }
- case eTradeMode.TRADEMODE_LISTING_SELECT://挂牌点选
- goods.formType = eOrderFormType.Listting;
- if (goods.TradeProperty == eTradeProperty.TRADEPROPERTY_CANSHORT) //收益权【改名前=保证金】
- {
- return new TradeListingViewModel(goods, orderBase);
- }
- else
- {
- return new TradeListingFullViewModel(goods, orderBase); //所有权不能建空,只能买(建),卖(平)-》有头寸
- }
- //case eTradeMode.TRADEMODE_SALE:
- //case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
- //case eTradeMode.TRADEMODE_BIDDING:
- //case eTradeMode.TRADEMODE_MARKETMAKE:
- // if (priceMode == ePriceMode.PRICEMODE_MARKET)
- // {
- // return new MarketTradeViewModel(goods, orderBase);
- // }
- // else
- // {
- // return new MarketTradeViewModel(goods, orderBase, priceMode);
- // }
- //case eTradeMode.TRADEMODE_BIDDING:
- // if (goods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN)
- // {
- // return new BidTradeViewModel(goods, orderBase);
- // }
- // else
- // {
- // return new BidPayTradeViewModel(goods, orderBase);
- // }
- //case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
- // if (goods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN)
- // {
- // return new MixTradeViewModel(goods, orderBase);
- // }
- // else
- // {
- // return new MixPayTradeViewModel(goods, orderBase);
- // }
- //case eTradeMode.TRADEMODE_SALE:
- // return new SaleTradeViewModel(goods, Direction.Bid);
- case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
- return new ChannelTradeViewMode(goods, orderBase, orderModel);
- default:
- if (priceMode != ePriceMode.PRICEMODE_MARKET)
- {
- return new MarketTradeViewModel(goods, orderBase);
- }
- else
- {
- return new MarketTradeViewModel(goods, orderBase, priceMode);
- }
- }
- }
- #region 【置灰】设置按键不可用
- private bool _oKButtonEnabled = true;
- /// <summary>
- ///设置按键不可用
- /// </summary>
- public bool OKButtonEnabled
- {
- get
- {
- return _oKButtonEnabled;
- }
- set
- {
- Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
- }
- }
- /// <summary>
- /// 传统模式显示确认
- /// </summary>
- public bool IsOKCommandVbs
- {
- get
- {
- return UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition;
- }
- }
- #endregion
- #region 是否忙
- /// <summary>
- /// 是否忙
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- #endregion
- #region "Public Commands"
- #region IsPopupOpenCheckedCommand
- private RelayCommand _isPopupOpenCheckedCommand;
- /// <summary>
- /// Gets the IsPopupOpenCheckedCommand.
- /// </summary>
- public RelayCommand IsPopupOpenCheckedCommand
- {
- get
- {
- return _isPopupOpenCheckedCommand
- ?? (_isPopupOpenCheckedCommand = new RelayCommand(
- () =>
- {
- if (IsChecked_IsPopupOpen)
- {
- IsDeliveryInfoStaysOpen = true;
- IsDeliveryInfoStaysOpen = false;
- IsChecked_IsPopupOpen = false;
- }
- else
- {
- IsDeliveryInfoStaysOpen = false;
- IsChecked_IsPopupOpen = true;
- }
- }));
- }
- }
- #endregion
- #region 窗口改变大小事件
- private RelayCommand _sizeChangedCommand;
- /// <summary>
- /// Gets the SizeChangedCommand.
- /// </summary>
- public RelayCommand SizeChangedCommand
- {
- get
- {
- return _sizeChangedCommand
- ?? (_sizeChangedCommand = new RelayCommand(
- () =>
- {
- if (IsChecked_IsPopupOpen && IsVisibilityGoodsOfPAndX)
- {
- IsChecked_IsPopupOpen = false;
- IsChecked_IsPopupOpen = true;
- }
- else
- {
- IsChecked_IsPopupOpen = false;
- }
- }));
- }
- }
- #endregion
- /// <summary>
- /// 快速下单窗口取消
- /// </summary>
- public RelayCommand<Window> CancelCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- dialog.DialogResult = false;
- });
- }
- }
- /// <summary>
- /// 传统下单
- /// </summary>
- public RelayCommand<int> TradionOKCommand
- {
- get
- {
- return new RelayCommand<int>((i) =>
- {
- if (_currentGoods == null)
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- MessageBoxHelper.ShowQuestion(Client_Resource.GoodsSelect_Vailed,
- Client_Resource.DeliveryOrderView_WarningTipsTitle);
- }));
- return;
- }
- TradeViewModel.Direction = (Direction)i;
-
- OKButtonEnabled = false;
- string errorMsg = string.Empty;
- bool validateBool = TradeViewModel.Validated(ref errorMsg); ////内容验证
- if (validateBool)
- {
- if (ComfirmCheck())
- {
- IsBusy = true;
- TradeViewModel.PostOrder(EntrurstSuccessCallBack, EntrurstErrorCallBack);
- }
- else
- {
- OKButtonEnabled = true;
- }
- }
- else
- {
- MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
- OKButtonEnabled = true;
- if (IsOKCommandVbs) ////传统下单
- {
- MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
- }
- }
- });
- }
- }
- private bool ComfirmCheck()
- {
- var userInfo = UserManager.GetCurrentUserInfo(); ////交易菜单设置
- if (userInfo.TradeParams == null)
- {
- userInfo.TradeParams = new TradeParams();
- }
- var result = true;
- if (userInfo.TradeParams.IsOrderComfrim)
- {
- var comfim = new OrderComfirmModel()
- {
- GoodsName = TradeViewModel.CurrentGoods.Name,
- Lot = TradeViewModel.Lot,
- Direction = TradeViewModel.Direction,
- OrderPrice = TradeViewModel.ExecutePrice,
- };
- var comfirm = new OrderComfirm() { DataContext = comfim, Owner = Application.Current.MainWindow };
- if (comfirm.ShowDialog() != true)
- {
- result = false;
- }
- }
- return result;
- }
- /// <summary>
- /// 下单确定
- /// </summary>
- public RelayCommand<Window> OKCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- OKButtonEnabled = false;
- string errorMsg = string.Empty;
- bool validateBool = TradeViewModel.Validated(ref errorMsg); ////内容验证
- if (validateBool)
- {
- if (ComfirmCheck() && TradeViewModel.CheckProfitLoss()/*新增加的判断,用于止盈止损下单界面,此方法已经有弹出框的提示,true表示放行*/)
- {
- IsBusy = true;
- _openWindow = dialog;
- TradeViewModel.PostOrder(EntrurstSuccessCallBack, EntrurstErrorCallBack);
- }
- else
- {
- OKButtonEnabled = true;
- }
- }
- else
- {
- MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
- OKButtonEnabled = true;
- if (IsOKCommandVbs) ////传统下单
- {
- MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
- }
- }
- });
- }
- }
- #endregion "Public Commands"
- /// <summary>
- /// 提交成功返回
- /// </summary>
- /// <param name="order"></param>
- private void EntrurstSuccessCallBack(OrderDetail order)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- OKButtonEnabled = true;
- CloseOrderWin();
- if (IsOKCommandVbs) ////传统下单
- {
- MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
- }
- }));
- if (TradeViewModel.OrderFlag == OrderMethods.NormalOrder)
- {
- //刷新正常单
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
- //MessengerHelper.DefaultSend(string.Empty, MessengerTokens.UpdateCacheGoodsToken);
- }
- else
- {
- //刷新预埋单
- MessengerHelper.DefaultSend(false, MessengerTokens.PreOrderUpdate);
- }
- //MessengerHelper.DefaultSend(string.Empty, MessengerTokens.OrderRefresh);//下单成功后刷新界面
- }
- /// <summary>
- /// 下单关窗口
- /// </summary>
- private void CloseOrderWin()
- {
- var userInfo = UserManager.GetCurrentUserInfo(); ////交易菜单设置
- if (userInfo.TradeParams == null)
- {
- userInfo.TradeParams = new TradeParams();
- }
- if (userInfo.TradeParams.IsSuccessComfrim) ////下单成功是否提示
- {
- if (OpenCloseMode.BUILDTYPE_CLOSETHENOPEN == TradeViewModel.OpenCloseMode) // 自动开平
- {
- MessageBoxHelper.ShowSuccess("操作成功!",
- Client_Resource.UI2014_Tips);
- }
- else
- {
- MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result,
- Client_Resource.UI2014_Tips);
- }
- }
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- }
- /// <summary>
- /// 委托失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void EntrurstErrorCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- #region 提示失败 也刷新单据
- if (TradeViewModel.OrderFlag == OrderMethods.NormalOrder)
- {
- //刷新正常单
- MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
- }
- else
- {
- //刷新预埋单
- MessengerHelper.DefaultSend(false, MessengerTokens.PreOrderUpdate);
- }
- #endregion
- OKButtonEnabled = true;
- ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
- if (_openWindow != null)
- {
- _openWindow.Close();
- this.Cleanup();
- }
- if (IsOKCommandVbs) ////传统下单
- {
- MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
- MessengerHelper.DefaultSend("", MessengerTokens.OrderChangeToRefeshTrade);// 刷新界面某个值
- }
- }));
- }
- private eDeliveryContractLink _relationMode;
- /// <summary>
- /// 关联模式
- /// </summary>
- public eDeliveryContractLink RelationMode
- {
- get
- {
- return _relationMode;
- }
- set
- {
- Set(() => RelationMode, ref _relationMode, value);
- }
- }
- private string _PDeliveryGoodsName;
- /// <summary>
- /// P交割模式商品
- /// </summary>
- public string PDeliveryGoodsName
- {
- get
- {
- return _PDeliveryGoodsName;
- }
- set
- {
- Set(() => PDeliveryGoodsName, ref _PDeliveryGoodsName, value);
- }
- }
- private string _BelowDeliveryInfoTips = Client_Resource.EntrustOrderView_DeliveryGoodsInfo_BelowIsDeliveryInfo;
- /// <summary>
- /// 交割模式信息提示
- /// </summary>
- public string BelowDeliveryInfoTips
- {
- get
- {
- return _BelowDeliveryInfoTips;
- }
- set
- {
- Set(() => BelowDeliveryInfoTips, ref _BelowDeliveryInfoTips, value);
- }
- }
- public bool IsDeliveryVisible
- {
- get
- {
- return ApplicationParameter.IsDeliveryVisible == 1 && UserManager.IsAccountLogin;
- }
- }
- private bool _isVisibilityGoodsOfPAndX = false;
- /// <summary>
- /// 是否显示P+X商品数据源LIST
- /// </summary>
- public bool IsVisibilityGoodsOfPAndX
- {
- get
- {
- return _isVisibilityGoodsOfPAndX;
- }
- set
- {
- Set(() => IsVisibilityGoodsOfPAndX, ref _isVisibilityGoodsOfPAndX, value);
- }
- }
- #region IsDeliveryInfoStaysOpen
- private bool _isDeliveryInfoStaysOpen = false;
- /// <summary>
- /// Sets and gets the IsDeliveryInfoStaysOpen property.
- /// </summary>
- public bool IsDeliveryInfoStaysOpen
- {
- get
- {
- return _isDeliveryInfoStaysOpen;
- }
- set
- {
- Set(() => IsDeliveryInfoStaysOpen, ref _isDeliveryInfoStaysOpen, value);
- }
- }
- #endregion
- #region 交割信息CheckBox按钮
- private bool _isChecked_IsPopupOpen = false;
- /// <summary>
- /// 交割信息CheckBox按钮
- /// </summary>
- public bool IsChecked_IsPopupOpen
- {
- get
- {
- return _isChecked_IsPopupOpen;
- }
- set
- {
- Set(() => IsChecked_IsPopupOpen, ref _isChecked_IsPopupOpen, value);
- }
- }
- #endregion
- /// <summary>
- /// 绑定关联交割商品信息
- /// </summary>
- /// <param name="goodsItem"></param>
- private void SelectGoodsOfPAndX_ItemSource(QuoteGoods goodsItem)
- {
- GoodsOfPandXInfoList.Clear();
- PDeliveryGoodsName = "";
- IsVisibilityGoodsOfPAndX = false;
- var tempPAndXList = CacheManager.AllDeliveryRelationList.Where(x => x.GoodsId == goodsItem.GoodsId).ToList();
- if (tempPAndXList != null && tempPAndXList.Count() > 0)
- {
- _deliveryService.SearchRelationPerformConfig(tempPAndXList.FirstOrDefault().RelationId, QueryRelationConfigSuccess, null);
- if (IsDeliveryVisible && tempPAndXList.FirstOrDefault().RelationMode != eDeliveryContractLink.None)
- {
- IsVisibilityGoodsOfPAndX = true;
- }
- foreach (var item in tempPAndXList)
- {
- if (string.IsNullOrEmpty(PDeliveryGoodsName))
- {
- IsVisibility_GoodsScale = Visibility.Visible;
- switch (item.RelationMode)
- {
- case eDeliveryContractLink.None:
- PDeliveryGoodsName = "N";
- BelowDeliveryInfoTips = Client_Resource.EntrustOrderView_DeliveryGoodsInfo_BelowIsDeliveryInfoN;
- break;
- case eDeliveryContractLink.Normal:
- PDeliveryGoodsName = "P";
- IsVisibility_GoodsScale = Visibility.Collapsed;
- break;
- case eDeliveryContractLink.PAndX:
- PDeliveryGoodsName = "P+X";
- break;
- }
- }
- if (!GoodsOfPandXInfoList.Any(x => x.GoodsId == item.GoodsId))
- {
- GoodsOfPandXInfoList.Add(new GoodsOfPAndX()
- {
- DeliveryGoodsName = item.deliverygoodsname,
- DeliveryGoodsCode = item.deliverygoodscode,
- RelationGoodsCode = item.RelationGoodscode,
- RelationGoodsName = item.RelationGoodsname,
- RelationGoodsNameCodeDisplay = item.RelationGoodsNameCodeDisplay,
- RelationMode = item.RelationMode,
- GoodsScale = item.GoodsScale,
- GoodsId = item.GoodsId,
- Conversion = item.Conversion,
- Deliverypricemove = item.DeliveryPriceMove,
- //AgreeUnit=item.AgreeUnit,
- GoodsUnitId = item.GoodsId,
- goodsUnitName = item.goodsUnitName,
- BrandList = item.BrandList,
- RankList = item.RankList,
- WarehouseList = item.WarehouseList
- });
- }
- }
- }
- if (!IsVisibilityGoodsOfPAndX)
- {
- IsChecked_IsPopupOpen = false;
- }
- }
- /// <summary>
- /// 设置订单价格
- /// </summary>
- /// <param name="price"></param>
- public void SetOrderPrice(decimal price)
- {
- if (this.TradeViewModel != null)
- {
- TradeViewModel.SetOrderPrice(price);
- }
- }
- public override void Cleanup()
- {
- if (this._tradeViewModel != null)
- {
- _tradeViewModel.Cleanup();
- }
- base.Cleanup();
- }
- /// <summary>
- /// 交割关系配置查询-成功返回
- /// </summary>
- /// <param name="itemList"></param>
- protected void QueryRelationConfigSuccess(List<RelationperformConfigModel> itemList)
- {
- if (itemList != null)
- {
- RelationPerformConfigList = itemList;
- }
- }
- /// <summary>
- /// 是否显示买卖价格的显示区域
- /// </summary>
- public bool ShowBuySellPriceArea
- {
- get { return ApplicationParameter.ShowBuyOrSellPrice; }
- }
- private bool _showOkCancel;
- public bool ShowOkCancel
- {
- get { return _showOkCancel; }
- set { Set(() => ShowOkCancel, ref _showOkCancel, value); }
- }
- }
- }
|