//Make the calories file if it doesn't already exist. If it does just read it. public DataHandler() { openToWrite(CALS_FILE_NAME); //If the file doesn't exist make it. if (new FileInfo(CALS_FILE_NAME).Length == 0) { inFile.Write("0\n0\n0\n0\n"); calories = new string[CALORIES_ARRAY_SIZE] { "0", "0", "0", "0" }; } close( ); //if we havn't read any calorie counts yet, read them. if (calories == null) { calories = new string[CALORIES_ARRAY_SIZE]; string line; openToRead(CALS_FILE_NAME); for (int i = 0; i < CALORIES_ARRAY_SIZE; i++) { line = outFile.ReadLine( ); calories[i] = line; } close( ); } //Check there is a meal file. openToWrite(MEALS_FILE_NAME); close( ); if (myMeals == null) { myMeals = new MealList( ); readMeals( ); } }
public List <MealList> getAllMealList() { List <MealList> mealListList = new List <MealList>(); using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("select * from MealChart", con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { MealList mealList = new MealList(); mealList.MemberId = Guid.Parse(rdr["MemberId"].ToString()); mealList.Morning = Convert.ToDouble(rdr["Morning"]); mealList.Lunch = Convert.ToDouble(rdr["Midday"]); mealList.Dinner = Convert.ToDouble(rdr["Evening"]); mealList.Date = rdr["Date"].ToString(); mealListList.Add(mealList); } } return(mealListList); }