private void Remove_Click(object sender, RoutedEventArgs e) { string value = RemoveNameTB.Text.Trim(); if (commander.IsInputInvalid(value, "Producer name or ID")) { MessageBox.Show($"Input value is default or empty, type correct value."); return; } if (int.TryParse(value, out int parsedIntValue)) { if (!commander.ExistsInDatabaseByID(OSHome.DbSources.Producers, parsedIntValue)) { MessageBox.Show($"Producer with ID: {parsedIntValue} doesn't exists in database."); return; } } else { if (!commander.ExistsInDatabaseByNameCaseSensitive(OSHome.DbSources.Producers, value)) { MessageBox.Show($"Producer with name: {value} doesn't exists in database."); return; } } if (parsedIntValue == 0) { int producerId = db.Producers.Single(x => x.producer_name == value).producer_id; if (commander.IsAssignedToEntity(OSHome.DbSources.Producers, producerId)) { MessageBox.Show($"Producer is already assigned to product, can't remove."); return; } if (!commander.FinalAcceptancePrompt()) { return; } commander.RemoveFromDb(OSHome.DbSources.Producers, producerId); } else { if (commander.IsAssignedToEntity(OSHome.DbSources.Producers, parsedIntValue)) { MessageBox.Show($"Producer is already assigned to product, can't remove."); return; } if (!commander.FinalAcceptancePrompt()) { return; } commander.RemoveFromDb(OSHome.DbSources.Producers, parsedIntValue); } MessageBox.Show("Producer successfully removed from database."); RemoveNameTB.Text = "Producer name or ID"; }
private void RemoveCat(int index) { if (commander.IsAssignedToEntity(OSHome.DbSources.Categories, index)) { MessageBox.Show($"Category is already assigned to product, can't remove."); return; } if (!commander.FinalAcceptancePrompt()) { return; } commander.RemoveFromDb(OSHome.DbSources.Categories, index); MessageBox.Show("Category successfully removed from database."); RemoveNameTB.Text = "Category name or ID"; }
private void Remove_Click(object sender, RoutedEventArgs e) { string stringId = RemoveIDTB.Text.Trim(); if (commander.IsInputInvalid(stringId, "ID") || !int.TryParse(stringId, out int id)) { MessageBox.Show($"{stringId} is not valid id."); return; } if (!commander.ExistsInDatabaseByID(OSHome.DbSources.Products, id) || commander.IsAssignedToEntity(OSHome.DbSources.Products, id)) { MessageBox.Show($"Product doesn't exist in database or is already assigned to some order."); return; } if (!commander.FinalAcceptancePrompt()) { return; } commander.RemoveFromDb(OSHome.DbSources.Products, id); MessageBox.Show($"Successfully removed from database."); RemoveIDTB.Text = "ID"; }