/// <summary>
        /// 获取当前行需要修改的数据
        /// </summary>
        /// <param name="handle">当前行号</param>
        private void UpdateSpotTradeRules(int handle)
        {
            try
            {
                if (handle < 0)
                {
                    return;
                }
                //显示添加现货规则窗体
                AddSpotTradeRulesUI addSpotTradeRulesUI = new AddSpotTradeRulesUI();
                addSpotTradeRulesUI.EditType = (int)UITypes.EditTypeEnum.UpdateUI;
                DataRow           _dr              = this.gdvSpotTradeRulesSelect.GetDataRow(handle);
                int               breedClassID     = Convert.ToInt32(_dr["BreedClassID"]);
                XH_SpotTradeRules xHSpotTradeRules = SpotManageCommon.GetModel(breedClassID);
                addSpotTradeRulesUI.XHSpotTradeRules = xHSpotTradeRules;

                if (addSpotTradeRulesUI.ShowDialog(this) == DialogResult.OK)
                {
                    this.QuerySpotTradeRules();
                    this.gdvSpotTradeRulesSelect.FocusedRowHandle = handle;
                }
            }
            catch (Exception ex)
            {
                string      errCode   = "GL-5023";
                string      errMsg    = "获取当前行需要修改的数据失败!";
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception.InnerException);
                throw exception;
            }
        }
        /// <summary>
        /// 获取现货的交割制度
        /// </summary>
        /// <param name="code">商品代码</param>
        /// <param name="fund">资金交割制度</param>
        /// <param name="stock">股票交割制度</param>
        /// <param name="strMessage">错误信息</param>
        /// <returns>是否成功获取</returns>
        public bool GetDeliveryInstitution(string code, out int fund, out int stock, ref string strMessage)
        {
            bool   result  = false;
            string errCode = "GT-8114";
            string errMsg  = "无法根据商品编码从管理中心获取对于的交割制度。";

            strMessage = errCode + ":" + errMsg;

            fund  = -1;
            stock = -1;

            CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(code);

            if (breedClass != null)
            {
                XH_SpotTradeRules rules = GetSpotTradeRulesByBreedClassID(breedClass.BreedClassID);
                if (rules != null)
                {
                    fund       = rules.FundDeliveryInstitution.Value;
                    stock      = rules.StockDeliveryInstitution.Value;
                    result     = true;
                    strMessage = "";
                }
            }

            return(result);
        }
        public IList <XH_ValidDeclareValue> GetValidDeclareValueByBreedClassID(int id)
        {
            XH_SpotTradeRules tradeRules = GetSpotTradeRulesByBreedClassID(id);

            if (tradeRules != null)
            {
                return(GetValidDeclareValueByBreedClassValidIDFromWCF(tradeRules.BreedClassValidID.Value));
            }

            return(null);
        }
        public XH_ValidDeclareType GetValidDeclareTypeByBreedClassID(int id)
        {
            XH_SpotTradeRules tradeRules = GetSpotTradeRulesByBreedClassID(id);

            if (tradeRules == null)
            {
                return(null);
            }

            return(GetValidDeclareTypeByBreedClassValidID(tradeRules.BreedClassValidID.Value));
        }
        public XH_SpotHighLowControlType GetSpotHighLowControlTypeByBreedClassID(int breedClassID)
        {
            XH_SpotHighLowControlType result = null;
            XH_SpotTradeRules         rules  = GetSpotTradeRulesByBreedClassID(breedClassID);

            if (rules != null)
            {
                if (rules.BreedClassHighLowID.HasValue)
                {
                    result = GetSpotHighLowControlTypeByBreedClassHighLowID(rules.BreedClassHighLowID.Value);
                }
            }

            return(result);
        }
        //================================  事件 ================================

        #region 添加或修改现货交易规则窗体的 AddSpotTradeRulesUI_Load事件

        /// <summary>
        /// 添加或修改现货交易规则窗体的 AddSpotTradeRulesUI_Load事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddSpotTradeRulesUI_Load(object sender, EventArgs e)
        {
            try
            {
                if (EditType == (int)UITypes.EditTypeEnum.AddUI)
                {
                    m_SpotTradeRules             = new XH_SpotTradeRules();
                    this.cmbBreedClassID.Enabled = true;
                    //this.btnMinChangePriceV.Visible = false;//添加交易规则时最小变动价位范围不显示
                }
                this.InitBindData();

                if (EditType == (int)UITypes.EditTypeEnum.UpdateUI)
                {
                    this.UpdateInitData();
                    this.btnAddXHSpotHighLowValue.Text = "涨跌幅";
                    //this.btnAddXHValidDeclareValue.Text = "有效申报";
                    this.Text = "现货交易规则";
                    this.cmbBreedClassID.Enabled = false;
                }

                string BreedClassName = SpotManageCommon.GetBreedClassNameByID(m_BreedClassID);

                //if (((int)CommonObject.Types.GetValueTypeEnum.Scope ==
                //     ((UComboItem)this.cmbMinChangePriceVType.SelectedItem).ValueIndex)
                //    && BreedClassName == "香港H股")
                //{
                //    this.txtMinChangePrice.Enabled = false;
                //}
                //else
                //{
                //    this.txtMinChangePrice.Enabled = true;
                //}
            }
            catch (Exception ex)
            {
                string      errCode   = "GL-5000";
                string      errMsg    = "添加或修改现货交易规则窗体加载失败!";
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception.InnerException);
            }
        }
        /// <summary>
        ///根据品种标识,品种涨跌幅标识,品种有效申报标识,删除现货品种交易规则(规则相关表全部删除)
        /// </summary>
        /// <param name="BreedClassID">品种标识</param>
        ///// <param name="BreedClassHighLowID">品种涨跌幅标识</param>
        ///// <param name="BreedClassValidID">品种有效申报标识</param>
        /// <returns></returns>
        public bool DeleteSpotTradeRulesAboutAll(int BreedClassID)
        {
            XH_SpotTradeRulesDAL    xHSpotTradeRulesDAL    = new XH_SpotTradeRulesDAL();
            XH_SpotPositionDAL      xHSpotPositionDAL      = new XH_SpotPositionDAL();
            XH_SpotHighLowValueDAL  xHSpotHighLowValueDAL  = new XH_SpotHighLowValueDAL();
            XH_ValidDeclareValueDAL xHValidDeclareValueDAL = new XH_ValidDeclareValueDAL();
            //XH_MinChangePriceValueDAL xHMinChangePriceValueDAL = new XH_MinChangePriceValueDAL();
            CM_FieldRangeDAL          cMFieldRangeDAL          = new CM_FieldRangeDAL();
            XH_ValidDeclareTypeDAL    xHValidDeclareTypeDAL    = new XH_ValidDeclareTypeDAL();
            XH_MinVolumeOfBusinessDAL xHMinVolumeOfBusinessDAL = new XH_MinVolumeOfBusinessDAL();

            XH_SpotHighLowControlTypeDAL xHSpotHighLowControlTypeDAL = new XH_SpotHighLowControlTypeDAL();
            CM_UnitConversionDAL         cM_UnitConversionDAL        = new CM_UnitConversionDAL();


            DbConnection Conn = null;
            Database     db   = DatabaseFactory.CreateDatabase();

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

            try
            {
                int BreedClassHighLowID            = AppGlobalVariable.INIT_INT;
                int BreedClassValidID              = AppGlobalVariable.INIT_INT;
                XH_SpotTradeRules xHSpotTradeRules = new XH_SpotTradeRules();
                xHSpotTradeRules = xHSpotTradeRulesDAL.GetModel(BreedClassID);
                if (xHSpotTradeRules != null)
                {
                    if (!string.IsNullOrEmpty(xHSpotTradeRules.BreedClassHighLowID.ToString()))
                    {
                        BreedClassHighLowID = Convert.ToInt32(xHSpotTradeRules.BreedClassHighLowID);
                    }
                    if (!string.IsNullOrEmpty(xHSpotTradeRules.BreedClassValidID.ToString()))
                    {
                        BreedClassValidID = Convert.ToInt32(xHSpotTradeRules.BreedClassValidID);
                    }
                    if (BreedClassHighLowID != AppGlobalVariable.INIT_INT)
                    {
                        if (!xHSpotHighLowValueDAL.DeleteSpotHighLowValue(BreedClassHighLowID, Tran, db))
                        {
                            Tran.Rollback();
                            return(false);
                        }
                    }
                    if (BreedClassValidID != AppGlobalVariable.INIT_INT)
                    {
                        if (!xHValidDeclareValueDAL.DeleteVDeclareValue(BreedClassValidID, Tran, db))
                        {
                            Tran.Rollback();
                            return(false);
                        }
                    }
                    //if (!xHMinChangePriceValueDAL.Delete(BreedClassID, Tran, db))
                    //{
                    //    Tran.Rollback();
                    //    return false;
                    //}

                    //List<Model.XH_MinChangePriceValue> xhMinCHangePriceV =
                    //    xHMinChangePriceValueDAL.GetListArray(string.Format("BreedClassID={0}", BreedClassID), Tran, db);
                    //foreach (Model.XH_MinChangePriceValue FieldRangeID in xhMinCHangePriceV)
                    //{
                    //    if (!cMFieldRangeDAL.Delete(FieldRangeID.FieldRangeID))
                    //    {
                    //        Tran.Rollback();
                    //        return false;
                    //    }
                    //}
                    if (!xHMinVolumeOfBusinessDAL.DeleteXHMinVolumeOfBusByBreedClassID(BreedClassID, Tran, db))
                    {
                        Tran.Rollback();
                        return(false);
                    }
                    //添加删除现货单位换算
                    List <Model.CM_UnitConversion> cMUnitC =
                        cM_UnitConversionDAL.GetListArray(string.Format("BreedClassID={0}", BreedClassID));
                    foreach (Model.CM_UnitConversion unitConversion in cMUnitC)
                    {
                        if (!cM_UnitConversionDAL.DeleteUnitConversionByBreedClassID(Convert.ToInt32(unitConversion.BreedClassID), Tran, db))
                        {
                            Tran.Rollback();
                            return(false);
                        }
                    }

                    if (!xHSpotTradeRulesDAL.Delete(BreedClassID, Tran, db))
                    {
                        Tran.Rollback();
                        return(false);
                    }
                    if (!xHValidDeclareTypeDAL.DeleteValidDeclareType(BreedClassValidID, Tran, db))
                    {
                        Tran.Rollback();
                        return(false);
                    }
                    if (!xHSpotHighLowControlTypeDAL.Delete(BreedClassHighLowID, Tran, db))
                    {
                        Tran.Rollback();
                        return(false);
                    }
                }
                Tran.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                Tran.Rollback();
                string      errCode   = "GL-5202";
                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>
        /// 添加或修改现货交易规则  btnOK_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (EditType == (int)UITypes.EditTypeEnum.AddUI)
                {
                    if (
                        SpotManageCommon.ExistsSpotTradeRules(
                            ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex))
                    {
                        ShowMessageBox.ShowInformation("此品种的交易规则已存在!");
                        return;
                    }
                }

                XH_SpotTradeRules xH_SpotTradeRules = new XH_SpotTradeRules();
                if (XHSpotTradeRules != null)
                {
                    ManagementCenter.Model.CommonClass.UtilityClass.CopyEntityToEntity(XHSpotTradeRules,
                                                                                       xH_SpotTradeRules);
                }

                if (!string.IsNullOrEmpty(this.cmbBreedClassID.Text))
                {
                    xH_SpotTradeRules.BreedClassID = ((UComboItem)this.cmbBreedClassID.SelectedItem).ValueIndex;
                }
                else
                {
                    xH_SpotTradeRules.BreedClassID = AppGlobalVariable.INIT_INT;
                }
                xH_SpotTradeRules.FundDeliveryInstitution  = Convert.ToInt32(this.speFundDeliveryIns.EditValue);
                xH_SpotTradeRules.StockDeliveryInstitution = Convert.ToInt32(this.speStockDeliveryIns.EditValue);

                //if (!string.IsNullOrEmpty(this.cmbMinChangePriceVType.Text))
                //{
                xH_SpotTradeRules.ValueTypeMinChangePrice = (int)GTA.VTS.Common.CommonObject.Types.GetValueTypeEnum.Single;
                //        ((UComboItem) this.cmbMinChangePriceVType.SelectedItem).ValueIndex;
                //}
                //else
                //{
                //    xH_SpotTradeRules.ValueTypeMinChangePrice = AppGlobalVariable.INIT_INT;
                //}
                if (!string.IsNullOrEmpty(this.txtMinChangePrice.Text))
                {
                    if (InputTest.DecimalTest(this.txtMinChangePrice.Text))
                    {
                        xH_SpotTradeRules.MinChangePrice = Convert.ToDecimal(this.txtMinChangePrice.Text);
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("格式不正确(只能包含数字和小数点)!");
                        return;
                    }
                }
                else
                {
                    //if ((int) CommonObject.Types.GetValueTypeEnum.Single ==
                    //    ((UComboItem) this.cmbMinChangePriceVType.SelectedItem).ValueIndex)
                    //{
                    //    this.txtMinChangePrice.Enabled = true;
                    ShowMessageBox.ShowInformation("最小变动价位不能为空!");
                    return;
                    //}
                    //this.txtMinChangePrice.Enabled = false;
                    //xH_SpotTradeRules.MinChangePrice = 0; //最小变动价位=0时说明是范围值// AppGlobalVariable.INIT_INT; //money类型
                }
                if (!string.IsNullOrEmpty(this.txtMaxLeaveQuantity.Text))
                {
                    if (InputTest.intTest(this.txtMaxLeaveQuantity.Text))
                    {
                        xH_SpotTradeRules.MaxLeaveQuantity = Convert.ToInt32(this.txtMaxLeaveQuantity.Text);
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("请输入数字且第一位数不能为0!");
                        return;
                    }
                }
                else
                {
                    //xH_SpotTradeRules.MaxLeaveQuantity = AppGlobalVariable.INIT_INT;
                    ShowMessageBox.ShowInformation("每笔最大委托量不能为空!");
                    return;
                }
                //if (!string.IsNullOrEmpty(this.cmbMaxLeaveQuantityUnit.Text))
                //根据20009.05.15界面修改确认结果 计价单位赋给每笔最大委托量单,每笔最大委托量单位在界面上不显示
                if (!string.IsNullOrEmpty(this.cmbPriceUnit.Text))
                {
                    xH_SpotTradeRules.MaxLeaveQuantityUnit =
                        ((UComboItem)this.cmbPriceUnit.SelectedItem).ValueIndex;
                }
                else
                {
                    xH_SpotTradeRules.MaxLeaveQuantityUnit = AppGlobalVariable.INIT_INT;
                }
                if (!string.IsNullOrEmpty(this.cmbPriceUnit.Text))
                {
                    xH_SpotTradeRules.PriceUnit = ((UComboItem)this.cmbPriceUnit.SelectedItem).ValueIndex;
                }
                else
                {
                    xH_SpotTradeRules.PriceUnit = AppGlobalVariable.INIT_INT;
                }
                if (!string.IsNullOrEmpty(this.cmbMarketUnitID.Text))
                {
                    xH_SpotTradeRules.MarketUnitID = ((UComboItem)this.cmbMarketUnitID.SelectedItem).ValueIndex;
                }
                else
                {
                    xH_SpotTradeRules.MarketUnitID = AppGlobalVariable.INIT_INT;
                }

                //根据20009.05.15界面修改确认结果 最小交易单位倍数在界面上不显示。此值从最小交易单位管理界面中已存在
                xH_SpotTradeRules.MinVolumeMultiples = 0;
                //判断品种涨跌幅ID或品种有效申报ID为空时提示添加品种涨跌幅和品种有效申报

                if (m_BreedClassHighLowID != AppGlobalVariable.INIT_INT && m_BreedClassValidID != AppGlobalVariable.INIT_INT)
                {
                    xH_SpotTradeRules.BreedClassHighLowID = m_BreedClassHighLowID;
                    xH_SpotTradeRules.BreedClassValidID   = m_BreedClassValidID;
                }
                else
                {
                    if (EditType == (int)UITypes.EditTypeEnum.AddUI)
                    {
                        ShowMessageBox.ShowInformation("请添加涨跌幅!");
                        return;
                    }
                }

                if (EditType == (int)UITypes.EditTypeEnum.AddUI)
                {
                    m_Result = SpotManageCommon.AddXHSpotTradeRules(xH_SpotTradeRules);
                    if (m_Result)
                    {
                        m_ValueType    = Convert.ToInt32(xH_SpotTradeRules.ValueTypeMinChangePrice);
                        m_BreedClassID = Convert.ToInt32(xH_SpotTradeRules.BreedClassID);
                        ShowMessageBox.ShowInformation("添加成功!");
                        this.ClearAll();
                    }
                    else
                    {
                        if (m_BreedClassValidID != AppGlobalVariable.INIT_INT)
                        {
                            SpotManageCommon.DeleteValidDeclareValue(m_BreedClassValidID);
                        }
                        if (m_BreedClassHighLowID != AppGlobalVariable.INIT_INT)
                        {
                            SpotManageCommon.DeleteSpotHighLowValue(m_BreedClassHighLowID);
                        }
                        ShowMessageBox.ShowInformation("添加失败!");
                    }
                }
                else if (EditType == (int)UITypes.EditTypeEnum.UpdateUI)
                {
                    m_Result = SpotManageCommon.UpdateSpotTradeRules(xH_SpotTradeRules);
                    if (m_Result)
                    {
                        ShowMessageBox.ShowInformation("修改成功!");
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                    else
                    {
                        ShowMessageBox.ShowInformation("修改失败!");
                    }
                }
            }
            catch (Exception ex)
            {
                string      errCode   = "GL-5001";
                string      errMsg    = "添加或修改现货交易规则失败!";
                VTException exception = new VTException(errCode, errMsg, ex);
                LogHelper.WriteError(exception.ToString(), exception.InnerException);
                return;
            }
        }