using System.Text; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; 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.Data.Model.Delivery; using Muchinfo.MTPClient.Infrastructure.Cache; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.MTPClient.Resources; using System; using System.Collections.Generic; using System.Linq; using System.Timers; using System.Windows; namespace Muchinfo.MTPClient.Delivery.ViewModels { /// /// 交割申报 /// public class DeliveryOrderViewModel : ViewModelBase { #region "Private Data Members" private Window _openWindow; ///下单窗口 private IDeliveryService _deliveryService; private IGoodsService _goodsService; private eDeliveryContractLink _currentLinkModel; private eMoneyMode _currentMoneyMode; private long _currentDeliveryGoodsId;//当前交割商品ID private decimal tempOtherCanMatchQty; private decimal usableFunds = UserManager.CurrentAccountUsableFunds(); private DeliveryOrderMessage _parameterInfo; #endregion "Private Data Members" #region "Constructor/Initialization" /// /// 构造函数 /// public DeliveryOrderViewModel() { this._parameterInfo = null; _deliveryService = SimpleIoc.Default.GetInstance(); _goodsService = SimpleIoc.Default.GetInstance(); // 初始化交割商品列表数据 InitData(); } public DeliveryOrderViewModel(DeliveryOrderMessage info) { this._parameterInfo = info; _deliveryService = SimpleIoc.Default.GetInstance(); _goodsService = SimpleIoc.Default.GetInstance(); // 初始化交割商品列表数据 InitData(); if (_parameterInfo != null && _parameterInfo.GoodsId > 0) { BuyOrSell = _parameterInfo.Direction; } } #endregion "Constructor/Initialization" #region "Interface implementation Or override" //To do interface implementation #endregion "Interface implementation Or override" #region "Public Properties To Get/Set " #region 当前账号提货人信息 private DepositPersonalInfoRspModel _currentDepositPersonalInfo; /// /// 当前账号提货人信息 /// public DepositPersonalInfoRspModel CurrentDepositPersonalInfo { get { return _currentDepositPersonalInfo; } set { Set(() => CurrentDepositPersonalInfo, ref _currentDepositPersonalInfo, value); } } #endregion #region 收货人 private string _RecievePerson = string.Empty; /// /// 收货人 /// public string RecievePerson { get { return _RecievePerson; } set { Set(() => RecievePerson, ref _RecievePerson, value); } } #endregion #region 收货地址 private string _RecieveAddress = string.Empty; /// /// 收货地址 /// public string RecieveAddress { get { return _RecieveAddress; } set { Set(() => RecieveAddress, ref _RecieveAddress, value); } } #endregion #region 联系方式 private string _PhoneNum = string.Empty; /// /// 联系方式 /// public string PhoneNum { get { return _PhoneNum; } set { Set(() => PhoneNum, ref _PhoneNum, value); } } #endregion #region 联系方式 private string _IdCardNum = string.Empty; /// /// 联系方式 /// public string IdCardNum { get { return _IdCardNum; } set { Set(() => IdCardNum, ref _IdCardNum, value); } } #endregion //------以下为卖交割相关------------------------ #region 剩余可配对数量 /// /// 剩余可配对数量 /// private decimal preOtherCanMatchQty = 0; private decimal _otherCanMatchQty = 0; /// /// 剩余可配对数量 /// public decimal OtherCanMatchQty { get { return _otherCanMatchQty; } set { value = Math.Round(value, 0); Set(() => OtherCanMatchQty, ref _otherCanMatchQty, value); } } #endregion #region 已配对数量 private decimal _aleadyMatchQty = 0; /// /// 已配对数量 /// public decimal AlreadyMatchQty { get { return _aleadyMatchQty; } set { value = Math.Round(value, 0); Set(() => AlreadyMatchQty, ref _aleadyMatchQty, value); } } #endregion #region 显示当卖交割 private Visibility _isVisibilitySellModel_Show = Visibility.Collapsed; /// /// 显示卖交割 /// public Visibility IsVisibilitySellModel_Show { get { return _isVisibilitySellModel_Show; } set { Set(() => IsVisibilitySellModel_Show, ref _isVisibilitySellModel_Show, value); } } #endregion #region 隐藏当卖交割 private Visibility _isVisibilitySellModel = Visibility.Collapsed; /// /// 隐藏卖交割 /// public Visibility IsVisibilitySellModel { get { return _isVisibilitySellModel; } set { Set(() => IsVisibilitySellModel, ref _isVisibilitySellModel, value); } } #endregion #region 是否隐藏持仓价格 private Visibility _isVisibilityHolderPrice = Visibility.Collapsed; /// /// Sets and gets the IsVisibilityFrezzMoney property. /// Changes to that property's value raise the PropertyChanged event. /// public Visibility IsVisibilityHolderPrice { get { return _isVisibilityHolderPrice; } set { Set(() => IsVisibilityHolderPrice, ref _isVisibilityHolderPrice, value); } } #endregion #region 申报仓单配对列表 public List TempDeliveryMatchOrderList = new List(); private List _deliveryMatchOrderList = new List(); /// /// 申报仓单配对列表 /// public List DeliveryMatchOrderList { get { return _deliveryMatchOrderList; } set { Set(() => DeliveryMatchOrderList, ref _deliveryMatchOrderList, value); } } #endregion #region 当前勾选单据LIST private List _currentSelectedWrDetail = null; /// /// 当前勾选的仓单配对 /// public List CurrentSelectedWrDetail { get { return _currentSelectedWrDetail; } set { Set(() => CurrentSelectedWrDetail, ref _currentSelectedWrDetail, value); } } #endregion #region 买方向是否可用 private bool _isBuyEnable = true; /// /// Sets and gets the IsBuyEnable property. /// public bool IsBuyEnable { get { return _isBuyEnable; } set { Set(() => IsBuyEnable, ref _isBuyEnable, value); } } #endregion #region 卖方向是否可用 private bool _IsSellEnable = true; /// /// 卖方向是否可用 /// public bool IsSellEnable { get { return _IsSellEnable; } set { Set(() => IsSellEnable, ref _IsSellEnable, value); } } #endregion #region 买卖方向 private Direction _buyOrSell = Direction.Bid; /// /// Sets and gets the BuyOrSell property. /// public Direction BuyOrSell { get { return _buyOrSell; } set { Set(() => BuyOrSell, ref _buyOrSell, value); if (value == Direction.unSet) { value = Direction.Bid; } SetDeliveryCount(); } } #endregion //------以上为卖交割相关------------------------ #region 关联交易商品-错误信息提示 private string _relationGoodsErrorMsg = string.Empty;//Client_Resource.DeliveryOrderView_RelationGoodsInfoNotFound; /// /// 错误信息提示 /// public string RelationGoodsErrorMsg { get { return _relationGoodsErrorMsg; } set { Set(() => RelationGoodsErrorMsg, ref _relationGoodsErrorMsg, value); } } #endregion #region 合计冻结货款[保证金、全额] private string _totalFreezenMoneyText = Client_Resource.DeliveryOrderView_FreezeDeliveryMoney; /// /// 合计冻结货款[保证金、全额] /// public string TotalFreezenMoneyText { get { return _totalFreezenMoneyText; } set { Set(() => TotalFreezenMoneyText, ref _totalFreezenMoneyText, value); } } #endregion #region 温馨提示内容 private string _warningTips = Client_Resource.DeliveryOrderView_WarningTips; /// /// 温馨提示内容 /// public string WarningTips { get { return _warningTips; } set { Set(() => WarningTips, ref _warningTips, value); } } #endregion #region 错误信息提示 private string _errorMsg = Client_Resource.DeliveryOrderView_MinMaxErrVisibility; /// /// 错误信息提示 /// public string ErrorMsg { get { return _errorMsg; } set { Set(() => ErrorMsg, ref _errorMsg, value); } } #endregion #region 交割关系表LIST private List _goodsDeliveryRelationList; public List GoodsDeliveryRelationList { get { return _goodsDeliveryRelationList; } set { _goodsDeliveryRelationList = value; } } #endregion #region 窗体标题 private string _title = string.Empty; /// /// 窗体标题 /// Changes to that property's value raise the PropertyChanged event. /// public string Title { get { return _title = Client_Resource.DeliveryOrderView_DeliveryDeclaration; } //set //{ // Set(() => Title, ref _title, value); //} } #endregion #region 交割商品列表 private List _deliveryGoodsList; /// /// 交割商品列表 /// public List DeliveryGoodsList { get { return _deliveryGoodsList; } set { Set(() => DeliveryGoodsList, ref _deliveryGoodsList, value); } } #endregion #region 持仓数量 private decimal _holdCount = 0; /// /// 当前商品持仓数量 /// public decimal HoldCount { get { return _holdCount; } set { Set(() => HoldCount, ref _holdCount, value); } } #endregion #region 申报数量 private decimal _deliveryCount = 0; /// /// 申报数量 /// public decimal DeliveryCount { get { return _deliveryCount; } set { Set(() => DeliveryCount, ref _deliveryCount, value); if (BuyOrSell == Direction.Ask) { RollBackMatchOrderList(); } DeliveryRelationInfoTrigger(); DeliveryCountEvent(); } } #endregion #region 合约单位名称枚举-交易商品 /// /// 合约单位名称枚举-交易商品 /// public string AgreeUnitType { get { if (CurrentGoods == null) { return string.Empty; } return CacheManager.TradeGoodsUnit.Where(x => x.UNITID == CurrentGoods.currentGoodsunit).Select(x => x.GOODSUNITNAME).FirstOrDefault(); } } #endregion #region 合约单位名称枚举-交割商品 private string _deliveryAgreeUnitType = string.Empty; /// /// 合约单位名称枚举-交割商品 /// public string DeliveryAgreeUnitType { get { return _deliveryAgreeUnitType; } set { Set(() => DeliveryAgreeUnitType, ref _deliveryAgreeUnitType, value); } } #endregion #region 冻结头寸数量 /// /// 冻结头寸数量 /// private decimal _positionFzQty; /// /// 冻结头寸数量 /// public decimal PositionFzQty { get { return _positionFzQty; } set { _positionFzQty = value; } } #endregion #region 冻结货款=交易货款+差价款 /// /// 冻结货款=交易货款+申报数量/兑换系数*交割合约单位*差价升贴水 /// 交易货款(保证金)=解占用扣全款 /// 交易货款(全款)=交割申报手数*持仓单对应的持仓金额 /// private decimal _freezeDeliveryMoney = decimal.Zero; /// /// 冻结货款 /// public decimal FreezeDeliveryMoney { get { return _freezeDeliveryMoney; } set { Set(() => FreezeDeliveryMoney, ref _freezeDeliveryMoney, value); RaisePropertyChanged(() => FreezeDeliveryMoneyFormat); } } /// /// 冻结货款 -格式化 /// public string FreezeDeliveryMoneyFormat { get { return FreezeDeliveryMoney.ToString("f2"); } } #endregion #region P交易商品冻结交易货款 private decimal _freezeTradeMoney = decimal.Zero; /// /// P交易商品冻结交易货款 /// public decimal FreezeTradeMoney { get { return _freezeTradeMoney; } set { Set(() => FreezeTradeMoney, ref _freezeTradeMoney, value); RaisePropertyChanged(() => FreezeTradeMoneyFormat); RaisePropertyChanged(() => FreezeTradeMoneyTooltip); } } /// /// 冻结交易货款 -格式化 /// public string FreezeTradeMoneyFormat { get { return FreezeTradeMoney.ToString("f2"); } } /// /// 冻结交易货款提示 /// public string FreezeTradeMoneyTooltip { get { var TempItem = CurrentGoodsDeliveryRelation; if (TempItem != null) { var sbBuilder = new StringBuilder(); decimal pfreeze = 0m; if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN) { //交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 关联交易商品合约单位-(单手占用资金 * 申报数量) sbBuilder.AppendLine(Muchinfo.MTPClient.Resources.Client_Resource.PGoods_FreezeTradeMoneyTooltip); pfreeze = DeliveryCount * Math.Round(DeliveryPrice, 2, MidpointRounding.AwayFromZero) * CurrentGoods.currentAgreeunit; sbBuilder.AppendLine( string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Calc_FreezeTradeMoneyTooltip, Math.Round(pfreeze, 2, MidpointRounding.AwayFromZero), DeliveryCount, DeliveryPriceFormat, CurrentGoods.currentAgreeunit)); } if (TempItem.RelationMode == eDeliveryContractLink.PAndX)//&& CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN { var RelationGoodsItem = FindRelationGoodsInfoByID(TempItem.RelationGoodsId); if (RelationGoodsItem != null && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN) { //关联交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 关联交易商品合约单位 sbBuilder.AppendLine(Muchinfo.MTPClient.Resources.Client_Resource.XGoods_FreezeTradeMoneyTooltip); var xfreeze = DeliveryCount * Math.Round(RelationGoodsHoldPrice, 2, MidpointRounding.AwayFromZero) * RelationGoodsItem.RelationAgreeunit; sbBuilder.AppendLine( string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Calc_FreezeTradeMoneyTooltip, Math.Round(xfreeze, 2, MidpointRounding.AwayFromZero), DeliveryCount, RelationGoodsHoldPriceFormat, RelationGoodsItem.RelationAgreeunit)); if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN) { sbBuilder.AppendLine(Muchinfo.MTPClient.Resources.Client_Resource.Sum_FreezeTradeMoneyTooltip); sbBuilder.AppendLine(string.Format("{0} ={1} + {2}", Math.Round(pfreeze + xfreeze, 2, MidpointRounding.AwayFromZero), Math.Round(pfreeze, 2, MidpointRounding.AwayFromZero), Math.Round(xfreeze, 2, MidpointRounding.AwayFromZero))); } } } return sbBuilder.ToString(); } return string.Empty; } } #endregion #region X交易商品冻结交易货款 private decimal _freezeDeliveryTradeMoney = decimal.Zero; /// /// X交易商品冻结交易货款 /// public decimal FreezeDeliveryTradeMoney { get { return _freezeDeliveryTradeMoney; } set { Set(() => FreezeDeliveryTradeMoney, ref _freezeDeliveryTradeMoney, value); RaisePropertyChanged(() => FreezeDeliveryTradeMoneyFormat); } } /// /// 交割商品冻结交易货款 -格式化 /// public string FreezeDeliveryTradeMoneyFormat { get { return FreezeDeliveryTradeMoney.ToString("f2"); } } #endregion #region 冻结差价款 private decimal _freezePriceMoveMoney = decimal.Zero; /// /// 冻结差价款 /// public decimal FreezePriceMoveMoney { get { return _freezePriceMoveMoney; } set { Set(() => FreezePriceMoveMoney, ref _freezePriceMoveMoney, value); RaisePropertyChanged(() => FreezePriceMoveMoneyFormat); RaisePropertyChanged(() => FreezePriceMoveMoneyTooltip); } } /// /// 冻结差价款 -格式化 /// public string FreezePriceMoveMoneyFormat { get { return FreezePriceMoveMoney.ToString("f2"); } } /// /// 冻结差价款提示 /// public string FreezePriceMoveMoneyTooltip { get { // var TempItem = tempDeliveryConfigList.FirstOrDefault(); var TempItem = CurrentGoodsDeliveryRelation; //差价款=申报数量/兑换系数*交割合约单位*差价升贴水 //FreezePriceMoveMoney = _deliveryCount / TempItem.Conversion * TempItem.AgreeUnit * TempItem.DeliveryPriceMove; if (TempItem != null) { return string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Deliviery_FreezePriceMoveMoneyTip, Math.Round(FreezePriceMoveMoney, 2, MidpointRounding.AwayFromZero), DeliveryCount, TempItem.Conversion, TempItem.currentAgreeunit, TempItem.DeliveryPriceMove); } return string.Empty; } } #endregion #region 交割价格 private decimal _deliveryPrice = decimal.Zero; /// /// 交割价格 /// Changes to that property's value raise the PropertyChanged event. /// public decimal DeliveryPrice { get { return _deliveryPrice; } set { Set(() => DeliveryPrice, ref _deliveryPrice, value); RaisePropertyChanged(() => DeliveryPriceFormat); } } /// /// 交割价格-格式化 /// public string DeliveryPriceFormat { get { if (DeliveryPrice > decimal.Zero) { return DeliveryPrice.ToString("f2"); } else { return "-"; } } } #endregion #region 交割价格-类型【0持仓价-1结算价-2协议价-3最新价】 private string _deliveryPriceTypeDisplay = string.Empty; /// /// 交割价格-类型【0持仓价-1结算价-2协议价-3最新价】 /// Changes to that property's value raise the PropertyChanged event. /// public string DeliveryPriceTypeDisplay { get { return _deliveryPriceTypeDisplay; } set { Set(() => DeliveryPriceTypeDisplay, ref _deliveryPriceTypeDisplay, value); } } #endregion #region 最小交割数量 private decimal _minDeliveryUnit = 1; /// /// 最小交割数量 /// public decimal MinDeliveryUnit { get { return _minDeliveryUnit; } set { Set(() => MinDeliveryUnit, ref _minDeliveryUnit, value); } } #endregion #region 最大交割数量 private decimal _maxDeliveryUnit = 1; /// /// 最大交割数量 /// public decimal MaxDeliveryUnit { get { return _maxDeliveryUnit; } set { Set(() => MaxDeliveryUnit, ref _maxDeliveryUnit, value); } } #endregion #region 交易规则转换单位 private string _tradeRuleTrans = string.Empty; /// /// 交易规则转换单位 /// public string TradeRuleTrans { get { return _tradeRuleTrans; } set { Set(() => TradeRuleTrans, ref _tradeRuleTrans, value); } } #endregion #region 是否显示交易规则转换单位 private Visibility _isVisibilityTradeRule = Visibility.Collapsed; /// /// 是否显示交易规则转换单位 /// public Visibility IsVisibilityTradeRule { get { return _isVisibilityTradeRule; } set { Set(() => IsVisibilityTradeRule, ref _isVisibilityTradeRule, value); } } #endregion #region 是否隐藏冻结资金 private Visibility _isVisibilityFreezeMoney = Visibility.Collapsed; /// /// Sets and gets the IsVisibilityFrezzMoney property. /// Changes to that property's value raise the PropertyChanged event. /// public Visibility IsVisibilityFreezeMoney { get { return _isVisibilityFreezeMoney; } set { Set(() => IsVisibilityFreezeMoney, ref _isVisibilityFreezeMoney, value); } } #endregion #region 是否隐藏交易货款 private Visibility _isVisibilityDeliveryTradeMoney = Visibility.Collapsed; /// /// Sets and gets the IsVisibilityMoneryModeMargin property. /// public Visibility IsVisibilityDeliveryTradeMoney { get { return _isVisibilityDeliveryTradeMoney; } set { Set(() => IsVisibilityDeliveryTradeMoney, ref _isVisibilityDeliveryTradeMoney, value); } } #endregion #region 当前选择交易商品 private GoodsDeliveryRelationModel _currentGoods; /// /// 当前选择交易商品 /// public GoodsDeliveryRelationModel CurrentGoods { get { return _currentGoods; } set { Set(() => CurrentGoods, ref _currentGoods, value); if (_currentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN) { //if (FreezeTradeMoney > decimal.Zero) IsVisibilityDeliveryTradeMoney = Visibility.Visible; //保证金开启冻结:提示,温馨提示 和全额保存一致 20161228 // WarningTips = Client_Resource.DeliveryOrderView_WarningTips_MONEYMODE_MARGIN; // TotalFreezenMoneyText = Client_Resource.DeliveryOrderView_FreezeDeliveryMoney_MONEYMODE_MARGIN; } else { IsVisibilityDeliveryTradeMoney = Visibility.Collapsed; //WarningTips = Client_Resource.DeliveryOrderView_WarningTips; //TotalFreezenMoneyText = Client_Resource.DeliveryOrderView_FreezeDeliveryMoney; } if (BuyOrSell == Direction.Ask) { RollBackMatchOrderList(); } //BuyOrSell = Direction.Bid;//重置买方向 SetDeliveryCount(); } } #endregion #region 当前商品的持仓单 private List _holdDetails; /// /// 当前商品的持仓单 /// public List HoldDetails { get { return _holdDetails; } set { Set(() => HoldDetails, ref _holdDetails, value); } } #endregion #region 持仓汇总 /// /// 持仓汇总 /// private decimal _totalHoldDetails; /// /// 持仓汇总 /// public decimal TotalHoldDetails { get { return _totalHoldDetails; } set { Set(() => TotalHoldDetails, ref _totalHoldDetails, value); } } #endregion #region 填写范围错误提示 private Visibility _MinMaxErrVisibility = Visibility.Hidden; /// /// 填写范围错误提示 /// public Visibility MinMaxErrVisibility { get { //if (MinMaxDeliNumVisibility != Visibility.Visible) //{ // _MinMaxErrVisibility = Visibility.Visible; //} return _MinMaxErrVisibility; } } #endregion #region 是否显示填写范围 private Visibility _minMaxDeliNumVisibility = Visibility.Visible; /// /// 是否显示填写范围 /// public Visibility MinMaxDeliNumVisibility { get { if (AvailHoldQty > 0 && MinDeliveryUnit <= MaxDeliveryUnit) { _minMaxDeliNumVisibility = Visibility.Visible; _MinMaxErrVisibility = Visibility.Hidden; } else //if(AvailHoldQty <= 0) { _minMaxDeliNumVisibility = Visibility.Hidden; _MinMaxErrVisibility = Visibility.Visible; } RaisePropertyChanged(() => MinMaxErrVisibility); return _minMaxDeliNumVisibility; } } #endregion #region 可用持仓数量 private decimal _availHoldQty = decimal.Zero; /// /// 可用持仓数量 /// public decimal AvailHoldQty { get { return _availHoldQty; } set { Set(() => AvailHoldQty, ref _availHoldQty, value); } } #endregion #region 当前持仓明细表 //private HoldingOrder _selectOrder; ///// ///// 当前持仓明细表商品 ///// //public HoldingOrder SelectOrder //{ // get { return _selectOrder; } // set // { // Set(() => SelectOrder, ref _selectOrder, value); // if (value != null) // { // //当前持仓可用数量 // DeliveryCount = HoldCount = SelectOrder.AvailQty; // } // } //} #endregion #region 申报数量-转交割数量 private decimal _relationNum = decimal.Zero; /// /// 申报数量-转交割数量 /// public decimal RelationNum { get { return _relationNum; } set { Set(() => RelationNum, ref _relationNum, value); RaisePropertyChanged(() => RelationNumDisplay); } } /// /// 申报数量-转交割数量-格式化 /// public string RelationNumDisplay { get { return RelationNum.ToString("f2"); } } #endregion #region 【置灰】设置按键不可用 private bool _oKButtonEnabled = true; /// ///设置按键不可用 /// public bool OKButtonEnabled { get { return _oKButtonEnabled; } set { Set(() => OKButtonEnabled, ref _oKButtonEnabled, value); } } #endregion #region 是否忙 private bool _isBusy; /// /// 是否忙 /// public bool IsBusy { get { return _isBusy; } set { Set(() => IsBusy, ref _isBusy, value); } } #endregion #region 服务忙提示 private string _busyTips; /// /// 服务忙提示 /// public string BusyTips { get { return _busyTips; } set { Set(() => BusyTips, ref _busyTips, value); } } #endregion #region 错误信息提示 private string _ShowErrorInfo = string.Empty; /// /// Sets and gets the ShowErrorInfo property. /// public string ShowErrorInfo { get { return _ShowErrorInfo; } set { Set(() => ShowErrorInfo, ref _ShowErrorInfo, value); } } private Visibility _IsShowErrorInfo = Visibility.Collapsed; /// /// Sets and gets the IsShowErrorInfo property. /// public Visibility IsShowErrorInfo { get { return _IsShowErrorInfo; } set { Set(() => IsShowErrorInfo, ref _IsShowErrorInfo, value); } } #endregion #region 当前交割配置明细/当前交割配置List public List tempDeliveryConfigList = new List(); private DeliveryConfig _currentDeliveryGoodsConfig = null; /// /// 当前交割配置明细 /// Changes to that property's value raise the PropertyChanged event. /// public DeliveryConfig CurrentDeliveryGoodsConfig { get { return _currentDeliveryGoodsConfig; } set { Set(() => CurrentDeliveryGoodsConfig, ref _currentDeliveryGoodsConfig, value); } } public List tempGoodsDeliveryRelationList = new List(); private GoodsDeliveryRelationModel _currentGoodsDeliveryRelation = null; /// /// 当前交割配置明细 /// Changes to that property's value raise the PropertyChanged event. /// public GoodsDeliveryRelationModel CurrentGoodsDeliveryRelation { get { return _currentGoodsDeliveryRelation; } set { Set(() => CurrentGoodsDeliveryRelation, ref _currentGoodsDeliveryRelation, value); } } #endregion #region 可申报数量 private int _canDeliveryCount = 0; /// /// 可申报数量 /// Changes to that property's value raise the PropertyChanged event. /// public int CanDeliveryCount { get { return _canDeliveryCount; } set { Set(() => CanDeliveryCount, ref _canDeliveryCount, value); } } #endregion #region 是否隐藏关联交易商品[P+X] private Visibility _isVisibilityRelationGoodsInfo = Visibility.Collapsed; /// /// 是否隐藏关联交易商品[P+X] /// public Visibility IsVisibilityRelationGoodsInfo { get { return _isVisibilityRelationGoodsInfo; } set { Set(() => IsVisibilityRelationGoodsInfo, ref _isVisibilityRelationGoodsInfo, value); } } #endregion #region 关联交易商品名称[P+X] private string _relationGoods = string.Empty; /// /// 关联交易商品名称[P+X] /// public string RelationGoodsName { get { return _relationGoods; } set { Set(() => RelationGoodsName, ref _relationGoods, value); } } #endregion #region 关联交易商品持仓数量[P+X] private decimal _relationGoodsHoldQty = decimal.Zero; /// /// 关联交易商品持仓数量[P+X] /// public decimal RelationGoodsHoldQty { get { return _relationGoodsHoldQty; } set { Set(() => RelationGoodsHoldQty, ref _relationGoodsHoldQty, value); } } #endregion #region 关联交易商品交割价格[P+X] private decimal _relationGoodsHoldPrice = decimal.Zero; /// /// 关联交易商品交割价格[P+X] /// public decimal RelationGoodsHoldPrice { get { return _relationGoodsHoldPrice; } set { Set(() => RelationGoodsHoldPrice, ref _relationGoodsHoldPrice, value); RaisePropertyChanged(() => RelationGoodsHoldPriceFormat); } } /// /// 关联交易商品交割价格[P+X]格式化 /// public string RelationGoodsHoldPriceFormat { get { if (RelationGoodsHoldPrice > decimal.Zero) { return RelationGoodsHoldPrice.ToString("f2"); } else { return "-"; } } } #endregion #region 当前关联交易商品的持仓单[P+X] private List _relationholdDetails; /// /// 当前关联交易商品的持仓单[P+X] /// public List RelationHoldDetails { get { return _relationholdDetails; } set { Set(() => RelationHoldDetails, ref _relationholdDetails, value); } } #endregion #region 差价升贴水 private string _deliveryPriceMoveDisplay = string.Empty; /// /// 差价升贴水 /// public string DeliveryPriceMoveDisplay { get { return _deliveryPriceMoveDisplay; } set { Set(() => DeliveryPriceMoveDisplay, ref _deliveryPriceMoveDisplay, value); } } #endregion #region 关联商品占用保证金均价 private decimal _relationPerUsedMargin = decimal.Zero; /// /// 占用保证金均价RelationPerUsedMargin /// public decimal RelationPerUsedMargin { get { return _relationPerUsedMargin; } set { Set(() => RelationPerUsedMargin, ref _relationPerUsedMargin, value); } } #endregion #region 当前商品占用保证金均价 private decimal _currentPerUsedMargin = decimal.Zero; /// /// 当前商品占用保证金均价 /// public decimal CurrentPerUsedMargin { get { return _currentPerUsedMargin; } set { Set(() => CurrentPerUsedMargin, ref _currentPerUsedMargin, value); } } private decimal _deliveryFee; /// /// 每手交割手续费 /// public decimal DeliveryFee { get { return _deliveryFee; } set { Set(() => DeliveryFee, ref _deliveryFee, value); } } private decimal _freezeFax; /// /// 每手交割税款 /// public decimal FreezeFax { get { return _freezeFax; } set { Set(() => FreezeFax, ref _freezeFax, value); } } /// /// 交割总税款 /// public decimal TotalFreezeFax { get { return Math.Round(FreezeFax * DeliveryCount, 2, MidpointRounding.AwayFromZero); } } /// /// 交割交割手续费 /// public decimal TotalDeliveryFee { get { return Math.Round(DeliveryFee * DeliveryCount, 2, MidpointRounding.AwayFromZero); ; } } #endregion #endregion "Public Properties To Get/Set " #region "Public Commands" #region 选中Command /// /// 选中 /// private RelayCommand selectCommand; public RelayCommand SelectCommand { get { return selectCommand ?? (selectCommand = new RelayCommand( (x) => { var sourceList = DeliveryMatchOrderList.ToList().FindAll(p => p.WRCode == x); for (int i = 0; i < sourceList.Count(); i++) { if (sourceList[i].NumSort == int.MaxValue) { sourceList[i].NumSort = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true).Count(); } } SettlementDeliveryMatchNum(); })); } } #endregion #region 取消选中Command /// /// 取消选中 /// private RelayCommand unSelectCommand; public RelayCommand UnSelectCommand { get { return unSelectCommand ?? (unSelectCommand = new RelayCommand( (x) => { var sourceList = DeliveryMatchOrderList.ToList().FindAll(p => p.WRCode == x); for (int i = 0; i < sourceList.Count(); i++) { if (sourceList[i].NumSort != int.MaxValue) { sourceList[i].NumSort = int.MaxValue; } } SettlementDeliveryMatchNum(); })); } } #endregion /// /// 下单窗口取消 /// public RelayCommand CancelCommand { get { return new RelayCommand((dialog) => { dialog.DialogResult = false; }); } } /// /// 下单确定 /// public RelayCommand OKCommand { get { return new RelayCommand((dialog) => { OKButtonEnabled = false; string errorMsg = string.Empty; bool validateBool = Validated(ref errorMsg); ////内容验证 if (validateBool) { IsBusy = true; _openWindow = dialog; var newOrder = new DeliveryOrderReqModel() { }; //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() && // UserManager.CurrentTradeAccount.FundsAccounts[0] != null) //{ // newOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} //else //{ // newOrder.AccountId = UserManager.CurrentTradeAccount.AccountId; //} try { //InitTimer(); //按照头寸交割单 _deliveryService.DeliveryApplyOrder(newOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack); } finally { //DisposeTimer(); } } else { MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title); OKButtonEnabled = true; } }); } } #region 测试提交Command private RelayCommand buttonCommand; public RelayCommand ButtonCommand { get { return buttonCommand ?? (buttonCommand = new RelayCommand( () => { int count = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true).Count; for (int i = 0; i < count; i++) MessageBox.Show(DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true)[i].WRCode + "," + DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == true)[i].EnableQty); })); } } #endregion #endregion "Public Commands" #region "Private Methods" private void DeliveryCountEvent() { ShowErrorInfo = string.Empty; if (FreezeDeliveryMoney > usableFunds) { ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_usableFundsNotEnough;// "资金不足,请修改交割数量"; } if (DeliveryCount > MaxDeliveryUnit) { ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_HolderNotEnough;// "持仓数量不足,请修改交割数量"; } if ((UserManager.CurrentTradeAccount.AccountType != eUserType.USERTYPE_INVESTOR&& CurrentGoods.currentTradeMode == eTradeMode.TRADEMODE_MARKETMAKE)) { ShowErrorInfo = Client_Resource.DeliveryOrderViewModel_AccountTypeNotEnough;// "交易员账户,且商品是做市商品时,不可以发起交割申报"; } IsEnableButtonEvent(); } /// /// 交割关联商品信息触发 /// private void DeliveryRelationInfoTrigger() { if (CurrentGoodsDeliveryRelation != null) { //var TempItem = tempDeliveryConfigList.FirstOrDefault(); var TempItem = CurrentGoodsDeliveryRelation; //交易商品数量-》转交割商品数量 RelationNum = _deliveryCount / TempItem.Conversion * TempItem.currentAgreeunit; //差价款=申报数量/兑换系数*交割合约单位*差价升贴水 FreezePriceMoveMoney = _deliveryCount / TempItem.Conversion * TempItem.currentAgreeunit * TempItem.DeliveryPriceMove; FreezeDeliveryTradeMoney = decimal.Zero; FreezeTradeMoney = decimal.Zero; FreezeDeliveryMoney = decimal.Zero; if (TempItem.RelationMode == eDeliveryContractLink.PAndX) { //X交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 交易商品合约单位 //var RelationGoodsItem = CacheManager.CacheGoodsBaseInfos.Find(x => x.GoodsParameters.GoodsId == TempItem.RelationGoodsId); var RelationGoodsItem = FindRelationGoodsInfoByID(TempItem.RelationGoodsId); if (RelationGoodsItem != null) { if (TempItem.RelationMode == eDeliveryContractLink.PAndX && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN)//&& CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN { FreezeDeliveryTradeMoney = _deliveryCount * Math.Round(RelationGoodsHoldPrice, 2, MidpointRounding.AwayFromZero) * RelationGoodsItem.RelationAgreeunit; } if (CurrentGoods.currentMoneymode != eMoneyMode.MONEYMODE_MARGIN && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN) { //交易货款=X交易货款 FreezeTradeMoney = FreezeDeliveryTradeMoney; } } } if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN) { //P交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 交易商品合约单位 FreezeTradeMoney = (_deliveryCount * Math.Round(DeliveryPrice, 2, MidpointRounding.AwayFromZero) * CurrentGoods.currentAgreeunit) + FreezeDeliveryTradeMoney; } //冻结货款=P交易货款+差价款+x交易货款 FreezeDeliveryMoney = FreezeTradeMoney + FreezePriceMoveMoney; FreezeDeliveryMoney += (TotalFreezeFax + TotalDeliveryFee); RaisePropertyChanged(() => TotalFreezeFax); RaisePropertyChanged(() => TotalDeliveryFee); } else { FreezeDeliveryTradeMoney = FreezeDeliveryMoney = FreezeTradeMoney = FreezePriceMoveMoney = RelationNum = decimal.Zero; } } /// /// 回滚仓单数据选择 /// private void RollBackMatchOrderList() { #region 重置勾选单据 CurrentSelectedWrDetail = null; if (DeliveryMatchOrderList != null && DeliveryMatchOrderList.Count() > 0) { var sourceList = DeliveryMatchOrderList.ToList(); for (int i = 0; i < sourceList.Count(); i++) { sourceList[i].IsSelected = false; sourceList[i].IsEnabled = true; } } OtherCanMatchQty = RelationNum;//tempOtherCanMatchQty; AlreadyMatchQty = 0; #endregion IsEnableButtonEvent(); } /// /// 计算可配数量、剩余数量 /// private void SettlementDeliveryMatchNum() { #region 配对数量仅能大于 等于 申报数量 AlreadyMatchQty = 0; preOtherCanMatchQty = OtherCanMatchQty = RelationNum; _currentSelectedWrDetail = new List(); decimal leaveCount = preOtherCanMatchQty; var sourceList = DeliveryMatchOrderList.OrderBy(x => x.NumSort).ToList().FindAll(p => p.IsSelected == true); for (int i = 0; i < sourceList.Count(); i++) { if (sourceList[i].PriceMove == int.MinValue) { //sourceList[i].PriceMove = 0; } if (leaveCount >= sourceList[i].EnableQty) { //CurrentSelectedWrDetail.Add(new WrDetailModel() { WRId = (sourceList[i].WRID), DeliveryQty = (long)sourceList[i].EnableQty }); } else { if (leaveCount > 0) { //CurrentSelectedWrDetail.Add(new WrDetailModel() { WRId = (sourceList[i].WRID), DeliveryQty = (long)leaveCount }); } } leaveCount = leaveCount - sourceList[i].EnableQty; AlreadyMatchQty += sourceList[i].EnableQty; } OtherCanMatchQty = OtherCanMatchQty - AlreadyMatchQty; if (OtherCanMatchQty < 0) { OtherCanMatchQty = 0; AlreadyMatchQty = preOtherCanMatchQty; } #endregion #region 屏蔽剩余勾选框 var sourceList_False = DeliveryMatchOrderList.ToList().FindAll(p => p.IsSelected == false); if (OtherCanMatchQty == 0) { for (int i = 0; i < sourceList_False.Count(); i++) { sourceList_False[i].IsEnabled = false; } } else { for (int i = 0; i < sourceList_False.Count(); i++) { sourceList_False[i].IsEnabled = true; } } #endregion IsEnableButtonEvent(); } /// /// 触发提交按钮是否可用 /// private void IsEnableButtonEvent() { //交易员账户,且商品是做市商品时,不可以发起交割申报 if (BuyOrSell == Direction.Ask) { if (CurrentSelectedWrDetail != null && CurrentSelectedWrDetail.Any() && CurrentSelectedWrDetail.Count() > 0 && AlreadyMatchQty == preOtherCanMatchQty && CurrentGoods != null && FreezeDeliveryMoney <= usableFunds && DeliveryCount <= MaxDeliveryUnit && DeliveryCount > 0 && (UserManager.CurrentTradeAccount.AccountType == eUserType.USERTYPE_INVESTOR || CurrentGoods.currentTradeMode != eTradeMode.TRADEMODE_MARKETMAKE) ) { OKButtonEnabled = true; } else { OKButtonEnabled = false; } } else { if (MaxDeliveryUnit <= 0 || MinDeliveryUnit <= 0 || CurrentGoods == null || FreezeDeliveryMoney > usableFunds || DeliveryCount > MaxDeliveryUnit || DeliveryCount <= 0 || (UserManager.CurrentTradeAccount.AccountType != eUserType.USERTYPE_INVESTOR && CurrentGoods.currentTradeMode == eTradeMode.TRADEMODE_MARKETMAKE) ) { OKButtonEnabled = false; } else { OKButtonEnabled = true; } } } #region 初始化下单计时时间 /// /// 初始化下单计时时间 /// //private void InitTimer() //{ // _countTime = ApplicationParameter.ServerTimeOut; // this._timer = new Timer(1000); // this._timer.AutoReset = true; // this._timer.Elapsed += _timer_Elapsed; // this._timer.Start(); // //IsOrderVisible = true; // BusyTips = string.Format(Client_Resource.Busy_Summit_Wait, _countTime); //} //void _timer_Elapsed(object sender, ElapsedEventArgs e) //{ // _countTime--; // BusyTips = string.Format(Client_Resource.Busy_Summit_Wait, _countTime); //} ///// ///// 清除计时器 ///// //private void DisposeTimer() //{ // this._timer.Stop(); // this._timer.Elapsed -= _timer_Elapsed; // this._timer.Close(); // //IsOrderVisible = false; //} #endregion /// /// 提交成功返回 /// /// private void EntrurstSuccessCallBack(DeliveryOrderRspModel order) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { OKButtonEnabled = true; MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result, Client_Resource.UI2014_Tips); if (_openWindow != null) { _openWindow.Close(); this.Cleanup(); } })); //刷新正常单 MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken); } /// /// 委托失败返回 /// /// private void EntrurstErrorCallBack(ErrorEntity errorEntity) { IsBusy = false; Application.Current.Dispatcher.BeginInvoke(new Action(() => { OKButtonEnabled = true; ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true); if (_openWindow != null) { _openWindow.Close(); //MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.HolderRefresh); //MessengerHelper.DefaultSend(string.Empty, MessengerTokens.OrderRefresh); MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.HolderUpdate); this.Cleanup(); } })); } /// /// 交割提货个人信息-成功返回 /// /// protected void QueryDepositPersonalInfoSuccess(DepositPersonalInfoRspModel itemModel) { if (itemModel != null) { CurrentDepositPersonalInfo = itemModel; if (CurrentDepositPersonalInfo != null) { RecieveAddress = CurrentDepositPersonalInfo.address; RecievePerson = CurrentDepositPersonalInfo.personName; PhoneNum = CurrentDepositPersonalInfo.telphone; } } IsBusy = false; } /// /// 查询-交割规则-成功返回 /// /// protected void QueryRelationSuccess(List itemList) { if (itemList != null) { GoodsDeliveryRelationList = itemList; #region 初始化交割商品 List tempGoods = new List(); //过滤全额商品->显示所有商品 //var GoodsList = CacheManager.CacheGoodsBaseInfos;//.Where(x => x.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY); if (UserManager.GetCacheOrders() != null && UserManager.GetCacheOrders().Distinct().ToList().Count() > 0) { //所有持仓单 var AllDeliveryGoodsIDList = UserManager.GetCacheOrders().Select((item) => item.GoodsId).Distinct().ToList(); foreach (var id in AllDeliveryGoodsIDList) { foreach (var item in GoodsDeliveryRelationList) { if (id == item.GoodsId && !tempGoods.Exists(x => x.GoodsId == item.GoodsId)) { tempGoods.Add(item); } } } } DeliveryGoodsList = tempGoods; if (DeliveryGoodsList != null && DeliveryGoodsList.Any() && DeliveryGoodsList.Count() > 0) { CurrentGoods = DeliveryGoodsList.FirstOrDefault(); if (_parameterInfo != null && _parameterInfo.GoodsId > 0) { CurrentGoods = DeliveryGoodsList.FirstOrDefault(x => x.GoodsId == _parameterInfo.GoodsId); } GetDepositPersonalInfo(); } #endregion } IsBusy = false; } /// /// 卖交割仓单信息查询-成功返回 /// /// protected void WhRecieptInfoSuccess(List itemList) { if (itemList != null) { DeliveryMatchOrderList = itemList.Where(x => x.EnableQty > 0).ToList(); } IsBusy = false; } /// /// 交割商品关系配置失败返回 /// /// private void DeliveryGoodsCallBack(ErrorEntity errorEntity) { IsBusy = false; } /// /// 获取交割提货个人信息失败返回 /// /// private void QueryDepositPersonalInfoCallBack(ErrorEntity errorEntity) { IsBusy = false; } /// /// 初始化交割商品列表数据 /// private void InitData() { IsBusy = true; _currentLinkModel = eDeliveryContractLink.None; _currentMoneyMode = eMoneyMode.MONEYMODE_MARGIN; _deliveryService.QueryGoodsDeliveryRelationList(QueryRelationSuccess, DeliveryGoodsCallBack); SetDeliveryCount(); } /// /// 重置数据初始值 /// private void ResetData() { IsVisibilityRelationGoodsInfo = Visibility.Collapsed; RelationGoodsHoldPrice = decimal.Zero; RelationGoodsHoldQty = decimal.Zero; DeliveryPrice = decimal.Zero; AvailHoldQty = decimal.Zero; CurrentGoodsDeliveryRelation = null; DeliveryPriceMoveDisplay = ""; IsVisibilityHolderPrice = Visibility.Collapsed; IsVisibilitySellModel = Visibility.Collapsed; IsVisibilitySellModel_Show = Visibility.Collapsed; OKButtonEnabled = true; DeliveryMatchOrderList = null; } /// /// 默认数据当没有获取到交割关系时 /// private void DefaultDataWhenNoRelation() { CanDeliveryCount = 0; DeliveryPriceTypeDisplay = "-"; DeliveryPrice = 0; TradeRuleTrans = "-"; MinDeliveryUnit = 0; MaxDeliveryUnit = 0; } /// /// 设置可交收数量 /// private void SetDeliveryCount() { ResetData(); if (CurrentGoods != null) { CurrentGoodsDeliveryRelation = GoodsDeliveryRelationList.FindAll(x => x.GoodsId == CurrentGoods.GoodsId).FirstOrDefault(); CheckIsSellEnable(); //P+X商品信息 GetPAndXDeliveryGoodsInfo(); IsBusy = false; #region 参数赋值 if (CurrentGoodsDeliveryRelation != null) { //当前交割商品ID _currentDeliveryGoodsId = CurrentGoodsDeliveryRelation.DeliveryGoodsId; if (BuyOrSell == Direction.Ask) { GetSellDeliveryWhRecieptInfo(); } _currentLinkModel = CurrentGoodsDeliveryRelation.RelationMode; if (CurrentGoodsDeliveryRelation.RelationMode != eDeliveryContractLink.None) { //最大最小交割手数设置 MinMaxDeliveryHandQty(); } else { DeliveryCount = MinDeliveryUnit = 1; if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX && BuyOrSell == Direction.Bid) { var tempAvailHoldQty = Math.Min(RelationGoodsHoldQty, AvailHoldQty); MaxDeliveryUnit = tempAvailHoldQty; } else { MaxDeliveryUnit = AvailHoldQty; } IsVisibilityFreezeMoney = Visibility.Collapsed; } DeliveryAgreeUnitType = CacheManager.TradeGoodsUnit.Where(x => x.UNITID == CurrentGoodsDeliveryRelation.GoodsUnitId).Select(x => x.GOODSUNITNAME).FirstOrDefault(); //交割价格-类型[//固定写死=》持仓价计算申报 20161209 xiaobao] DeliveryPriceTypeDisplay = Resources.Client_Resource.ReckonPriceCalcMethod_HolderPrice; if (BuyOrSell != Direction.Ask)//卖方向时候,屏蔽P+X信息 { IsVisibilityRelationGoodsInfo = CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX ? Visibility.Visible : Visibility.Collapsed; DeliveryPriceMoveDisplay = CurrentGoodsDeliveryRelation.DeliveryPriceMove != decimal.Zero ? CurrentGoodsDeliveryRelation.DeliveryPriceMove.ToString("f2") : "0"; if (IsVisibilityFreezeMoney == Visibility.Visible) { IsVisibilityHolderPrice = Visibility.Visible; } IsVisibilitySellModel = Visibility.Visible; MessengerHelper.DefaultSend(650, MessengerTokens.DeliveryBuyOrSellChanged); } else { IsVisibilitySellModel_Show = Visibility.Visible; MessengerHelper.DefaultSend(550, MessengerTokens.DeliveryBuyOrSellChanged); } //P+X 交割商品信息 //GetPAndXDeliveryGoodsInfo(); //交割算法取值 GetDeliveryPriceCalcMethod(); var maxLot = MaxDeliveryLots(); ////当前金额可交割数量 //&& _currentGoods.currentMoneymode != eMoneyMode.MONEYMODE_MARGIN 保证金也需要计算手数 if (FreezeDeliveryMoney != decimal.Zero && CurrentGoodsDeliveryRelation.RelationMode != eDeliveryContractLink.None) { MaxDeliveryUnit = Math.Min(maxLot, MaxDeliveryUnit); } } else { //默认数据当没有获取到交割关系时 DefaultDataWhenNoRelation(); } if (FreezeDeliveryMoney == decimal.Zero) { IsVisibilityFreezeMoney = Visibility.Collapsed; } #endregion } IsEnableButtonEvent(); RaisePropertyChanged(() => MinMaxDeliNumVisibility); } /// /// 检测卖方向是否可用 /// private void CheckIsSellEnable() { IsSellEnable = false; if (CurrentGoods != null) { var currentGoodsMoneymode = CurrentGoods.currentMoneymode; var currentGoodsTradeMode = CurrentGoods.currentTradeMode; decimal AvailQty = decimal.Zero; var holders = UserManager.GetCacheOrders(); if (holders != null && holders.Any()) { HoldDetails = holders.Where((item) => item.GoodsId == CurrentGoods.GoodsId && item.Direction == Direction.Ask).ToList();//卖方向持仓 if (HoldDetails != null && HoldDetails.Any()) { var tempFzQty = HoldDetails.FirstOrDefault().PositionFzQty; var totalHoldQty = HoldDetails.Sum((order) => order.Lot - order.LockQty); AvailQty = totalHoldQty - tempFzQty; } } //无卖持仓时,卖方向不可选置灰,仅竞价与混合-保证金商品-才可以发起卖交割 if (AvailQty > decimal.Zero && CurrentGoodsDeliveryRelation != null && CurrentGoodsDeliveryRelation.Sponsor == eSponsorType.Both && currentGoodsMoneymode == eMoneyMode.MONEYMODE_MARGIN && (currentGoodsTradeMode == eTradeMode.TRADEMODE_BIDDING || currentGoodsTradeMode == eTradeMode.TRADEMODE_BIDDINGMARKETMAKE)) { IsSellEnable = true; } } } /// /// 获取交割提货个人信息 /// private void GetDepositPersonalInfo() { if (CurrentGoods != null) { var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} var ReqModel = new DepositPersonalInfoReqModel(); ReqModel.accountId = (long)accountid; IsBusy = true; //交割提货个人信息查询 _deliveryService.SearchDepositPersonalInfoReq(ReqModel, QueryDepositPersonalInfoSuccess, QueryDepositPersonalInfoCallBack); } } /// /// 获取卖交割仓单信息 /// private void GetSellDeliveryWhRecieptInfo() { if (_currentDeliveryGoodsId > 0) { var accountid = UserManager.CurrentTradeAccount.AccountId; //if (UserManager.CurrentTradeAccount.FundsAccounts != null && UserManager.CurrentTradeAccount.FundsAccounts.Any()) //{ // accountid = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId; //} IsBusy = true; //卖交割仓单查询 _deliveryService.QueryDeliveryWhRecieptInfo((uint)accountid, (uint)_currentDeliveryGoodsId, WhRecieptInfoSuccess, DeliveryGoodsCallBack); } } /// /// 获取P+X交割商品信息 /// private void GetPAndXDeliveryGoodsInfo() { var holders = UserManager.GetCacheOrders(); if (holders != null && holders.Any()) { HoldDetails = holders.Where((item) => item.GoodsId == CurrentGoods.GoodsId && item.Direction == BuyOrSell).ToList();//买卖方向持仓 if (HoldDetails != null && HoldDetails.Any()) { #region 买卖方向持仓逻辑 _positionFzQty = HoldDetails.FirstOrDefault().PositionFzQty; _totalHoldDetails = HoldDetails.Sum((order) => order.Lot - order.LockQty); AvailHoldQty = _totalHoldDetails - _positionFzQty; if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN) { CurrentPerUsedMargin = HoldDetails.Sum((order) => order.UsedMargin) / HoldDetails.Sum((order) => order.Lot - order.LockQty); } #region [P+X]商品信息 if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX) { if (CurrentGoodsDeliveryRelation.RelationGoodsId != 0 && CurrentGoodsDeliveryRelation.RelationGoodsId > 0) { if (GoodsDeliveryRelationList.Find(x => x.RelationGoodsId == CurrentGoodsDeliveryRelation.RelationGoodsId) != null)//未找到关联交易商品 { RelationGoodsName = FindRelationGoodsInfoByID(CurrentGoodsDeliveryRelation.RelationGoodsId).RelationGoodsname; //当前关联交易商品的持仓单[P+X] RelationHoldDetails = holders.Where((item) => item.GoodsId == CurrentGoodsDeliveryRelation.RelationGoodsId && item.Direction == BuyOrSell).ToList(); } else { OKButtonEnabled = false; } } if (RelationHoldDetails != null && RelationHoldDetails.Any()) { var RelationGoodsItem = FindRelationGoodsInfoByID(CurrentGoodsDeliveryRelation.RelationGoodsId); RelationGoodsHoldPrice = RelationHoldDetails.Sum((order) => order.HoldAmount - order.lockHolderAmount) / RelationHoldDetails.Sum((item) => item.Lot - item.LockQty) / RelationGoodsItem.RelationAgreeunit; //X交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 交易商品合约单位 if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX && RelationGoodsItem != null && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN)//&& CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN { RelationPerUsedMargin = RelationHoldDetails.Sum((order) => order.UsedMargin) / RelationHoldDetails.Sum((item) => item.Lot - item.LockQty); FreezeDeliveryTradeMoney = DeliveryCount * Math.Round(RelationGoodsHoldPrice, 2, MidpointRounding.AwayFromZero) * RelationGoodsItem.RelationAgreeunit; IsVisibilityDeliveryTradeMoney = Visibility.Visible; } //关联交易商品持仓可用数量=持仓总数-冻结头寸 RelationGoodsHoldQty = RelationHoldDetails.Sum((order) => order.Lot - order.LockQty) - RelationHoldDetails.FirstOrDefault().PositionFzQty; if (AvailHoldQty > RelationGoodsHoldQty && RelationGoodsHoldQty >= 0 && BuyOrSell == Direction.Bid) { //最大可申报数量 以小的为标准 MaxDeliveryUnit = Math.Min((RelationGoodsHoldQty - RelationGoodsHoldQty % MinDeliveryUnit), MaxDeliveryUnit); } } } #endregion #endregion } } } /// /// 交割算法取值 /// private void GetDeliveryPriceCalcMethod() { switch (CurrentGoodsDeliveryRelation.DeliveryPriceCalcMethod) { case eReckonPriceCalcMethodType.LastPrice: case eReckonPriceCalcMethodType.HolderPriceMove: case eReckonPriceCalcMethodType.AgreedPrice: case eReckonPriceCalcMethodType.ReckonPrice: case eReckonPriceCalcMethodType.HolderPrice: //持仓价 if (HoldDetails != null && HoldDetails.Any()) { #region 按先建先冻原则计算持仓均价 //HoldDetails = HoldDetails.OrderBy(x => x.OpenDate).ToList(); /////交易货款 //var tempDeliveryPrice = decimal.Zero; ////申报数量 //var tempDeliveryCount = DeliveryCount;// *CurrentGoodsDeliveryRelation.Conversion; //foreach (var item in HoldDetails) //{ // //可用数量 // var currentLot = (item.Lot - item.LockQty); // if (currentLot <= 0) // { // continue; // } // if (tempDeliveryCount >= currentLot) // { // //先建先冻原则=>总价+=建仓总价 // tempDeliveryPrice += (item.HoldAmount); // tempDeliveryCount = tempDeliveryCount - currentLot; // } // else // { // //总价+=建仓单价 * 申报剩余数量 // tempDeliveryPrice += (item.HoldAmount / currentLot) * tempDeliveryCount; // tempDeliveryCount = 0; // break; // } //} ////持仓价均价=交割价格 //DeliveryPrice = tempDeliveryPrice / DeliveryCount / _CurrentGoods.currentAgreeunit; ////交易货款=交割申报手数*持仓单对应的持仓金额 //FreezeTradeMoney = tempDeliveryPrice; ////差价款=申报数量/兑换系数*交割合约单位*差价升贴水 //FreezePriceMoveMoney=DeliveryCount / CurrentGoodsDeliveryRelation.Conversion * _CurrentGoods.currentAgreeunit * CurrentGoodsDeliveryRelation.DeliveryPriceMove; #endregion //持仓价=持仓价均价 DeliveryPrice = decimal.Zero; //#26006 N模式的交割申报不需要显示交割价格 if (HoldDetails.Sum((item) => item.Lot - item.LockQty) > 0) DeliveryPrice = HoldDetails.Sum((order) => order.HoldAmount - order.lockHolderAmount) / HoldDetails.Sum((item) => item.Lot - item.LockQty) / CurrentGoods.currentAgreeunit; //差价款=申报数量/兑换系数*交割合约单位*差价升贴水 FreezePriceMoveMoney = DeliveryCount / CurrentGoodsDeliveryRelation.Conversion * CurrentGoodsDeliveryRelation.currentAgreeunit * CurrentGoodsDeliveryRelation.DeliveryPriceMove; FreezeTradeMoney = decimal.Zero; FreezeDeliveryMoney = decimal.Zero; if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN) { //交易货款=交割申报手数*持仓单对应的持仓价均价+X交易货款 FreezeTradeMoney = DeliveryCount * Math.Round(DeliveryPrice, 2, MidpointRounding.AwayFromZero) * CurrentGoods.currentAgreeunit + FreezeDeliveryTradeMoney; } if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX) { //var RelationGoodsItem = CacheManager.CacheGoodsBaseInfos.Find(x => x.GoodsParameters.GoodsId == CurrentGoodsDeliveryRelation.RelationGoodsId); var RelationGoodsItem = FindRelationGoodsInfoByID(CurrentGoodsDeliveryRelation.RelationGoodsId); if (RelationGoodsItem != null && CurrentGoods.currentMoneymode != eMoneyMode.MONEYMODE_MARGIN && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN) { //交易货款=X交易货款 FreezeTradeMoney = FreezeDeliveryTradeMoney; } } //冻结货款=P交易货款+差价款+X交易货款 FreezeDeliveryMoney = FreezeTradeMoney + FreezePriceMoveMoney; } break; } } /// /// 最大最小交割手数 /// private void MinMaxDeliveryHandQty() { if (GoodsDeliveryRelationList.Find(x => x.GoodsId == CurrentGoods.GoodsId) != null) { MinDeliveryUnit = GoodsDeliveryRelationList.Find(x => x.GoodsId == CurrentGoods.GoodsId).minDeliveryQty; //最小交割手数转换为交易手数 MinDeliveryUnit = Math.Round(MinDeliveryUnit * CurrentGoodsDeliveryRelation.Conversion, 2, MidpointRounding.AwayFromZero); } else { //ShowErrorInfo = "没有设置最小交割手数" + "\r"; } if (GoodsDeliveryRelationList.Find(x => x.GoodsId == CurrentGoods.GoodsId) != null) { MaxDeliveryUnit = GoodsDeliveryRelationList.Find(x => x.GoodsId == CurrentGoods.GoodsId).maxDeliveryQty; //最大交割手数转换为交易手数 var tempMaxDeliveryUnit = Math.Round(MaxDeliveryUnit * CurrentGoodsDeliveryRelation.Conversion, 2, MidpointRounding.AwayFromZero); MaxDeliveryUnit = tempMaxDeliveryUnit - tempMaxDeliveryUnit % MinDeliveryUnit; if (CurrentGoodsDeliveryRelation.RelationMode == eDeliveryContractLink.PAndX && BuyOrSell == Direction.Bid) { var tempAvailHoldQty = Math.Min(RelationGoodsHoldQty, AvailHoldQty); MaxDeliveryUnit = Math.Min((tempAvailHoldQty - tempAvailHoldQty % MinDeliveryUnit), MaxDeliveryUnit); } else { MaxDeliveryUnit = Math.Min((AvailHoldQty - AvailHoldQty % MinDeliveryUnit), MaxDeliveryUnit); } } else { //ShowErrorInfo = "没有设置最大交割手数" + "\r"; } DeliveryCount = MinDeliveryUnit; //交易商品数量-》转交割商品数量 RelationNum = DeliveryCount / CurrentGoodsDeliveryRelation.Conversion * CurrentGoodsDeliveryRelation.currentAgreeunit; IsVisibilityFreezeMoney = Visibility.Visible; } /// /// 资金计算最大可下单数据 /// /// private long MaxDeliveryLots() { //错误信息提示 if (FreezeDeliveryMoney > usableFunds) { ErrorMsg = Resources.Client_Resource.DeliveryOrderView_MinMaxErrVisibility_LowMoney; } usableFunds = usableFunds >= 0 ? usableFunds : 0; var pirce = GetDeliveryGoodsPay(); FreezeDeliveryMoney += (TotalFreezeFax + TotalDeliveryFee); RaisePropertyChanged(() => TotalFreezeFax); RaisePropertyChanged(() => TotalDeliveryFee); return pirce == 0 ? 0 : (long)Math.Floor(usableFunds / pirce); } /// /// 查找商品信息BY商品ID /// private GoodsDeliveryRelationModel FindGoodsInfoByID(long goodsId) { if (GoodsDeliveryRelationList.Any() && GoodsDeliveryRelationList.Count > 0) { return GoodsDeliveryRelationList.Find(x => x.GoodsId == goodsId); } return null; } /// /// 查找关联商品信息BY商品ID /// private GoodsDeliveryRelationModel FindRelationGoodsInfoByID(long RelationGoodsId) { if (GoodsDeliveryRelationList.Any() && GoodsDeliveryRelationList.Count > 0) { return GoodsDeliveryRelationList.Find(x => x.RelationGoodsId == RelationGoodsId); } return null; } /// /// 计算每个交割单位的冻结金额 /// /// private decimal GetDeliveryGoodsPay() { var TempItem = CurrentGoodsDeliveryRelation; // 1、全款模式 //最大申报手数=可用资金/[交割合约单位*(手续费+差价升贴水)/兑换系数] //2、保证金模式 //最大申报手数=可用资金/[交割合约单位*(手续费+差价升贴水)/兑换系数+持仓均价*交易合约单位] var payMargin = TempItem.currentAgreeunit * TempItem.DeliveryPriceMove / TempItem.Conversion; //差价升贴水+手续费 if (TempItem.RelationMode == eDeliveryContractLink.PAndX) { //var RelationGoodsItem = CacheManager.CacheGoodsBaseInfos.Find(x => x.GoodsParameters.GoodsId == TempItem.RelationGoodsId); var RelationGoodsItem = FindRelationGoodsInfoByID(TempItem.RelationGoodsId); if (RelationGoodsItem != null && TempItem.RelationMode == eDeliveryContractLink.PAndX && RelationGoodsItem.RelationMoneymode == eMoneyMode.MONEYMODE_MARGIN) { payMargin += RelationGoodsHoldPrice * RelationGoodsItem.RelationAgreeunit; //X 持仓均价*交易合约单位 } } if (CurrentGoods.currentMoneymode == eMoneyMode.MONEYMODE_MARGIN) { //P交易商品交易货款=交割申报手数*持仓单对应的持仓价均价 * 交易商品合约单位 payMargin += DeliveryPrice * CurrentGoods.currentAgreeunit; //p 持仓均价*交易合约单位 } //买卖交割手续费 decimal tempDeliveryFee = (BuyOrSell == Direction.Bid ? TempItem.buyDeliveryFee : TempItem.AskDeliveryFee); //var payfee = TempItem.buyDeliveryMode == (int)eCalMode.CALMODE_FIXEDRATIO //百分比 // ? DeliveryFeePercentCalculate() // : tempDeliveryFee; var payfee = tempDeliveryFee; DeliveryFee = TempItem.buyDeliveryMode == (int)eCalMode.CALMODE_FIXEDRATIO ? DeliveryFeePercentCalculate() : TempItem.currentAgreeunit * payfee / TempItem.Conversion; ////手续费 payMargin += DeliveryFee; FreezeFax = TempItem.currentAgreeunit * TempItem.BasePrice * TempItem.FaxValue / 100 / TempItem.Conversion; payMargin += FreezeFax; ////税款 return payMargin; } #endregion /// /// 按比例买卖交割单手手续费-计算 /// private decimal DeliveryFeePercentCalculate() { var TempItem = CurrentGoodsDeliveryRelation; decimal result = decimal.Zero; #region P模式-手续费公式要求 //手续费设置为固定金额时:交割申报手数/兑换系数*交易合约单位*手续费单价 //手续费设置为比例时:(交易货款+差价款)*手续费比例 //其中交易货款=持仓均价*交割手数*交易合约单位 //其中差价款=申报手数*交易合约单位/兑换系数*差价升贴水 #endregion #region P+X模式-手续费公式要求 // 手续费设置为固定金额时:交割申报手数/兑换系数*交易合约单位*手续费单价 // 手续费设置为比例时:(交易货款+差价款)*手续费比例 //其中交易货款=主商品持仓均价*交割手数*主商品交易合约单位+辅商品持仓均价*交割手数*辅商品交易合约单位 //其中差价款=申报手数*主商品交易合约单位/兑换系数*差价升贴水 #endregion if (TempItem.RelationMode != eDeliveryContractLink.None) { //交易货款=持仓均价*交割手数*交易合约单位 var tempDeliveryTradeMoney = Math.Round(DeliveryPrice, 2, MidpointRounding.AwayFromZero) * CurrentGoods.currentAgreeunit; //差价款=申报手数*交易合约单位/兑换系数*差价升贴水 var tempPriceMoveMoney = TempItem.currentAgreeunit * TempItem.DeliveryPriceMove / TempItem.Conversion; //手续费参数值 decimal tempDeliveryFee = (BuyOrSell == Direction.Bid ? TempItem.buyDeliveryFee : TempItem.AskDeliveryFee); switch (TempItem.RelationMode) { case eDeliveryContractLink.Normal: //手续费 =(交易货款+差价款)*手续费比例 result = (Math.Round(tempDeliveryTradeMoney, 2, MidpointRounding.AwayFromZero) + Math.Round(tempPriceMoveMoney, 2, MidpointRounding.AwayFromZero)) * tempDeliveryFee; break; case eDeliveryContractLink.PAndX: var RelationGoodsItem = FindRelationGoodsInfoByID(TempItem.RelationGoodsId); //X交易货=款辅商品持仓均价*交割手数*辅商品交易合约单位 var tempXDeliveryTradeMoney = RelationGoodsHoldPrice * RelationGoodsItem.RelationAgreeunit; //手续费 =(交易货款+差价款)*手续费比例 result = (Math.Round(tempDeliveryTradeMoney, 2, MidpointRounding.AwayFromZero) + Math.Round(tempXDeliveryTradeMoney, 2, MidpointRounding.AwayFromZero) + Math.Round(tempPriceMoveMoney, 2, MidpointRounding.AwayFromZero)) * tempDeliveryFee; break; } } return result; } #region "Other Methods like Validated" /// /// 数据验证 /// /// /// public bool Validated(ref string msg) { //申报数量 > 最大可申报数量 if (DeliveryCount > MaxDeliveryUnit) { msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.EntrustOrderViewModel_OpenLotGreatThanMaxLot, MaxDeliveryUnit); return false; } //申报数量应为最小交割数量的整数倍 if (MinDeliveryUnit != 0 && DeliveryCount % MinDeliveryUnit != 0 && _currentLinkModel != eDeliveryContractLink.None) { msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.DeliveryCountShoutBeMinUnitDouble, MinDeliveryUnit); ; return false; } if (DeliveryCount <= 0 || DeliveryCount == decimal.Zero) { //数量不在正确范围内 msg = string.Format(Muchinfo.MTPClient.Resources.Client_Resource.Delivery_ChooseCorrectDeclareNum, MaxDeliveryUnit); ; return false; } if (RecievePerson.Trim() == "") { msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecievePerson + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite; return false; } if (RecieveAddress.Trim() == "") { msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_RecieveAddress + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite; return false; } if (PhoneNum.Trim() == "") { msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNum + Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_NeedToWrite; return false; } if (PhoneNum.Trim() != "" && !PhoneNum.StartsWith("1") || PhoneNum.Length != 11 || !ValidationHelper.IsMobile(PhoneNum)) { msg = Muchinfo.MTPClient.Resources.Client_Resource.TakaDeliveryGoodsApplyViewModel_PhoneNumErrFormat; return false; } return true; } #endregion } }