Exemple #1
0
        private void btnDelelteSupClick_Click(object sender, EventArgs e)
        {
            Supplier delSupplier = suppliers[supplierDataGridView.CurrentCell.RowIndex];

            if (delSupplier != null)
            {
                DialogResult result = MessageBox.Show("Are you sure you want to delete " + delSupplier.SupplierName
                                                      + " supplier ID " + delSupplier.SupplierID + "? ", "Confirm Delete",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button2);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        SupplierDB.DeleteSupplier(delSupplier);
                        suppliers = SupplierDB.GetAllSuppliers();
                        supplierDataGridView.DataSource = suppliers;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else
            {
                MessageBox.Show("Please select a supplier to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //add panels in product tab
            listPanelProduct.Add(panelProductAdd);
            listPanelProduct.Add(panelProductEdit);

            //add panels of package tab
            listPanelPackage.Add(panelAddPkg);
            listPanelPackage.Add(panelEditPkg);

            //add panels of supplier tab
            listPanelSupplier.Add(panelAddSupplier);
            listPanelSupplier.Add(panelEditSupplier);

            //hide all panels when form loads
            panelProductAdd.Visible   = false;
            panelProductEdit.Visible  = false;
            panelAddPkg.Visible       = false;
            panelEditPkg.Visible      = false;
            panelAddSupplier.Visible  = false;
            panelEditSupplier.Visible = false;
            panelDetailPkg.Visible    = false;

            //Load products data in gridview from database
            try
            {
                products = ProductDB.GetProducts();

                productBindingSource.DataSource = products;

                //load supplier data
                suppliers = SupplierDB.GetAllSuppliers();
                //supplierNameComboBox.DataSource = suppliers;
                //comboBoxPEditSupID.DataSource = suppliers;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }

            //Load supplier data in gridview from database

            try
            {
                suppliers = SupplierDB.GetAllSuppliers();

                supplierDataGridView.DataSource = suppliers;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Exemple #3
0
        private void btnEditSupplier_Click(object sender, EventArgs e)
        {
            //Get the supplier name value from the textbox.
            string updatedSupName = txtboxEditSupName.Text;

            updatedSupName = updatedSupName.Trim();

            if (updatedSupName != "")//check if a value was provided
            {
                Supplier oldSupplier = suppliers[supplierDataGridView.CurrentCell.RowIndex];
                if (updatedSupName != oldSupplier.SupplierName)
                {
                    //Make a copy of the supplier we are updating
                    Supplier newSupplier = oldSupplier.GetCopy();

                    //Update the information in the new supplier;
                    newSupplier.SupplierName = updatedSupName;

                    try
                    {
                        bool result = SupplierDB.UpdateSupplier(oldSupplier, newSupplier);
                        if (result)
                        {
                            //Update the UI
                            suppliers = SupplierDB.GetAllSuppliers();
                            supplierDataGridView.DataSource = suppliers;


                            MessageBox.Show("The new supplier name has been saved", "Supplier Updated",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("The changes were not saved", "Updated Failed",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }

                        panelEditSupplier.Visible  = false;
                        btnDelelteSupClick.Enabled = true;
                        btnAddSupClick.Enabled     = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString(),
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Event is fired when the add button on the supplier tab is clicked.
        ///
        /// </summary>
        /// <param name="sender">The button that was clicked</param>
        /// <param name="e">The arguements of the event</param>
        private void btnAddSupplier_Click(object sender, EventArgs e)
        {
            //Get the information from the text box
            string newSupName = txtboxAddSupName.Text;

            newSupName = newSupName.Trim();

            if (newSupName != "") //A value was provided
            {
                //Create a new supplier and assign the supplier name provided to the
                //SupplierName property
                Supplier newSupplier = new Supplier();
                newSupplier.SupplierName = newSupName;

                //Write the new supplier to the DB
                try
                {
                    int newSupID = SupplierDB.AddSupplier(newSupplier);

                    //Read supplier data again
                    suppliers = SupplierDB.GetAllSuppliers();
                    supplierDataGridView.DataSource = suppliers;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error Message");
                }

                //setup the UI after adding a new supplier
                panelAddSupplier.Visible   = false;
                btnDelelteSupClick.Enabled = true;
                btnEditSupClick.Enabled    = true;
            }
            else
            {
                MessageBox.Show("Please provide the suppliers name", "Required information");
            }
            txtboxAddSupName.Text = "";
        }