private bool ValidateChangeItem(ClosePositionSecurityItem changeItem)
        {
            if (string.IsNullOrEmpty(changeItem.SecuCode))
            {
                return(false);
            }

            if (changeItem.EntrustAmount <= 0)
            {
                return(false);
            }

            if (changeItem.CommandPrice <= 0)
            {
                return(false);
            }

            if (changeItem.EDirection != Model.EnumType.EntrustDirection.BuyClose &&
                changeItem.EDirection != Model.EnumType.EntrustDirection.SellOpen &&
                changeItem.EDirection != Model.EnumType.EntrustDirection.BuySpot &&
                changeItem.EDirection != Model.EnumType.EntrustDirection.SellSpot)
            {
                return(false);
            }

            return(true);
        }
        private void LoadChangeOut(ClosePositionSecurityItem closeSecuItem)
        {
            AutoItem autoItem = new AutoItem
            {
                Id   = closeSecuItem.SecuCode,
                Name = closeSecuItem.SecuName
            };

            this.acSecuOut.SetCurrentItem(autoItem);

            string longShort = string.Format("{0}", (int)closeSecuItem.PositionType);

            ComboBoxUtil.SetComboBoxSelect(this.cbOutDirection, longShort);

            //股票设置调出为卖出,调入为买入
            //股指期货设置调出为买入平仓,调入为卖出开仓
            EntrustDirection eOutDirection;
            EntrustDirection eInDirection;

            if (closeSecuItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
            {
                eOutDirection = EntrustDirection.Sell;
                eInDirection  = EntrustDirection.Buy;
            }
            else if (closeSecuItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
            {
                eOutDirection = EntrustDirection.Buy;
                eInDirection  = EntrustDirection.Sell;
            }
            else
            {
                eOutDirection = EntrustDirection.Sell;
                eInDirection  = EntrustDirection.Buy;
            }

            string outDirection = string.Format("{0}", (int)eOutDirection);

            ComboBoxUtil.SetComboBoxSelect(this.cbOutDirection, outDirection);

            this.tbOutAmount.Text = string.Format("{0}", closeSecuItem.AvailableAmount);

            //设置调入
            string inDirection = string.Format("{0}", (int)eInDirection);

            ComboBoxUtil.SetComboBoxSelect(this.cbInDirection, inDirection);
        }
        private void LoadAutoComplete(ClosePositionSecurityItem closeSecuItem)
        {
            IList <AutoItem> dataSource = new List <AutoItem>();
            var matchItems = _secuInfoList.Where(p => p.SecuType == closeSecuItem.SecuType && !p.SecuCode.Equals(closeSecuItem.SecuCode)).ToList();

            foreach (var item in matchItems)
            {
                AutoItem autoItem = new AutoItem
                {
                    Id   = item.SecuCode,
                    Name = item.SecuName,
                };

                dataSource.Add(autoItem);
            }

            this.acSecuOut.AutoDataSource = dataSource;
            this.acSecuIn.AutoDataSource  = dataSource;
        }
        private ClosePositionSecurityItem GetChangeOutItem()
        {
            ClosePositionSecurityItem changeOutItem = new ClosePositionSecurityItem
            {
                SecuCode      = _originItem.SecuCode,
                SecuName      = _originItem.SecuName,
                SecuType      = _originItem.SecuType,
                InstanceId    = _originItem.InstanceId,
                PortfolioId   = _originItem.PortfolioId,
                PortfolioName = _originItem.PortfolioName,
                ExchangeCode  = _originItem.ExchangeCode,
                PositionType  = _originItem.PositionType,
            };

            int temp;

            if (int.TryParse(this.tbOutAmount.Text, out temp))
            {
                changeOutItem.EntrustAmount = temp;
            }

            double dtemp;

            if (double.TryParse(this.tbOutPrice.Text, out dtemp))
            {
                changeOutItem.CommandPrice = dtemp;
            }

            if (changeOutItem.SecuType == SecurityType.Futures)
            {
                changeOutItem.EDirection = EntrustDirection.BuyClose;
            }
            else if (changeOutItem.SecuType == SecurityType.Stock)
            {
                changeOutItem.EDirection = EntrustDirection.SellSpot;
            }

            return(changeOutItem);
        }
        private void Button_Confirm_Click(object sender, System.EventArgs e)
        {
            var changeInItem  = GetChangeInItem();
            var changeOutItem = GetChangeOutItem();

            if (!ValidateChangeItem(changeInItem) || !ValidateChangeItem(changeOutItem))
            {
                MessageDialog.Error(this, msgChgPositionConfirm);
                return;
            }

            ClosePositionSecurityItem[] datas = new ClosePositionSecurityItem[2];
            datas[0] = changeInItem;
            datas[1] = changeOutItem;
            if (OnSave(this, datas))
            {
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            //else
            //{
            //    DialogResult = System.Windows.Forms.DialogResult.No;
            //}
        }
        private bool Form_LoadData(object sender, object data)
        {
            if (data == null)
            {
                return(false);
            }
            if (!(data is ClosePositionSecurityItem))
            {
                return(false);
            }

            _secuInfoList = SecurityInfoManager.Instance.Get();
            if (_secuInfoList == null)
            {
                return(false);
            }

            _originItem = data as ClosePositionSecurityItem;

            LoadAutoComplete(_originItem);
            LoadChangeOut(_originItem);

            return(true);
        }
        private ClosePositionSecurityItem GetChangeInItem()
        {
            var secuItem = this.acSecuIn.GetCurrentItem();

            ClosePositionSecurityItem changeInItem = new ClosePositionSecurityItem();

            changeInItem.SecuCode = secuItem.Id;
            changeInItem.SecuName = secuItem.Name;

            var findItem = _secuInfoList.Find(p => p.SecuCode.Equals(changeInItem.SecuCode));

            if (findItem != null)
            {
                changeInItem.SecuType     = findItem.SecuType;
                changeInItem.ExchangeCode = findItem.ExchangeCode;
            }

            int temp;

            if (int.TryParse(this.tbInAmount.Text, out temp))
            {
                changeInItem.EntrustAmount = temp;
            }

            double dtemp;

            if (double.TryParse(this.tbInPrice.Text, out dtemp))
            {
                changeInItem.CommandPrice = dtemp;
            }

            changeInItem.InstanceId    = _originItem.InstanceId;
            changeInItem.PortfolioId   = _originItem.PortfolioId;
            changeInItem.PortfolioName = _originItem.PortfolioName;

            switch (_originItem.PositionType)
            {
            case PositionType.FuturesLong:
            {
                if (changeInItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
                {
                    changeInItem.PositionType = PositionType.FuturesShort;
                }
            }
            break;

            case PositionType.FuturesShort:
            {
                if (changeInItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
                {
                    changeInItem.PositionType = PositionType.FuturesLong;
                }
            }
            break;

            case PositionType.SpotLong:
            {
                if (changeInItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
                {
                    changeInItem.PositionType = PositionType.SpotShort;
                }
            }
            break;

            case PositionType.SpotShort:
            {
                if (changeInItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
                {
                    changeInItem.PositionType = PositionType.SpotLong;
                }
            }
            break;

            default:
                break;
            }

            if (changeInItem.SecuType == SecurityType.Futures)
            {
                changeInItem.EDirection = EntrustDirection.SellOpen;
            }
            else if (changeInItem.SecuType == SecurityType.Stock)
            {
                changeInItem.EDirection = EntrustDirection.BuySpot;
            }

            //switch (_originItem.EDirection)
            //{
            //    case Model.EnumType.EntrustDirection.BuySpot:
            //        {
            //            if (outItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
            //            {
            //                outItem.EDirection = Model.EnumType.EntrustDirection.SellSpot;
            //            }
            //        }
            //        break;
            //    case Model.EnumType.EntrustDirection.SellSpot:
            //        {
            //            if (outItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
            //            {
            //                outItem.EDirection = Model.EnumType.EntrustDirection.BuySpot;
            //            }
            //        }
            //        break;
            //    case Model.EnumType.EntrustDirection.BuyClose:
            //        {
            //            if (outItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
            //            {
            //                outItem.EDirection = Model.EnumType.EntrustDirection.SellOpen;
            //            }
            //        }
            //        break;
            //    case Model.EnumType.EntrustDirection.SellOpen:
            //        {
            //            if (outItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
            //            {
            //                outItem.EDirection = Model.EnumType.EntrustDirection.BuyClose;
            //            }
            //        }
            //        break;
            //    default:
            //        break;
            //}

            return(changeInItem);
        }