public ResourceRecord2(string DBCulture, int IndexPos, string[] fields) { this.DBCulture = DBCulture; this.IndexPos = IndexPos; Row = Ints.ParseStorage(fields[0]); if (fields.Length != 5) { Row = 0; Name = null; Meal = null; Brand = null; DataPos = 0; return; } Meal = fields[1]; Name = fields[2]; Brand = fields[3]; DataPos = Ints.ParseStorage(fields[4]); if (Name != null && Name.Length == 0) { Name = null; } if (Meal != null && Meal.Length == 0) { Meal = null; } if (Brand != null && Brand.Length == 0) { Brand = null; } if (Name != null && Brand != null) { Name += " (" + Brand + ")"; } if (Meal == null) { if (Brand == null && Row % 3 != 0) { Meal = "P"; } if (Brand != null && Row % 5 != 0) { Meal = "P"; } } }
public FoodItem ItemFromResourceRecord(ResourceRecord2 record) { if (record.IndexPos <= 0) { return(null); } if (record.DataPos <= 0) { return(null); } int endofrecord = Data.IndexOf(RECORDDELIMIT, record.DataPos); if (endofrecord <= 0) { return(null); } string row = data.Substring(record.DataPos, endofrecord - record.DataPos - 1); FoodItem result = new FoodItem(record.Name, false); //result.TextDB = record.Name; result.DescriptionDB = null; result.Culture = record.DBCulture; result.CommonMeal = record.Meal; var values = row.Split(FIELDDELIMIT); //Row ID AllWeights AllProperties if (Ints.ParseStorage(values[0]) != record.Row) { throw new ArgumentOutOfRangeException("pos"); } result.SourceID = values[1]; //result.ServingSizesData = values[2]; string ss = values[2]; string pp = values[3]; result.NutritionDB = pp; result.ServingSizesDB = ss.Replace(",", "."); return(result); }