Ejemplo n.º 1
0
        /// <summary>
        /// When user clicks 'Connect product to supplier' 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 btnAddPS_Click(object sender, EventArgs e)
        {
            currentlyDGVSelectedProductName  = "";
            currentlyDGVSelectedSupplierName = "";
            frmPSAddModify secondForm = new frmPSAddModify();

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

            //If a product was succesfully added, update products DGV.
            if (result == DialogResult.OK)
            {
                dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition);
            }
        }
Ejemplo n.º 2
0
        /// <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 dgvPS_CellClick(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.
                dgvPS.Rows[e.RowIndex].Selected  = true;
                currentlyDGVSelectedProductName  = dgvPS.SelectedCells[2].Value.ToString();
                currentlyDGVSelectedSupplierName = dgvPS.SelectedCells[3].Value.ToString();

                //Check how many records in Packages_Products_Suppliers also contain this combination
                //of product and supplier.
                //If none, simply ask if user wishes to delete.
                if (PPSDB.GetPPSWithPS(dgvPS.SelectedCells[2].Value.ToString(), dgvPS.SelectedCells[3].Value.ToString()).Count == 0)
                {
                    DialogResult dialogresult = MessageBox.Show("Are you sure you wish to delete \n\n" + dgvPS.SelectedCells[2].Value.ToString() + " provided by " + dgvPS.SelectedCells[3].Value.ToString() + "?", "Confirm delete", MessageBoxButtons.YesNo);

                    //If user says yes, try to delete record.
                    if (dialogresult == DialogResult.Yes)
                    {
                        if (PSDB.DeletePSThenConfirm(dgvPS.SelectedCells[2].Value.ToString(), dgvPS.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");
                            dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition);
                        }
                        else
                        {
                            MessageBox.Show("You have deleted \n\n" + dgvPS.SelectedCells[2].Value.ToString() + " provided by " + dgvPS.SelectedCells[3].Value.ToString() + ".", "Success!");
                            if (PSDB.GetPS(productFilterCondition, supplierFilterCondition).Count > 0)
                            {
                                dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition);
                            }
                            else
                            {
                                dgvPS.DataSource = PSDB.GetPS("", "");
                            }
                        }
                    }
                }

                //If some packages already contain this product and supplier,
                //inform user that deleting this product and supplier will also
                //delete it from those packages. Confirm if user wishes to proceed.
                else
                {
                    frmPSDeleteUpdate secondForm = new frmPSDeleteUpdate();
                    secondForm.mainFormPS           = this;
                    secondForm.isDeleteAndNotUpdate = true;
                    DialogResult result = secondForm.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        if (PPSDB.DeletePPSWithPSThenConfirm(dgvPS.SelectedCells[2].Value.ToString(), dgvPS.SelectedCells[3].Value.ToString()) != true)
                        {
                            MessageBox.Show("Someone has deleted or changed that product(s) in the package(s).", "Concurrency error");
                        }

                        if (PSDB.DeletePSThenConfirm(dgvPS.SelectedCells[2].Value.ToString(), dgvPS.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");
                            dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition);
                        }
                        else
                        {
                            MessageBox.Show("You have deleted \n\n" + dgvPS.SelectedCells[2].Value.ToString() + " provided by " + dgvPS.SelectedCells[3].Value.ToString() + ".", "Success!");
                            if (PSDB.GetPS(productFilterCondition, supplierFilterCondition).Count > 0)
                            {
                                dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition);
                            }
                            else
                            {
                                dgvPS.DataSource = PSDB.GetPS("", "");
                            }
                        }
                    }
                }
            }

            //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)
            {
                dgvPS.Rows[e.RowIndex].Selected = true;

                currentlyDGVSelectedProductName  = dgvPS.SelectedCells[2].Value.ToString();
                currentlyDGVSelectedSupplierName = dgvPS.SelectedCells[3].Value.ToString();
                frmPSAddModify secondForm = new frmPSAddModify();
                secondForm.mainForm = this;
                DialogResult result = secondForm.ShowDialog();

                //If update was successful, update products DGV.
                if (result == DialogResult.OK)
                {
                    dgvPS.DataSource = PSDB.GetPS(productFilterCondition, supplierFilterCondition);
                }
            }
        }