Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #3
0
        private void btnEditProductSupplier_Click(object sender, EventArgs e)
        {
            panelEditProductSupplier.Visible = true;
            btnAddProductSupplier.Enabled    = false;
            btnDeleteProductSupplier.Enabled = false;



            ProductSupplier productSupplierToEdit = productSuppliers[productSupplierDataGridView.CurrentCell.RowIndex];

            txtProductIDOnEditProductSuppliersPanel.Text = productSupplierToEdit.ProductID.ToString();
            txtProdNameOnEditProductSupplierPanel.Text   = productSupplierToEdit.ProductName;

            cboSupplierNameOnEditProdSupplierPanel.DataSource    = suppliers;
            cboSupplierNameOnEditProdSupplierPanel.DisplayMember = "SupplierName";
            cboSupplierNameOnEditProdSupplierPanel.ValueMember   = "SupplierID";
            cboSupplierNameOnEditProdSupplierPanel.SelectedValue = productSupplierToEdit.SupplierID;
        }
        public static List <ProductSupplier> GetProductSupplierByPackageID(int id)
        {
            List <ProductSupplier> productsSuppliers = new List <ProductSupplier>();

            SqlConnection connection      = TravelExpertsDB.GetConnection();
            string        selectStatement = "SELECT ps.ProductSupplierId, pro.ProdName, s.SupName, bd.BasePrice " +
                                            "FROM Packages pac, Packages_Products_Suppliers pps, Products_Suppliers ps, " +
                                            "Products pro, Suppliers s, BookingDetails bd " +
                                            "WHERE pac.PackageId='" + id + "' " +
                                            "AND pac.PackageId=pps.PackageId " +
                                            "AND pps.ProductSupplierId=ps.ProductSupplierId " +
                                            "AND ps.ProductId=pro.ProductId " +
                                            "AND ps.SupplierId=s.SupplierId " +
                                            "AND bd.ProductSupplierId=ps.ProductSupplierId";

            SqlCommand selectCommand =
                new SqlCommand(selectStatement, connection);

            try
            {
                connection.Open();
                SqlDataReader reader = selectCommand.ExecuteReader();
                while (reader.Read())
                {
                    ProductSupplier productSupplier = new ProductSupplier();

                    productSupplier.ProductSupplierId = (int)reader["ProductSupplierId"];
                    productSupplier.ProdName          = (string)reader["ProdName"];
                    productSupplier.SupName           = (string)reader["SupName"];
                    productSupplier.BasePrice         = (decimal)reader["BasePrice"];

                    productsSuppliers.Add(productSupplier);
                }
                return(productsSuppliers);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #5
0
        public static List <ProductSupplier> GetProductSupplierByPackageID(int id)
        {
            List <ProductSupplier> productsSuppliers = new List <ProductSupplier>();

            SqlConnection connection      = TravelExpertsDB.GetConnection();
            string        selectStatement = "select Products_Suppliers.ProductSupplierId, Products.ProdName, Suppliers.SupName " +
                                            "from Packages, Packages_Products_Suppliers, Products_Suppliers, " +
                                            "Products, Suppliers " +
                                            "where Packages.PackageId='" + id + "' and Packages.PackageId=Packages_Products_Suppliers.PackageId and " +
                                            "Packages_Products_Suppliers.ProductSupplierId=Products_Suppliers.ProductSupplierId and " +
                                            "Products_Suppliers.ProductId=Products.ProductId and " +
                                            "Products_Suppliers.SupplierId=Suppliers.SupplierId";

            SqlCommand selectCommand =
                new SqlCommand(selectStatement, connection);

            try
            {
                connection.Open();
                SqlDataReader reader = selectCommand.ExecuteReader();
                while (reader.Read())
                {
                    ProductSupplier productSupplier = new ProductSupplier();

                    productSupplier.ProductSupplierId = (int)reader["ProductSupplierId"];
                    productSupplier.ProdName          = (string)reader["ProdName"];
                    productSupplier.SupName           = (string)reader["SupName"];

                    productsSuppliers.Add(productSupplier);
                }
                return(productsSuppliers);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
Beispiel #6
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);
                }
            }
        }