private void btnAccept_Click(object sender, EventArgs e)
 {
     if (addSupplier)
     {
         supplier = new Suppliers();
         this.PutSupplierData(supplier);
         try
         {
             supplier.SupplierId = SuppliersDB.AddSupplier(supplier);
             this.DialogResult   = DialogResult.OK;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
     else
     {
         Suppliers newSupplier = new Suppliers();
         newSupplier.SupplierId = supplier.SupplierId;
         this.PutSupplierData(newSupplier);
         try
         {
             if (!SuppliersDB.UpdateSupplier(supplier, newSupplier))
             {
                 MessageBox.Show("Another user has updated or " +
                                 "deleted that supplier.", "Database Error");
                 this.DialogResult = DialogResult.Retry;
             }
             else
             {
                 supplier          = newSupplier;
                 this.DialogResult = DialogResult.OK;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
 }
Beispiel #2
0
 private void DisplaySupplierData()
 {
     supplierIds      = SuppliersDB.GetSuppliersIds();
     cboId.DataSource = supplierIds;
     if (supplierIds != null)
     {
         txtName.Text       = currentSupplier.SupName;
         cboId.SelectedItem = currentSupplier.SupplierId;
         lstView.Items.Clear();//start with empty list box
         lstView.Items.Add("Id " + ": " + "Supplier Name");
         foreach (int id in supplierIds)
         {
             Suppliers s = SuppliersDB.GetSupplierById(id);
             lstView.Items.Add(s);
         }
     }
     else // null this product does not exist - need to refresh combo box
     {
         supplierIds = SuppliersDB.GetSuppliersIds();
     }
 }
        // accept supplier UPDATE click
        private void btnAcceptEdit_Click(object sender, EventArgs e)
        {
            Suppliers currentSupplier = SuppliersDB.GetSupplierById((int)supId);
            Suppliers newSupplier     = new Suppliers();

            newSupplier.SupplierId = currentSupplier.SupplierId;
            this.PutSupplierData(newSupplier);

            if (currentSupplier.SupName == null)
            {
                MessageBox.Show("Fill in name before adding product", "Please check");
                this.DialogResult = DialogResult.OK;
            }

            else if (Validator.IsPresent(txtSupName))
            {
                try
                {
                    if (!SuppliersDB.UpdateSupplier(currentSupplier, newSupplier))
                    {
                        MessageBox.Show("Another user has updated or " +
                                        "deleted that Supplier.", "Database Error");
                        this.DialogResult = DialogResult.Retry;
                    }
                    else
                    {
                        supplier = newSupplier;
                        MessageBox.Show("Supplier updated", "Success!");
                        this.DialogResult = DialogResult.OK;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
            this.Close();
        }
Beispiel #4
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());
                    }
                }
            }
        }
Beispiel #5
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();
                }
            }
        }
Beispiel #6
0
        private void cboId_SelectedIndexChanged(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                int selectedID = (int)cboId.SelectedValue;
                lblName.Text = "Product Name";
                try
                {
                    currentProd = ProductsDB.GetProductById(selectedID);
                    DisplayCurrentProductData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving product with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else if (tableName == "Suppliers")
            {
                int selectedID = (int)cboId.SelectedValue;
                lblName.Text = "Supplier Name";
                try
                {
                    currentSupplier = SuppliersDB.GetSupplierById(selectedID);
                    DisplayCurrentSupplierData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving supplier with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else if (tableName == "Products_Suppliers")
            {
                int selectedID = (int)cboId.SelectedValue;
                try
                {
                    currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(selectedID);
                    DisplayCurrentProductSupplierData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving product supplier with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else if (tableName == "Packages_Products_Suppliers")
            {
                int selectedID = (int)cboId.SelectedValue;
                try
                {
                    productSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(selectedID);
                    DisplayCurrentPackageProductSupplierData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving package product supplier with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else if (tableName == "Packages")
            {
                int selectedID = (int)cboId.SelectedValue;
                lblName.Text = "Package Name";
                try
                {
                    productSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(selectedID);
                    DisplayCurrentPackageProductSupplierData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving package product supplier with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
                try
                {
                    currentPackage = PackagesDB.GetPackageById(selectedID);
                    txtName.Text   = currentPackage.PkgName;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving package with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
        }
 // set user inputted information to supplier object
 private void PutSupplierData(Suppliers sup)
 {
     //sup.SupplierId = Convert.ToInt32(txtSupplierID.Text);
     sup.SupName = txtSupName.Text;
 }
Beispiel #8
0
 private void PutSuppliers_Data(Suppliers suppliers)
 {
     suppliers.SuppliersId = Convert.ToInt32(txtSupplierId.Text);
     suppliers.SupName     = txtSupName.Text;
 }
Beispiel #9
0
        private void btnSupplier_Click(object sender, EventArgs e)
        {
            Suppliers supp = new Suppliers();

            supp.Show();
        }
Beispiel #10
0
 private void PutSupplier(Suppliers supplier)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
        // delete item button based on which radio button and item is selected
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (radPackages.Checked == false && radProducts.Checked == false && radSuppliers.Checked == false)
            {
                MessageBox.Show("Please select a database to delete from.", "Select a Database");
            }
            else if (radPackages.Checked)
            {
                string   i            = lstView.SelectedItem.ToString();
                string[] s            = i.Split('|');
                int      packageId    = Int32.Parse(s[0].Trim());
                string   nameSelected = s[1].Trim();

                currentPackage = PackagesDB.GetPackageById(packageId);

                DialogResult result = MessageBox.Show("Delete Packages " + nameSelected + "?",
                                                      "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(packageId);
                        }
                        else
                        {
                            this.DisplayPackages();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (radProducts.Checked)
            {
                string   i            = lstView.SelectedItem.ToString();
                string[] s            = i.Split('|');
                int      productId    = Int32.Parse(s[0].Trim());
                string   nameSelected = s[1].Trim();

                currentProduct = ProductsDB.GetProductById(productId);

                DialogResult result = MessageBox.Show("Delete Product " + nameSelected + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!ProductsDB.DeleteProduct(currentProduct))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                            currentProduct = ProductsDB.GetProductById(productId);
                        }
                        else
                        {
                            this.DisplayProducts();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (radSuppliers.Checked)
            {
                string   i            = lstView.SelectedItem.ToString();
                string[] s            = i.Split('|');
                int      supplierId   = Int32.Parse(s[0].Trim());
                string   nameSelected = s[1].Trim();

                currentSupplier = SuppliersDB.GetSupplierById(supplierId);

                DialogResult result = MessageBox.Show("Delete Supplier " + nameSelected + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!SuppliersDB.DeleteSupplier(currentSupplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                            currentSupplier = SuppliersDB.GetSupplierById(supplierId);
                        }
                        else
                        {
                            this.DisplaySuppliers();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
 private void PutSupplierData(Suppliers supplier)
 {
     supplier.SupName = txtSupName.Text;
 }