private void btnAdd_Click(object sender, EventArgs e)
        {
            if (dgvNotAddedPS.SelectedRows.Count == 0)
            {
                // show error message if nothing selected and return
                MessageBox.Show("Select a product to add!", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            var selectedItems = dgvNotAddedPS.SelectedRows;

            // for each item in selection, move to addedPS list
            foreach (DataGridViewRow selectedItem in selectedItems)
            {
                Product_Supplier PSItem = (Product_Supplier)selectedItem.DataBoundItem;

                // add item to product supplier list
                AddedPSList.Add(PSItem);

                // remove item from other product suppliers list
                NotAddedPSList = NotAddedPSList.Where(PS => PS.ProductSupplierId != PSItem.ProductSupplierId).ToList();
            }
            // refresh datagrids
            RefreshPSData();
        }
Ejemplo n.º 2
0
 // Remove a product supplier from all packages
 public static void removePSFromAllPkg(Product_Supplier ps)
 {
     using (SqlConnection conn = new SqlConnection(Settings.connectionString))
     {
         conn.Open();
         conn.Execute(Settings.removePSFromAllPkgQuery, new { ps.ProductId, ps.SupplierId });
     }
 }
Ejemplo n.º 3
0
        } //delete supplier

        private void btnAddProdToList_Click(object sender, EventArgs e) //add new products to suppliers
        {
            if (dataGridAllProd.SelectedRows.Count == 0)
            {
                MessageBox.Show(@"No product/s to add! " + @"Try Again", @"No Product", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            int newProdId = ((Product)dataGridAllProd.CurrentRow.DataBoundItem).ProductId;

            var products = from ps in prodSuppList
                           where ps.ProductId == newProdId
                           select ps;

            if (products.Count() != 0)
            {
                MessageBox.Show(@"This Product is already added!", @"Duplicate", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            Product_Supplier newProdSupp = new Product_Supplier();

            try
            {
                newProdSupp.ProductId  = newProdId;
                newProdSupp.SupplierId = currentSupp.SupplierId;

                newProdSupp.ProductSupplierId = ProductsSuppliersDB.AddToProdSupp(newProdSupp);

                currentSupp = dataGridSuppliers.CurrentRow.DataBoundItem as Supplier;
                if (currentSupp != null)
                {
                    GetSuppliersProducts(currentSupp.SupplierId);

                    Display();
                }

                Display();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static int AddToProdSupp(Product_Supplier prodSupp)
        {
            int add = 0;

            //int productSupplier;
            using (SqlConnection con = new SqlConnection(Settings.connectionString2))
            {
                try
                {
                    con.Open();

                    con.Execute(Settings.AddProdToSuppByIDQuery, new { prodSupp.SupplierId, prodSupp.ProductId });
                    add = Convert.ToInt32(con.ExecuteScalar(Settings.LastProdSuppQuery));
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                return(add);
            }
        }
Ejemplo n.º 5
0
        private void btnRemoveProdFrList_Click(object sender, EventArgs e)
        {
            if (dataGridProdSupp.CurrentRow != null)
            {
                if (packageList.Count != 0)
                {
                    string confirmString =
                        @"This product is currently part of one or more packages! Are you sure you want to remove this product? (This action will also remove the product from all packages!)";

                    if (MessageBox.Show(confirmString, "Delete Product", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                        DialogResult.Yes)
                    {
                        Product_Supplier PS = new Product_Supplier();
                        PS.ProductId  = currentProd.ProductId;
                        PS.SupplierId = currentSupp.SupplierId;
                        PS.RemoveFromAllPkg();

                        currentProd.RemoveFromSupplier(currentSupp.SupplierId); //delete selected product from supplier
                    }
                }
                else
                {
                    string confirmString = "Are you sure you want to remove this " + currentProd + " Product?";
                    if (MessageBox.Show(confirmString, @"Delete Product", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                        DialogResult.Yes)
                    {
                        currentProd.RemoveFromSupplier(currentSupp.SupplierId); //delete selected product from supplier
                    }
                }
                Display();
            }
            else
            {
                MessageBox.Show(@"No Product Selected!", @"No Product Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }