| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689 |
- 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
- {
- /// <summary>
- /// 交割申报
- /// </summary>
- 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"
- /// <summary>
- /// 构造函数
- /// </summary>
- public DeliveryOrderViewModel()
- {
- this._parameterInfo = null;
- _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
- _goodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
- // 初始化交割商品列表数据
- InitData();
- }
- public DeliveryOrderViewModel(DeliveryOrderMessage info)
- {
- this._parameterInfo = info;
- _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
- _goodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
- // 初始化交割商品列表数据
- 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;
- /// <summary>
- /// 当前账号提货人信息
- /// </summary>
- public DepositPersonalInfoRspModel CurrentDepositPersonalInfo
- {
- get
- {
- return _currentDepositPersonalInfo;
- }
- set
- {
- Set(() => CurrentDepositPersonalInfo, ref _currentDepositPersonalInfo, value);
- }
- }
- #endregion
- #region 收货人
- private string _RecievePerson = string.Empty;
- /// <summary>
- /// 收货人
- /// </summary>
- public string RecievePerson
- {
- get
- {
- return _RecievePerson;
- }
- set
- {
- Set(() => RecievePerson, ref _RecievePerson, value);
- }
- }
- #endregion
- #region 收货地址
- private string _RecieveAddress = string.Empty;
- /// <summary>
- /// 收货地址
- /// </summary>
- public string RecieveAddress
- {
- get
- {
- return _RecieveAddress;
- }
- set
- {
- Set(() => RecieveAddress, ref _RecieveAddress, value);
- }
- }
- #endregion
- #region 联系方式
- private string _PhoneNum = string.Empty;
- /// <summary>
- /// 联系方式
- /// </summary>
- public string PhoneNum
- {
- get
- {
- return _PhoneNum;
- }
- set
- {
- Set(() => PhoneNum, ref _PhoneNum, value);
- }
- }
- #endregion
- #region 联系方式
- private string _IdCardNum = string.Empty;
- /// <summary>
- /// 联系方式
- /// </summary>
- public string IdCardNum
- {
- get
- {
- return _IdCardNum;
- }
- set
- {
- Set(() => IdCardNum, ref _IdCardNum, value);
- }
- }
- #endregion
- //------以下为卖交割相关------------------------
- #region 剩余可配对数量
- /// <summary>
- /// 剩余可配对数量
- /// </summary>
- private decimal preOtherCanMatchQty = 0;
- private decimal _otherCanMatchQty = 0;
- /// <summary>
- /// 剩余可配对数量
- /// </summary>
- public decimal OtherCanMatchQty
- {
- get
- {
- return _otherCanMatchQty;
- }
- set
- {
- value = Math.Round(value, 0);
- Set(() => OtherCanMatchQty, ref _otherCanMatchQty, value);
- }
- }
- #endregion
- #region 已配对数量
- private decimal _aleadyMatchQty = 0;
- /// <summary>
- /// 已配对数量
- /// </summary>
- 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;
- /// <summary>
- /// 显示卖交割
- /// </summary>
- public Visibility IsVisibilitySellModel_Show
- {
- get
- {
- return _isVisibilitySellModel_Show;
- }
- set
- {
- Set(() => IsVisibilitySellModel_Show, ref _isVisibilitySellModel_Show, value);
- }
- }
- #endregion
- #region 隐藏当卖交割
- private Visibility _isVisibilitySellModel = Visibility.Collapsed;
- /// <summary>
- /// 隐藏卖交割
- /// </summary>
- public Visibility IsVisibilitySellModel
- {
- get
- {
- return _isVisibilitySellModel;
- }
- set
- {
- Set(() => IsVisibilitySellModel, ref _isVisibilitySellModel, value);
- }
- }
- #endregion
- #region 是否隐藏持仓价格
- private Visibility _isVisibilityHolderPrice = Visibility.Collapsed;
- /// <summary>
- /// Sets and gets the IsVisibilityFrezzMoney property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public Visibility IsVisibilityHolderPrice
- {
- get
- {
- return _isVisibilityHolderPrice;
- }
- set
- {
- Set(() => IsVisibilityHolderPrice, ref _isVisibilityHolderPrice, value);
- }
- }
- #endregion
- #region 申报仓单配对列表
- public List<DeliveryWhRecieptInfo> TempDeliveryMatchOrderList = new List<DeliveryWhRecieptInfo>();
- private List<DeliveryWhRecieptInfo> _deliveryMatchOrderList = new List<DeliveryWhRecieptInfo>();
- /// <summary>
- /// 申报仓单配对列表
- /// </summary>
- public List<DeliveryWhRecieptInfo> DeliveryMatchOrderList
- {
- get { return _deliveryMatchOrderList; }
- set
- {
- Set(() => DeliveryMatchOrderList, ref _deliveryMatchOrderList, value);
- }
- }
- #endregion
- #region 当前勾选单据LIST
- private List<WrDetailModel> _currentSelectedWrDetail = null;
- /// <summary>
- /// 当前勾选的仓单配对
- /// </summary>
- public List<WrDetailModel> CurrentSelectedWrDetail
- {
- get
- {
- return _currentSelectedWrDetail;
- }
- set
- {
- Set(() => CurrentSelectedWrDetail, ref _currentSelectedWrDetail, value);
- }
- }
- #endregion
- #region 买方向是否可用
- private bool _isBuyEnable = true;
- /// <summary>
- /// Sets and gets the IsBuyEnable property.
- /// </summary>
- public bool IsBuyEnable
- {
- get
- {
- return _isBuyEnable;
- }
- set
- {
- Set(() => IsBuyEnable, ref _isBuyEnable, value);
- }
- }
- #endregion
- #region 卖方向是否可用
- private bool _IsSellEnable = true;
- /// <summary>
- /// 卖方向是否可用
- /// </summary>
- public bool IsSellEnable
- {
- get
- {
- return _IsSellEnable;
- }
- set
- {
- Set(() => IsSellEnable, ref _IsSellEnable, value);
- }
- }
- #endregion
- #region 买卖方向
- private Direction _buyOrSell = Direction.Bid;
- /// <summary>
- /// Sets and gets the BuyOrSell property.
- /// </summary>
- 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;
- /// <summary>
- /// 错误信息提示
- /// </summary>
- public string RelationGoodsErrorMsg
- {
- get
- {
- return _relationGoodsErrorMsg;
- }
- set
- {
- Set(() => RelationGoodsErrorMsg, ref _relationGoodsErrorMsg, value);
- }
- }
- #endregion
- #region 合计冻结货款[保证金、全额]
- private string _totalFreezenMoneyText = Client_Resource.DeliveryOrderView_FreezeDeliveryMoney;
- /// <summary>
- /// 合计冻结货款[保证金、全额]
- /// </summary>
- public string TotalFreezenMoneyText
- {
- get
- {
- return _totalFreezenMoneyText;
- }
- set
- {
- Set(() => TotalFreezenMoneyText, ref _totalFreezenMoneyText, value);
- }
- }
- #endregion
- #region 温馨提示内容
- private string _warningTips = Client_Resource.DeliveryOrderView_WarningTips;
- /// <summary>
- /// 温馨提示内容
- /// </summary>
- public string WarningTips
- {
- get
- {
- return _warningTips;
- }
- set
- {
- Set(() => WarningTips, ref _warningTips, value);
- }
- }
- #endregion
- #region 错误信息提示
- private string _errorMsg = Client_Resource.DeliveryOrderView_MinMaxErrVisibility;
- /// <summary>
- /// 错误信息提示
- /// </summary>
- public string ErrorMsg
- {
- get
- {
- return _errorMsg;
- }
- set
- {
- Set(() => ErrorMsg, ref _errorMsg, value);
- }
- }
- #endregion
- #region 交割关系表LIST
- private List<GoodsDeliveryRelationModel> _goodsDeliveryRelationList;
- public List<GoodsDeliveryRelationModel> GoodsDeliveryRelationList
- {
- get { return _goodsDeliveryRelationList; }
- set { _goodsDeliveryRelationList = value; }
- }
- #endregion
- #region 窗体标题
- private string _title = string.Empty;
- /// <summary>
- /// 窗体标题
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public string Title
- {
- get
- {
- return _title = Client_Resource.DeliveryOrderView_DeliveryDeclaration;
- }
- //set
- //{
- // Set(() => Title, ref _title, value);
- //}
- }
- #endregion
- #region 交割商品列表
- private List<GoodsDeliveryRelationModel> _deliveryGoodsList;
- /// <summary>
- /// 交割商品列表
- /// </summary>
- public List<GoodsDeliveryRelationModel> DeliveryGoodsList
- {
- get { return _deliveryGoodsList; }
- set
- {
- Set(() => DeliveryGoodsList, ref _deliveryGoodsList, value);
- }
- }
- #endregion
- #region 持仓数量
- private decimal _holdCount = 0;
- /// <summary>
- /// 当前商品持仓数量
- /// </summary>
- public decimal HoldCount
- {
- get
- {
- return _holdCount;
- }
- set
- {
- Set(() => HoldCount, ref _holdCount, value);
- }
- }
- #endregion
- #region 申报数量
- private decimal _deliveryCount = 0;
- /// <summary>
- /// 申报数量
- /// </summary>
- public decimal DeliveryCount
- {
- get
- {
- return _deliveryCount;
- }
- set
- {
- Set(() => DeliveryCount, ref _deliveryCount, value);
- if (BuyOrSell == Direction.Ask)
- {
- RollBackMatchOrderList();
- }
- DeliveryRelationInfoTrigger();
- DeliveryCountEvent();
- }
- }
- #endregion
- #region 合约单位名称枚举-交易商品
- /// <summary>
- /// 合约单位名称枚举-交易商品
- /// </summary>
- 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;
- /// <summary>
- /// 合约单位名称枚举-交割商品
- /// </summary>
- public string DeliveryAgreeUnitType
- {
- get
- {
- return _deliveryAgreeUnitType;
- }
- set
- {
- Set(() => DeliveryAgreeUnitType, ref _deliveryAgreeUnitType, value);
- }
- }
- #endregion
- #region 冻结头寸数量
- /// <summary>
- /// 冻结头寸数量
- /// </summary>
- private decimal _positionFzQty;
- /// <summary>
- /// 冻结头寸数量
- /// </summary>
- public decimal PositionFzQty
- {
- get { return _positionFzQty; }
- set { _positionFzQty = value; }
- }
- #endregion
- #region 冻结货款=交易货款+差价款
- /// <summary>
- /// 冻结货款=交易货款+申报数量/兑换系数*交割合约单位*差价升贴水
- /// 交易货款(保证金)=解占用扣全款
- /// 交易货款(全款)=交割申报手数*持仓单对应的持仓金额
- /// </summary>
- private decimal _freezeDeliveryMoney = decimal.Zero;
- /// <summary>
- /// 冻结货款
- /// </summary>
- public decimal FreezeDeliveryMoney
- {
- get
- {
- return _freezeDeliveryMoney;
- }
- set
- {
- Set(() => FreezeDeliveryMoney, ref _freezeDeliveryMoney, value);
- RaisePropertyChanged(() => FreezeDeliveryMoneyFormat);
- }
- }
- /// <summary>
- /// 冻结货款 -格式化
- /// </summary>
- public string FreezeDeliveryMoneyFormat
- {
- get
- {
- return FreezeDeliveryMoney.ToString("f2");
- }
- }
- #endregion
- #region P交易商品冻结交易货款
- private decimal _freezeTradeMoney = decimal.Zero;
- /// <summary>
- /// P交易商品冻结交易货款
- /// </summary>
- public decimal FreezeTradeMoney
- {
- get
- {
- return _freezeTradeMoney;
- }
- set
- {
- Set(() => FreezeTradeMoney, ref _freezeTradeMoney, value);
- RaisePropertyChanged(() => FreezeTradeMoneyFormat);
- RaisePropertyChanged(() => FreezeTradeMoneyTooltip);
- }
- }
- /// <summary>
- /// 冻结交易货款 -格式化
- /// </summary>
- public string FreezeTradeMoneyFormat
- {
- get
- {
- return FreezeTradeMoney.ToString("f2");
- }
- }
- /// <summary>
- /// 冻结交易货款提示
- /// </summary>
- 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;
- /// <summary>
- /// X交易商品冻结交易货款
- /// </summary>
- public decimal FreezeDeliveryTradeMoney
- {
- get
- {
- return _freezeDeliveryTradeMoney;
- }
- set
- {
- Set(() => FreezeDeliveryTradeMoney, ref _freezeDeliveryTradeMoney, value);
- RaisePropertyChanged(() => FreezeDeliveryTradeMoneyFormat);
- }
- }
- /// <summary>
- /// 交割商品冻结交易货款 -格式化
- /// </summary>
- public string FreezeDeliveryTradeMoneyFormat
- {
- get
- {
- return FreezeDeliveryTradeMoney.ToString("f2");
- }
- }
- #endregion
- #region 冻结差价款
- private decimal _freezePriceMoveMoney = decimal.Zero;
- /// <summary>
- /// 冻结差价款
- /// </summary>
- public decimal FreezePriceMoveMoney
- {
- get
- {
- return _freezePriceMoveMoney;
- }
- set
- {
- Set(() => FreezePriceMoveMoney, ref _freezePriceMoveMoney, value);
- RaisePropertyChanged(() => FreezePriceMoveMoneyFormat);
- RaisePropertyChanged(() => FreezePriceMoveMoneyTooltip);
- }
- }
- /// <summary>
- /// 冻结差价款 -格式化
- /// </summary>
- public string FreezePriceMoveMoneyFormat
- {
- get
- {
- return FreezePriceMoveMoney.ToString("f2");
- }
- }
- /// <summary>
- /// 冻结差价款提示
- /// </summary>
- 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;
- /// <summary>
- /// 交割价格
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public decimal DeliveryPrice
- {
- get
- {
- return _deliveryPrice;
- }
- set
- {
- Set(() => DeliveryPrice, ref _deliveryPrice, value);
- RaisePropertyChanged(() => DeliveryPriceFormat);
- }
- }
- /// <summary>
- /// 交割价格-格式化
- /// </summary>
- 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;
- /// <summary>
- /// 交割价格-类型【0持仓价-1结算价-2协议价-3最新价】
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public string DeliveryPriceTypeDisplay
- {
- get
- {
- return _deliveryPriceTypeDisplay;
- }
- set
- {
- Set(() => DeliveryPriceTypeDisplay, ref _deliveryPriceTypeDisplay, value);
- }
- }
- #endregion
- #region 最小交割数量
- private decimal _minDeliveryUnit = 1;
- /// <summary>
- /// 最小交割数量
- /// </summary>
- public decimal MinDeliveryUnit
- {
- get
- {
- return _minDeliveryUnit;
- }
- set
- {
- Set(() => MinDeliveryUnit, ref _minDeliveryUnit, value);
- }
- }
- #endregion
- #region 最大交割数量
- private decimal _maxDeliveryUnit = 1;
- /// <summary>
- /// 最大交割数量
- /// </summary>
- public decimal MaxDeliveryUnit
- {
- get
- {
- return _maxDeliveryUnit;
- }
- set
- {
- Set(() => MaxDeliveryUnit, ref _maxDeliveryUnit, value);
- }
- }
- #endregion
- #region 交易规则转换单位
- private string _tradeRuleTrans = string.Empty;
- /// <summary>
- /// 交易规则转换单位
- /// </summary>
- public string TradeRuleTrans
- {
- get
- {
- return _tradeRuleTrans;
- }
- set
- {
- Set(() => TradeRuleTrans, ref _tradeRuleTrans, value);
- }
- }
- #endregion
- #region 是否显示交易规则转换单位
- private Visibility _isVisibilityTradeRule = Visibility.Collapsed;
- /// <summary>
- /// 是否显示交易规则转换单位
- /// </summary>
- public Visibility IsVisibilityTradeRule
- {
- get
- {
- return _isVisibilityTradeRule;
- }
- set
- {
- Set(() => IsVisibilityTradeRule, ref _isVisibilityTradeRule, value);
- }
- }
- #endregion
- #region 是否隐藏冻结资金
- private Visibility _isVisibilityFreezeMoney = Visibility.Collapsed;
- /// <summary>
- /// Sets and gets the IsVisibilityFrezzMoney property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public Visibility IsVisibilityFreezeMoney
- {
- get
- {
- return _isVisibilityFreezeMoney;
- }
- set
- {
- Set(() => IsVisibilityFreezeMoney, ref _isVisibilityFreezeMoney, value);
- }
- }
- #endregion
- #region 是否隐藏交易货款
- private Visibility _isVisibilityDeliveryTradeMoney = Visibility.Collapsed;
- /// <summary>
- /// Sets and gets the IsVisibilityMoneryModeMargin property.
- /// </summary>
- public Visibility IsVisibilityDeliveryTradeMoney
- {
- get
- {
- return _isVisibilityDeliveryTradeMoney;
- }
- set
- {
- Set(() => IsVisibilityDeliveryTradeMoney, ref _isVisibilityDeliveryTradeMoney, value);
- }
- }
- #endregion
- #region 当前选择交易商品
- private GoodsDeliveryRelationModel _currentGoods;
- /// <summary>
- /// 当前选择交易商品
- /// </summary>
- 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<HoldingOrder> _holdDetails;
- /// <summary>
- /// 当前商品的持仓单
- /// </summary>
- public List<HoldingOrder> HoldDetails
- {
- get { return _holdDetails; }
- set { Set(() => HoldDetails, ref _holdDetails, value); }
- }
- #endregion
- #region 持仓汇总
- /// <summary>
- /// 持仓汇总
- /// </summary>
- private decimal _totalHoldDetails;
- /// <summary>
- /// 持仓汇总
- /// </summary>
- public decimal TotalHoldDetails
- {
- get
- {
- return _totalHoldDetails;
- }
- set
- {
- Set(() => TotalHoldDetails, ref _totalHoldDetails, value);
- }
- }
- #endregion
- #region 填写范围错误提示
- private Visibility _MinMaxErrVisibility = Visibility.Hidden;
- /// <summary>
- /// 填写范围错误提示
- /// </summary>
- public Visibility MinMaxErrVisibility
- {
- get
- {
- //if (MinMaxDeliNumVisibility != Visibility.Visible)
- //{
- // _MinMaxErrVisibility = Visibility.Visible;
- //}
- return _MinMaxErrVisibility;
- }
- }
- #endregion
- #region 是否显示填写范围
- private Visibility _minMaxDeliNumVisibility = Visibility.Visible;
- /// <summary>
- /// 是否显示填写范围
- /// </summary>
- 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;
- /// <summary>
- /// 可用持仓数量
- /// </summary>
- public decimal AvailHoldQty
- {
- get
- {
- return _availHoldQty;
- }
- set
- {
- Set(() => AvailHoldQty, ref _availHoldQty, value);
- }
- }
- #endregion
- #region 当前持仓明细表
- //private HoldingOrder _selectOrder;
- ///// <summary>
- ///// 当前持仓明细表商品
- ///// </summary>
- //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;
- /// <summary>
- /// 申报数量-转交割数量
- /// </summary>
- public decimal RelationNum
- {
- get
- {
- return _relationNum;
- }
- set
- {
- Set(() => RelationNum, ref _relationNum, value);
- RaisePropertyChanged(() => RelationNumDisplay);
- }
- }
- /// <summary>
- /// 申报数量-转交割数量-格式化
- /// </summary>
- public string RelationNumDisplay
- {
- get { return RelationNum.ToString("f2"); }
- }
- #endregion
- #region 【置灰】设置按键不可用
- private bool _oKButtonEnabled = true;
- /// <summary>
- ///设置按键不可用
- /// </summary>
- public bool OKButtonEnabled
- {
- get
- {
- return _oKButtonEnabled;
- }
- set
- {
- Set(() => OKButtonEnabled, ref _oKButtonEnabled, value);
- }
- }
- #endregion
- #region 是否忙
- private bool _isBusy;
- /// <summary>
- /// 是否忙
- /// </summary>
- public bool IsBusy
- {
- get { return _isBusy; }
- set { Set(() => IsBusy, ref _isBusy, value); }
- }
- #endregion
- #region 服务忙提示
- private string _busyTips;
- /// <summary>
- /// 服务忙提示
- /// </summary>
- public string BusyTips
- {
- get
- {
- return _busyTips;
- }
- set
- {
- Set(() => BusyTips, ref _busyTips, value);
- }
- }
- #endregion
- #region 错误信息提示
- private string _ShowErrorInfo = string.Empty;
- /// <summary>
- /// Sets and gets the ShowErrorInfo property.
- /// </summary>
- public string ShowErrorInfo
- {
- get
- {
- return _ShowErrorInfo;
- }
- set
- {
- Set(() => ShowErrorInfo, ref _ShowErrorInfo, value);
- }
- }
- private Visibility _IsShowErrorInfo = Visibility.Collapsed;
- /// <summary>
- /// Sets and gets the IsShowErrorInfo property.
- /// </summary>
- public Visibility IsShowErrorInfo
- {
- get
- {
- return _IsShowErrorInfo;
- }
- set
- {
- Set(() => IsShowErrorInfo, ref _IsShowErrorInfo, value);
- }
- }
- #endregion
- #region 当前交割配置明细/当前交割配置List
- public List<DeliveryConfig> tempDeliveryConfigList = new List<DeliveryConfig>();
- private DeliveryConfig _currentDeliveryGoodsConfig = null;
- /// <summary>
- /// 当前交割配置明细
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public DeliveryConfig CurrentDeliveryGoodsConfig
- {
- get
- {
- return _currentDeliveryGoodsConfig;
- }
- set
- {
- Set(() => CurrentDeliveryGoodsConfig, ref _currentDeliveryGoodsConfig, value);
- }
- }
- public List<GoodsDeliveryRelationModel> tempGoodsDeliveryRelationList = new List<GoodsDeliveryRelationModel>();
- private GoodsDeliveryRelationModel _currentGoodsDeliveryRelation = null;
- /// <summary>
- /// 当前交割配置明细
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public GoodsDeliveryRelationModel CurrentGoodsDeliveryRelation
- {
- get
- {
- return _currentGoodsDeliveryRelation;
- }
- set
- {
- Set(() => CurrentGoodsDeliveryRelation, ref _currentGoodsDeliveryRelation, value);
- }
- }
- #endregion
- #region 可申报数量
- private int _canDeliveryCount = 0;
- /// <summary>
- /// 可申报数量
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public int CanDeliveryCount
- {
- get
- {
- return _canDeliveryCount;
- }
- set
- {
- Set(() => CanDeliveryCount, ref _canDeliveryCount, value);
- }
- }
- #endregion
- #region 是否隐藏关联交易商品[P+X]
- private Visibility _isVisibilityRelationGoodsInfo = Visibility.Collapsed;
- /// <summary>
- /// 是否隐藏关联交易商品[P+X]
- /// </summary>
- public Visibility IsVisibilityRelationGoodsInfo
- {
- get
- {
- return _isVisibilityRelationGoodsInfo;
- }
- set
- {
- Set(() => IsVisibilityRelationGoodsInfo, ref _isVisibilityRelationGoodsInfo, value);
- }
- }
- #endregion
- #region 关联交易商品名称[P+X]
- private string _relationGoods = string.Empty;
- /// <summary>
- /// 关联交易商品名称[P+X]
- /// </summary>
- public string RelationGoodsName
- {
- get
- {
- return _relationGoods;
- }
- set
- {
- Set(() => RelationGoodsName, ref _relationGoods, value);
- }
- }
- #endregion
- #region 关联交易商品持仓数量[P+X]
- private decimal _relationGoodsHoldQty = decimal.Zero;
- /// <summary>
- /// 关联交易商品持仓数量[P+X]
- /// </summary>
- public decimal RelationGoodsHoldQty
- {
- get
- {
- return _relationGoodsHoldQty;
- }
- set
- {
- Set(() => RelationGoodsHoldQty, ref _relationGoodsHoldQty, value);
- }
- }
- #endregion
- #region 关联交易商品交割价格[P+X]
- private decimal _relationGoodsHoldPrice = decimal.Zero;
- /// <summary>
- /// 关联交易商品交割价格[P+X]
- /// </summary>
- public decimal RelationGoodsHoldPrice
- {
- get
- {
- return _relationGoodsHoldPrice;
- }
- set
- {
- Set(() => RelationGoodsHoldPrice, ref _relationGoodsHoldPrice, value);
- RaisePropertyChanged(() => RelationGoodsHoldPriceFormat);
- }
- }
- /// <summary>
- /// 关联交易商品交割价格[P+X]格式化
- /// </summary>
- public string RelationGoodsHoldPriceFormat
- {
- get
- {
- if (RelationGoodsHoldPrice > decimal.Zero)
- {
- return RelationGoodsHoldPrice.ToString("f2");
- }
- else
- {
- return "-";
- }
- }
- }
- #endregion
- #region 当前关联交易商品的持仓单[P+X]
- private List<HoldingOrder> _relationholdDetails;
- /// <summary>
- /// 当前关联交易商品的持仓单[P+X]
- /// </summary>
- public List<HoldingOrder> RelationHoldDetails
- {
- get { return _relationholdDetails; }
- set { Set(() => RelationHoldDetails, ref _relationholdDetails, value); }
- }
- #endregion
- #region 差价升贴水
- private string _deliveryPriceMoveDisplay = string.Empty;
- /// <summary>
- /// 差价升贴水
- /// </summary>
- public string DeliveryPriceMoveDisplay
- {
- get
- {
- return _deliveryPriceMoveDisplay;
- }
- set
- {
- Set(() => DeliveryPriceMoveDisplay, ref _deliveryPriceMoveDisplay, value);
- }
- }
- #endregion
- #region 关联商品占用保证金均价
- private decimal _relationPerUsedMargin = decimal.Zero;
- /// <summary>
- /// 占用保证金均价RelationPerUsedMargin
- /// </summary>
- public decimal RelationPerUsedMargin
- {
- get
- {
- return _relationPerUsedMargin;
- }
- set
- {
- Set(() => RelationPerUsedMargin, ref _relationPerUsedMargin, value);
- }
- }
- #endregion
- #region 当前商品占用保证金均价
- private decimal _currentPerUsedMargin = decimal.Zero;
- /// <summary>
- /// 当前商品占用保证金均价
- /// </summary>
- public decimal CurrentPerUsedMargin
- {
- get
- {
- return _currentPerUsedMargin;
- }
- set
- {
- Set(() => CurrentPerUsedMargin, ref _currentPerUsedMargin, value);
- }
- }
- private decimal _deliveryFee;
- /// <summary>
- /// 每手交割手续费
- /// </summary>
- public decimal DeliveryFee
- {
- get { return _deliveryFee; }
- set { Set(() => DeliveryFee, ref _deliveryFee, value); }
- }
- private decimal _freezeFax;
- /// <summary>
- /// 每手交割税款
- /// </summary>
- public decimal FreezeFax
- {
- get
- {
- return _freezeFax;
- }
- set { Set(() => FreezeFax, ref _freezeFax, value); }
- }
- /// <summary>
- /// 交割总税款
- /// </summary>
- public decimal TotalFreezeFax
- {
- get
- {
- return Math.Round(FreezeFax * DeliveryCount, 2, MidpointRounding.AwayFromZero);
- }
- }
- /// <summary>
- /// 交割交割手续费
- /// </summary>
- public decimal TotalDeliveryFee
- {
- get
- {
- return Math.Round(DeliveryFee * DeliveryCount, 2, MidpointRounding.AwayFromZero); ;
- }
- }
- #endregion
- #endregion "Public Properties To Get/Set "
- #region "Public Commands"
- #region 选中Command
- /// <summary>
- /// 选中
- /// </summary>
- private RelayCommand<string> selectCommand;
- public RelayCommand<string> SelectCommand
- {
- get
- {
- return selectCommand ?? (selectCommand = new RelayCommand<string>(
- (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
- /// <summary>
- /// 取消选中
- /// </summary>
- private RelayCommand<string> unSelectCommand;
- public RelayCommand<string> UnSelectCommand
- {
- get
- {
- return unSelectCommand ?? (unSelectCommand = new RelayCommand<string>(
- (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
- /// <summary>
- /// 下单窗口取消
- /// </summary>
- public RelayCommand<Window> CancelCommand
- {
- get
- {
- return new RelayCommand<Window>((dialog) =>
- {
- dialog.DialogResult = false;
- });
- }
- }
- /// <summary>
- /// 下单确定
- /// </summary>
- public RelayCommand<Window> OKCommand
- {
- get
- {
- return new RelayCommand<Window>((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();
- }
- /// <summary>
- /// 交割关联商品信息触发
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 回滚仓单数据选择
- /// </summary>
- 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();
- }
- /// <summary>
- /// 计算可配数量、剩余数量
- /// </summary>
- private void SettlementDeliveryMatchNum()
- {
- #region 配对数量仅能大于 等于 申报数量
- AlreadyMatchQty = 0;
- preOtherCanMatchQty = OtherCanMatchQty = RelationNum;
- _currentSelectedWrDetail = new List<WrDetailModel>();
- 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();
- }
- /// <summary>
- /// 触发提交按钮是否可用
- /// </summary>
- 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 初始化下单计时时间
- /// <summary>
- /// 初始化下单计时时间
- /// </summary>
- //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);
- //}
- ///// <summary>
- ///// 清除计时器
- ///// </summary>
- //private void DisposeTimer()
- //{
- // this._timer.Stop();
- // this._timer.Elapsed -= _timer_Elapsed;
- // this._timer.Close();
- // //IsOrderVisible = false;
- //}
- #endregion
- /// <summary>
- /// 提交成功返回
- /// </summary>
- /// <param name="order"></param>
- 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);
- }
- /// <summary>
- /// 委托失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- 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();
- }
- }));
- }
- /// <summary>
- /// 交割提货个人信息-成功返回
- /// </summary>
- /// <param name="orders"></param>
- protected void QueryDepositPersonalInfoSuccess(DepositPersonalInfoRspModel itemModel)
- {
- if (itemModel != null)
- {
- CurrentDepositPersonalInfo = itemModel;
- if (CurrentDepositPersonalInfo != null)
- {
- RecieveAddress = CurrentDepositPersonalInfo.address;
- RecievePerson = CurrentDepositPersonalInfo.personName;
- PhoneNum = CurrentDepositPersonalInfo.telphone;
-
- }
- }
- IsBusy = false;
- }
- /// <summary>
- /// 查询-交割规则-成功返回
- /// </summary>
- /// <param name="orders"></param>
- protected void QueryRelationSuccess(List<GoodsDeliveryRelationModel> itemList)
- {
- if (itemList != null)
- {
- GoodsDeliveryRelationList = itemList;
- #region 初始化交割商品
- List<GoodsDeliveryRelationModel> tempGoods = new List<GoodsDeliveryRelationModel>();
- //过滤全额商品->显示所有商品
- //var GoodsList = CacheManager.CacheGoodsBaseInfos;//.Where(x => x.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY);
- if (UserManager.GetCacheOrders<HoldingOrder>() != null && UserManager.GetCacheOrders<HoldingOrder>().Distinct().ToList().Count() > 0)
- { //所有持仓单
- var AllDeliveryGoodsIDList = UserManager.GetCacheOrders<HoldingOrder>().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;
- }
- /// <summary>
- /// 卖交割仓单信息查询-成功返回
- /// </summary>
- /// <param name="itemList"></param>
- protected void WhRecieptInfoSuccess(List<DeliveryWhRecieptInfo> itemList)
- {
- if (itemList != null)
- {
- DeliveryMatchOrderList = itemList.Where(x => x.EnableQty > 0).ToList();
- }
- IsBusy = false;
- }
- /// <summary>
- /// 交割商品关系配置失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void DeliveryGoodsCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- }
- /// <summary>
- /// 获取交割提货个人信息失败返回
- /// </summary>
- /// <param name="errorEntity"></param>
- private void QueryDepositPersonalInfoCallBack(ErrorEntity errorEntity)
- {
- IsBusy = false;
- }
- /// <summary>
- /// 初始化交割商品列表数据
- /// </summary>
- private void InitData()
- {
- IsBusy = true;
- _currentLinkModel = eDeliveryContractLink.None;
- _currentMoneyMode = eMoneyMode.MONEYMODE_MARGIN;
- _deliveryService.QueryGoodsDeliveryRelationList(QueryRelationSuccess, DeliveryGoodsCallBack);
- SetDeliveryCount();
- }
- /// <summary>
- /// 重置数据初始值
- /// </summary>
- 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;
- }
- /// <summary>
- /// 默认数据当没有获取到交割关系时
- /// </summary>
- private void DefaultDataWhenNoRelation()
- {
- CanDeliveryCount = 0;
- DeliveryPriceTypeDisplay = "-";
- DeliveryPrice = 0;
- TradeRuleTrans = "-";
- MinDeliveryUnit = 0;
- MaxDeliveryUnit = 0;
- }
- /// <summary>
- /// 设置可交收数量
- /// </summary>
- 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);
- }
- /// <summary>
- /// 检测卖方向是否可用
- /// </summary>
- private void CheckIsSellEnable()
- {
- IsSellEnable = false;
- if (CurrentGoods != null)
- {
- var currentGoodsMoneymode = CurrentGoods.currentMoneymode;
- var currentGoodsTradeMode = CurrentGoods.currentTradeMode;
- decimal AvailQty = decimal.Zero;
- var holders = UserManager.GetCacheOrders<HoldingOrder>();
- 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;
- }
- }
- }
- /// <summary>
- /// 获取交割提货个人信息
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 获取卖交割仓单信息
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 获取P+X交割商品信息
- /// </summary>
- private void GetPAndXDeliveryGoodsInfo()
- {
- var holders = UserManager.GetCacheOrders<HoldingOrder>();
- 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
- }
- }
- }
- /// <summary>
- /// 交割算法取值
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 最大最小交割手数
- /// </summary>
- 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;
- }
- /// <summary>
- /// 资金计算最大可下单数据
- /// </summary>
- /// <returns></returns>
- 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);
- }
- /// <summary>
- /// 查找商品信息BY商品ID
- /// </summary>
- private GoodsDeliveryRelationModel FindGoodsInfoByID(long goodsId)
- {
- if (GoodsDeliveryRelationList.Any() && GoodsDeliveryRelationList.Count > 0)
- {
- return GoodsDeliveryRelationList.Find(x => x.GoodsId == goodsId);
- }
- return null;
- }
- /// <summary>
- /// 查找关联商品信息BY商品ID
- /// </summary>
- private GoodsDeliveryRelationModel FindRelationGoodsInfoByID(long RelationGoodsId)
- {
- if (GoodsDeliveryRelationList.Any() && GoodsDeliveryRelationList.Count > 0)
- {
- return GoodsDeliveryRelationList.Find(x => x.RelationGoodsId == RelationGoodsId);
- }
- return null;
- }
- /// <summary>
- /// 计算每个交割单位的冻结金额
- /// </summary>
- /// <returns></returns>
- 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
- /// <summary>
- /// 按比例买卖交割单手手续费-计算
- /// </summary>
- 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"
- /// <summary>
- /// 数据验证
- /// </summary>
- /// <param name="msg"></param>
- /// <returns></returns>
- 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
- }
- }
|