コード例 #1
0
ファイル: DBQuery.cs プロジェクト: kuffert/Brewers-Bench
        /// <summary>
        /// /Inserts a list of effects into the Database.
        /// </summary>
        /// <param name="effects"></param>
        public void insertNewEffects(List <Effect> effects, string typeId, int id)
        {
            connection = new SqlConnection(connectionString);
            connection.Open();

            string queryIdSubstring = "";

            switch (typeId)
            {
            case "BaseId":
                queryIdSubstring = "@BaseId, NULL, NULL";
                break;

            case "IngredientId":
                queryIdSubstring = "NULL, @IngredientId, NULL";
                break;

            case "PotionId":
                queryIdSubstring = "NULL, NULL, @PotionId";
                break;
            }

            foreach (Effect e in effects)
            {
                string     query = "";
                EffectType type  = e.getEffectEnumType();
                SqlCommand command;
                switch (type)
                {
                case EffectType.NONE:
                    NoEffect ne = (NoEffect)e;
                    query = "INSERT INTO Effect VALUES(@Name, @EffectType, NULL, NULL, NULL, " + queryIdSubstring + ", NULL)";
                    Console.WriteLine(query);
                    command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Name", ne.name);
                    command.Parameters.AddWithValue("@EffectType", (int)type);
                    command.Parameters.AddWithValue("@" + typeId, id);
                    command.ExecuteNonQuery();
                    break;

                case EffectType.STAT:
                    StatEffect se = (StatEffect)e;
                    query   = "INSERT INTO Effect VALUES(@Name, @EffectType, @StatType, NULL, NULL, " + queryIdSubstring + ", @Intensity)";
                    command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Name", se.name);
                    command.Parameters.AddWithValue("@EffectType", (int)type);
                    command.Parameters.AddWithValue("@StatType", (int)se.getAffectedStat());
                    command.Parameters.AddWithValue("@" + typeId, id);
                    command.Parameters.AddWithValue("@Intensity", se.getIntensity());
                    command.ExecuteNonQuery();
                    break;

                case EffectType.BUFF:
                    BuffEffect be = (BuffEffect)e;
                    query   = "INSERT INTO Effect VALUES(@Name, @EffectType, NULL, @BuffType, NULL, " + queryIdSubstring + ", @Intensity)";
                    command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Name", be.name);
                    command.Parameters.AddWithValue("@EffectType", (int)type);
                    command.Parameters.AddWithValue("@BuffType", (int)be.getBuff());
                    command.Parameters.AddWithValue("@" + typeId, id);
                    command.Parameters.AddWithValue("@Intensity", be.getIntensity());
                    command.ExecuteNonQuery();
                    break;

                case EffectType.DEBUFF:
                    DebuffEffect de = (DebuffEffect)e;
                    query   = "INSERT INTO Effect VALUES(@Name, @EffectType, NULL, NULL, @DebuffType, " + queryIdSubstring + ", @Intensity)";
                    command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@Name", de.name);
                    command.Parameters.AddWithValue("@EffectType", (int)type);
                    command.Parameters.AddWithValue("@DebuffType", (int)de.getDebuff());
                    command.Parameters.AddWithValue("@" + typeId, id);
                    command.Parameters.AddWithValue("@Intensity", de.getIntensity());
                    command.ExecuteNonQuery();
                    break;
                }
            }
            connection.Close();
        }
コード例 #2
0
        /// <summary>
        /// Handles "effect" user input.
        /// </summary>
        /// <returns></returns>
        private List <Effect> handleEffect()
        {
            int           step          = 0;
            string        name          = "";
            int           intensity     = 0;
            EffectType    type          = EffectType.NONE;
            int           effectSubtype = 0;
            List <Effect> effects       = new List <Effect>();

            while (step < 4)
            {
                oh.outputEffectRequiredNextInput(step, type);
                string input = Console.ReadLine();
                if (input == "done")
                {
                    return(effects);
                }
                switch (step)
                {
                case 0:
                    name = input;
                    step++;
                    break;

                case 1:
                    switch (input)
                    {
                    case "Stat":
                        type = EffectType.STAT;
                        step++;
                        break;

                    case "Buff":
                        type = EffectType.BUFF;
                        step++;
                        break;

                    case "Debuff":
                        type = EffectType.DEBUFF;
                        step++;
                        break;

                    default:
                        oh.outputEffectInputError(step);
                        break;
                    }
                    break;

                case 2:
                    switch (type)
                    {
                    case EffectType.STAT:
                        try
                        {
                            effectSubtype = (int)StatEffect.getImbiberStatByString(input);
                        }
                        catch (FormatException)
                        {
                            oh.outputEffectInputError(step);
                            break;
                        }
                        step++;
                        break;

                    case EffectType.BUFF:
                        try
                        {
                            effectSubtype = (int)BuffEffect.getBuffEffectByString(input);
                        }
                        catch (FormatException)
                        {
                            oh.outputEffectInputError(step);
                            break;
                        }
                        step++;
                        break;

                    case EffectType.DEBUFF:
                        try
                        {
                            effectSubtype = (int)DebuffEffect.getDebuffEffectByString(input);
                        }
                        catch (FormatException)
                        {
                            oh.outputEffectInputError(step);
                            break;
                        }
                        step++;
                        break;
                    }
                    break;

                case 3:
                    if (Int32.TryParse(input, out intensity))
                    {
                        step++;
                        break;
                    }
                    oh.outputEffectInputError(step);
                    break;
                }
                if (step == 4)
                {
                    Effect e = Effect.GenerateEffect(name, type, effectSubtype, intensity);
                    effects.Add(e);
                    oh.outputEffectSuccess();
                    step = 0;
                }
            }
            return(effects);
        }