private void AddButton_Click(object sender, RoutedEventArgs e) { if (!(buttonsChecked["toy"] && buttonsChecked["age"] && buttonsChecked["size"] && buttonsChecked["material"])) { MessageBox.Show("Please choose some more parametrs", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } else { switch (valueChecked["toy"]) { case "Ball": { if (!(buttonsChecked["color"] && buttonsChecked["gameorsport"])) { MessageBox.Show("Please choose some more parameters", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } else { Ball ball = new Ball(); if (valueChecked["gameorsport"] == "Game") { ball.SetParameters(valueChecked["age"], valueChecked["size"], valueChecked["material"], valueChecked["color"], true); } else { ball.SetParameters(valueChecked["age"], valueChecked["size"], valueChecked["material"], valueChecked["color"], false); } ToyRoom toyRoom = (this.Owner as MainWindow).toyRoom; if (!toyRoom.AddNewToy(ball)) { MessageBox.Show("It costs too much.", "Max price", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } this.DialogResult = true; this.Close(); } break; } case "Car": { if (!(buttonsChecked["type"] && buttonsChecked["mechanic"])) { MessageBox.Show("Please choose some more parameters", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } else { Car car = new Car(); if (valueChecked["mechanic"] == "Inercic") { car.SetParameters(valueChecked["age"], valueChecked["size"], valueChecked["material"], true, valueChecked["type"]); } else { car.SetParameters(valueChecked["age"], valueChecked["size"], valueChecked["material"], false, valueChecked["color"]); } ToyRoom toyRoom = (this.Owner as MainWindow).toyRoom; if (!toyRoom.AddNewToy(car)) { MessageBox.Show("It costs too much.", "Max price", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } this.DialogResult = true; this.Close(); } break; } case "Doll": { if (!buttonsChecked["speaking"]) { MessageBox.Show("Please choose some more parameters", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } else { Doll doll = new Doll(); if (valueChecked["mechanic"] == "Yes") { doll.SetParameters(valueChecked["age"], valueChecked["size"], valueChecked["material"], true); } else { doll.SetParameters(valueChecked["age"], valueChecked["size"], valueChecked["material"], false); } ToyRoom toyRoom = (this.Owner as MainWindow).toyRoom; if (!toyRoom.AddNewToy(doll)) { MessageBox.Show("It costs too much.", "Max price", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly); } this.DialogResult = true; this.Close(); } break; } } } }
public MainWindow() { InitializeComponent(); toyRoom = new ToyRoom(); }