public static IEnumerable<Fermentable> GetAvailableFermentables(SQLiteConnection connection)
        {
            SQLiteCommand selectFermentablesCommand = connection.CreateCommand();
            selectFermentablesCommand.CommandText = "SELECT name, yield, yieldByWeight, color, origin, notes, diastaticPower, type, maltCategory, gravityPoint FROM Fermentables";
            using (SQLiteDataReader reader = selectFermentablesCommand.ExecuteReader())
            {
                while (reader.Read())
                {
                    string name = reader.GetString(0);
                    string yieldValue = reader[1].ToString();
                    float? yield = !yieldValue.IsNullOrEmpty() ? (float?) float.Parse(yieldValue) : null;
                    string yieldByWeightValue = reader[2].ToString();
                    float? yieldByWeight = !yieldByWeightValue.IsNullOrEmpty() ? (float?) float.Parse(yieldByWeightValue) : null;
                    float color = reader.GetFloat(3);
                    string origin = reader.GetString(4);
                    string notes = reader.GetString(5);
                    string diastaticPowerValue = reader[6].ToString();
                    float? diastaticPower = !diastaticPowerValue.IsNullOrEmpty() ? (float?) float.Parse(diastaticPowerValue) : null;
                    FermentableType type = EnumConverter.Parse<FermentableType>(reader.GetString(7));
                    string maltCategoryValue = reader[8].ToString();
                    MaltCategory? maltCategory = !maltCategoryValue.IsNullOrEmpty() ? (MaltCategory?) EnumConverter.Parse<MaltCategory>(maltCategoryValue) : null;
                    int gravityPoint = reader.GetInt32(9);

                    FermentableCharacteristics characteristics = new FermentableCharacteristics(yield, color, diastaticPower) {
                        YieldByWeight = yieldByWeight, Type = type, MaltCategory = maltCategory, GravityPoint = gravityPoint };
                    yield return new Fermentable(name, characteristics, notes, origin);
                }
            }
        }
示例#2
0
 internal static IEnumerable <FermentableIngredientDataModel> GetFermentableIngredientsForRecipe(int recipeId, SQLiteConnection connection)
 {
     using SQLiteCommand selectIngredientsCommand = connection.CreateCommand();
     selectIngredientsCommand.CommandText         = "SELECT FermentableIngredients.id, FermentableIngredients.amount, Fermentables.name, Fermentables.yield, Fermentables.yieldByWeight, Fermentables.color, Fermentables.origin, Fermentables.notes, Fermentables.diastaticPower, Fermentables.type, Fermentables.maltCategory, Fermentables.gravityPoint FROM FermentableIngredients " +
                                                    "JOIN FermentablesInRecipe ON FermentablesInRecipe.fermentableIngredient = FermentableIngredients.id AND FermentablesInRecipe.recipe = @recipeId " +
                                                    "JOIN Fermentables ON Fermentables.id = FermentableIngredients.fermentableInfo";
     selectIngredientsCommand.Parameters.AddWithValue("recipeId", recipeId);
     using SQLiteDataReader reader = selectIngredientsCommand.ExecuteReader();
     while (reader.Read())
     {
         string       yieldValue          = reader[3].ToString();
         float?       yield               = !yieldValue.IsNullOrEmpty() ? (float?)float.Parse(yieldValue) : null;
         string       yieldByWeightValue  = reader[4].ToString();
         float?       yieldByWeight       = !yieldByWeightValue.IsNullOrEmpty() ? (float?)float.Parse(yieldByWeightValue) : null;
         string       diastaticPowerValue = reader[8].ToString();
         float?       diastaticPower      = !diastaticPowerValue.IsNullOrEmpty() ? (float?)float.Parse(diastaticPowerValue) : null;
         string       maltCategoryValue   = reader[10].ToString();
         MaltCategory?maltCategory        = !maltCategoryValue.IsNullOrEmpty() ? EnumConverter.Parse <MaltCategory>(maltCategoryValue) : null;
         var          characteristics     = new FermentableCharacteristics(yield, reader.GetFloat(5), diastaticPower)
         {
             GravityPoint  = reader.GetInt32(11),
             Type          = EnumConverter.Parse <FermentableType>(reader.GetString(9)),
             MaltCategory  = maltCategory,
             YieldByWeight = yieldByWeight
         };
         var fermentableInfo = new Fermentable(reader.GetString(2), characteristics, reader.GetString(7), reader.GetString(6));
         yield return(new FermentableIngredientDataModel(fermentableInfo, reader.GetInt32(0))
         {
             Amount = reader.GetFloat(1)
         });
     }
 }
