Exemple #1
0
        private void btnDeleteProductSupplier_Click(object sender, EventArgs e)
        {
            //suppliers[supplierDataGridView.CurrentCell.RowIndex]
            ProductSupplier delProductSupplier = productSuppliers[productSupplierDataGridView.CurrentCell.RowIndex];

            if (delProductSupplier != null)
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete Product Supplier with ID: "
                                                      + delProductSupplier.ProductSupplierID
                                                      + "? ", "Confirm Delete",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button2);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        ProductsSuppliersDB.DeleteProductSupplier(delProductSupplier);
                        productSuppliers = ProductsSuppliersDB.GetAllProductSuppliers();
                        productSupplierDataGridView.DataSource = productSuppliers;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else
            {
                MessageBox.Show("Please select a product supplier to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #2
0
        //Event for adding Product Suppliers to the database
        private void btnAddOnProdSupplierPanel_Click(object sender, EventArgs e)
        {
            if (cboProdNameOnAddProductSupplierPanel.SelectedIndex != -1 &&
                cboProdSupplierIDOnAddProductSupplierPanel.SelectedIndex != -1) //Check that something is selected in both combo boxes
            {
                //Create a new product supplier
                ProductSupplier newProdSup = new ProductSupplier();

                //Set the properties of the new product supplier
                newProdSup.ProductID   = products[cboProdNameOnAddProductSupplierPanel.SelectedIndex].ProductID;
                newProdSup.ProductName = products[cboProdNameOnAddProductSupplierPanel.SelectedIndex].ProdName;
                newProdSup.SupplierID  = suppliers[cboProdSupplierIDOnAddProductSupplierPanel.SelectedIndex].SupplierID;
                newProdSup.SupName     = suppliers[cboProdSupplierIDOnAddProductSupplierPanel.SelectedIndex].SupplierName;

                //Write new product supplier to database
                try
                {
                    ProductsSuppliersDB.AddProductSupplier(newProdSup);
                    productSupplierDataGridView.DataSource = ProductsSuppliersDB.GetAllProductSuppliers();
                    btnCancelOnAddProdSupplierPanel_Click(null, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString(),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please select a product and a supplier", "Select a value",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #3
0
        private void btnUpdateOnEditProdSuppliersPanel_Click(object sender, EventArgs e)
        {
            ProductSupplier productSupplierToEdit = productSuppliers[productSupplierDataGridView.CurrentCell.RowIndex];
            ProductSupplier newProductSupplier    = productSupplierToEdit.GetCopy();

            //Update the new copy with UI information
            Supplier selectedSupplier = suppliers[cboSupplierNameOnEditProdSupplierPanel.SelectedIndex];

            newProductSupplier.SupplierID = selectedSupplier.SupplierID;
            newProductSupplier.SupName    = selectedSupplier.SupplierName;

            if (newProductSupplier.SupplierID != productSupplierToEdit.SupplierID) //Check if there was a change
            {
                try
                {
                    bool result = ProductsSuppliersDB.UpdateProductSupplier(productSupplierToEdit, newProductSupplier);

                    if (result)
                    {
                        //Update the UI
                        productSuppliers = ProductsSuppliersDB.GetAllProductSuppliers();
                        productSupplierDataGridView.DataSource = productSuppliers;

                        MessageBox.Show("The new supplier has been saved.", "Product Supplier Updated",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("The changes were not saved", "Updated Failed",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    btnCancelOnEditProdSupplierPanel_Click(null, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString(),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #4
0
        //Delete button method
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete product from supplier?", "Delete", MessageBoxButtons.YesNo);

            bool deleted          = false;
            ProductsSuppliers obj = new ProductsSuppliers();

            obj.ProductId  = Convert.ToInt32(lstProducts.SelectedValue);
            obj.SupplierId = Convert.ToInt32(comboBoxSupplier.SelectedValue);

            deleted = ProductsSuppliersDB.DeleteProductSupplier(obj);

            if (deleted)
            {
                MessageBox.Show("Delete Successful");
                loadList();
            }
            else
            {
                MessageBox.Show("Delete Failed.");
            }
        }
Exemple #5
0
 private void btnCreatePackage_Click(object sender, EventArgs e)
 {
     ProductsSuppliersDB.AddProdSup(selectedProductId, selectedSupplierID);
     loadList();
 }
Exemple #6
0
 //Method called to get productsupplier data and load to UI
 //when the product supplier tab is gets focus
 private void loadUIforProductSuppliers()
 {
     productSuppliers = ProductsSuppliersDB.GetAllProductSuppliers();
     productSupplierDataGridView.DataSource = productSuppliers;
 }