Пример #1
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());
                    }
                }
            }
        }
Пример #2
0
        private void addToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (uxTreeView.SelectedNode.Name)
            {
            case "rootPackages":        // open AddEditPackage form in NewPackage mode
                frmAddModifyPackages frmNewPackage = new frmAddModifyPackages();
                frmNewPackage.add = true;
                if (frmNewPackage.ShowDialog() == DialogResult.OK)
                {
                    RefreshPackages();      // Refresh the Supplier List and the TreeView Node
                    frmMain.DisplayMessage("A new package has been added successfully.");
                }
                break;

            case "rootProducts":        // open AddEditProduct form in NewProduct mode
                frmProductAddEdit frmNewProduct = new frmProductAddEdit();
                frmNewProduct.xNewProduct = true;
                if (frmNewProduct.ShowDialog() == DialogResult.OK)
                {
                    RefreshProducts();      // Refresh the Product List and the TreeView Node
                    frmMain.DisplayMessage("A new product has been added successfully.");
                }
                break;

            case "rootSuppliers":       // open AddEditSupplier form in NewSupplier mode
                frmAddModifySupplier frmNewSupplier = new frmAddModifySupplier();
                frmNewSupplier.add = true;
                if (frmNewSupplier.ShowDialog() == DialogResult.OK)
                {
                    RefreshSuppliers();      // Refresh the Supplier List and the TreeView Node
                    frmMain.DisplayMessage("A new supplier has been added successfully.");
                }
                break;

            default:
                break;
            }
        }
Пример #3
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());
                }
            }
        }