示例#3
0
        public static IEnumerable <Fermentable> GetAvailableFermentables(SQLiteConnection connection)
        {
            SQLiteCommand selectFermentablesCommand = connection.CreateCommand();

            selectFermentablesCommand.CommandText = "SELECT name, yield, yieldByWeight, color, origin, notes, diastaticPower, type, maltCategory, gravityPoint FROM Fermentables";
            using SQLiteDataReader reader         = selectFermentablesCommand.ExecuteReader();
            while (reader.Read())
            {
                string          name                = reader.GetString(0);
                string          yieldValue          = reader[1].ToString();
                float?          yield               = !yieldValue.IsNullOrEmpty() ? (float?)float.Parse(yieldValue) : null;
                string          yieldByWeightValue  = reader[2].ToString();
                float?          yieldByWeight       = !yieldByWeightValue.IsNullOrEmpty() ? (float?)float.Parse(yieldByWeightValue) : null;
                float           color               = reader.GetFloat(3);
                string          origin              = reader.GetString(4);
                string          notes               = reader.GetString(5);
                string          diastaticPowerValue = reader[6].ToString();
                float?          diastaticPower      = !diastaticPowerValue.IsNullOrEmpty() ? (float?)float.Parse(diastaticPowerValue) : null;
                FermentableType type                = EnumConverter.Parse <FermentableType>(reader.GetString(7));
                string          maltCategoryValue   = reader[8].ToString();
                MaltCategory?   maltCategory        = !maltCategoryValue.IsNullOrEmpty() ? (MaltCategory?)EnumConverter.Parse <MaltCategory>(maltCategoryValue) : null;
                int             gravityPoint        = reader.GetInt32(9);

                var characteristics = new FermentableCharacteristics(yield, color, diastaticPower)
                {
                    YieldByWeight = yieldByWeight,
                    Type          = type,
                    MaltCategory  = maltCategory,
                    GravityPoint  = gravityPoint
                };
                yield return(new Fermentable(name, characteristics, notes, origin));
            }
        }
 public static Fermentable GetFermentable(XElement fermentableEntry)
 {
     string name = GetNameFromRecord(fermentableEntry);
     string origin = fermentableEntry.Element("ORIGIN").Value;
     string notes = GetNotesFromRecord(fermentableEntry);
     FermentableType type = EnumConverter.Parse<FermentableType>(fermentableEntry.Element("TYPE").Value);
     float yieldValue = (float) Convert.ToDouble(fermentableEntry.Element("YIELD").Value);
     float? yield = type == FermentableType.Grain ? (float?) yieldValue : null;
     float? yieldByWeight = type != FermentableType.Grain ? (float?) yieldValue : null;
     float color = (float) Convert.ToDouble(fermentableEntry.Element("COLOR").Value);
     float diastaticPowerParsed;
     bool diastaticPowerIsntNull = float.TryParse(fermentableEntry.Element("DIASTATIC_POWER").Value, out diastaticPowerParsed);
     float? diastaticPower = diastaticPowerIsntNull ? (float?) diastaticPowerParsed : null;
     double potential = Convert.ToDouble(fermentableEntry.Element("POTENTIAL").Value);
     int gravityUnit = AlcoholUtility.GetGravityUnit(potential);
     FermentableCharacteristics characteristics = new FermentableCharacteristics(yield, color, diastaticPower) { Type = type, YieldByWeight = yieldByWeight, GravityPoint = gravityUnit };
     return new Fermentable(name, characteristics, notes, origin);
 }
        public static Fermentable GetFermentable(XElement fermentableEntry)
        {
            var name              = GetNameFromRecord(fermentableEntry);
            var origin            = fermentableEntry.GetChildElementValue("ORIGIN");
            var notes             = GetNotesFromRecord(fermentableEntry);
            var type              = EnumConverter.Parse <FermentableType>(fermentableEntry.GetChildElementValue("TYPE"));
            var yieldValue        = Convert.ToSingle(fermentableEntry.GetChildElementValue("YIELD"));
            var yield             = type == FermentableType.Grain ? (float?)yieldValue : null;
            var color             = Convert.ToSingle(fermentableEntry.GetChildElementValue("COLOR"));
            var diastaticPower    = float.TryParse(fermentableEntry.GetChildElementValue("DIASTATIC_POWER"), out var diastaticPowerParsed) ? (float?)diastaticPowerParsed : null;
            var potential         = Convert.ToDouble(fermentableEntry.GetChildElementValue("POTENTIAL"));
            var maltCategoryValue = fermentableEntry.Element("malt-category")?.Value;
            var characteristics   = new FermentableCharacteristics(yield, color, diastaticPower)
            {
                Type          = type,
                YieldByWeight = type != FermentableType.Grain ? yieldValue : null,
                GravityPoint  = AlcoholUtility.GetGravityUnit(potential),
                MaltCategory  = maltCategoryValue != null?EnumConverter.Parse <MaltCategory>(maltCategoryValue) : null
            };

            return(new Fermentable(name, characteristics, notes, origin));
        }
