예제 #1
0
 private void mainForm_Load(object sender, EventArgs e)
 {
     packageList          = PackagesDB.GetAll();
     productList          = ProductsDB.GetAll();
     supplierList         = SupplierDB.ListSupplier();
     suppliersContactList = SupplierContactsDB.listSuppliers();
 }
예제 #2
0
 //sets up the form pn load and displays the datagridview
 private void frmSuppliers_Load(object sender, EventArgs e)
 {
     try       // tries to get info from the db and refreshes the dgv and loads the combobox
     {
         suppliersContacts = SupplierContactsDB.listSuppliers();
         refreshDGV();
         loadComboBox();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
     }
 }
예제 #3
0
        // 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");
            }
        }
예제 #4
0
        // btn to bring up the addmodify form to edit a record
        private void btnEdit_Click(object sender, EventArgs e)
        {
            // checks if there is a record selected
            if (dgvSuppliers.SelectedRows.Count > 0)
            {
                //creates the form and sets the options
                int index = dgvSuppliers.SelectedRows[0].Index;
                frmAddModifySupplier editsupplier = new frmAddModifySupplier();
                editsupplier.add             = false;
                editsupplier.supplierContact = suppliersContacts[index];
                DialogResult result = editsupplier.ShowDialog();
                if (result == DialogResult.OK)
                {
                    try      // if the edit for good redisplay the dgv
                    {
                        suplierContact    = editsupplier.supplierContact;
                        suppliersContacts = SupplierContactsDB.listSuppliers();

                        refreshDGV();

                        // selects the edited record
                        int n = -1;
                        foreach (SupplierContacts sc in suppliersContacts)
                        {
                            if (sc.SupplierContactId == suplierContact.SupplierContactId)
                            {
                                n = suppliersContacts.IndexOf(sc);
                                break;
                            }
                        }
                        dgvSuppliers.Rows[n].Selected = true;
                        //dgvSuppliers.FirstDisplayedScrollingRowIndex = n;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
예제 #5
0
        // button to bring up the addmodify form to add data to the DB
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // creates the new form and sets the options
            frmAddModifySupplier newaddfrm = new frmAddModifySupplier();

            newaddfrm.add = true;
            DialogResult result = newaddfrm.ShowDialog();

            // if the results are good redisplay the dgv
            if (result == DialogResult.OK)
            {
                try     // tries to get the data from the db and refresh the dgv
                {
                    suplierContact    = newaddfrm.supplierContact;
                    suppliersContacts = SupplierContactsDB.listSuppliers();

                    refreshDGV();

                    // select the newly made record
                    int n = -1;
                    foreach (SupplierContacts sc in suppliersContacts)
                    {
                        if (sc.SupplierContactId == suplierContact.SupplierContactId)
                        {
                            n = suppliersContacts.IndexOf(sc);
                            break;
                        }
                    }
                    dgvSuppliers.Rows[n].Selected = true;
                    dgvSuppliers.FirstDisplayedScrollingRowIndex = n;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }