Beispiel #1
0
        /// <summary>
        /// 根据期货类型(股指期货,商品期货)绑定期货涨跌幅文字
        /// </summary>
        private void BindFuturesHighLowStopVText()
        {
            try
            {
                int breedClassID = AppGlobalVariable.INIT_INT;//品种ID
                if (!string.IsNullOrEmpty(this.cmbBreedClassID.Text))
                {
                    breedClassID = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex;

                    CM_BreedClass cM_BreedClass = new CM_BreedClass();
                    cM_BreedClass = CommonParameterSetCommon.GetBreedClassByBClassID(breedClassID);
                    if (cM_BreedClass != null)
                    {
                        int breedClassTypeID = Convert.ToInt32(cM_BreedClass.BreedClassTypeID);//品种类型ID
                        if (breedClassTypeID == (int)Types.BreedClassTypeEnum.CommodityFuture)
                        {
                            m_DiffFuturesType = false;
                            this.labNewBreedFPHighLowStopV.Text       = "新品种合约上市" + "\n" + "当日涨跌幅:";
                            this.labNewMonthFPactHighLowStopV.Text    = "新月份合约上市" + "\n" + "当日涨跌幅:";
                            this.labNewBreedFPHighLowStopV.Visible    = true;
                            this.labNewMonthFPactHighLowStopV.Visible = true;
                            this.txtNewBreedFPHighLowStopV.Visible    = true;
                            this.txtNewMonthFPactHighLowStopV.Visible = true;
                            this.labNewBreedB.Visible  = true;
                            this.labNewMonthB.Visible  = true;
                            labNewBreedFPHighL.Visible = true;
                            labNewMonthFPactH.Visible  = true;
                        }
                        else if (breedClassTypeID == (int)Types.BreedClassTypeEnum.StockIndexFuture)
                        {
                            m_DiffFuturesType = true;
                            this.labNewBreedFPHighLowStopV.Text       = "季月合约上市首" + "\n" + "日涨跌幅:";
                            this.labNewMonthFPactHighLowStopV.Text    = "合约最后交易日" + "\n" + "涨跌幅:";
                            this.labNewBreedFPHighLowStopV.Visible    = true;
                            this.labNewMonthFPactHighLowStopV.Visible = true;
                            this.txtNewBreedFPHighLowStopV.Visible    = true;
                            this.txtNewMonthFPactHighLowStopV.Visible = true;
                            this.labNewBreedB.Visible  = true;
                            this.labNewMonthB.Visible  = true;
                            labNewBreedFPHighL.Visible = true;
                            labNewMonthFPactH.Visible  = true;
                        }
                    }
                }
            }
            catch
            {
                return;
            }
        }
        /// <summary>
        /// 港股最小交易单位校验
        /// 供调用者直接调用
        /// </summary>
        /// <param name="request">委托</param>
        /// <param name="position">当前委托对应的商品的持仓量</param>
        /// <param name="errMsg">错误信息</param>
        /// <returns>是否校验成功</returns>
        public static bool ValidateHKMinVolumeOfBusiness(HKOrderRequest request, int position, ref string errMsg)
        {
            CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(request.Code, Types.BreedClassTypeEnum.HKStock);

            bool result = false;

            if (breedClass != null)
            {
                int breedClassTypeID = breedClass.BreedClassTypeID.Value;
                int breedClassID     = breedClass.BreedClassID;

                if (breedClassTypeID != (int)Types.BreedClassTypeEnum.HKStock)
                {
                    return(false);
                }

                HKStockMinVolumeOfBusinessCommand command = new HKStockMinVolumeOfBusinessCommand(breedClassID, position);
                result = command.Validate(request, ref errMsg);
            }

            return(result);
        }
        private static XHCostResult InternalComputeXHCost(StockOrderRequest request, XH_SpotCosts cost)
        {
            CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(request.Code);


            XHCostResult result = new XHCostResult();

            result.Code = request.Code;

            decimal orderPrice = (decimal)request.OrderPrice;
            //期货合约乘数300
            decimal scale = MCService.GetTradeUnitScale(request.Code, request.OrderUnitType);
            //以计价单位计算的委托量
            var orderAmount = (decimal)request.OrderAmount * scale;

            //成交额
            var dealAmount = orderPrice * orderAmount;

            /// 1.印花税
            decimal stamp = cost.StampDuty / 100;

            decimal stampStart = cost.StampDutyStartingpoint;

            if (cost.StampDutyTypeID.HasValue)
            {
                int stampType = cost.StampDutyTypeID.Value;

                #region old code
                //if (stampType == (int)Types.GetValueTypeEnum.SingleSell &&
                //    request.BuySell == Types.TransactionDirection.Selling)
                //{
                //    decimal stampVal = stamp * dealAmount;
                //    if (stampVal < stampStart)
                //        stampVal = stampStart;

                //    stampVal = Utils.Round(stampVal);

                //    result.StampDuty = stampVal;
                //}
                #endregion
                decimal stampVal = stamp * dealAmount;
                if (stampVal < stampStart)
                {
                    stampVal = stampStart;
                }
                stampVal = Utils.Round(stampVal);

                switch ((Types.GetValueTypeEnum)stampType)
                {
                case Types.GetValueTypeEnum.Single:
                    break;

                case Types.GetValueTypeEnum.Scope:
                    break;

                case Types.GetValueTypeEnum.Turnover:
                    break;

                case Types.GetValueTypeEnum.Thigh:
                    break;

                case Types.GetValueTypeEnum.SingleBuy:
                    if (request.BuySell == Types.TransactionDirection.Buying)
                    {
                        result.StampDuty = stampVal;
                    }
                    break;

                case Types.GetValueTypeEnum.SingleSell:
                    if (request.BuySell == Types.TransactionDirection.Selling)
                    {
                        result.StampDuty = stampVal;
                    }
                    break;

                case Types.GetValueTypeEnum.TwoEdge:
                    result.StampDuty = stampVal;
                    break;

                case Types.GetValueTypeEnum.No:
                    break;

                default:
                    break;
                }
            }


            /// 2.佣金
            //public decimal Commision { get; set; }
            if (cost.Commision.HasValue)
            {
                decimal comm = cost.Commision.Value / 100;

                decimal commVal = comm * dealAmount;

                decimal commStart = cost.CommisionStartingpoint;

                if (commVal < commStart)
                {
                    commVal = commStart;
                }

                commVal = Utils.Round(commVal);

                result.Commision = commVal;
            }


            /// 3.过户费
            //public decimal TransferToll { get; set; }
            decimal trans = cost.TransferToll / 100;

            int transType = cost.TransferTollTypeID;

            decimal transVal = 0;

            //过户费类型 [按股] [按成交额]
            switch (transType)
            {
            case (int)Types.GetValueTypeEnum.Thigh:
                transVal = trans * orderAmount;
                break;

            case (int)Types.GetValueTypeEnum.Turnover:
                transVal = trans * dealAmount;
                break;
            }
            transVal = Utils.Round(transVal);

            if (cost.TransferTollStartingpoint.HasValue)
            {
                decimal transStart = cost.TransferTollStartingpoint.Value;
                if (transVal < transStart)
                {
                    transVal = transStart;
                }
            }

            transVal            = Utils.Round(transVal);
            result.TransferToll = transVal;

            /// 4.交易手续费
            //public decimal PoundageSingleValue { get; set; }
            if (cost.GetValueTypeID.HasValue)
            {
                int poundType = cost.GetValueTypeID.Value;

                //交易手续费单值 single double
                switch (poundType)
                {
                case (int)Types.GetValueTypeEnum.Single:
                    decimal pound      = cost.PoundageSingleValue.Value / 100;
                    decimal poundValue = pound * dealAmount;
                    poundValue = Utils.Round(poundValue);
                    result.PoundageSingleValue = poundValue;
                    break;

                case (int)Types.GetValueTypeEnum.Scope:
                    //IList<XH_SpotRangeCost> costs =
                    //    MCService.SpotTradeRules.GetSpotRangeCostByBreedClassID(breedClass.BreedClassID);

                    //foreach (XH_SpotRangeCost spotRangeCost in costs)
                    //{
                    //    //int fieldRangeID = spotRangeCost.FieldRangeID;
                    //    decimal pound2 = spotRangeCost.Value.Value;
                    //    pound2 = Utils.Round(pound2);

                    //    CM_FieldRange fieldRange = MCService.GetFieldRange(fieldRangeID);

                    //    //是否在当前字段范围内
                    //    bool isExist = MCService.CheckFieldRange(dealAmount, fieldRange);
                    //    if (isExist)
                    //    {
                    //        result.PoundageSingleValue = pound2;
                    //        break;
                    //    }
                    //}
                    break;
                }
            }


            /// 5.监管费
            //public decimal MonitoringFee { get; set; }
            if (cost.MonitoringFee.HasValue)
            {
                decimal monitor = cost.MonitoringFee.Value / 100;

                decimal monitorVal = monitor * dealAmount;
                monitorVal = Utils.Round(monitorVal);

                result.MonitoringFee = monitorVal;
            }


            /// 6.结算费
            if (cost.ClearingFees.HasValue)
            {
                decimal clear    = cost.ClearingFees.Value / 100;
                decimal clearval = clear * dealAmount;
                clearval = Utils.Round(clearval);

                result.ClearingFees = clearval;
            }


            /// 7.交易系统使用费(港股)
            if (cost.SystemToll.HasValue)
            {
                result.TradeSystemFees = cost.SystemToll.Value;
            }

            string format = "现货费用计算[代码={0},价格={1},数量={2},单位={3},方向={4}]";
            string desc   = string.Format(format, request.Code, request.OrderPrice, request.OrderAmount,
                                          request.OrderUnitType, request.BuySell);
            LogHelper.WriteDebug(desc + result);
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// 根据商品代码删除交易商品(相关表的记录同时删除)
        /// </summary>
        /// <param name="CommodityCode">商品代码</param>
        /// <param name="BreedClassID">品种ID</param>
        /// <returns></returns>
        public bool DeleteCMCommodity(string CommodityCode, int BreedClassID)
        {
            CM_CommodityDAL            cMCommodityDAL          = new CM_CommodityDAL();
            RC_TradeCommodityAssignDAL TradeCommodityAssignDAL = new RC_TradeCommodityAssignDAL();
            CM_CommodityFuseDAL        cMCommodityFuseDAL      = new CM_CommodityFuseDAL();
            CM_FuseTimesectionDAL      cMFuseTimesectionDAL    = new CM_FuseTimesectionDAL();
            CM_BreedClassBLL           cM_BreedClassBLL        = new CM_BreedClassBLL();
            DbConnection Conn = null;
            Database     db   = DatabaseFactory.CreateDatabase();

            Conn = db.CreateConnection();
            if (Conn.State != ConnectionState.Open)
            {
                Conn.Open();
            }
            DbTransaction Tran = Conn.BeginTransaction();

            try
            {
                int breedClassTypeID = AppGlobalVariable.INIT_INT;//品种类型ID
                List <CM_BreedClass> cM_BreedClassList =
                    cM_BreedClassBLL.GetListArray(string.Format("BreedClassID={0}", BreedClassID));
                if (cM_BreedClassList.Count > 0)
                {
                    CM_BreedClass cM_BreedClass = cM_BreedClassList[0];
                    if (cM_BreedClass != null)
                    {
                        breedClassTypeID = Convert.ToInt32(cM_BreedClass.BreedClassTypeID);
                    }
                }
                if (breedClassTypeID == (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.StockIndexFuture)
                {
                    if (!string.IsNullOrEmpty(CommodityCode))
                    {
                        if (!cMFuseTimesectionDAL.DeleteByCommodityCode(CommodityCode, Tran, db))
                        {
                            Tran.Rollback();
                            return(false);
                        }
                        else
                        {
                            if (!cMCommodityFuseDAL.Delete(CommodityCode, Tran, db))
                            {
                                Tran.Rollback();
                                return(false);
                            }
                        }
                    }
                    TradeCommodityAssignDAL.DeleteByCommodityCode(CommodityCode, Tran, db);
                    if (!cMCommodityDAL.Delete(CommodityCode, Tran, db))
                    {
                        Tran.Rollback();
                        return(false);
                    }
                }
                else
                {
                    TradeCommodityAssignDAL.DeleteByCommodityCode(CommodityCode, Tran, db);
                    if (!cMCommodityDAL.Delete(CommodityCode, Tran, db))
                    {
                        Tran.Rollback();
                        return(false);
                    }
                }
                Tran.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                Tran.Rollback();
                string      errCode   = "GL-4301";
                string      errMsg    = "删除交易商品失败!";
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception.InnerException);
                return(false);
            }
            finally
            {
                if (Conn.State == ConnectionState.Open)
                {
                    Conn.Close();
                }
            }
        }
        /// <summary>
        /// 确定按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            //通过判断状态来执行不同的操作 1:添加  2:修改
            if (m_EditType == 1)
            {
                #region 添加

                try
                {
                    CM_BreedClass cM_BreedClas = new CM_BreedClass();
                    if (!string.IsNullOrEmpty(txtBreedClassName.Text))
                    {
                        if (!CommonParameterSetCommon.IsExistBreedClassName(txtBreedClassName.Text))
                        {
                            ShowMessageBox.ShowInformation("品种名称已存在!");
                            return;
                        }
                        cM_BreedClas.BreedClassName = txtBreedClassName.Text;
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("品种名称不能为空!");
                        return;
                    }

                    int _BreedClassMaxId = CommonParameterSetCommon.GetCMBreedClassMaxId();
                    if (_BreedClassMaxId != AppGlobalVariable.INIT_INT)
                    {
                        if (_BreedClassMaxId > 1500)                      //交易商品品种表中的最大ID大于系统默认的ID,1500时
                        {
                            cM_BreedClas.BreedClassID = _BreedClassMaxId; //因为在DAL层返回的最大ID已经加1
                        }
                        else
                        {
                            cM_BreedClas.BreedClassID = 1500 + 1;
                        }
                    }
                    if (!string.IsNullOrEmpty(cmbBourseType.Text))
                    {
                        cM_BreedClas.BourseTypeID = ((UComboItem)cmbBourseType.SelectedItem).ValueIndex;
                    }
                    else
                    {
                        cM_BreedClas.BourseTypeID = AppGlobalVariable.INIT_INT;
                    }

                    if (!string.IsNullOrEmpty(cmbBreedClassType.Text))
                    {
                        cM_BreedClas.BreedClassTypeID = ((UComboItem)cmbBreedClassType.SelectedItem).ValueIndex;
                        ;
                    }
                    else
                    {
                        cM_BreedClas.BreedClassTypeID = AppGlobalVariable.INIT_INT;
                    }

                    if (!string.IsNullOrEmpty(cmbAccountTypeIDFund.Text))
                    {
                        cM_BreedClas.AccountTypeIDFund =
                            ((UComboItem)cmbAccountTypeIDFund.SelectedItem).ValueIndex;
                    }
                    else
                    {
                        cM_BreedClas.AccountTypeIDFund = AppGlobalVariable.INIT_INT;
                    }
                    if (!string.IsNullOrEmpty(cmbAccountTypeIDHold.Text))
                    {
                        cM_BreedClas.AccountTypeIDHold =
                            ((UComboItem)cmbAccountTypeIDHold.SelectedItem).ValueIndex;
                    }
                    else
                    {
                        cM_BreedClas.AccountTypeIDHold = AppGlobalVariable.INIT_INT;
                    }
                    cM_BreedClas.ISSysDefaultBreed = (int)GTA.VTS.Common.CommonObject.Types.IsYesOrNo.No;
                    //用户添加的代码不是系统默认代码
                    if (cM_BreedClas.BreedClassTypeID ==
                        (int)GTA.VTS.Common.CommonObject.Types.BreedClassTypeEnum.HKStock)
                    {
                        cM_BreedClas.ISHKBreedClassType = (int)GTA.VTS.Common.CommonObject.Types.IsYesOrNo.Yes;
                        //当品种类型是港股时,标识为港股
                    }
                    else
                    {
                        cM_BreedClas.ISHKBreedClassType = (int)GTA.VTS.Common.CommonObject.Types.IsYesOrNo.No;
                        //当其它品种类型是时,标识为否
                    }
                    bool result = CommonParameterSetCommon.AddCMBreedClass(cM_BreedClas);
                    if (result) // != AppGlobalVariable.INIT_INT)
                    {
                        ShowMessageBox.ShowInformation("添加成功!");
                        ClearAll();
                        this.QueryCMBreedClass();
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("添加失败!");
                    }
                }
                catch (Exception ex)
                {
                    string      errCode   = "GL-4001";
                    string      errMsg    = "添加交易商品品种失败!";
                    VTException exception = new VTException(errCode, errMsg, ex);
                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                    return;
                }

                #endregion
            }
            else if (m_EditType == 2)
            {
                #region 修改

                try
                {
                    CM_BreedClass cM_BreedClas = new CM_BreedClass();
                    if (m_BreedClassID == AppGlobalVariable.INIT_INT)
                    {
                        ShowMessageBox.ShowInformation("请选择更新数据!");
                        return;
                    }
                    cM_BreedClas.BreedClassID = m_BreedClassID;

                    if (!string.IsNullOrEmpty(txtBreedClassName.Text))
                    {
                        cM_BreedClas.BreedClassName = txtBreedClassName.Text;
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("品种名称不能为空!");
                        return;
                    }
                    cM_BreedClas.BourseTypeID      = ((UComboItem)this.cmbBourseType.SelectedItem).ValueIndex;
                    cM_BreedClas.BreedClassTypeID  = ((UComboItem)this.cmbBreedClassType.SelectedItem).ValueIndex;
                    cM_BreedClas.AccountTypeIDFund = ((UComboItem)this.cmbAccountTypeIDFund.SelectedItem).ValueIndex;
                    cM_BreedClas.AccountTypeIDHold = ((UComboItem)this.cmbAccountTypeIDHold.SelectedItem).ValueIndex;

                    m_Result = CommonParameterSetCommon.UpdateCMBreedClass(cM_BreedClas);
                    if (m_Result)
                    {
                        ShowMessageBox.ShowInformation("修改成功!");
                        this.ClearAll();
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("修改失败!");
                    }
                    this.QueryCMBreedClass();
                }
                catch (Exception ex)
                {
                    string      errCode   = "GL-4003";
                    string      errMsg    = "修改交易商品品种失败!";
                    VTException exception = new VTException(errCode, errMsg, ex);
                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                    return;
                }

                #endregion
            }
        }
        /// <summary>
        /// 把新增的现货代码(StockInfo表和HKStockInfo表中)新增的代码自动添加到交易商品_撮合机_分配表中
        /// </summary>
        public void XHCodeAutoRCTradeCommodityAssign()
        {
            try
            {
                //交易所类型ID
                int            bourseTypeID   = 0;
                StockInfoBLL   stockInfoBLL   = new StockInfoBLL();
                HKStockInfoBLL hKStockInfoBLL = new HKStockInfoBLL();

                CM_BreedClassBLL           cM_BreedClassBLL            = new CM_BreedClassBLL();
                RC_MatchCenterBLL          rcMatchCenterBll            = new RC_MatchCenterBLL();
                RC_MatchMachineBLL         rcMatchMachineBll           = new RC_MatchMachineBLL();
                RC_TradeCommodityAssignBLL rcTradeCommodityAssignBll   = new RC_TradeCommodityAssignBLL();
                RC_MatchMachine            rcMatchMachine              = new RC_MatchMachine();
                RC_MatchCenter             rcMatchCenterModel          = new RC_MatchCenter();
                RC_TradeCommodityAssign    rcTradeCommodityAssignModel = new RC_TradeCommodityAssign();

                //获取撮合中心记录
                List <ManagementCenter.Model.RC_MatchCenter> rcMatchCenters = rcMatchCenterBll.GetListArray(string.Empty);
                if (rcMatchCenters.Count == 0)
                {
                    string errCode = "GL-7005";
                    string errMsg  = "撮合中心记录不存在!";
                    LogHelper.WriteDebug(errCode + errMsg);
                    VTException exception = new VTException(errCode, errMsg);
                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                    return;
                }

                //获取所有新添加的普通代码
                string           strWhereStock = " StockCode not in (select CommodityCode from CM_Commodity) ";
                List <StockInfo> stockInfoList = stockInfoBLL.GetStockInfoList(strWhereStock);
                //获取所有新添加的港股代码
                string             strWhereHKStock = " StockCode not in (select HKCommodityCode from HK_Commodity) ";
                List <HKStockInfo> hKStockInfoList = hKStockInfoBLL.GetHKStockInfoList(strWhereHKStock);

                if (stockInfoList.Count > 0)
                {
                    int breedClassID = 0;//品种标识
                    foreach (StockInfo info in stockInfoList)
                    {
                        if (breedClassID != info.BreedClassID)
                        {
                            breedClassID = info.BreedClassID;
                            //获取相同品种ID的所有代码
                            string           strWhereStock1 = " StockCode not in (select CommodityCode from CM_Commodity) and BreedClassID={0} ";
                            List <StockInfo> _stockInfoList =
                                stockInfoBLL.GetStockInfoList(string.Format(strWhereStock1, breedClassID));//(string.Format(" and BreedClassID={0}", breedClassID));
                            if (_stockInfoList == null || _stockInfoList.Count == 0)
                            {
                                string errCode = "GL-7006";
                                string errMsg  = "相同品种ID的所有普通代码为空!";
                                LogHelper.WriteDebug(errCode + errMsg);
                                VTException exception = new VTException(errCode, errMsg);
                                LogHelper.WriteError(exception.ToString(), exception.InnerException);
                                continue;
                            }
                            //根据品种ID获取交易所ID
                            CM_BreedClass cmBreedClass = cM_BreedClassBLL.GetModel(breedClassID);
                            if (cmBreedClass != null)
                            {
                                bourseTypeID = (int)cmBreedClass.BourseTypeID;
                                //根据交易所类型ID,获取撮合机记录
                                List <ManagementCenter.Model.RC_MatchMachine> rcMatchMachines =
                                    rcMatchMachineBll.GetListArray(string.Format("BourseTypeID={0}", bourseTypeID));
                                if (rcMatchMachines.Count == 0)
                                {
                                    string errCode = "GL-7007";
                                    string errMsg  = "获取撮合机记录不存在!";
                                    LogHelper.WriteDebug(errCode + errMsg);
                                    VTException exception = new VTException(errCode, errMsg);
                                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                                    return;
                                }
                                //把同一品种ID的所有代码添加到交易商品_撮合机_分配表中
                                foreach (StockInfo _stockInfo in _stockInfoList)
                                {
                                    rcTradeCommodityAssignModel.CommodityCode  = _stockInfo.StockCode;
                                    rcTradeCommodityAssignModel.MatchMachineID = rcMatchMachines[0].MatchMachineID;
                                    rcTradeCommodityAssignModel.CodeFormSource = (int)GTA.VTS.Common.CommonObject.Types.IsCodeFormSource.Yes; //_stockInfo.CodeFromSource;
                                    rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel);
                                }
                            }
                        }
                        continue;
                    }
                }
                if (hKStockInfoList.Count > 0)
                {
                    int breedClassID = 0;//品种标识
                    foreach (HKStockInfo hKInfo in hKStockInfoList)
                    {
                        if (breedClassID != hKInfo.BreedClassID)
                        {
                            breedClassID = hKInfo.BreedClassID;
                            //获取相同品种ID的所有港股代码
                            string strWhereHKStock1 = " StockCode not in (select HKCommodityCode from HK_Commodity) and BreedClassID={0} ";

                            List <HKStockInfo> _hKStockInfoList =
                                hKStockInfoBLL.GetHKStockInfoList(string.Format(strWhereHKStock1, breedClassID));//(string.Format(" and BreedClassID={0}", breedClassID));

                            if (_hKStockInfoList == null || _hKStockInfoList.Count == 0)
                            {
                                string errCode = "GL-7008";
                                string errMsg  = "相同品种ID的所有港股代码为空!";
                                LogHelper.WriteDebug(errCode + errMsg);
                                VTException exception = new VTException(errCode, errMsg);
                                LogHelper.WriteError(exception.ToString(), exception.InnerException);
                                continue;
                            }
                            //根据品种ID获取交易所ID
                            CM_BreedClass cmBreedClass = cM_BreedClassBLL.GetModel(breedClassID);
                            if (cmBreedClass != null)
                            {
                                bourseTypeID = (int)cmBreedClass.BourseTypeID;
                                //根据交易所类型ID,获取撮合机记录
                                List <ManagementCenter.Model.RC_MatchMachine> rcMatchMachines =
                                    rcMatchMachineBll.GetListArray(string.Format("BourseTypeID={0}", bourseTypeID));
                                if (rcMatchMachines.Count == 0)
                                {
                                    string errCode = "GL-7009";
                                    string errMsg  = "获取撮合机记录不存在!";
                                    LogHelper.WriteDebug(errCode + errMsg);
                                    VTException exception = new VTException(errCode, errMsg);
                                    LogHelper.WriteError(exception.ToString(), exception.InnerException);
                                    return;
                                }
                                //把同一品种ID的所有港股代码添加到交易商品_撮合机_分配表中
                                foreach (HKStockInfo _hKStockInfo in _hKStockInfoList)
                                {
                                    rcTradeCommodityAssignModel.CommodityCode  = _hKStockInfo.StockCode;
                                    rcTradeCommodityAssignModel.MatchMachineID = rcMatchMachines[0].MatchMachineID;
                                    rcTradeCommodityAssignModel.CodeFormSource = (int)GTA.VTS.Common.CommonObject.Types.IsCodeFormSource.No; //_hKStockInfo.CodeFromSource;
                                    rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel);
                                }
                            }
                        }
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                string errCode = "GL-7010";
                string errMsg  = "把新增的现货代码(StockInfo表和HKStockInfo表中)新增的代码添加到交易商品_撮合机_分配表中失败!";
                LogHelper.WriteDebug(errCode + errMsg);
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception.InnerException);
            }
        }
        /// <summary>
        /// 把期货新增的代码自动添加到可交易商品_撮合机_分配表中
        /// </summary>
        /// <param name="CommodityName">商品代码</param>
        /// <param name="BreedClassID">品种ID</param>
        public void QHCodeAutoRCTradeCommodityAssign(string CommodityName, int BreedClassID)
        {
            try
            {
                //交易所类型ID
                int bourseTypeID = 0;
                CM_BreedClassBLL           cM_BreedClassBLL            = new CM_BreedClassBLL();
                RC_MatchCenterBLL          rcMatchCenterBll            = new RC_MatchCenterBLL();
                RC_MatchMachineBLL         rcMatchMachineBll           = new RC_MatchMachineBLL();
                RC_TradeCommodityAssignBLL rcTradeCommodityAssignBll   = new RC_TradeCommodityAssignBLL();
                RC_MatchMachine            rcMatchMachine              = new RC_MatchMachine();
                RC_MatchCenter             rcMatchCenterModel          = new RC_MatchCenter();
                RC_TradeCommodityAssign    rcTradeCommodityAssignModel = new RC_TradeCommodityAssign();
                //根据品种ID获取交易所ID
                CM_BreedClass cmBreedClass = cM_BreedClassBLL.GetModel(BreedClassID);
                if (cmBreedClass != null)
                {
                    bourseTypeID = (int)cmBreedClass.BourseTypeID;
                }
                //获取撮合中心记录
                List <ManagementCenter.Model.RC_MatchCenter> rcMatchCenters = rcMatchCenterBll.GetListArray(string.Empty);
                //撮合中心记录存在
                if (rcMatchCenters.Count > 0)
                {
                    //根据交易所类型ID,获取撮合机记录
                    List <ManagementCenter.Model.RC_MatchMachine> rcMatchMachines = rcMatchMachineBll.GetListArray(string.Format("BourseTypeID={0}", bourseTypeID));

                    //有撮合机存在,则向可交易商品_撮合机_分配表中添加新代码
                    if (rcMatchMachines.Count > 0)
                    {
                        //判断代码分配记录已存在则退出 add by 董鹏 2010-03-31
                        if (rcTradeCommodityAssignBll.Exists(CommodityName, rcMatchMachines[0].MatchMachineID))
                        {
                            return;
                        }
                        rcTradeCommodityAssignModel.CommodityCode  = CommodityName;
                        rcTradeCommodityAssignModel.MatchMachineID = rcMatchMachines[0].MatchMachineID;
                        rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel);
                    }
                    else
                    {
                        //撮合机不存在,则添加撮合机
                        rcMatchMachine.MatchCenterID    = rcMatchCenters[0].MatchCenterID;
                        rcMatchMachine.MatchMachineName = "自动添加的撮合机名称";//保证不重复
                        rcMatchMachine.BourseTypeID     = bourseTypeID;
                        int result = rcMatchMachineBll.Add(rcMatchMachine);
                        if (result > 0)
                        {
                            rcTradeCommodityAssignModel.CommodityCode  = CommodityName;
                            rcTradeCommodityAssignModel.MatchMachineID = rcMatchMachines[0].MatchMachineID;
                            rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel);
                        }
                        else
                        {
                            //写错误日志
                            LogHelper.WriteDebug("添加撮合机失败");
                        }
                    }
                }
                else
                {
                    //添加撮合中心记录
                    rcMatchCenterModel.MatchCenterName = "自动添加的撮合中心名称";
                    rcMatchCenterModel.IP            = "127.0.0.1";
                    rcMatchCenterModel.Port          = 9281;
                    rcMatchCenterModel.CuoHeService  = "OrderDealRpt";
                    rcMatchCenterModel.XiaDanService = "DoOrderService";
                    int addrcMatchCResultID = rcMatchCenterBll.Add(rcMatchCenterModel);
                    if (addrcMatchCResultID > 0)
                    {
                        //撮合中心添加成功,则添加撮合机
                        rcMatchMachine.MatchCenterID    = addrcMatchCResultID; // rcMatchCenterslist[0].MatchCenterID;
                        rcMatchMachine.MatchMachineName = "自动添加的撮合机名称";        //保证不重复
                        rcMatchMachine.BourseTypeID     = bourseTypeID;
                        int resultMatchMachineID = rcMatchMachineBll.Add(rcMatchMachine);
                        //撮合机添加成功,则向可交易商品_撮合机_分配表中添加新代码
                        if (resultMatchMachineID > 0)
                        {
                            rcTradeCommodityAssignModel.CommodityCode  = CommodityName;
                            rcTradeCommodityAssignModel.MatchMachineID = resultMatchMachineID;// rcMatchMachineslist[0].MatchMachineID;
                            rcTradeCommodityAssignBll.Add(rcTradeCommodityAssignModel);
                        }
                        else
                        {
                            //写错误日志
                            LogHelper.WriteDebug("向可交易商品_撮合机_分配表中添加新代码失败");
                        }
                    }
                    else
                    {
                        //写错误日志
                        LogHelper.WriteDebug("添加撮合中心失败");
                    }
                }
            }
            catch (Exception ex)
            {
                string      errCode   = "GL-7004";
                string      errMsg    = "执行期货新增代码自动添加到可交易商品撮合机分配表中失败";
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception.InnerException);
                return;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 更新交易商品品种
        /// </summary>
        /// <param name="model">交易商品品种实体</param>
        /// <returns></returns>
        public static bool UpdateCMBreedClass(CM_BreedClass model)
        {
            CM_BreedClassBLL cM_BreedClassBLL = new CM_BreedClassBLL();

            return(cM_BreedClassBLL.UpdateCMBreedClass(model));
        }