public static IEnumerable <Style> GetAvailableBeerStyles() { using var connection = DatabaseUtility.GetNewConnection(); var stylesCommand = connection.CreateCommand(); stylesCommand.CommandText = "SELECT Styles.name, Styles.notes, Styles.profile, Styles.ingredients, Styles.examples, StyleCategories.name, StyleCategories.number, StyleCategories.type, StyleClassifications.letter, StyleClassifications.guide FROM Styles " + "JOIN StyleCategories ON Styles.category = StyleCategories.id " + "JOIN StyleClassifications ON Styles.classification = StyleClassifications.id"; using var reader = stylesCommand.ExecuteReader(); while (reader.Read()) { var category = new StyleCategory(reader.GetString(5), reader.GetInt32(6), EnumConverter.Parse <StyleType>(reader.GetString(7))); var classification = new StyleClassification(reader.GetString(8), reader.GetString(9)); string styleName = reader.GetString(0); var thresholds = GetStyleThresholds(styleName, connection).ToList(); yield return(new Style(styleName, category, classification, thresholds) { Notes = reader.GetString(1), Profile = reader.GetString(2), Ingredients = reader.GetString(3), Examples = reader.GetString(4) }); } connection.Close(); }
public static IEnumerable<Style> GetAvailableBeerStyles() { using (SQLiteConnection connection = DatabaseUtility.GetNewConnection()) { SQLiteCommand stylesCommand = connection.CreateCommand(); stylesCommand.CommandText = "SELECT Styles.name, Styles.notes, Styles.profile, Styles.ingredients, Styles.examples, StyleCategories.name, StyleCategories.number, StyleCategories.type, StyleClassifications.letter, StyleClassifications.guide FROM Styles " + "JOIN StyleCategories ON Styles.category = StyleCategories.id " + "JOIN StyleClassifications ON Styles.classification = StyleClassifications.id"; using (SQLiteDataReader reader = stylesCommand.ExecuteReader()) { while (reader.Read()) { StyleCategory category = new StyleCategory(reader.GetString(5), reader.GetInt32(6), reader.GetString(7)); StyleClassification classification = new StyleClassification(reader.GetString(8), reader.GetString(9)); string styleName = reader.GetString(0); List<StyleThreshold> thresholds = GetStyleThresholds(styleName, connection).ToList(); yield return new Style(styleName, category, classification, thresholds) { Notes = reader.GetString(1), Profile = reader.GetString(2), Ingredients = reader.GetString(3), Examples = reader.GetString(4) }; } } connection.Close(); } }
public static Style GetStyle(XElement styleEntry) { string name = GetNameFromRecord(styleEntry); List<StyleThreshold> thresholds = new List<StyleThreshold>() { new StyleThreshold("og", (float) Convert.ToDouble(styleEntry.Element("OG_MIN").Value), (float) Convert.ToDouble(styleEntry.Element("OG_MAX").Value)), new StyleThreshold("fg", (float) Convert.ToDouble(styleEntry.Element("FG_MIN").Value), (float) Convert.ToDouble(styleEntry.Element("FG_MAX").Value)), new StyleThreshold("ibu", (float) Convert.ToDouble(styleEntry.Element("IBU_MIN").Value), (float) Convert.ToDouble(styleEntry.Element("IBU_MAX").Value)), new StyleThreshold("color", (float) Convert.ToDouble(styleEntry.Element("COLOR_MIN").Value), (float) Convert.ToDouble(styleEntry.Element("COLOR_MAX").Value)), new StyleThreshold("carb", (float) Convert.ToDouble(styleEntry.Element("CARB_MIN").Value), (float) Convert.ToDouble(styleEntry.Element("CARB_MAX").Value)), new StyleThreshold("abv", (float) Convert.ToDouble(styleEntry.Element("ABV_MIN").Value), (float) Convert.ToDouble(styleEntry.Element("ABV_MAX").Value)), }; string categoryName = styleEntry.Element("CATEGORY").Value; int categoryNumber = Convert.ToInt32(styleEntry.Element("CATEGORY_NUMBER").Value); string type = styleEntry.Element("TYPE").Value; StyleCategory category = new StyleCategory(categoryName, categoryNumber, type); string styleLetter = styleEntry.Element("STYLE_LETTER").Value; string styleGuide = styleEntry.Element("STYLE_GUIDE").Value; StyleClassification classification = new StyleClassification(styleLetter, styleGuide); return new Style(name, category, classification, thresholds) { Notes = GetNotesFromRecord(styleEntry), Profile = styleEntry.Element("PROFILE").Value, Ingredients = styleEntry.Element("INGREDIENTS").Value, Examples = styleEntry.Element("EXAMPLES").Value }; }