//After this point, all code written by Ricky.

        /// <summary>
        /// Some cells in the products DGV contain buttons.
        /// This method contains method for the different buttons.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            //If user clicks a button next to record in column index 0, which is the Delete button,
            //get ready to delete it.
            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0 &&
                e.ColumnIndex == 0)
            {
                //Select record and confirm with user to delete it.
                dgvPPS.Rows[e.RowIndex].Selected = true;
                DialogResult dialogresult = MessageBox.Show("Are you sure you wish to delete \n\n" + dgvPPS.SelectedCells[2].Value.ToString() + " provided by " + dgvPPS.SelectedCells[3].Value.ToString() + "\n\nfrom the package " + packageDataGridView.SelectedCells[1].Value.ToString() + "?", "Confirm delete", MessageBoxButtons.YesNo);

                //If user says yes, try to delete record.
                if (dialogresult == DialogResult.Yes)
                {
                    if (PPSDB.DeletePPSWithPackageIdThenConfirm(Convert.ToInt32(packageDataGridView.SelectedCells[0].Value), dgvPPS.SelectedCells[2].Value.ToString(), dgvPPS.SelectedCells[3].Value.ToString()) != true)
                    {
                        MessageBox.Show("Someone has deleted or changed that record in the database. Click OK to refresh the data displayed here.", "Concurrency error");
                        dgvPPS.DataSource = PPSDB.GetPPSWithPackageId(Convert.ToInt32(packageDataGridView[0, packageDataGridView.SelectedCells[0].RowIndex].Value));
                    }
                    else
                    {
                        MessageBox.Show("You have deleted \n\n" + dgvPPS.SelectedCells[2].Value.ToString() + " provided by " + dgvPPS.SelectedCells[3].Value.ToString() + "\n\nfrom the package " + packageDataGridView.SelectedCells[1].Value.ToString() + ".", "Success!");
                        dgvPPS.DataSource = PPSDB.GetPPSWithPackageId(Convert.ToInt32(packageDataGridView[0, packageDataGridView.SelectedCells[0].RowIndex].Value));
                    }
                }
            }

            //If user clicks a button next to record in column index 1, which is the Update button,
            //update the global variables for the Add/Modify form dialog to access,
            //then create Add/Modify form dialog.
            else if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                     e.RowIndex >= 0 &&
                     e.ColumnIndex == 1)
            {
                dgvPPS.Rows[e.RowIndex].Selected = true;
                currentlySelectedPackageId       = Convert.ToInt32(packageDataGridView.SelectedCells[0].Value);
                currentlySelectedPackageName     = packageDataGridView.SelectedCells[1].Value.ToString();
                currentlySelectedProductName     = dgvPPS.SelectedCells[2].Value.ToString();
                currentlySelectedSupplierName    = dgvPPS.SelectedCells[3].Value.ToString();
                frmPPSAddModify secondForm = new frmPPSAddModify();
                secondForm.mainPackageForm = this;
                DialogResult result = secondForm.ShowDialog();

                //If update was successful, update products DGV.
                if (result == DialogResult.OK)
                {
                    dgvPPS.DataSource = PPSDB.GetPPSWithPackageId(Convert.ToInt32(packageDataGridView[0, packageDataGridView.SelectedCells[0].RowIndex].Value));
                }
            }
        }
        /// <summary>
        /// When user clicks 'Add product to package' button, update
        /// the global variables for the Add/Modify form dialog to access,
        /// then create Add/Modify form dialog.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddPPS_Click(object sender, EventArgs e)
        {
            currentlySelectedPackageId    = Convert.ToInt32(packageDataGridView.SelectedCells[0].Value);
            currentlySelectedPackageName  = packageDataGridView.SelectedCells[1].Value.ToString();
            currentlySelectedProductName  = "";
            currentlySelectedSupplierName = "";
            frmPPSAddModify secondForm = new frmPPSAddModify();

            secondForm.mainPackageForm = this;
            DialogResult result = secondForm.ShowDialog();

            //If a product was succesfully added, update products DGV.
            if (result == DialogResult.OK)
            {
                dgvPPS.DataSource = PPSDB.GetPPSWithPackageId(Convert.ToInt32(packageDataGridView[0, packageDataGridView.SelectedCells[0].RowIndex].Value));
            }
        }