private static Schedule BuildSchedule(int schedNum) { Schedule sched = new Schedule(); const string selectNameSql = "SELECT * FROM FeedSchedule WHERE id= ?"; SQLiteCommand command = Data.DataBaseAccess.DbConnection.CreateCommand(selectNameSql, schedNum); Schedule feedSchedule = command.ExecuteQuery <Schedule>().SingleOrDefault(); const string selectNutrientIdsSql = "SELECT nuteId FROM SchedXNute WHERE schedId = ?"; command = Data.DataBaseAccess.DbConnection.CreateCommand(selectNutrientIdsSql, schedNum); int[] nutrientIds = command.ExecuteQuery <SchedXNute>().Select(x => x.NuteId).ToArray(); List <Nutrient> nutes = new List <Nutrient>(); const string selectNutrientsSql = "SELECT * FROM Nutrients where Id = ?"; const string selectDosesSql = "SELECT * FROM NuteXDose WHERE Id = ? ORDER BY week"; foreach (int i in nutrientIds) { command = Data.DataBaseAccess.DbConnection.CreateCommand(selectNutrientsSql, i); Nutrient nuteresult = command.ExecuteQuery <Nutrient>().SingleOrDefault(); nuteresult.WeekAndDoseDict = new Dictionary <int, double>(); command = Data.DataBaseAccess.DbConnection.CreateCommand(selectDosesSql, i); List <NuteXDose> results = command.ExecuteQuery <NuteXDose>().ToList(); if (nuteresult.IsConstantValue) { int x = 0; while (x < feedSchedule.Weeks) { nuteresult?.WeekAndDoseDict.Add(x, nuteresult.ConstantDose); x++; } nutes.Add(nuteresult); break; } foreach (NuteXDose item in results) { nuteresult?.WeekAndDoseDict.Add(item.Week, item.Dose); } nutes.Add(nuteresult); } if (feedSchedule == null) { return(null); } sched.Name = feedSchedule.Name; sched.Id = feedSchedule.Id; sched.Weeks = feedSchedule.Weeks; sched.Nutrients = nutes; return(sched); }
private void PopulateValues() { List <Nutrient> nutrients = new List <Nutrient>(); List <string> names = new List <string>() { "name1", "name2", "name311223", "name4", "name5", "name6", "name7", "name8", "name9", "name10" }; // build the list foreach (string name in names) { Nutrient nute = new Nutrient(CurrentWeek, name); nutrients.Add(nute); } //get the current week foreach (Nutrient item in nutrients) { double dose = item.WeekAndDoseDict.SingleOrDefault(x => x.Key == CurrentWeek).Value; string Name = item.Name; NameAndDose.Add(Name, dose.ToString()); } }