private void DeleteBtn(object sender, RoutedEventArgs e) { DogsBaseEntities db = new DogsBaseEntities(); int dogID; if (!int.TryParse(ID_txt.Text, out dogID)) { MessageBox.Show("Dog ID must be numeric", errorbox); return; } else if (dogID <= 0) { MessageBox.Show("There is no Dog with that id: " + dogID, errorbox); } else { Dog dogs = new Dog(); var deletedog = from Dog in db.Dogs where Dog.Id == dogID select Dog; //// delete dog by id in ID_txt foreach (var Dog in deletedog) { db.Dogs.Remove(Dog); } MessageBox.Show("Dog deleted successfully!", done); db.SaveChanges(); dogProfileData.ItemsSource = dogsService.GetDogList(); ID_txt.Text = String.Empty; } }
public DogsWindow() { InitializeComponent(); DogsBaseEntities db = new DogsBaseEntities(); dogsService = new DogsService(db); dogProfileData.ItemsSource = dogsService.GetDogList(); }
public JuniorWindow() { InitializeComponent(); DogsBaseEntities db = new DogsBaseEntities(); dogsService = new DogsService(db); NewScoreGrid.ItemsSource = db.Scores.ToList(); }
public Highscore() { InitializeComponent(); DogsBaseEntities db = new DogsBaseEntities(); dogsService = new DogsService(db); HighscoreGrid.ItemsSource = dogsService.GetHighscoreList(); }
public AddDog() { InitializeComponent(); DogsBaseEntities db = new DogsBaseEntities(); dogsService = new DogsService(db); AddDogDG.ItemsSource = dogsService.GetDogList(); }
public AddOwner() { InitializeComponent(); DogsBaseEntities db = new DogsBaseEntities(); dogsService = new DogsService(db); OwnerProfile.ItemsSource = dogsService.GetOwnerList(); }
private void EditBtn(object sender, RoutedEventArgs e) { DogsBaseEntities db = new DogsBaseEntities(); int editDogID; int parsedID; if (!int.TryParse(EditID_txt.Text, out editDogID)) { MessageBox.Show("Dog ID must be numeric", errorbox); return; } else if (editDogID <= 0) { MessageBox.Show("There is no Dog with that id: " + editDogID, errorbox); } else if (EditDogName_txt.Text == "") { MessageBox.Show("Please enter the dog's name", errorbox); } else if (EditDogBreed_txt.Text == "") { MessageBox.Show("Please enter the dog's breed", errorbox); } else if (EditDogOwner_txt.Text == "") { MessageBox.Show("Please enter the dog's owner id", errorbox); } else if (!int.TryParse(EditDogOwner_txt.Text, out parsedID)) { MessageBox.Show("Dogs owner ID must be numeric", errorbox); return; } else { Dog dogs = new Dog(); //var updateDog = // from Dog in db.Dogs // where Dog.Id == dogID // select Dog; var updateDog = db.Dogs.Where(d => d.Id == editDogID).FirstOrDefault(); updateDog.Name = EditDogName_txt.Text; updateDog.Breed = EditDogBreed_txt.Text; updateDog.Owner_id = parsedID; MessageBox.Show("Dog edited.", done); db.SaveChanges(); Close(); DogsWindow dogsWindow = new DogsWindow(); dogsWindow.ShowDialog(); } }
private void AddNewDog(object sender, RoutedEventArgs e) { int parsedInput; if (DogName_txt.Text == "") { MessageBox.Show("Please enter the dog's name", errorbox); } else if (DogBreed_txt.Text == "") { MessageBox.Show("Please enter the dog's breed", errorbox); } else if (DogOwner_txt.Text == "") { MessageBox.Show("Please enter the dog's owner id", errorbox); } else if (!int.TryParse(DogOwner_txt.Text, out parsedInput)) { MessageBox.Show("Dogs owner ID must be numeric", errorbox); return; } else { int ownerinput = int.Parse(DogOwner_txt.Text); DogsBaseEntities db = new DogsBaseEntities(); //DogsOwner dogsOwner = new DogsOwner(); //var ownerid = db.DogsOwners.Single(o => ownerinput == o.Owner_id); Dog dogs = new Dog() { Name = DogName_txt.Text, Breed = DogBreed_txt.Text, Owner_id = ownerinput, }; db.Dogs.Add(dogs); db.SaveChanges(); MessageBox.Show("Dog added successfully!", newdog); AddDogDG.ItemsSource = dogsService.GetDogList(); DogName_txt.Text = String.Empty; DogBreed_txt.Text = String.Empty; DogOwner_txt.Text = String.Empty; } }
private void OwnerDelete(object sender, RoutedEventArgs e) { Dog dogs = new Dog(); DogsBaseEntities db = new DogsBaseEntities(); int ownerID; if (!int.TryParse(delOwnerID.Text, out ownerID)) { MessageBox.Show("Owner ID must be numeric!"); return; } else if (delOwnerID.Text == "") { MessageBox.Show("Please enter Owner ID!"); } else if (ownerID <= 0) { MessageBox.Show("There is no owner with that ID"); } else { DogsOwner dogsOwner = new DogsOwner(); var deleteOwner = from DogsOwner in db.DogsOwners where DogsOwner.Owner_id == ownerID select DogsOwner; foreach (var DogsOwner in deleteOwner) { db.DogsOwners.Remove(DogsOwner); } MessageBox.Show("Owner deleted successfully"); db.SaveChanges(); OwnerProfile.ItemsSource = dogsService.GetOwnerList(); delOwnerID.Text = String.Empty; } }
private void DeleteScorebtn(object sender, RoutedEventArgs e) { DogsBaseEntities db = new DogsBaseEntities(); int scoreID; if (!int.TryParse(DeleteScoreID.Text, out scoreID)) { MessageBox.Show("Score ID must be numeric!"); return; } else if (DeleteScoreID.Text == "") { MessageBox.Show("Please enter Score ID!"); } else if (scoreID <= 0) { MessageBox.Show("There is no score with that ID"); } else { Score score = new Score(); var deletescore = from Score in db.Scores // przypisanie do deletescore where Score.Score_id == scoreID // wiersza Score gdzie id = id podanemu w textboxie select Score; foreach (var Score in deletescore) { db.Scores.Remove(Score); // usuwanie danego wiersza } MessageBox.Show("Score deleted successfully!"); db.SaveChanges(); NewScoreGrid.ItemsSource = db.Scores.ToList(); DeleteScoreID.Text = String.Empty; } }
private void NewScore(object sender, RoutedEventArgs e) { int juroridparse; int jurorid; int dogidparse; int dogoutfitparse; int dogspeedparse; int dogfocusparse; if (!int.TryParse(JurorID_txt.Text, out juroridparse)) { MessageBox.Show("Juror ID must be numeric!"); return; } else if (JurorID_txt.Text == "") { MessageBox.Show("Please enter a juror id!"); } jurorid = int.Parse(JurorID_txt.Text); if (jurorid > 3 || jurorid < 1) { MessageBox.Show("There are 3 jurors! John #1, Mateusz #2, Rick #3."); } else if (!int.TryParse(DogId_txt.Text, out dogidparse)) { MessageBox.Show("Dog ID must be numeric!"); return; } else if (DogId_txt.Text == "") { MessageBox.Show("Please enter a dog id!"); } else if (!int.TryParse(DogOutfit_txt.Text, out dogoutfitparse)) { MessageBox.Show("Score for OUTFIT must be numeric!"); return; } else if (DogOutfit_txt.Text == "") { MessageBox.Show("You have to write a OUTFIT SCORE!"); } else if (dogoutfitparse < 0 || dogoutfitparse > 10) { MessageBox.Show("You have to type a number between 0-10!"); } else if (!int.TryParse(DogSpeed_txt.Text, out dogspeedparse)) { MessageBox.Show("Score for OUTFIT must be numeric!"); return; } else if (DogSpeed_txt.Text == "") { MessageBox.Show("You have to write a OUTFIT SCORE!"); } else if (dogspeedparse < 0 || dogspeedparse > 10) { MessageBox.Show("You have to type a number between 0-10!"); } else if (!int.TryParse(DogFocus_txt.Text, out dogfocusparse)) { MessageBox.Show("Score for OUTFIT must be numeric!"); return; } else if (DogFocus_txt.Text == "") { MessageBox.Show("You have to write a OUTFIT SCORE!"); } else if (dogoutfitparse < 0 || dogoutfitparse > 10) { MessageBox.Show("You have to type a number between 0-10!"); } else { int dogid = int.Parse(DogId_txt.Text); int dogoutfit = int.Parse(DogOutfit_txt.Text); int dogspeed = int.Parse(DogSpeed_txt.Text); int dogfocus = int.Parse(DogFocus_txt.Text); int total = 0; total += dogoutfit + dogspeed + dogfocus; DogsBaseEntities db = new DogsBaseEntities(); Score score = new Score(); { score.Outfit = dogoutfit; score.Speed = dogspeed; score.Focus = dogfocus; score.Total = total; score.Dog_id = dogid; score.Juror_id = jurorid; } db.Scores.Add(score); db.SaveChanges(); MessageBox.Show("Score added succesfully"); NewScoreGrid.ItemsSource = db.Scores.ToList(); } }
private void AddOwner_Click(object sender, RoutedEventArgs e) { int age; if (OwnerName_txt.Text == "") { MessageBox.Show("Please enter new owner name", errorbox); } else if (OwnerSurname_txt.Text == "") { MessageBox.Show("Please enter new owner surname", errorbox); } else if (OwnerCity_txt.Text == "") { MessageBox.Show("Please enter new owner city", errorbox); } else if (OwnerPhone_txt.Text == "") { MessageBox.Show("Please enter new owner PhoneNumber", errorbox); } else if (OwnerPhone_txt.Text.Length >= 10) { MessageBox.Show("Phone number can not be longer than 9 digits!"); } else if (!int.TryParse(OwnerAge_txt.Text, out age)) { MessageBox.Show("Owner Age must be numeric", errorbox); return; } else { int parsedAge = int.Parse(OwnerAge_txt.Text); DogsBaseEntities db = new DogsBaseEntities(); DogsOwner dogsOwner = new DogsOwner(); dogsOwner.Name = OwnerName_txt.Text; dogsOwner.Surname = OwnerSurname_txt.Text; dogsOwner.Age = parsedAge; dogsOwner.City = OwnerCity_txt.Text; dogsOwner.PhoneNumber = OwnerPhone_txt.Text; dogsService.AddOwner(dogsOwner); MessageBox.Show("New Owner added successfully!", newowner); OwnerProfile.ItemsSource = dogsService.GetOwnerList(); //DogsOwner dogsOwner = new DogsOwner(); //{ // dogsOwner.Name = OwnerName_txt.Text; // dogsOwner.Surname = OwnerSurname_txt.Text; // dogsOwner.Age = parsedAge; // dogsOwner.City = OwnerCity_txt.Text; // dogsOwner.PhoneNumber = OwnerPhone_txt.Text; //} //db.DogsOwners.Add(dogsOwner); //db.SaveChanges(); } }