private void detach_Packages_Products_Suppliers(Packages_Products_Supplier entity)
 {
     this.SendPropertyChanging();
     entity.Products_Supplier = null;
 }
 partial void DeletePackages_Products_Supplier(Packages_Products_Supplier instance);
 partial void InsertPackages_Products_Supplier(Packages_Products_Supplier instance);
 private void attach_Packages_Products_Suppliers(Packages_Products_Supplier entity)
 {
     this.SendPropertyChanging();
     entity.Package = this;
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            int productID  = Convert.ToInt32(cbProducts.SelectedValue);
            int supplierID = Convert.ToInt32(cbSuppliers.SelectedValue);
            int prodSuppID = GetPSID(productID, supplierID);


            if (isAddPPS) // if new PPS combo, then we add it to the list with a new ID.
            {
                if (Validator.IsSelectedCB(cbProducts) &&
                    Validator.IsSelectedCB(cbSuppliers) &&
                    Validator.IsValidID(prodSuppID)
                    ) // check if both combo boxes have values
                {
                    try
                    {
                        using (TravelExpertDataDataContext dbContext = new TravelExpertDataDataContext())
                        {
                            Packages_Products_Supplier newPPS = new Packages_Products_Supplier
                            {
                                PackageId         = packageID,
                                ProductSupplierId = prodSuppID
                            };

                            if (newPPS != null)
                            {
                                dbContext.Packages_Products_Suppliers.InsertOnSubmit(newPPS);
                                dbContext.SubmitChanges();
                            }
                            else
                            {
                                MessageBox.Show("This Product/Supplier combo already exists.", "Entry Error");
                                DialogResult = DialogResult.Retry;
                            }
                        }
                        DialogResult = DialogResult.OK;
                    }
                    catch (ChangeConflictException)
                    {
                        MessageBox.Show("Another user changed or deleted the current record", "Concurrency Exception");
                        DialogResult = DialogResult.Retry;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Product/Supplier combo already exists or an SQL error occured:\n\n"
                                        + ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else // Modify. retrieve an already existing product supplier, and link it to a package
            {
                if (Validator.IsSelectedCB(cbProducts) &&
                    Validator.IsSelectedCB(cbSuppliers) &&
                    Validator.IsValidID(prodSuppID)
                    ) // check if both combo boxes have values
                {
                    try
                    {
                        using (TravelExpertDataDataContext dbContext = new TravelExpertDataDataContext())
                        {
                            // get the pps row to be modified. It gets back a row that matches the package ID and old PSID.
                            //Packages_Products_Supplier pps = dbContext.Packages_Products_Suppliers.Single(p => p.ProductSupplierId == oldPSID && p.PackageId == packageID);

                            //Packages_Products_Supplier pps = dbContext.Packages_Products_Suppliers.Single

                            // issue here
                            //Packages_Products_Supplier pps = (from p in dbContext.Packages_Products_Suppliers
                            //           where p.ProductSupplierId == prodSuppID
                            //           && p.PackageId == Convert.ToInt32(txtPackageID.Text)
                            //           select p).Single();

                            var pps = (from p in dbContext.Packages_Products_Suppliers
                                       where p.ProductSupplierId == oldPSID &&
                                       p.PackageId == packageID
                                       select p).Single();

                            pps.ProductSupplierId = prodSuppID;
                            dbContext.SubmitChanges();
                            MessageBox.Show("Product/Supplier combo updated successfully.", "Success!");
                            DialogResult = DialogResult.OK;

                            //if (pps != null) // if the product/supplier combo exist already, show error.
                            //{
                            //  MessageBox.Show("This record already exists.", "Concurrency Exception");
                            //  DialogResult = DialogResult.Cancel;
                            //}
                            //else // change the product supplier ID
                            //{
                            //  pps.ProductSupplierId = prodSuppID; // reassign the prodSuppID;
                            //  dbContext.SubmitChanges();
                            //  DialogResult = DialogResult.OK; // close form
                            //}
                        }
                    }
                    catch (ChangeConflictException)
                    {
                        MessageBox.Show("Another user changed or deleted the current record", "Concurrency Exception");
                        DialogResult = DialogResult.Retry;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Product/Supplier combo already exists or an SQL error occured:\n\n"
                                        + ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }