| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- 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 Muchinfo.WPF.Controls.Windows;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- namespace Muchinfo.MTPClient.Account.ViewModels
- {
- /// <summary>
- /// This class contains properties that a View can data bind to.
- /// <para>
- /// See http://www.galasoft.ch/mvvm
- /// </para>
- /// </summary>
- public class PrePostDetailViewModel : MarketOrdersBase<PrePostDetail>
- {
- #region "Private Data Members"
- //To declare private service data
- #endregion "Private Data Members"
- #region "Constructor/Initialization"
- /// <summary>
- /// Initializes a new instance of the PrePostDetailViewModel class.
- /// </summary>
- public PrePostDetailViewModel()
- {
- MessengerHelper.DefaultRegister<TradeTreeMenu>(this, MessengerTokens.CancalOrder, (e) =>
- {
- CancelHoldingCammand.Execute(null);
- });
- }
- #endregion "Constructor/Initialization"
- #region "Interface implementation Or override"
- public override string SearchOrderCountId
- {
- get { return QueryStatement.SearchAllPrePostOrderCount; }
- }
- /// <summary>
- /// 单据注册消息
- /// </summary>
- public override void RegisterMessage()
- {
- base.RegisterMessage();
- //当选择时刷新
- var cacheData = UserManager.GetTradeCacheData(UserManager.CurrentTradeAccount.AccountId);
- if (!cacheData.OpenPrePostOrderFlag)
- {
- RefreshCommand.Execute(null);
- }
- else
- {
- UpdateOrders();
- }
- MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.PreOrderNoticeToken);
- MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.PreOrderNoticeToken, (e) =>
- {
- //下单成功后刷新预埋单界面
- RefreshCommand.Execute(null);
- });
- }
- public override void QueryMarketOrder(eTradeMode marketType)
- {
- if (marketType == eTradeMode.TRADEMODE_SALE)
- {
- return;
- }
- IsBusy = true;
- var queryCommonParams = new List<QueryCommonParam>();
- var accountid = UserManager.CurrentTradeAccount.AccountId;
- //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any())
- //{
- // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- //}
- queryCommonParams.Add(new QueryCommonParam() { ParamKey = "accountId", ParamValue = accountid + string.Empty });
- _orderService.QueryPrePostOrders(marketType, queryCommonParams, MarketOrderSuccess, QueryErrorCallback);
- }
- protected override void MarketOrderSuccess(eTradeMode marketType, List<PrePostDetail> orders)
- {
- IsBusy = false;
- UpdateOrders();
- base.MarketOrderSuccess(marketType, orders);
- }
- public override void UnRegisterMessage()
- {
- MessengerHelper.DefaultUnregister<TradeAccount>(this, MessengerTokens.OrderNotify);
- base.UnRegisterMessage();
- }
- /// <summary>
- /// 创建预埋单对象
- /// </summary>
- /// <returns></returns>
- public virtual NewEntrustOrder BuildEntrustOrder()
- {
- var entrustOrder = new NewEntrustOrder()
- {
- OperaterId = UserManager.CurrentTradeAccount.AccountId,
- TriggerType = (uint)CurrentLimitOrder.TriggerType,
- TriggerPrice = CurrentLimitOrder.TriggerPrice,
- GoodsCode = CurrentLimitOrder.goodscode,
- GoodsId = (uint)CurrentLimitOrder.GoodsId,
- BuyOrSell = CurrentLimitOrder.BuyOrSell,
- OrderFlag = (uint)OrderMethods.PreOrder,
- EntrustPrice = CurrentLimitOrder.orderprice,
- EntrustQuantity = CurrentLimitOrder.orderqty,
- BuildType = OpenCloseMode.BUILDTYPE_OPEN,
- EntrurstTime = ApplicationParameter.ServerTimeNow,
- //RelationTicket = CurrentLimitOrder.PreOrderId,
- };
- //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
- // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
- //{
- // entrustOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
- //}
- //else
- //{
- // entrustOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
- //}
- return entrustOrder;
- }
- #endregion "Interface implementation Or override"
- #region "Public Properties To Get/Set "
- #region 当前选择的预埋单单
- private PrePostDetail _currentLimitOrder;
- /// <summary>
- /// 当前选择的预埋单单
- /// </summary>
- public PrePostDetail CurrentLimitOrder
- {
- get { return _currentLimitOrder; }
- set
- {
- Set(() => CurrentLimitOrder, ref _currentLimitOrder, value);
- }
- }
- #endregion
- #endregion "Public Properties To Get/Set "
- #region "Public Commands"
- private RelayCommand<PrePostDetail> _dataGridMouseEnter;
- /// <summary>
- /// 多个DataGird中改变当前选中的CurrentHoldingSummaryItem
- /// </summary>
- public RelayCommand<PrePostDetail> DataGridMouseEnter
- {
- get
- {
- return _dataGridMouseEnter
- ?? (_dataGridMouseEnter = new RelayCommand<PrePostDetail>(
- p =>
- {
- if (p != null)
- {
- CurrentLimitOrder = p;
- }
- }));
- }
- }
- /// <summary>
- /// 撤销预埋单
- /// </summary>
- public RelayCommand CancelHoldingCammand
- {
- get
- {
- return new RelayCommand(() =>
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- if (CurrentLimitOrder == null) return;
- long orderNumber = CurrentLimitOrder.PreOrderId;
- var boxResult = MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.Models_MakesureCancel + orderNumber + Muchinfo.MTPClient.Resources.Client_Resource.Models_Bill,
- Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips);
- if (boxResult == MessageBoxResult.Yes)
- {
- IsBusy = true;
- PostCancelOrder();
- }
- }));
- }, () => CanCancelOrderDetial());
- }
- }
- #endregion "Public Commands"
- #region "Private Methods"
- /// <summary>
- /// 更新当前单据
- /// </summary>
- private void UpdateOrders()
- {
- OrderSource = UserManager.GetMarketCommonOrder<PrePostDetail>(UserManager.CurrentTradeAccount);
- if (OrderSource != null && OrderSource.Any())
- {
- DicOrderCount[CurrentTradeMode] = OrderSource[CurrentTradeMode].Count;
- }
- else
- {
- var dicCountZero = new Dictionary<eTradeMode, int>();
- foreach (var marketType in MarketTypes)
- {
- dicCountZero[marketType] = 0;
- }
- DicOrderCount = dicCountZero;
- }
- //if (OrderSource != null && OrderSource.Any())
- //{
- // var dicCount = new Dictionary<eTradeMode, int>();
- // foreach (var marketType in MarketTypes)
- // {
- // if (OrderSource.ContainsKey(marketType))
- // {
- // dicCount[marketType] = OrderSource[marketType].Count;
- // }
- // else
- // {
- // dicCount[marketType] = 0;
- // }
- // }
- // DicOrderCount = dicCount;
- //}
- //else
- //{
- // var dicCountZero = new Dictionary<eTradeMode, int>();
- // foreach (var marketType in MarketTypes)
- // {
- // dicCountZero[marketType] = 0;
- // }
- // DicOrderCount = dicCountZero;
- //}
- }
- /// <summary>
- /// 提交成功返回
- /// </summary>
- /// <param name="order"></param>
- private void EntrurstSuccessCallBack(OrderDetail order)
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- MessageBoxHelper.ShowSuccess(Muchinfo.MTPClient.Resources.Client_Resource.Account_CancelSuccess,
- Client_Resource.Cancel_MessageBox_Title);
- IsBusy = false;
- }));
- //刷新预埋单
- MessengerHelper.DefaultSend(false, MessengerTokens.PreOrderUpdate);
- }
- /// <summary>
- /// 委托失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void EntrurstErrorCallBack(ErrorEntity errorEntity)
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
- IsBusy = false;
- }));
- }
- #endregion "Private Methods"
- #region "Other Methods like Validated"
- //public void QueryComplateOrderSuccessCallback(List<PrePostDetail> prePostOrders)
- //{
- // IsBusy = false;
- // UpdateOrders();
- //}
- /// <summary>
- /// 是否可撤单
- /// </summary>
- /// <returns></returns>
- public bool CanCancelOrderDetial()
- {
- if (_currentLimitOrder == null)
- {
- return false;
- }
- return (_currentLimitOrder.OrderStatus == PrepostStatus.PREPOST_STATUS_MARKET );
- }
- /// <summary>
- /// 发送撤单命令
- /// </summary>
- /// <param name="limitOrder">撤消的单据</param>
- /// <returns>错误代码</returns>
- public void PostCancelOrder()
- {
- var order = BuildEntrustOrder();
- var currentGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault(
- (goods) => goods.GoodsParameters.GoodsId == CurrentLimitOrder.GoodsId);
- if (currentGoods == null) { return; }
- switch (currentGoods.TradeMode)
- {
- //case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
- //_orderService.MixMarketEntrustOrder(order, EntrurstSuccessCallBack, EntrurstErrorCallBack);
- //break;
- case eTradeMode.TRADEMODE_BIDDING:
- //_orderService.BidMarketEntrustOrder(order, EntrurstSuccessCallBack, EntrurstErrorCallBack);
- //break;
- case eTradeMode.TRADEMODE_MARKETMAKE:
- _orderService.MakeMarketEntrustOrder(order, EntrurstSuccessCallBack, EntrurstErrorCallBack);
- break;
- //case eTradeMode.TRADEMODE_SALE:
- // var isaleService = SimpleIoc.Default.GetInstance<ISaleService>();
- // isaleService.SaleEntrurstOrder(order, EntrurstSuccessCallBack, EntrurstErrorCallBack);
- // break;
- default:
- break;
- }
- }
- #endregion "Other Methods like Validated"
- }
- }
|