| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //----------------------------------------------------------------
- //Module Name: $safeprojectname$
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime 2016/7/25 10:08:08
- //Author
- //Description Create
- //----------------------------------------------------------------
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.Data.Model.GoodRules;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- namespace Muchinfo.MTPClient.Trade.ViewModels
- {
- public class SaleTradeViewModel :TradeBaseViewModel
- {
- public SaleTradeViewModel(QuoteGoods goods, Direction direction)
- : base(goods, Direction.Bid) //申购目前只有买入
- {
- PriceMode = ePriceMode.PRICEMODE_MARKET;
- ExecutePrice = goods.GoodsParameters.IssuePrice;
- SetMinMaxQtyVaule(); //设置数量
- }
-
- public override void PostOrder(Action<OrderDetail> successAction, Action<ErrorEntity> errorAction)
- {
- var entrustOrder = BuildEntrustOrder();
- entrustOrder.BuildType = OpenCloseMode.BUILDTYPE_OPEN; //发售只建仓
- var saleService = SimpleIoc.Default.GetInstance<ISaleService>();
- saleService.SaleEntrurstOrder(entrustOrder, successAction, errorAction);
-
- }
- public override bool IsPriceModeVisible
- {
- get { return false; }
- }
- /// <summary>
- /// 发售不显示卖
- /// </summary>
- public override bool IsSellVsb
- {
- get { return false; }
- }
- public override string BuyTitle
- {
- get
- {
- return Muchinfo.MTPClient.Resources.Client_Resource.Order_Sale_Buy;
- }
- }
- #region 申购单位
- private decimal _perOrderQty = decimal.Zero;
- /// <summary>
- /// 申购单位
- /// </summary>
- public decimal PerOrderQty
- {
- get
- {
- return _perOrderQty;
- }
- set
- {
- Set(() => PerOrderQty, ref _perOrderQty, value);
- }
- }
- #endregion
- public override bool Validated(ref string msg)
- {
- if (Lot.ToString().Length <= 0 || Lot <= 0 || Lot == decimal.Zero || Lot > MaxLot)
- {
- //数量不在正确范围内
- msg = Muchinfo.MTPClient.Resources.Client_Resource.ErrorNumRange;
- return false;
- }
- if (Lot > MaxLot)
- {
- //msg = "申购数量超过单笔最大申购数量";
- msg = Muchinfo.MTPClient.Resources.Client_Resource.ErrorSaleNum;
- return false;
- }
- if (Lot < MinLot)
- {
- //msg = "申购数量应大于单笔最小申购数量";
- msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Error_SaleNum, MinLot);
- return false;
- }
- if (Lot != 0 && (Lot % PerOrderQty) != 0)
- {
- //数量输入有误!应为{设定申购单位}的倍数.
- msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.SaleOrderViewModel_InputNumShouldBeRight, PerOrderQty);
- return false;
- }
- return true;
- }
- public override bool IsExecutePriceVbs
- {
- get { return true; }
- }
- protected new void SetMinMaxQtyVaule()
- {
- var minQty = _goodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId, _currentGoods.TradeMode, GoodsTradeConts.MINOPENTRADEQTY);
- var maxQty = _goodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId, _currentGoods.TradeMode, GoodsTradeConts.MAXOPENTRADEQTY);
- //NEW 申购单位 【错误 #29137】
- var tempPerOrderQty = _goodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId, _currentGoods.TradeMode, GoodsTradeConts.MinSalePerOrderQty);
- PerOrderQty = tempPerOrderQty.FeeValue;
- MaxLot = maxQty == null ? defaut_maxLot : Math.Round(maxQty.FeeValue, 2, MidpointRounding.AwayFromZero);
- MinLot = minQty == null ? defaut_minLot : Math.Round(minQty.FeeValue, 2, MidpointRounding.AwayFromZero);
- Lot = PerOrderQty;
- var enableOpenNum = GetEnableNum(ExecutePrice); //根据资金算出可建仓数
- enableOpenNum = MinLot == 0 ? enableOpenNum : Math.Floor(enableOpenNum / PerOrderQty) * PerOrderQty; ////下单数量应该为申购单位整数倍
- enableOpenNum = Math.Max(0, enableOpenNum); ////是大于等0
- MaxLot = Math.Min(enableOpenNum, MaxLot);
- MaxLot = Math.Round(MaxLot, 2, MidpointRounding.AwayFromZero);
- MinLot = Math.Round(MinLot, 2, MidpointRounding.AwayFromZero);
-
- }
-
- }
- }
|