private void addRelationship_button_Click(object sender, EventArgs e) { NewOrdersProducts form = new NewOrdersProducts(bindingNavigator_OrdersProducts); form.Show(); }
public static void addNewOrdersProducts(TextBox amountTextBox, ComboBox orderIdComboBox, ComboBox productIdComboBox, BindingNavigator bindingNavigatorOrdersProducts, NewOrdersProducts newOrderProductsForm) { if (!validateFields(amountTextBox, orderIdComboBox, productIdComboBox)) { return; } try { int last_page = bindingNavigatorOrdersProducts.BindingSource.Count; int orderId = Int32.Parse(orderIdComboBox.GetItemText(orderIdComboBox.SelectedItem)); int productId = Int32.Parse(productIdComboBox.GetItemText(productIdComboBox.SelectedItem)); float amount = float.Parse(amountTextBox.Text); // Check for DUPLICATE KEY if (NewOrdersProductsDAO.checkIfKeyAlreadyExists(orderId, productId)) { ViewMessages.DuplicateKeyError(); return; } NewOrdersProductsDAO.addNewOrdersProducts(orderId, productId, amount); foreach (KeyValuePair <string, Label> entry in App.GetOrdersProductsLabels()) { entry.Value.DataBindings.Clear(); } db.BindOrdersProductsData(App.GetOrdersProductsLabels(), bindingNavigatorOrdersProducts); bindingNavigatorOrdersProducts.BindingSource.Position = last_page; // Added! newOrderProductsForm.Close(); } catch (SqlException e) { ViewMessages.ExceptionOccured(e); } }