public static void citire() { calories.Alimente.Clear(); if (!File.Exists("alimente.bin")) { calories.Alimente.AddRange(calories.AlimenteDefault); scrie(); return; } using (BinaryReader br = new BinaryReader(File.OpenRead("alimente.bin"))) { while (br.BaseStream.Position != br.BaseStream.Length) { var nume = br.ReadString(); var glucide = br.ReadSingle(); var zaharuri = br.ReadSingle(); var lipide = br.ReadSingle(); var proteine = br.ReadSingle(); var acg = br.ReadSingle(); var cal = br.ReadSingle(); var aliment = new Aliment(nume, glucide, zaharuri, lipide, proteine, acg, cal); calories.Alimente.Add(aliment); } } }
private void adauga_Click(object sender, RoutedEventArgs e) { var name = nume_aliment.Text; var Glucide = float.Parse(glucide.Text); var Lipide = float.Parse(lipide.Text); var Zaharuri = float.Parse(zaharuri.Text); var Proteine = float.Parse(proteine.Text); var Acg = float.Parse(acg.Text); var Cal = float.Parse(cal.Text); var aliment = new Aliment(name, Glucide, Zaharuri, Lipide, Proteine, Acg, Cal); calories.Alimente.Add(aliment); reading_writing.scrie(); }