using Microsoft.AspNetCore.Html; using System; using System.Net; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Office.Interop.Word; using System.Text.RegularExpressions; namespace JRCookbookBusiness { public class Ingredient { public Guid? ingredientID = null; private String _name = String.Empty; public String source = String.Empty; public Guid ingredientfolderID = Guid.Empty; public String comments = String.Empty; public Single water = 0; public Single calories = 0; public Single caloriesfromfat = 0; public Single percentcaloriesfromfat = 0; public Single energy = 0; public Single protein = 0; public Single totalfat = 0; public Single sugar = 0; public Single totalcarbohydrate = 0; public Single fiber = 0; public Single calcium = 0; public Single phosphorus = 0; public Single iron = 0; public Single sodium = 0; public Single potassium = 0; public Single magnesium = 0; public Single zinc = 0; public Single copper = 0; public Single manganese = 0; public Single selenium = 0; public Single vitamina = 0; public Single vitamine = 0; public Single thiamin = 0; public Single riboflavin = 0; public Single niacin = 0; public Single pantothenicacid = 0; public Single vitaminb6 = 0; public Single folate = 0; public Single vitaminb12 = 0; public Single vitaminc = 0; public Single saturatedfat = 0; public Single monounsaturatedfat = 0; public Single polyunsaturatedfat = 0; public Single cholesterol = 0; public Single alcohol = 0; public Single caffeine = 0; public Int16 selectedweight = 0; public String usdaingredient = String.Empty; public String useringredient = String.Empty; public Guid? selectedmeasureid = null; public Single biotin = 0; public String commonname = String.Empty; public Single energyfromfat = 0; public String nutritionsource = String.Empty; public Double servingsize = 0; public Guid? servingsizemeasureid = null; public Single sugaralcohols = 0; public Single transfattyacids = 0; public Single vitamind = 0; public Single caloriesfromalcohol = 0; public Single caloriesfromcarbs = 0; public Single caloriesfromprotein = 0; public Single energyfromalcohol = 0; public Single energyfromcarbs = 0; public Single energyfromprotein = 0; public Single percentcaloriesfromalcohol = 0; public Single percentcaloriesfromcarbs = 0; public Single percentcaloriesfromprotein = 0; public Single alanine = 0; public Single alcoholfactor = 0; public Single alphacarotene = 0; public Single alphalinolenicacid = 0; public Single arachidonicacid = 0; public Single arginine = 0; public Single ash = 0; public Single asparticacid = 0; public Single betacarotene = 0; public Single betacryptoxanthin = 0; public Single betasitosterol = 0; public Single betatocopherol = 0; public Single campesterol = 0; public Single carbohydratefactor = 0; public Single chloride = 0; public Single choline = 0; public Single chromium = 0; public Single cystine = 0; public Single deltatocopherol = 0; public Single dihomogammalinolenicacid = 0; public Single docosahexaenoicacid = 0; public Single docosapentaenoicacid = 0; public Single eicosadienoicacid = 0; public Single eicosapentaenoicacid = 0; public Single fatfactor = 0; public Single fluoride = 0; public Single fructose = 0; public Single galactose = 0; public Single gammalinolenicacid = 0; public Single gammatocopherol = 0; public Single glucose = 0; public Single glutamicacid = 0; public Single glycine = 0; public Single histidine = 0; public Single hydroxyproline = 0; public Single iodine = 0; public Single isoleucine = 0; public Single lactose = 0; public Single leucine = 0; public Single linoleicacid = 0; public Single lycopene = 0; public Single lysine = 0; public Single maltose = 0; public Single methionine = 0; public Single molybdenum = 0; public Single monounsaturatedfattyacid_14_1 = 0; public Single monounsaturatedfattyacid_15_1 = 0; public Single monounsaturatedfattyacid_16_1 = 0; public Single monounsaturatedfattyacid_17_1 = 0; public Single monounsaturatedfattyacid_18_1 = 0; public Single monounsaturatedfattyacid_20_1 = 0; public Single monounsaturatedfattyacid_22_1 = 0; public Single monounsaturatedfattyacid_24_1 = 0; public Single netcarbohydrates = 0; public String nutritioncalculationmode = String.Empty; public Single omega3fattyacids = 0; public Single omega6fattyacids = 0; public Single phenylalanine = 0; public Single phytosterols = 0; public Single polyunsaturatedfattyacid_18_2 = 0; public Single polyunsaturatedfattyacid_18_3 = 0; public Single polyunsaturatedfattyacid_18_4 = 0; public Single polyunsaturatedfattyacid_20_3 = 0; public Single polyunsaturatedfattyacid_20_4 = 0; public Single polyunsaturatedfattyacid_21_5 = 0; public Single polyunsaturatedfattyacid_22_4 = 0; public Single proline = 0; public Single proteinfactor = 0; public Single refuse = 0; public Single retinol = 0; public Single saturatedfattyacid_10_0 = 0; public Single saturatedfattyacid_12_0 = 0; public Single saturatedfattyacid_13_0 = 0; public Single saturatedfattyacid_14_0 = 0; public Single saturatedfattyacid_15_0 = 0; public Single saturatedfattyacid_16_0 = 0; public Single saturatedfattyacid_17_0 = 0; public Single saturatedfattyacid_18_0 = 0; public Single saturatedfattyacid_20_0 = 0; public Single saturatedfattyacid_22_0 = 0; public Single saturatedfattyacid_24_0 = 0; public Single saturatedfattyacid_4_0 = 0; public Single saturatedfattyacid_6_0 = 0; public Single saturatedfattyacid_8_0 = 0; public Single serine = 0; public Single starch = 0; public Single stigmasterol = 0; public Single sucrose = 0; public Single theobromine = 0; public Single threonine = 0; public Single transmonoenoicfattyacids = 0; public Single transpolyenoicfattyacids = 0; public Single tryptophan = 0; public Single tyrosine = 0; public Single valine = 0; public Single vitamink = 0; public Single volume = 0; private String _normalizedIngredientName = String.Empty; public Dictionary ingredientMeasureDictionary = new Dictionary(); private static List _allIngredients = null; public Ingredient() { } public Ingredient(Guid ingredientID) { PopulateByID(ingredientID); } public string? name { get => _name; set { _name = value; _normalizedIngredientName = RecipeIngredient.NormalizeRecipeIngredientName(value); } } public string? normalizedIngredientName { get { return _normalizedIngredientName; } } //public void Delete() //{ // clsDatabaseLayer.GetDatabaseLayer().DeleteIngredientByID(ingredientID); //} public static Ingredient GetIngredientByID(Guid ingredientID) { return new Ingredient(ingredientID); } public static Ingredient GetIngredientByDataRow(DataRow dataRow) { var newIngredient = new Ingredient(); newIngredient.PopulateFromDataRow(dataRow); return newIngredient; } public static List GetAllIngredients() { if (_allIngredients == null) { _allIngredients = new List(); DataSet recordSet; recordSet = clsDatabaseLayer.GetDatabaseLayer().GetAllIngredients(); foreach (DataRow dataRow in recordSet.Tables[0].Rows) { var newIngredient = GetIngredientByDataRow(dataRow); _allIngredients.Add(newIngredient); } } return _allIngredients; } public static List GetIngredientsBySearchString(String searchString) { var returnValue = new List(); //var searchRegEx = new Regex(@"\A" + new Regex(@"\.|\$|\^|\{|\[|\(|\||\)|\*|\+|\?|\\").Replace(searchString, ch => @"\" + ch).Replace('_', '.').Replace("%", ".*") + @"\z", RegexOptions.Singleline); var searchRegEx = new Regex(new Regex(@"\.|\$|\^|\{|\[|\(|\||\)|\*|\+|\?|\\").Replace(searchString, ch => @"\" + ch).Replace('_', '.').Replace("%", ".*"), RegexOptions.Singleline); foreach (var item in GetAllIngredients()) { if (searchRegEx.IsMatch(item.normalizedIngredientName)) { returnValue.Add(item); } } //DataSet recordSet; //recordSet = clsDatabaseLayer.GetDatabaseLayer().GetIngredientsBySearchString(searchString); //foreach (DataRow dataRow in recordSet.Tables[0].Rows) //{ // var newIngredient = GetIngredientByDataRow(dataRow); // returnValue.Add(newIngredient); //} return returnValue; } //public static void DeleteByID(Guid ingredientID) //{ // var ingredient = new Ingredient(ingredientID); // ingredient.Delete(); //} private void PopulateByID(Guid ingredientID) { DataSet recordSet; recordSet = clsDatabaseLayer.GetDatabaseLayer().GetIngredientByID(ingredientID); if (recordSet.Tables[0].Rows.Count > 0) { DataRow ldbrwRow; ldbrwRow = recordSet.Tables[0].Rows[0]; PopulateFromDataRow(ldbrwRow); } } private void PopulateFromDataRow(DataRow dataRow) { InitializeAllFields(); if (dataRow.IsNull("ingredientid")) ingredientID = null; else ingredientID = (Guid)dataRow["ingredientid"]; if (dataRow.IsNull("name")) name = String.Empty; else name = (String)dataRow["name"]; if (dataRow.IsNull("source")) source = String.Empty; else source = (String)dataRow["source"]; if (dataRow.IsNull("ingredientfolderid")) ingredientfolderID = Guid.Empty; else ingredientfolderID = (Guid)dataRow["ingredientfolderid"]; if (dataRow.IsNull("comments")) comments = String.Empty; else comments = (String)dataRow["comments"]; if (dataRow.IsNull("water")) water = 0; else water = (Single)dataRow["water"]; if (dataRow.IsNull("calories")) calories = 0; else calories = (Single)dataRow["calories"]; if (dataRow.IsNull("caloriesfromfat")) caloriesfromfat = 0; else caloriesfromfat = (Single)dataRow["caloriesfromfat"]; if (dataRow.IsNull("percentcaloriesfromfat")) percentcaloriesfromfat = 0; else percentcaloriesfromfat = (Single)dataRow["percentcaloriesfromfat"]; if (dataRow.IsNull("energy")) energy = 0; else energy = (Single)dataRow["energy"]; if (dataRow.IsNull("protein")) protein = 0; else protein = (Single)dataRow["protein"]; if (dataRow.IsNull("totalfat")) totalfat = 0; else totalfat = (Single)dataRow["totalfat"]; if (dataRow.IsNull("sugar")) sugar = 0; else sugar = (Single)dataRow["sugar"]; if (dataRow.IsNull("totalcarbohydrate")) totalcarbohydrate = 0; else totalcarbohydrate = (Single)dataRow["totalcarbohydrate"]; if (dataRow.IsNull("fiber")) fiber = 0; else fiber = (Single)dataRow["fiber"]; if (dataRow.IsNull("calcium")) calcium = 0; else calcium = (Single)dataRow["calcium"]; if (dataRow.IsNull("phosphorus")) phosphorus = 0; else phosphorus = (Single)dataRow["phosphorus"]; if (dataRow.IsNull("iron")) iron = 0; else iron = (Single)dataRow["iron"]; if (dataRow.IsNull("sodium")) sodium = 0; else sodium = (Single)dataRow["sodium"]; if (dataRow.IsNull("potassium")) potassium = 0; else potassium = (Single)dataRow["potassium"]; if (dataRow.IsNull("magnesium")) magnesium = 0; else magnesium = (Single)dataRow["magnesium"]; if (dataRow.IsNull("zinc")) zinc = 0; else zinc = (Single)dataRow["zinc"]; if (dataRow.IsNull("copper")) copper = 0; else copper = (Single)dataRow["copper"]; if (dataRow.IsNull("manganese")) manganese = 0; else manganese = (Single)dataRow["manganese"]; if (dataRow.IsNull("selenium")) selenium = 0; else selenium = (Single)dataRow["selenium"]; if (dataRow.IsNull("vitamina")) vitamina = 0; else vitamina = (Single)dataRow["vitamina"]; if (dataRow.IsNull("vitamine")) vitamine = 0; else vitamine = (Single)dataRow["vitamine"]; if (dataRow.IsNull("thiamin")) thiamin = 0; else thiamin = (Single)dataRow["thiamin"]; if (dataRow.IsNull("riboflavin")) riboflavin = 0; else riboflavin = (Single)dataRow["riboflavin"]; if (dataRow.IsNull("niacin")) niacin = 0; else niacin = (Single)dataRow["niacin"]; if (dataRow.IsNull("pantothenicacid")) pantothenicacid = 0; else pantothenicacid = (Single)dataRow["pantothenicacid"]; if (dataRow.IsNull("vitaminb6")) vitaminb6 = 0; else vitaminb6 = (Single)dataRow["vitaminb6"]; if (dataRow.IsNull("folate")) folate = 0; else folate = (Single)dataRow["folate"]; if (dataRow.IsNull("vitaminb12")) vitaminb12 = 0; else vitaminb12 = (Single)dataRow["vitaminb12"]; if (dataRow.IsNull("vitaminc")) vitaminc = 0; else vitaminc = (Single)dataRow["vitaminc"]; if (dataRow.IsNull("saturatedfat")) saturatedfat = 0; else saturatedfat = (Single)dataRow["saturatedfat"]; if (dataRow.IsNull("monounsaturatedfat")) monounsaturatedfat = 0; else monounsaturatedfat = (Single)dataRow["monounsaturatedfat"]; if (dataRow.IsNull("polyunsaturatedfat")) polyunsaturatedfat = 0; else polyunsaturatedfat = (Single)dataRow["polyunsaturatedfat"]; if (dataRow.IsNull("cholesterol")) cholesterol = 0; else cholesterol = (Single)dataRow["cholesterol"]; if (dataRow.IsNull("alcohol")) alcohol = 0; else alcohol = (Single)dataRow["alcohol"]; if (dataRow.IsNull("caffeine")) caffeine = 0; else caffeine = (Single)dataRow["caffeine"]; if (dataRow.IsNull("selectedweight")) selectedweight = 0; else selectedweight = (Int16)dataRow["selectedweight"]; if (dataRow.IsNull("usdaingredient")) usdaingredient = String.Empty; else usdaingredient = (String)dataRow["usdaingredient"]; if (dataRow.IsNull("useringredient")) useringredient = String.Empty; else useringredient = (String)dataRow["useringredient"]; if (dataRow.IsNull("selectedmeasureid")) selectedmeasureid = null; else selectedmeasureid = (Guid)dataRow["selectedmeasureid"]; if (dataRow.IsNull("biotin")) biotin = 0; else biotin = (Single)dataRow["biotin"]; if (dataRow.IsNull("commonname")) commonname = String.Empty; else commonname = (String)dataRow["commonname"]; if (dataRow.IsNull("energyfromfat")) energyfromfat = 0; else energyfromfat = (Single)dataRow["energyfromfat"]; if (dataRow.IsNull("nutritionsource")) nutritionsource = String.Empty; else nutritionsource = (String)dataRow["nutritionsource"]; if (dataRow.IsNull("servingsize")) servingsize = 0; else servingsize = (Double)dataRow["servingsize"]; if (dataRow.IsNull("servingsizemeasureid")) servingsizemeasureid = null; else servingsizemeasureid = (Guid)dataRow["servingsizemeasureid"]; if (dataRow.IsNull("sugaralcohols")) sugaralcohols = 0; else sugaralcohols = (Single)dataRow["sugaralcohols"]; if (dataRow.IsNull("transfattyacids")) transfattyacids = 0; else transfattyacids = (Single)dataRow["transfattyacids"]; if (dataRow.IsNull("vitamind")) vitamind = 0; else vitamind = (Single)dataRow["vitamind"]; if (dataRow.IsNull("caloriesfromalcohol")) caloriesfromalcohol = 0; else caloriesfromalcohol = (Single)dataRow["caloriesfromalcohol"]; if (dataRow.IsNull("caloriesfromcarbs")) caloriesfromcarbs = 0; else caloriesfromcarbs = (Single)dataRow["caloriesfromcarbs"]; if (dataRow.IsNull("caloriesfromprotein")) caloriesfromprotein = 0; else caloriesfromprotein = (Single)dataRow["caloriesfromprotein"]; if (dataRow.IsNull("energyfromalcohol")) energyfromalcohol = 0; else energyfromalcohol = (Single)dataRow["energyfromalcohol"]; if (dataRow.IsNull("energyfromcarbs")) energyfromcarbs = 0; else energyfromcarbs = (Single)dataRow["energyfromcarbs"]; if (dataRow.IsNull("energyfromprotein")) energyfromprotein = 0; else energyfromprotein = (Single)dataRow["energyfromprotein"]; if (dataRow.IsNull("percentcaloriesfromalcohol")) percentcaloriesfromalcohol = 0; else percentcaloriesfromalcohol = (Single)dataRow["percentcaloriesfromalcohol"]; if (dataRow.IsNull("percentcaloriesfromcarbs")) percentcaloriesfromcarbs = 0; else percentcaloriesfromcarbs = (Single)dataRow["percentcaloriesfromcarbs"]; if (dataRow.IsNull("percentcaloriesfromprotein")) percentcaloriesfromprotein = 0; else percentcaloriesfromprotein = (Single)dataRow["percentcaloriesfromprotein"]; if (dataRow.IsNull("alanine")) alanine = 0; else alanine = (Single)dataRow["alanine"]; if (dataRow.IsNull("alcoholfactor")) alcoholfactor = 0; else alcoholfactor = (Single)dataRow["alcoholfactor"]; if (dataRow.IsNull("alphacarotene")) alphacarotene = 0; else alphacarotene = (Single)dataRow["alphacarotene"]; if (dataRow.IsNull("alphalinolenicacid")) alphalinolenicacid = 0; else alphalinolenicacid = (Single)dataRow["alphalinolenicacid"]; if (dataRow.IsNull("arachidonicacid")) arachidonicacid = 0; else arachidonicacid = (Single)dataRow["arachidonicacid"]; if (dataRow.IsNull("arginine")) arginine = 0; else arginine = (Single)dataRow["arginine"]; if (dataRow.IsNull("ash")) ash = 0; else ash = (Single)dataRow["ash"]; if (dataRow.IsNull("asparticacid")) asparticacid = 0; else asparticacid = (Single)dataRow["asparticacid"]; if (dataRow.IsNull("betacarotene")) betacarotene = 0; else betacarotene = (Single)dataRow["betacarotene"]; if (dataRow.IsNull("betacryptoxanthin")) betacryptoxanthin = 0; else betacryptoxanthin = (Single)dataRow["betacryptoxanthin"]; if (dataRow.IsNull("betasitosterol")) betasitosterol = 0; else betasitosterol = (Single)dataRow["betasitosterol"]; if (dataRow.IsNull("betatocopherol")) betatocopherol = 0; else betatocopherol = (Single)dataRow["betatocopherol"]; if (dataRow.IsNull("campesterol")) campesterol = 0; else campesterol = (Single)dataRow["campesterol"]; if (dataRow.IsNull("carbohydratefactor")) carbohydratefactor = 0; else carbohydratefactor = (Single)dataRow["carbohydratefactor"]; if (dataRow.IsNull("chloride")) chloride = 0; else chloride = (Single)dataRow["chloride"]; if (dataRow.IsNull("choline")) choline = 0; else choline = (Single)dataRow["choline"]; if (dataRow.IsNull("chromium")) chromium = 0; else chromium = (Single)dataRow["chromium"]; if (dataRow.IsNull("cystine")) cystine = 0; else cystine = (Single)dataRow["cystine"]; if (dataRow.IsNull("deltatocopherol")) deltatocopherol = 0; else deltatocopherol = (Single)dataRow["deltatocopherol"]; if (dataRow.IsNull("dihomogammalinolenicacid")) dihomogammalinolenicacid = 0; else dihomogammalinolenicacid = (Single)dataRow["dihomogammalinolenicacid"]; if (dataRow.IsNull("docosahexaenoicacid")) docosahexaenoicacid = 0; else docosahexaenoicacid = (Single)dataRow["docosahexaenoicacid"]; if (dataRow.IsNull("docosapentaenoicacid")) docosapentaenoicacid = 0; else docosapentaenoicacid = (Single)dataRow["docosapentaenoicacid"]; if (dataRow.IsNull("eicosadienoicacid")) eicosadienoicacid = 0; else eicosadienoicacid = (Single)dataRow["eicosadienoicacid"]; if (dataRow.IsNull("eicosapentaenoicacid")) eicosapentaenoicacid = 0; else eicosapentaenoicacid = (Single)dataRow["eicosapentaenoicacid"]; if (dataRow.IsNull("fatfactor")) fatfactor = 0; else fatfactor = (Single)dataRow["fatfactor"]; if (dataRow.IsNull("fluoride")) fluoride = 0; else fluoride = (Single)dataRow["fluoride"]; if (dataRow.IsNull("fructose")) fructose = 0; else fructose = (Single)dataRow["fructose"]; if (dataRow.IsNull("galactose")) galactose = 0; else galactose = (Single)dataRow["galactose"]; if (dataRow.IsNull("gammalinolenicacid")) gammalinolenicacid = 0; else gammalinolenicacid = (Single)dataRow["gammalinolenicacid"]; if (dataRow.IsNull("gammatocopherol")) gammatocopherol = 0; else gammatocopherol = (Single)dataRow["gammatocopherol"]; if (dataRow.IsNull("glucose")) glucose = 0; else glucose = (Single)dataRow["glucose"]; if (dataRow.IsNull("glutamicacid")) glutamicacid = 0; else glutamicacid = (Single)dataRow["glutamicacid"]; if (dataRow.IsNull("glycine")) glycine = 0; else glycine = (Single)dataRow["glycine"]; if (dataRow.IsNull("histidine")) histidine = 0; else histidine = (Single)dataRow["histidine"]; if (dataRow.IsNull("hydroxyproline")) hydroxyproline = 0; else hydroxyproline = (Single)dataRow["hydroxyproline"]; if (dataRow.IsNull("iodine")) iodine = 0; else iodine = (Single)dataRow["iodine"]; if (dataRow.IsNull("isoleucine")) isoleucine = 0; else isoleucine = (Single)dataRow["isoleucine"]; if (dataRow.IsNull("lactose")) lactose = 0; else lactose = (Single)dataRow["lactose"]; if (dataRow.IsNull("leucine")) leucine = 0; else leucine = (Single)dataRow["leucine"]; if (dataRow.IsNull("linoleicacid")) linoleicacid = 0; else linoleicacid = (Single)dataRow["linoleicacid"]; if (dataRow.IsNull("lycopene")) lycopene = 0; else lycopene = (Single)dataRow["lycopene"]; if (dataRow.IsNull("lysine")) lysine = 0; else lysine = (Single)dataRow["lysine"]; if (dataRow.IsNull("maltose")) maltose = 0; else maltose = (Single)dataRow["maltose"]; if (dataRow.IsNull("methionine")) methionine = 0; else methionine = (Single)dataRow["methionine"]; if (dataRow.IsNull("molybdenum")) molybdenum = 0; else molybdenum = (Single)dataRow["molybdenum"]; if (dataRow.IsNull("monounsaturatedfattyacid_14_1")) monounsaturatedfattyacid_14_1 = 0; else monounsaturatedfattyacid_14_1 = (Single)dataRow["monounsaturatedfattyacid_14_1"]; if (dataRow.IsNull("monounsaturatedfattyacid_15_1")) monounsaturatedfattyacid_15_1 = 0; else monounsaturatedfattyacid_15_1 = (Single)dataRow["monounsaturatedfattyacid_15_1"]; if (dataRow.IsNull("monounsaturatedfattyacid_16_1")) monounsaturatedfattyacid_16_1 = 0; else monounsaturatedfattyacid_16_1 = (Single)dataRow["monounsaturatedfattyacid_16_1"]; if (dataRow.IsNull("monounsaturatedfattyacid_17_1")) monounsaturatedfattyacid_17_1 = 0; else monounsaturatedfattyacid_17_1 = (Single)dataRow["monounsaturatedfattyacid_17_1"]; if (dataRow.IsNull("monounsaturatedfattyacid_18_1")) monounsaturatedfattyacid_18_1 = 0; else monounsaturatedfattyacid_18_1 = (Single)dataRow["monounsaturatedfattyacid_18_1"]; if (dataRow.IsNull("monounsaturatedfattyacid_20_1")) monounsaturatedfattyacid_20_1 = 0; else monounsaturatedfattyacid_20_1 = (Single)dataRow["monounsaturatedfattyacid_20_1"]; if (dataRow.IsNull("monounsaturatedfattyacid_22_1")) monounsaturatedfattyacid_22_1 = 0; else monounsaturatedfattyacid_22_1 = (Single)dataRow["monounsaturatedfattyacid_22_1"]; if (dataRow.IsNull("monounsaturatedfattyacid_24_1")) monounsaturatedfattyacid_24_1 = 0; else monounsaturatedfattyacid_24_1 = (Single)dataRow["monounsaturatedfattyacid_24_1"]; if (dataRow.IsNull("netcarbohydrates")) netcarbohydrates = 0; else netcarbohydrates = (Single)dataRow["netcarbohydrates"]; if (dataRow.IsNull("nutritioncalculationmode")) nutritioncalculationmode = String.Empty; else nutritioncalculationmode = (string)dataRow["nutritioncalculationmode"]; if (dataRow.IsNull("omega3fattyacids")) omega3fattyacids = 0; else omega3fattyacids = (Single)dataRow["omega3fattyacids"]; if (dataRow.IsNull("omega6fattyacids")) omega6fattyacids = 0; else omega6fattyacids = (Single)dataRow["omega6fattyacids"]; if (dataRow.IsNull("phenylalanine")) phenylalanine = 0; else phenylalanine = (Single)dataRow["phenylalanine"]; if (dataRow.IsNull("phytosterols")) phytosterols = 0; else phytosterols = (Single)dataRow["phytosterols"]; if (dataRow.IsNull("polyunsaturatedfattyacid_18_2")) polyunsaturatedfattyacid_18_2 = 0; else polyunsaturatedfattyacid_18_2 = (Single)dataRow["polyunsaturatedfattyacid_18_2"]; if (dataRow.IsNull("polyunsaturatedfattyacid_18_3")) polyunsaturatedfattyacid_18_3 = 0; else polyunsaturatedfattyacid_18_3 = (Single)dataRow["polyunsaturatedfattyacid_18_3"]; if (dataRow.IsNull("polyunsaturatedfattyacid_18_4")) polyunsaturatedfattyacid_18_4 = 0; else polyunsaturatedfattyacid_18_4 = (Single)dataRow["polyunsaturatedfattyacid_18_4"]; if (dataRow.IsNull("polyunsaturatedfattyacid_20_3")) polyunsaturatedfattyacid_20_3 = 0; else polyunsaturatedfattyacid_20_3 = (Single)dataRow["polyunsaturatedfattyacid_20_3"]; if (dataRow.IsNull("polyunsaturatedfattyacid_20_4")) polyunsaturatedfattyacid_20_4 = 0; else polyunsaturatedfattyacid_20_4 = (Single)dataRow["polyunsaturatedfattyacid_20_4"]; if (dataRow.IsNull("polyunsaturatedfattyacid_21_5")) polyunsaturatedfattyacid_21_5 = 0; else polyunsaturatedfattyacid_21_5 = (Single)dataRow["polyunsaturatedfattyacid_21_5"]; if (dataRow.IsNull("polyunsaturatedfattyacid_22_4")) polyunsaturatedfattyacid_22_4 = 0; else polyunsaturatedfattyacid_22_4 = (Single)dataRow["polyunsaturatedfattyacid_22_4"]; if (dataRow.IsNull("proline")) proline = 0; else proline = (Single)dataRow["proline"]; if (dataRow.IsNull("proteinfactor")) proteinfactor = 0; else proteinfactor = (Single)dataRow["proteinfactor"]; if (dataRow.IsNull("refuse")) refuse = 0; else refuse = (Single)dataRow["refuse"]; if (dataRow.IsNull("retinol")) retinol = 0; else retinol = (Single)dataRow["retinol"]; if (dataRow.IsNull("saturatedfattyacid_10_0")) saturatedfattyacid_10_0 = 0; else saturatedfattyacid_10_0 = (Single)dataRow["saturatedfattyacid_10_0"]; if (dataRow.IsNull("saturatedfattyacid_12_0")) saturatedfattyacid_12_0 = 0; else saturatedfattyacid_12_0 = (Single)dataRow["saturatedfattyacid_12_0"]; if (dataRow.IsNull("saturatedfattyacid_13_0")) saturatedfattyacid_13_0 = 0; else saturatedfattyacid_13_0 = (Single)dataRow["saturatedfattyacid_13_0"]; if (dataRow.IsNull("saturatedfattyacid_14_0")) saturatedfattyacid_14_0 = 0; else saturatedfattyacid_14_0 = (Single)dataRow["saturatedfattyacid_14_0"]; if (dataRow.IsNull("saturatedfattyacid_15_0")) saturatedfattyacid_15_0 = 0; else saturatedfattyacid_15_0 = (Single)dataRow["saturatedfattyacid_15_0"]; if (dataRow.IsNull("saturatedfattyacid_16_0")) saturatedfattyacid_16_0 = 0; else saturatedfattyacid_16_0 = (Single)dataRow["saturatedfattyacid_16_0"]; if (dataRow.IsNull("saturatedfattyacid_17_0")) saturatedfattyacid_17_0 = 0; else saturatedfattyacid_17_0 = (Single)dataRow["saturatedfattyacid_17_0"]; if (dataRow.IsNull("saturatedfattyacid_18_0")) saturatedfattyacid_18_0 = 0; else saturatedfattyacid_18_0 = (Single)dataRow["saturatedfattyacid_18_0"]; if (dataRow.IsNull("saturatedfattyacid_20_0")) saturatedfattyacid_20_0 = 0; else saturatedfattyacid_20_0 = (Single)dataRow["saturatedfattyacid_20_0"]; if (dataRow.IsNull("saturatedfattyacid_22_0")) saturatedfattyacid_22_0 = 0; else saturatedfattyacid_22_0 = (Single)dataRow["saturatedfattyacid_22_0"]; if (dataRow.IsNull("saturatedfattyacid_24_0")) saturatedfattyacid_24_0 = 0; else saturatedfattyacid_24_0 = (Single)dataRow["saturatedfattyacid_24_0"]; if (dataRow.IsNull("saturatedfattyacid_4_0")) saturatedfattyacid_4_0 = 0; else saturatedfattyacid_4_0 = (Single)dataRow["saturatedfattyacid_4_0"]; if (dataRow.IsNull("saturatedfattyacid_6_0")) saturatedfattyacid_6_0 = 0; else saturatedfattyacid_6_0 = (Single)dataRow["saturatedfattyacid_6_0"]; if (dataRow.IsNull("saturatedfattyacid_8_0")) saturatedfattyacid_8_0 = 0; else saturatedfattyacid_8_0 = (Single)dataRow["saturatedfattyacid_8_0"]; if (dataRow.IsNull("serine")) serine = 0; else serine = (Single)dataRow["serine"]; if (dataRow.IsNull("starch")) starch = 0; else starch = (Single)dataRow["starch"]; if (dataRow.IsNull("stigmasterol")) stigmasterol = 0; else stigmasterol = (Single)dataRow["stigmasterol"]; if (dataRow.IsNull("sucrose")) sucrose = 0; else sucrose = (Single)dataRow["sucrose"]; if (dataRow.IsNull("theobromine")) theobromine = 0; else theobromine = (Single)dataRow["theobromine"]; if (dataRow.IsNull("threonine")) threonine = 0; else threonine = (Single)dataRow["threonine"]; if (dataRow.IsNull("transmonoenoicfattyacids")) transmonoenoicfattyacids = 0; else transmonoenoicfattyacids = (Single)dataRow["transmonoenoicfattyacids"]; if (dataRow.IsNull("transpolyenoicfattyacids")) transpolyenoicfattyacids = 0; else transpolyenoicfattyacids = (Single)dataRow["transpolyenoicfattyacids"]; if (dataRow.IsNull("tryptophan")) tryptophan = 0; else tryptophan = (Single)dataRow["tryptophan"]; if (dataRow.IsNull("tyrosine")) tyrosine = 0; else tyrosine = (Single)dataRow["tyrosine"]; if (dataRow.IsNull("valine")) valine = 0; else valine = (Single)dataRow["valine"]; if (dataRow.IsNull("vitamink")) vitamink = 0; else vitamink = (Single)dataRow["vitamink"]; if (dataRow.IsNull("volume")) volume = 0; else volume = (Single)dataRow["volume"]; _normalizedIngredientName = RecipeIngredient.NormalizeRecipeIngredientName(name); DataSet recordSet; recordSet = clsDatabaseLayer.GetDatabaseLayer().GetIngredientMeasureByIngredientID(ingredientID.Value); if (recordSet.Tables[0].Rows.Count > 0) { foreach (DataRow ldbrwRow in recordSet.Tables[0].Rows) { var ingredientMeasure = IngredientMeasure.GetIngredientMeasureByDataRow(ldbrwRow); ingredientMeasureDictionary.Add(ingredientMeasure.measureID.Value, ingredientMeasure); } } } private void InitializeAllFields() { ingredientID = null; name = String.Empty; source = String.Empty; ingredientfolderID = Guid.Empty; comments = String.Empty; water = 0; calories = 0; caloriesfromfat = 0; percentcaloriesfromfat = 0; energy = 0; protein = 0; totalfat = 0; sugar = 0; totalcarbohydrate = 0; fiber = 0; calcium = 0; phosphorus = 0; iron = 0; sodium = 0; potassium = 0; magnesium = 0; zinc = 0; copper = 0; manganese = 0; selenium = 0; vitamina = 0; vitamine = 0; thiamin = 0; riboflavin = 0; niacin = 0; pantothenicacid = 0; vitaminb6 = 0; folate = 0; vitaminb12 = 0; vitaminc = 0; saturatedfat = 0; monounsaturatedfat = 0; polyunsaturatedfat = 0; cholesterol = 0; alcohol = 0; caffeine = 0; selectedweight = 0; usdaingredient = String.Empty; useringredient = String.Empty; selectedmeasureid = null; biotin = 0; commonname = String.Empty; energyfromfat = 0; nutritionsource = String.Empty; servingsize = 0; servingsizemeasureid = null; sugaralcohols = 0; transfattyacids = 0; vitamind = 0; caloriesfromalcohol = 0; caloriesfromcarbs = 0; caloriesfromprotein = 0; energyfromalcohol = 0; energyfromcarbs = 0; energyfromprotein = 0; percentcaloriesfromalcohol = 0; percentcaloriesfromcarbs = 0; percentcaloriesfromprotein = 0; alanine = 0; alcoholfactor = 0; alphacarotene = 0; alphalinolenicacid = 0; arachidonicacid = 0; arginine = 0; ash = 0; asparticacid = 0; betacarotene = 0; betacryptoxanthin = 0; betasitosterol = 0; betatocopherol = 0; campesterol = 0; carbohydratefactor = 0; chloride = 0; choline = 0; chromium = 0; cystine = 0; deltatocopherol = 0; dihomogammalinolenicacid = 0; docosahexaenoicacid = 0; docosapentaenoicacid = 0; eicosadienoicacid = 0; eicosapentaenoicacid = 0; fatfactor = 0; fluoride = 0; fructose = 0; galactose = 0; gammalinolenicacid = 0; gammatocopherol = 0; glucose = 0; glutamicacid = 0; glycine = 0; histidine = 0; hydroxyproline = 0; iodine = 0; isoleucine = 0; lactose = 0; leucine = 0; linoleicacid = 0; lycopene = 0; lysine = 0; maltose = 0; methionine = 0; molybdenum = 0; monounsaturatedfattyacid_14_1 = 0; monounsaturatedfattyacid_15_1 = 0; monounsaturatedfattyacid_16_1 = 0; monounsaturatedfattyacid_17_1 = 0; monounsaturatedfattyacid_18_1 = 0; monounsaturatedfattyacid_20_1 = 0; monounsaturatedfattyacid_22_1 = 0; monounsaturatedfattyacid_24_1 = 0; netcarbohydrates = 0; nutritioncalculationmode = String.Empty; omega3fattyacids = 0; omega6fattyacids = 0; phenylalanine = 0; phytosterols = 0; polyunsaturatedfattyacid_18_2 = 0; polyunsaturatedfattyacid_18_3 = 0; polyunsaturatedfattyacid_18_4 = 0; polyunsaturatedfattyacid_20_3 = 0; polyunsaturatedfattyacid_20_4 = 0; polyunsaturatedfattyacid_21_5 = 0; polyunsaturatedfattyacid_22_4 = 0; proline = 0; proteinfactor = 0; refuse = 0; retinol = 0; saturatedfattyacid_10_0 = 0; saturatedfattyacid_12_0 = 0; saturatedfattyacid_13_0 = 0; saturatedfattyacid_14_0 = 0; saturatedfattyacid_15_0 = 0; saturatedfattyacid_16_0 = 0; saturatedfattyacid_17_0 = 0; saturatedfattyacid_18_0 = 0; saturatedfattyacid_20_0 = 0; saturatedfattyacid_22_0 = 0; saturatedfattyacid_24_0 = 0; saturatedfattyacid_4_0 = 0; saturatedfattyacid_6_0 = 0; saturatedfattyacid_8_0 = 0; serine = 0; starch = 0; stigmasterol = 0; sucrose = 0; theobromine = 0; threonine = 0; transmonoenoicfattyacids = 0; transpolyenoicfattyacids = 0; tryptophan = 0; tyrosine = 0; valine = 0; vitamink = 0; volume = 0; ingredientMeasureDictionary = new Dictionary(); } public Single GramWeightByMeasureID(Guid measureID) { IngredientMeasure ingredientMeasure; if (ingredientMeasureDictionary.TryGetValue(measureID, out ingredientMeasure)) { return ingredientMeasure.gramWeight; } else { return 0F; } } public override string ToString() { return this.name; } } }