private void Lisa(object sender, RoutedEventArgs e) { string TempNimetus; int TempHind; TempNimetus = Nimetus.Text; bool result = int.TryParse(Hind.Text, out TempHind); if (TempNimetus == "") { MessageBox.Show("Toote nimetus pole lisatud!", "Viga"); } else { if (result == false) { MessageBox.Show("Vale hind!", "Viga"); } else { bool State = true; foreach (var item in Tooted) { if (item.Nimetus == TempNimetus) { State = false; } } if (State == true) { Tooted.Add(new Toode() { Nimetus = TempNimetus, Hind = TempHind, Kogus = 0 }); Nimetus.Text = Nimetus.Name; Hind.Text = Hind.Name; } else if (State == false) { MessageBox.Show("Niisugune toode on juba olemas!", "Viga"); } } } TootedList.ItemsSource = null; TootedList.ItemsSource = Tooted; }
public void UpdateTooted() { string[] TootedText = new string[] { }; try { TootedText = File.ReadAllLines("../../../Tooted.txt"); } catch (FileNotFoundException) { File.Create("../../../Tooted.txt"); } int i = 0; string TempNimetus = ""; int TempHind = 0; foreach (var item in TootedText) { i++; if (i == 1) { TempNimetus = item; } else if (i == 2) { TempHind = int.Parse(item); Tooted.Add(new Toode() { Nimetus = TempNimetus, Hind = TempHind, Kogus = 0 }); } else if (i == 3) { i = 0; //ToDo: Check } } i = 0; TempNimetus = null; TempHind = 0; }