示例#6
0
 public Fermentable(string name, FermentableCharacteristics characteristics, string notes, string origin)
     : base(name, notes)
 {
     m_characteristics = characteristics;
     m_origin = origin;
 }
 internal static IEnumerable<FermentableIngredientDataModel> GetFermentableIngredientsForRecipe(int recipeId, SQLiteConnection connection)
 {
     using (SQLiteCommand selectIngredientsCommand = connection.CreateCommand())
     {
         selectIngredientsCommand.CommandText = "SELECT FermentableIngredients.id, FermentableIngredients.amount, Fermentables.name, Fermentables.yield, Fermentables.yieldByWeight, Fermentables.color, Fermentables.origin, Fermentables.notes, Fermentables.diastaticPower, Fermentables.type, Fermentables.maltCategory, Fermentables.gravityPoint FROM FermentableIngredients " +
             "JOIN FermentablesInRecipe ON FermentablesInRecipe.fermentableIngredient = FermentableIngredients.id AND FermentablesInRecipe.recipe = @recipeId " +
             "JOIN Fermentables ON Fermentables.id = FermentableIngredients.fermentableInfo";
         selectIngredientsCommand.Parameters.AddWithValue("recipeId", recipeId);
         using (SQLiteDataReader reader = selectIngredientsCommand.ExecuteReader())
         {
             while (reader.Read())
             {
                 string yieldValue = reader[3].ToString();
                 float? yield = !yieldValue.IsNullOrEmpty() ? (float?) float.Parse(yieldValue) : null;
                 string yieldByWeightValue = reader[4].ToString();
                 float? yieldByWeight = !yieldByWeightValue.IsNullOrEmpty() ? (float?) float.Parse(yieldByWeightValue) : null;
                 string diastaticPowerValue = reader[8].ToString();
                 float? diastaticPower = !diastaticPowerValue.IsNullOrEmpty() ? (float?) float.Parse(diastaticPowerValue) : null;
                 string maltCategoryValue = reader[10].ToString();
                 MaltCategory? maltCategory = !maltCategoryValue.IsNullOrEmpty() ? (MaltCategory?) EnumConverter.Parse<MaltCategory>(maltCategoryValue) : null;
                 FermentableCharacteristics characteristics = new FermentableCharacteristics(yield, reader.GetFloat(5), diastaticPower)
                 {
                     GravityPoint = reader.GetInt32(11),
                     Type = EnumConverter.Parse<FermentableType>(reader.GetString(9)),
                     MaltCategory = maltCategory,
                     YieldByWeight = yieldByWeight
                 };
                 Fermentable fermentableInfo = new Fermentable(reader.GetString(2), characteristics, reader.GetString(7), reader.GetString(6));
                 yield return new FermentableIngredientDataModel(fermentableInfo, reader.GetInt32(0)) { Amount = reader.GetFloat(1) };
             }
         }
     }
 }