/// <summary>
        /// 配置管理页 层选择改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbBoxLayerSet_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtMisSol1.ReadOnly = false;
            txtMisSol2.ReadOnly = false;
            txtMisSol3.ReadOnly = false;
            txtMisSol4.ReadOnly = false;
            txtMisSol5.ReadOnly = false;
            txtMisSol6.ReadOnly = false;
            txtMisSol7.ReadOnly = false;
            btnMisSetSave.Enabled = true;

            DB_mysteryData entity = new DB_mysteryData
                                        {
                                            Difficulty = Convert.ToString(cbBoxDifSet.SelectedIndex + 1),
                                            Level = Convert.ToString(cbBoxLayerSet.SelectedIndex + 1)
                                        };
            DataSet ds = entity.Select(entity);

            //普通难度(1,2,3为单纵队并且只有步兵,4,5,6,7为双纵队并且没有弓,6,7,8,9,10为三纵队并且三兵种都齐全)
            if (cbBoxDifSet.SelectedIndex == 0)
            {
                if (cbBoxLayerSet.SelectedIndex >= 0 && cbBoxLayerSet.SelectedIndex <= 2)
                {
                    txtMisSol4.ReadOnly = true;
                    txtMisSol5.ReadOnly = true;
                    txtMisSol6.ReadOnly = true;
                    txtMisSol7.ReadOnly = true;
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                string soldierType = ds.Tables[0].Rows[i]["soldier_type"].ToString();
                                string soldierCount = ds.Tables[0].Rows[i]["soldier_count"].ToString();
                                switch (soldierType)
                                {
                                    case "剑步":
                                        txtMisSol1.Text = soldierCount;
                                        break;
                                    case "矛步":
                                        txtMisSol2.Text = soldierCount;
                                        break;
                                    case "斧步":
                                        txtMisSol3.Text = soldierCount;
                                        break;
                                }
                            }
                        }
                    }
                }
                else if (cbBoxLayerSet.SelectedIndex >= 3 && cbBoxLayerSet.SelectedIndex <= 6)
                {
                    txtMisSol4.ReadOnly = true;
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                string soldierType = ds.Tables[0].Rows[i]["soldier_type"].ToString();
                                string soldierCount = ds.Tables[0].Rows[i]["soldier_count"].ToString();
                                switch (soldierType)
                                {
                                    case "剑步":
                                        txtMisSol1.Text = soldierCount;
                                        break;
                                    case "矛步":
                                        txtMisSol2.Text = soldierCount;
                                        break;
                                    case "斧步":
                                        txtMisSol3.Text = soldierCount;
                                        break;
                                    case "剑骑":
                                        txtMisSol5.Text = soldierCount;
                                        break;
                                    case "矛骑":
                                        txtMisSol6.Text = soldierCount;
                                        break;
                                    case "斧骑":
                                        txtMisSol7.Text = soldierCount;
                                        break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                string soldierType = ds.Tables[0].Rows[i]["soldier_type"].ToString();
                                string soldierCount = ds.Tables[0].Rows[i]["soldier_count"].ToString();
                                switch (soldierType)
                                {
                                    case "剑步":
                                        txtMisSol1.Text = soldierCount;
                                        break;
                                    case "矛步":
                                        txtMisSol2.Text = soldierCount;
                                        break;
                                    case "斧步":
                                        txtMisSol3.Text = soldierCount;
                                        break;
                                    case "弓":
                                        txtMisSol4.Text = soldierCount;
                                        break;
                                    case "剑骑":
                                        txtMisSol5.Text = soldierCount;
                                        break;
                                    case "矛骑":
                                        txtMisSol6.Text = soldierCount;
                                        break;
                                    case "斧骑":
                                        txtMisSol7.Text = soldierCount;
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            //恐怖难度(均为三纵队,可能重复)
            if (cbBoxDifSet.SelectedIndex == 1)
            {
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            string soldierType = ds.Tables[0].Rows[i]["soldier_type"].ToString();
                            string soldierCount = ds.Tables[0].Rows[i]["soldier_count"].ToString();
                            switch (soldierType)
                            {
                                case "剑步":
                                    txtMisSol1.Text = soldierCount;
                                    break;
                                case "矛步":
                                    txtMisSol2.Text = soldierCount;
                                    break;
                                case "斧步":
                                    txtMisSol3.Text = soldierCount;
                                    break;
                                case "弓":
                                    txtMisSol4.Text = soldierCount;
                                    break;
                                case "剑骑":
                                    txtMisSol5.Text = soldierCount;
                                    break;
                                case "矛骑":
                                    txtMisSol6.Text = soldierCount;
                                    break;
                                case "斧骑":
                                    txtMisSol7.Text = soldierCount;
                                    break;
                            }
                        }
                    }
                }
            }

            //噩梦难度(未知)
        }
        /// <summary>
        /// 兵种列表选择改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CbBoxSoldierSelectedIndexChanged(object sender, EventArgs e)
        {
            string preValue = "";
            string difficulty = "";
            string level = "";
            string soldierType = "";

            string cbBoxName = ((ComboBox)sender).Name;

            switch (cbBoxName)
            {
                case "cbBoxSoldier1":
                    preValue = cbBoxSoldier1.Tag.ToString();
                    ChangeTxtBoxes(preValue);
                    cbBoxSoldier1.Tag = cbBoxSoldier1.Text;
                    soldierType = cbBoxSoldier1.Text;
                    break;
                case "cbBoxSoldier2":
                    preValue = cbBoxSoldier2.Tag.ToString();
                    ChangeTxtBoxes(preValue);
                    cbBoxSoldier2.Tag = cbBoxSoldier2.Text;
                    soldierType = cbBoxSoldier2.Text;
                    break;
                case "cbBoxSoldier3":
                    preValue = cbBoxSoldier3.Tag.ToString();
                    ChangeTxtBoxes(preValue);
                    cbBoxSoldier3.Tag = cbBoxSoldier3.Text;
                    soldierType = cbBoxSoldier3.Text;
                    break;
            }

            switch (cbBoxDif.Text)
            {
                case "普通": difficulty = "1";
                    break;
                case "恐怖": difficulty = "2";
                    break;
                case "噩梦": difficulty = "3";
                    break;
                default: return;
            }

            level = cbBoxLayer.Text;

            var dbMystery = new DB_mysteryData { Difficulty = difficulty, Level = level, Type = soldierType };

            var count = "0";
            var ds = dbMystery.Select(dbMystery);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    count = ds.Tables[0].Rows[0]["soldier_count"].ToString();
                }
            }

            switch (soldierType)
            {
                case "剑步": txtBoxPower1.Text = count; break;
                case "矛步": txtBoxPower2.Text = count; break;
                case "斧步": txtBoxPower3.Text = count; break;
                case "弓": txtBoxPower4.Text = count; break;
                case "剑骑": txtBoxPower5.Text = count; break;
                case "矛骑": txtBoxPower6.Text = count; break;
                case "斧骑": txtBoxPower7.Text = count; break;
                default:
                    break;
            }

            SortSoldier();

            CalculatePower();
        }
        /// <summary>
        /// 计算某层所需各种兵的最大量
        /// </summary>
        private void CalculateAllPower()
        {
            lblDCount.Text = "单兵种最大量";
            //初始化兵力数量
            //迷洞兵力数量
            int cSwordInfantry = 0;
            int cSpearInfantry = 0;
            int cAxInfantry = 0;
            int cBow = 0;
            int cSwordRide = 0;
            int cSpearRide = 0;
            int cAxRide = 0;

            //需要最大数量
            int cNeedSwordInfantry = 0;
            int cNeedSpearInfantry = 0;
            int cNeedAxInfantry = 0;
            int cNeedBow = 0;
            int cNeedSwordRide = 0;
            int cNeedSpearRide = 0;
            int cNeedAxRide = 0;

            //查询选择层的各兵种数量
            var entity = new DB_mysteryData { Difficulty = Convert.ToString(cbBoxDif.SelectedIndex + 1), Level = Convert.ToString(cbBoxLayer.SelectedIndex + 1) };
            var ds = entity.Select(entity);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        var soldierType = ds.Tables[0].Rows[i]["soldier_type"].ToString();
                        switch (soldierType)
                        {
                            case "剑步":
                                cSwordInfantry = Convert.ToInt32(ds.Tables[0].Rows[i]["soldier_count"]);
                                break;
                            case "矛步":
                                cSpearInfantry = Convert.ToInt32(ds.Tables[0].Rows[i]["soldier_count"]);
                                break;
                            case "斧步":
                                cAxInfantry = Convert.ToInt32(ds.Tables[0].Rows[i]["soldier_count"]);
                                break;
                            case "弓":
                                cBow = Convert.ToInt32(ds.Tables[0].Rows[i]["soldier_count"]);
                                break;
                            case "剑骑":
                                cSwordRide = Convert.ToInt32(ds.Tables[0].Rows[i]["soldier_count"]);
                                break;
                            case "矛骑":
                                cSpearRide = Convert.ToInt32(ds.Tables[0].Rows[i]["soldier_count"]);
                                break;
                            case "斧骑":
                                cAxRide = Convert.ToInt32(ds.Tables[0].Rows[i]["soldier_count"]);
                                break;
                        }
                    }
                }
            }

            //己方数据
            //满意度和士气值在4500-9000之间分为3个档次,4500-5000为一档,5001-6000为一档,6001-8000为一档,8001-9000为一档,加成分别为0.00,0.01,0.03,0.05
            double satisfiction = double.Parse(txtBox_satisfy.Text);
            double morale = double.Parse(txtBox_morale.Text);

            //满意度加成
            satisfiction = SatisAndMorConvert(satisfiction);

            //士气值加成
            morale = SatisAndMorConvert(morale);

            double satisAndMorale = satisfiction + morale;

            //科技神满意度加成(其它一级1%,弓一级2%)
            double tecSword = double.Parse(txtBox_sword.Text) / 100;
            double tecSpear = double.Parse(txtBox_spear.Text) / 100;
            double tecAx = double.Parse(txtBox_ax.Text) / 100;
            double tecInfantry = double.Parse(txtBox_infantry.Text) / 100;
            double tecBow = double.Parse(txtBox_bow.Text) * 2 / 100;
            double tecRide = double.Parse(txtBox_ride.Text) / 100;
            double godBow = double.Parse(txtBox_godadd_bow.Text);
            double godInfantry = double.Parse(txtBox_godadd_infantry.Text);
            double godRide = double.Parse(txtBox_godadd_ride.Text);

            //单位战力
            double unitTotalPowerInfantrySword = SpartanConst.UnitPower.INFANTRY_SWORD * (1 + satisAndMorale + tecSword + tecInfantry) + godInfantry; ;
            double unitTotalPowerInfantrySpear = SpartanConst.UnitPower.INFANTRY_SPEAR * (1 + satisAndMorale + tecSpear + tecInfantry) + godInfantry; ;
            double unitTotalPowerInfantryAx = SpartanConst.UnitPower.INFANTRY_AX * (1 + satisAndMorale + tecAx + tecInfantry) + godInfantry;
            double unitTotalPowerBow = SpartanConst.UnitPower.BOW * (1 + satisAndMorale + tecBow) + godBow;
            double unitTotalPowerRideSword = SpartanConst.UnitPower.RIDE_SWORD * (1 + satisAndMorale + tecSword + tecRide) + godRide;
            double unitTotalPowerRideSpear = SpartanConst.UnitPower.RIDE_SPEAR * (1 + satisAndMorale + tecSpear + tecRide) + godRide;
            double unitTotalPowerRideAx = SpartanConst.UnitPower.RIDE_AX * (1 + satisAndMorale + tecAx + tecRide) + godRide;

            //计算单兵种最大量的话只需要枚举最苛刻的条件即可
            //需要最大量剑步,条件:剑步VS矛骑
            cNeedSwordInfantry = Convert.ToInt32(Math.Round(SpartanConst.UnitPower.RIDE_SPEAR * cSpearRide * 2 * 1.2 / (0.3 * unitTotalPowerInfantrySword)));
            //需要最大量矛步,条件:矛步VS斧骑
            cNeedSpearInfantry = Convert.ToInt32(Math.Round(SpartanConst.UnitPower.RIDE_AX * cAxRide * 2 * 1.2 / (0.3 * unitTotalPowerInfantrySpear)));
            //需要最大量斧步,条件:斧步VS剑骑
            cNeedAxInfantry = Convert.ToInt32(Math.Round(SpartanConst.UnitPower.RIDE_SWORD * cSwordRide * 2 * 1.2 / (0.3 * unitTotalPowerInfantryAx)));
            //需要最大量弓,条件:弓VS三步中总战力最高的步
            int swordPower = SpartanConst.UnitPower.INFANTRY_SWORD * cSwordInfantry;
            int spearPower = SpartanConst.UnitPower.INFANTRY_SPEAR * cSpearInfantry;
            int axPower = SpartanConst.UnitPower.INFANTRY_AX * cAxInfantry;
            int infantryPower = CompareThreeInfantryPower(swordPower, spearPower, axPower);
            cNeedBow = Convert.ToInt32(Math.Round(infantryPower / (0.3 * unitTotalPowerBow)));
            //需要最大量剑骑,条件:剑骑VS斧骑
            cNeedSwordRide = Convert.ToInt32(Math.Round(SpartanConst.UnitPower.RIDE_AX * cAxRide * 2 / (0.2 * unitTotalPowerRideSword)));
            //需要最大量矛骑,条件:矛骑VS剑骑
            cNeedSpearRide = Convert.ToInt32(Math.Round(SpartanConst.UnitPower.RIDE_SWORD * cSwordRide * 2 / (0.2 * unitTotalPowerRideSpear)));
            //需要最大量斧骑,条件:斧骑VS矛骑
            cNeedAxRide = Convert.ToInt32(Math.Round(SpartanConst.UnitPower.RIDE_SPEAR * cSpearRide * 2 / (0.2 * unitTotalPowerRideAx)));

            //将需要的最大数据填入免暴输出框
            txtBoxDPower1.Text = cNeedSwordInfantry.ToString("n0");
            txtBoxDPower2.Text = cNeedSpearInfantry.ToString("n0");
            txtBoxDPower3.Text = cNeedAxInfantry.ToString("n0");
            txtBoxDPower4.Text = cNeedBow.ToString("n0");
            txtBoxDPower5.Text = cNeedSwordRide.ToString("n0");
            txtBoxDPower6.Text = cNeedSpearRide.ToString("n0");
            txtBoxDPower7.Text = cNeedAxRide.ToString("n0");
        }