Ejemplo n.º 1
0
        private void frmProduct_Supplier_Activated(object sender, EventArgs e)
        {
            products  = ProductsDB.GetProducts();   //All the products are retreived using ProductsDB.GetProducts()
            suppliers = SuppliersDB.GetSuppliers(); //All the suppliers are retreived using SuppliersDB.GetSuppliers()

            ReloadListboxes();
        }
Ejemplo n.º 2
0
        //* Overall button controls *//
        //This method controls the show all button. When this button is clicked all the products and suppliers will be shown in the
        //listboxes
        private void btnShowAll_Click(object sender, EventArgs e)
        {
            products  = ProductsDB.GetProducts();   //All the products are retreived using ProductsDB.GetProducts()
            suppliers = SuppliersDB.GetSuppliers(); //All the suppliers are retreived using SuppliersDB.GetSuppliers()

            ReloadListboxes();
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            //check if the information is valid and present
            if (Validator.IsPresent(txtSupplierId) && Validator.IsPresent(txtSupplierName) &&
                Validator.NonNegativeInt32(txtSupplierId))
            {
                string           supName    = txtSupplierName.Text;
                int              supplierId = Convert.ToInt32(txtSupplierId.Text);
                bool             exists     = false;
                bool             attempt    = false;
                List <Suppliers> suppliers  = SuppliersDB.GetSuppliers();
                //for each supplier in suppliers list, check if the new name is present
                foreach (Suppliers supplier in suppliers)
                {
                    if (supplier.SupName == supName)
                    {
                        exists = true;
                    }
                }

                if (!exists)
                {
                    //if there is no name by the name
                    try
                    {
                        //replace the information
                        attempt = SuppliersDB.UpdateSupplier(supplierId, supName, oldsupplierid, oldsupName);
                    }
                    catch (SqlException ex)
                    {
                        MessageBox.Show("Error modifying supplier\n" + ex);
                    }

                    if (attempt)
                    {
                        MessageBox.Show("Successfully modified");
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Supplier name is already in the database");
                }
            }
        }
Ejemplo n.º 4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (Validator.IsPresent(txtSupplierId) && Validator.IsPresent(txtSupplierName) &&
                Validator.NonNegativeInt32(txtSupplierId))
            {
                string supName    = txtSupplierName.Text;
                int    supplierId = Convert.ToInt32(txtSupplierId.Text);
                bool   exists     = false;
                bool   attempt    = false;

                List <Suppliers> suppliers = SuppliersDB.GetSuppliers();
                foreach (Suppliers supplier in suppliers)
                {
                    if (supplier.SupName == supName)
                    {
                        exists = true;
                    }
                }
                if (!exists)
                {
                    try
                    {
                        attempt = SuppliersDB.InsertSupplier(supplierId, supName);
                    }
                    catch
                    {
                        MessageBox.Show("Provided Supplier ID already exists, please enter a different one");
                        txtSupplierId.Focus();
                    }

                    if (attempt)
                    {
                        MessageBox.Show("Successfully added " + supName + " to the database");
                        this.Close();
                    }
                }
            }
        }