private void btnAdd_Click(object sender, EventArgs e)
        {
            if (lstProdSup.SelectedIndex < 0) // no selection
            {
                MessageBox.Show("Please select product supplier to add");
            }
            else
            {
                Packages currentPackage = PackagesDB.GetPackageById((int)id);
                string   i         = lstProdSup.SelectedItem.ToString();
                string[] s         = i.Split('|');
                int      prodSupId = Int32.Parse(s[0].Trim());

                Products_Suppliers selectedProductSupplier = Products_SuppliersDB.GetProductSupplierById(prodSupId);

                try
                {
                    if (!Packages_Products_SuppliersDB.AddPackageProductSupplier(currentPackage.PackageId, selectedProductSupplier.ProductSupplierId))
                    {
                        MessageBox.Show("Product added", "Success!");
                        this.DialogResult = DialogResult.OK;
                        DisplayPackage();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Example #2
0
        // ADD a supplier to current product click
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int index = cboSupplier.SelectedIndex;
            int supId = suppliersList[index].SupplierId;
            Products_Suppliers productsSuppliers = new Products_Suppliers();

            if (supId < 1)
            {
                MessageBox.Show("Please select supplier to add");
            }
            else
            {
                try
                {
                    int ProductSupplierId = Products_SuppliersDB.AddSupplierById((int)prodId, supId);
                    MessageBox.Show("Supplier added", "Success!");
                    this.DialogResult = DialogResult.OK;
                    Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(ProductSupplierId);
                    currentProductSupplierIds.Add(ps);
                    DisplayProductSupplier();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Example #3
0
        private void RadioButton3_CheckedChanged_1(object sender, EventArgs e)
        {
            //panelProductSuppliers.Show();20190604
            //20190604--
            panel25.BringToFront();
            //panel25.Visible = true;
            //--20190604

            comboBox3.DataSource    = ProductsDB.GetProducts();
            comboBox3.DisplayMember = "ProdName";
            comboBox3.ValueMember   = "ProductId";

            int  fid;
            bool parseOK = Int32.TryParse(comboBox3.SelectedValue.ToString(), out fid);

            comboBox4.DataSource    = Products_SuppliersDB.GetSuppliersByProductID(fid);
            comboBox4.DisplayMember = "SupName";
            comboBox4.ValueMember   = "SupplierId";

            comboBox7.DataSource    = ProductsDB.GetProducts();
            comboBox7.DisplayMember = "ProdName";
            comboBox7.ValueMember   = "ProductId";


            comboBox6.DataSource    = Products_SuppliersDB.GetSuppliersByProductID(fid);
            comboBox6.DisplayMember = "SupName";
            comboBox6.ValueMember   = "SupplierId";
        }
Example #4
0
        // DELETE a supplier to current product click
        private void btnRemove_Click(object sender, EventArgs e)
        {
            string i = lstSuppliers.SelectedItem.ToString();

            string[]           s                 = i.Split('|');
            int                prodSupId         = Int32.Parse(s[0].Trim());
            Products_Suppliers productsSuppliers = new Products_Suppliers();

            if (prodSupId < 1) // no selection
            {
                MessageBox.Show("Please select supplier to add");
            }
            else // user selected a product to add
            {
                try
                {
                    this.DialogResult = DialogResult.OK;
                    Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(prodSupId);
                    Products_SuppliersDB.DeleteProductSupplier(ps);
                    MessageBox.Show("Supplier deleted", "Success!");
                    loadData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Example #5
0
        private void Button1_Click(object sender, EventArgs e)
        {
            int prodID = Convert.ToInt32(comboBox3.SelectedValue);
            int supID  = Convert.ToInt32(comboBox4.SelectedValue);

            Products_SuppliersDB.AddPS(prodID, supID);
        }
Example #6
0
 private void GetSupplier()
 {
     if (Int32.TryParse(productIdTextBox.Text, out int ProductId))
     {
         dgvSuppliers.DataSource = Products_SuppliersDB.GetSupplierByProducts(ProductId);
     }
 }
Example #7
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int index  = cboProducts.SelectedIndex;
            int prodId = productsList[index].ProductId;
            Products_Suppliers productsSuppliers = new Products_Suppliers();

            if (prodId < 1) // no selection
            {
                MessageBox.Show("Please select supplier to add");
            }
            else // user selected a product to add
            {
                try
                {
                    int ProductSupplierId = Products_SuppliersDB.AddSupplierById(prodId, (int)supId);
                    MessageBox.Show("Product deleted", "Success!");
                    this.DialogResult = DialogResult.OK;
                    Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(ProductSupplierId); // selected product
                                                                                                            //add selected product
                    currentProductSupplierIds.Add(ps);                                                      // add to current  product supplier list
                    loadData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
                //DisplayCurrentPackageProductSupplierData();
            }
        }
Example #8
0
        private void Button2_Click(object sender, EventArgs e)
        {
            int pid  = Convert.ToInt32(comboBox7.SelectedValue);
            int sid  = Convert.ToInt32(comboBox6.SelectedValue);
            int psid = Products_SuppliersDB.GetPSID_By_P_SID(pid, sid);

            Products_SuppliersDB.UpdatePS(psid, pid, sid);
        }
Example #9
0
        private void ComboBox7_SelectedIndexChanged(object sender, EventArgs e)
        {
            int  fid;
            bool parseOK = Int32.TryParse(comboBox7.SelectedValue.ToString(), out fid);

            comboBox6.DataSource    = Products_SuppliersDB.GetSuppliersByProductID(fid);
            comboBox6.DisplayMember = "SupName";
            comboBox6.ValueMember   = "SupplierId";
        }
Example #10
0
 private void DisplayProductSupplierData()
 {
     productSupplierIds = Products_SuppliersDB.GetProductSupplierIds();
     lstProdSup.Items.Clear();//start with empty list box
     lstProdSup.Items.Add("Id " + ": " + "Product Name" + ",  " + "Supplier Name");
     foreach (int id in productSupplierIds)
     {
         //Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(id);
         // lstProdSup.Items.Add(ps);
     }
 }
Example #11
0
        // display ProductSuppliers by DB method, passing through the productID inherited from main form
        private List <Products_Suppliers> DisplayProductSupplier()
        {
            lstSuppliers.Items.Clear();
            List <Products_Suppliers> productSuppliers = Products_SuppliersDB.ProductSuppliers((int)prodId);

            foreach (Products_Suppliers psup in productSuppliers)
            {
                lstSuppliers.Items.Add(psup);
            }
            return(productSuppliers);
        }
Example #12
0
 private void DisplayProductSupplier()
 {
     productSuppliers = Products_SuppliersDB.GetProductSupplier();
     if (productSuppliers != null) // if we have product suppliers to display
     {
         lstView.Items.Clear();    //start with empty list box
         foreach (Products_Suppliers prodsup in productSuppliers)
         {
             lstView.Items.Add(prodsup);
         }
     }
 }
Example #13
0
        private void LoadSupplierBox(int id)
        {
            sList = Products_SuppliersDB.GetSuppliersByProductID(id);

            listBox2.DataSource = null;
            if (sList.Capacity != 0)
            {
                listBox2.DataSource    = sList;
                listBox2.DisplayMember = "SupName";
                listBox2.SetSelected(0, true);
            }
        }
        // btn to delete a record
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvSuppliers.SelectedRows.Count > 0)
            {
                // sets the object to delete
                int index = dgvSuppliers.SelectedRows[0].Index;
                suplierContact = suppliersContacts[index];

                // asks user if they are sure
                DialogResult result = MessageBox.Show("Delete the supplier " + suplierContact.SupConCompany + "?", "Confirm Delete",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    // creates the other table objects
                    Supplier supplier = new Supplier();
                    List <Products_Suppliers> products_suppliers = new List <Products_Suppliers>();
                    try              // tries to delete the table records
                    {
                        // gets the data for the tasble records that need to be deleted
                        supplier           = SupplierDB.GetSupplier(suplierContact.SupplierId);
                        products_suppliers = Products_SuppliersDB.GetAllProdSupOnID(suplierContact.SupplierId);

                        // deletes each productsuppliers table record
                        foreach (Products_Suppliers ps in products_suppliers)
                        {
                            Products_SuppliersDB.DeleteProdSup(ps);
                        }

                        // deltes the suppliercontacts record
                        SupplierContactsDB.DeleteSup(suplierContact);

                        // deltes the supplier record
                        SupplierDB.DeleteSup(supplier);

                        // redisplays the dgv
                        suppliersContacts = SupplierContactsDB.listSuppliers();

                        refreshDGV();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }

            else
            {
                MessageBox.Show("Please select a Product");
            }
        }
Example #15
0
        private void BtnAdd_Click(object sender, EventArgs e)

        /*Adds a new Product to the Supplier by creating new Supplier and Product objects
         * and getting the IDs from the appropriate control to pass as args.
         * Added by Shanice Talan*/
        {
            TravelExpertsClass.Products prod = new TravelExpertsClass.Products(); //there's 2 Products.cs
            Supplier sup = new Supplier();

            prod.ProductsID = Convert.ToInt32(productIdTextBox.Text);
            sup.SupplierID  = Convert.ToInt32(supNameComboBox.SelectedValue);

            Products_SuppliersDB.AddProductSupplier(sup, prod);
        }
        // load data if a SupplierID is passed from Main form
        private void loadData()
        {
            lstProducts.Items.Clear();
            List <Suppliers>          supplierDetails  = new List <Suppliers>();
            List <Products_Suppliers> supplierProducts = new List <Products_Suppliers>();

            supplierDetails    = SuppliersDB.SupplierDetail((int)supId);
            txtSupplierID.Text = supplierDetails[0].SupplierId.ToString();
            txtSupName.Text    = supplierDetails[0].SupName.ToString();
            supplierProducts   = Products_SuppliersDB.SupplierProducts((int)supId);
            foreach (Products_Suppliers sprod in supplierProducts)
            {
                lstProducts.Items.Add(sprod);
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int    index = lstPackProdSupp.SelectedIndex;
            string i     = lstPackProdSupp.SelectedItem.ToString();

            string[] s   = i.Split('|');
            int      pid = Int32.Parse(s[0].Trim());

            //Packages_Products_Suppliers currentPackage = Packages_Products_SuppliersDB.GetPackageIds

            if (pid < 1) // no selection
            {
                MessageBox.Show("Please select product supplier to delete");
            }
            else // user selected a product to delete
            {
                if (type == "View")
                {
                    Products_Suppliers pps    = Products_SuppliersDB.GetProductSupplierById(pid); // selected product
                    DialogResult       answer =
                        MessageBox.Show("Are you sure to delete " + pps.ProdName + "?",
                                        "Please Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (answer == DialogResult.Yes)
                    {
                        //delete selected package product supplier
                        try
                        {
                            if (!Packages_Products_SuppliersDB.DeletePackageProductSupplier((int)id, pps.ProductSupplierId))
                            {
                                MessageBox.Show("Another user has updated or deleted " +
                                                "that product.", "Database Error");
                            }
                            else
                            {
                                currentProductSupplierIds.RemoveAt(index - 1);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, ex.GetType().ToString());
                        }
                        // remove from the current  product supplier  list
                        DisplayCurrentPackageProductSupplierData();
                    }
                }
            }
        }
Example #18
0
 private void DisplayCurrentPackageProductSupplierData()
 {
     if (productSupplierIds != null)         // if we have product suppliers to display
     {
         lstProductSupplierId.Items.Clear(); //start with empty list box
         lstProductSupplierId.Items.Add("Id " + ": " + "Product Name" + ",  " + "Supplier Name");
         foreach (int id in productSupplierIds)
         {
             Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById(id);
             lstProductSupplierId.Items.Add(ps);
         }
     }
     else // null this product does not exist - need to refresh combo box
     {
         packageIds = Packages_Products_SuppliersDB.GetPackageIds();
     }
 }
Example #19
0
 // display ProductSupplier attached to package by DB method, passing through the packageID inherited from main form
 private void DisplayCurrentPackageProductSupplierData()
 {
     if (currentProductSupplierIds != null) // if we have product suppliers to display
     {
         lstPackProdSupp.Items.Clear();     //start with empty list box
         lstPackProdSupp.Items.Add("Id " + ": " + "Product Name" + ",  " + "Supplier Name");
         foreach (int id in currentProductSupplierIds)
         {
             Products_Suppliers ps = Products_SuppliersDB.GetProductSupplierById((int)id);
             lstPackProdSupp.Items.Add(ps);
         }
     }
     else
     {
         lstPackProdSupp.Items.Clear();
     }
 }
        // if product combo box selected item changes updates the suppliers combobox
        private void cmbProductBName_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <Products_Suppliers> cbSuppliers = new List <Products_Suppliers>();

            try
            {
                if (cmbProductBName.SelectedIndex != -1)
                {
                    cbSuppliers                = Products_SuppliersDB.GetAllProdSupOnProdID((int)cmbProductBName.SelectedValue);
                    cmbSuppliers.DataSource    = cbSuppliers;
                    cmbSuppliers.DisplayMember = "SupName";
                    cmbSuppliers.ValueMember   = "ProductSupplierId";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Example #21
0
 // button to delete fa product from the list of products
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dgvProducts.SelectedRows.Count > 0)
     {
         // for adding
         if (add)
         {
             productSuppliers.RemoveAt(this.dgvProducts.SelectedRows[0].Index);
             RedisplayList();
         }
         //for modifing
         else
         {
             DialogResult result = MessageBox.Show("Are you sure you want to delete this Product offered by Supplier?",
                                                   "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (result == DialogResult.Yes)
             {
                 int index = this.dgvProducts.SelectedRows[0].Index;
                 try
                 {
                     if (!Products_SuppliersDB.DeleteProdSup(productSuppliers[index]))
                     {
                         MessageBox.Show("That product has been updated or deleted already.", "Database Error");
                     }
                     else
                     {
                         productSuppliers = Products_SuppliersDB.GetAllProdSupOnID(supplierContact.SupplierId);
                         this.RedisplayList();
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message, ex.GetType().ToString());
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Please select a Product");
     }
 }
Example #22
0
        private void PopulateViewer(string NodeName, string ParentNodeName)
        {
            uxListView.Columns.Clear();
            uxListView.Items.Clear();

            switch (ParentNodeName)
            {
            case "rootPackages":
                uxListView.Columns.Add("Product Name", 150);
                uxListView.Columns.Add("Supplier Name", 150);
                List <Products_Suppliers> package_products = Products_SuppliersDB.GetProductsByPackageName(NodeName);
                foreach (Products_Suppliers item in package_products)
                {
                    uxListView.Items.Add(new ListViewItem(new string[] { item.productName, item.SupName }));
                }
                break;

            case "rootProducts":
                uxListView.Columns.Add("Product Name", 75);
                uxListView.Columns.Add("Supplier Name", 150);
                List <Products_Suppliers> product_suppliers = Products_SuppliersDB.GetSuppliersByProductName(NodeName);
                foreach (Products_Suppliers item in product_suppliers)
                {
                    uxListView.Items.Add(new ListViewItem(new string[] { item.productName, item.SupName }));
                }
                break;

            case "rootSuppliers":
                uxListView.Columns.Add("Supplier Name", 250);
                uxListView.Columns.Add("Product Name", 150);
                List <Products_Suppliers> supplier_products = Products_SuppliersDB.GetProductsBySupplierName(NodeName);
                foreach (Products_Suppliers item in supplier_products)
                {
                    uxListView.Items.Add(new ListViewItem(new string[] { item.SupName, item.productName }));
                }
                break;

            default:
                ;
                break;
            }
        }
 private void btnAccept_Click(object sender, EventArgs e)
 {
     if (addProductSupplier)
     {
         productSupplier = new Products_Suppliers();
         this.PutProductSupplierData(productSupplier);
         try
         {
             productSupplier.ProductSupplierId = Products_SuppliersDB.AddProductSupplier(productSupplier);
             this.DialogResult = DialogResult.OK;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
     else
     {
         Products_Suppliers newProductSupplier = new Products_Suppliers();
         newProductSupplier.ProductSupplierId = productSupplier.ProductSupplierId;
         this.PutProductSupplierData(newProductSupplier);
         try
         {
             if (!Products_SuppliersDB.UpdateProductSupplier(productSupplier, newProductSupplier))
             {
                 MessageBox.Show("Another user has updated or " +
                                 "deleted that product supplier.", "Database Error");
                 this.DialogResult = DialogResult.Retry;
             }
             else
             {
                 productSupplier   = newProductSupplier;
                 this.DialogResult = DialogResult.OK;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
 }
Example #24
0
        private void DeleteSupplier(Supplier sp)
        {
            SupplierContacts suplierContact = SupplierContactsDB.GetSupplierbySupID(sp.SupplierId);

            // asks user if they are sure
            DialogResult result = MessageBox.Show("Delete the supplier " + suplierContact.SupConCompany + "?", "Confirm Delete",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                // creates the other table objects
                Supplier supplier = new Supplier();
                List <Products_Suppliers> products_suppliers = new List <Products_Suppliers>();
                try              // tries to delete the table records
                {
                    // gets the data for the tasble records that need to be deleted
                    supplier           = SupplierDB.GetSupplier(suplierContact.SupplierId);
                    products_suppliers = Products_SuppliersDB.GetAllProdSupOnID(suplierContact.SupplierId);

                    // deletes each productsuppliers table record
                    foreach (Products_Suppliers ps in products_suppliers)
                    {
                        Products_SuppliersDB.DeleteProdSup(ps);
                    }

                    // deletes the suppliercontacts record
                    SupplierContactsDB.DeleteSup(suplierContact);

                    // deletes the supplier record
                    SupplierDB.DeleteSup(supplier);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
                RefreshSuppliers();
            }
        }
Example #25
0
        // button to add a product to the supplier
        private void btnProduct_Click(object sender, EventArgs e)
        {
            if (cmbProductBName.IsPresent())
            {
                // for adding a supplier
                if (add)
                {
                    Products_Suppliers product = new Products_Suppliers();
                    product.productid   = (int)cmbProductBName.SelectedValue;
                    product.productName = cmbProductBName.Text;

                    productSuppliers.Add(product);

                    RedisplayList();
                    cmbProductBName.SelectedIndex = -1;
                }
                //for modifing a supplier
                else
                {
                    Products_Suppliers product = new Products_Suppliers();
                    product.productid   = (int)cmbProductBName.SelectedValue;
                    product.productName = cmbProductBName.Text;
                    product.supplierid  = supplier.SupplierId;
                    try
                    {
                        Products_SuppliersDB.AddProdSupp(product);
                        productSuppliers = Products_SuppliersDB.GetAllProdSupOnID(supplierContact.SupplierId);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                    RedisplayList();
                    cmbProductBName.SelectedIndex = -1;
                }
            }
        }
Example #26
0
        // sets up the form on load
        private void frmAddModifySupplier_Load(object sender, EventArgs e)
        {
            this.LoadProductComboBox();
            // does the fiollowing if its a add
            if (this.add)
            {
                // find the next availble supplierid and suppliercontactid
                supplierContact.SupplierContactId = SupplierContactsDB.GetNextAvailableID();
                txtSCID.Text = supplierContact.SupplierContactId.ToString();

                supplierContact.SupplierId = SupplierDB.GetNextAvailableID();
                supplier.SupplierId        = SupplierDB.GetNextAvailableID();
                this.Text     = "Add a Supplier";
                lblTitle.Text = "Add Supplier Information";
                cmbProductBName.SelectedIndex = -1;
            }
            //else does this for modify
            else
            {
                this.Text     = "Modify a Supplier";
                lblTitle.Text = "Modify Supplier Information";

                try
                {
                    supplier         = SupplierDB.GetSupplier(supplierContact.SupplierId);
                    productSuppliers = Products_SuppliersDB.GetAllProdSupOnID(supplierContact.SupplierId);
                    this.DisplaySupplier();
                    this.RedisplayList();
                    cmbProductBName.SelectedIndex = -1;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Example #27
0
        private void cboTableNames_SelectedIndexChanged(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                pnlName.Visible  = true;
                pnlName2.Visible = false;
                lblId.Text       = "Product Id";
                productIds       = ProductsDB.GetProductsIds();

                if (productIds.Count > 0) // if there are prodcuts
                {
                    cboId.DataSource    = productIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no products. " +
                                    "Add some products in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
                DisplayProductData();
            }
            else if (tableName == "Suppliers")
            {
                lblId.Text       = "Supplier Id";
                supplierIds      = SuppliersDB.GetSuppliersIds();
                pnlName.Visible  = true;
                pnlName2.Visible = false;
                if (supplierIds.Count > 0) // if there are suppliers
                {
                    cboId.DataSource    = supplierIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no suppliers. " +
                                    "Add some supplier in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
                DisplaySupplierData();
            }
            else if (tableName == "Products_Suppliers")
            {
                lblId.Text         = "ProductSupplier Id";
                lblName.Text       = "Product Name";
                lblName2.Text      = "Supplier Name";
                pnlName.Visible    = true;
                pnlName2.Visible   = true;
                productSupplierIds = Products_SuppliersDB.GetProductSupplierIds();

                if (productSupplierIds.Count > 0) // if there are suppliers
                {
                    cboId.DataSource    = productSupplierIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no product_suppliers. " +
                                    "Add some product_supplier in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
                DisplayProductSupplierData();
            }
            else if (tableName == "Packages_Products_Suppliers")
            {
                lblId.Text       = "Package Id";
                packageIds       = Packages_Products_SuppliersDB.GetPackageIds();
                pnlName.Visible  = false;
                pnlName2.Visible = false;

                if (packageIds.Count > 0) // if there are packages
                {
                    cboId.DataSource    = packageIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no packages with products_suppliers. " +
                                    "Add some packages with product_supplier in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
            }
            else if (tableName == "Packages")
            {
                lblId.Text       = "Package Id";
                pnlName.Visible  = true;
                pnlName2.Visible = false;
                packageIds       = PackagesDB.GetPackageIds();
                DisplayPackages();
                if (packageIds.Count > 0) // if there are suppliers
                {
                    cboId.DataSource    = packageIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no packages. " +
                                    "Add some packages in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
            }
        }
Example #28
0
 private void DisplayCurrentProductSupplierData()
 {
     currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId);
     txtName.Text           = currentProductSupplier.ProdName;
     txtName2.Text          = currentProductSupplier.SupName;
 }
Example #29
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                frmAddUpdateProducts updateProductForm = new frmAddUpdateProducts();
                updateProductForm.addProduct = false;
                updateProductForm.product    = currentProd;
                DialogResult result = updateProductForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    currentProd = updateProductForm.product;
                    this.DisplayProductData();
                }
                else if (result == DialogResult.Retry)
                {
                    currentProd = ProductsDB.GetProductById(currentProd.ProductId);
                    if (currentProd != null)
                    {
                        this.DisplayProductData();
                    }
                }
            }
            else if (tableName == "Suppliers")
            {
                frmAddUpdateSuppliers updateSupplierForm = new frmAddUpdateSuppliers();
                updateSupplierForm.addSupplier = false;
                updateSupplierForm.supplier    = currentSupplier;
                DialogResult result = updateSupplierForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    currentSupplier = updateSupplierForm.supplier;
                    this.DisplaySupplierData();
                }
                else if (result == DialogResult.Retry)
                {
                    currentSupplier = SuppliersDB.GetSupplierById(currentSupplier.SupplierId);
                    if (currentSupplier != null)
                    {
                        this.DisplaySupplierData();
                    }
                }
            }
            else if (tableName == "Products_Suppliers")
            {
                frmAddUpdateProductSupplier updateProductSupplierForm = new frmAddUpdateProductSupplier();
                updateProductSupplierForm.addProductSupplier = false;
                updateProductSupplierForm.productSupplier    = currentProductSupplier;
                DialogResult result = updateProductSupplierForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    this.DisplayCurrentProductSupplierData();
                    this.DisplayProductSupplierData();
                }
                else if (result == DialogResult.Retry)
                {
                    currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId);
                    if (currentProductSupplier != null)
                    {
                        this.DisplayCurrentProductSupplierData();
                    }
                    this.DisplayProductSupplierData();
                }
            }
            else if (tableName == "Packages")
            {
                frmAddUpdatePackages updatePackageForm = new frmAddUpdatePackages();
                updatePackageForm.addPackage = false;
                updatePackageForm.package    = currentPackage;
                updatePackageForm.currentProductSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(currentPackage.PackageId);
                DialogResult result = updatePackageForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    this.DisplayPackages();
                    DisplayCurrentPackageProductSupplierData();
                }
                else if (result == DialogResult.Retry)
                {
                    currentPackage = PackagesDB.GetPackageById(currentPackage.PackageId);
                    if (currentPackage != null)
                    {
                        DisplayCurrentPackageProductSupplierData();
                    }
                    this.DisplayPackages();
                }
            }
        }
Example #30
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                DialogResult result = MessageBox.Show("Delete " + currentProd.ProdName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!ProductsDB.DeleteProduct(currentProd))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that product.", "Database Error");
                            currentProd = ProductsDB.GetProductById(currentProd.ProductId);
                            if (currentProd != null)
                            {
                                this.DisplayProductData();
                            }
                        }
                        else
                        {
                            this.DisplayProductData();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Suppliers")
            {
                DialogResult result = MessageBox.Show("Delete " + currentSupplier.SupName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!SuppliersDB.DeleteSupplier(currentSupplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that supplier.", "Database Error");
                            currentSupplier = SuppliersDB.GetSupplierById(currentSupplier.SupplierId);
                            if (currentSupplier != null)
                            {
                                this.DisplaySupplierData();
                            }
                        }
                        else
                        {
                            this.DisplaySupplierData();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Products_Suppliers")
            {
                DialogResult result = MessageBox.Show("Delete Product Supplier " + currentProductSupplier.ProductSupplierId + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!Products_SuppliersDB.DeleteProductSupplier(currentProductSupplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that product_supplier.", "Database Error");
                            currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId);
                            if (currentProductSupplier != null)
                            {
                                this.DisplayCurrentProductSupplierData();
                            }
                            this.DisplayProductSupplierData();
                        }
                        else
                        {
                            this.DisplayCurrentProductSupplierData();
                        }
                        this.DisplayProductSupplierData();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Packages")
            {
                DialogResult result = MessageBox.Show("Delete Packages " + currentPackage.PkgName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!PackagesDB.DeletePackage(currentPackage))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                            currentPackage = PackagesDB.GetPackageById(currentPackage.PackageId);
                            if (currentPackage != null)
                            {
                                //this.DisplayCurrentProductSupplierData();
                                this.DisplayProductSupplierData();
                            }
                        }
                        else
                        {
                            //this.DisplayCurrentProductSupplierData();
                            this.DisplayPackages();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }