コード例 #1
0
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            switch (uxTreeView.SelectedNode.Parent.Name)
            {
            case "rootPackages":        // open AddEditPackage form with related Package object in Edit mode
                Package pkg = frmMain.packageList[frmMain.packageList.FindIndex(pk => pk.PkgName == uxTreeView.SelectedNode.Name)];
                frmAddModifyPackages frmEditPackage = new frmAddModifyPackages();
                frmEditPackage.add     = false;
                frmEditPackage.package = pkg;
                if (frmEditPackage.ShowDialog() == DialogResult.OK)
                {
                    RefreshPackages();      // Refresh the Package List and the TreeView Node
                    frmMain.DisplayMessage("The package has been modified successfully.");
                }
                break;

            case "rootProducts":        // open AddEditProduct form with related Product object in Edit mode
                Product           prd            = frmMain.productList[frmMain.productList.FindIndex(pr => pr.ProdName == uxTreeView.SelectedNode.Name)];
                frmProductAddEdit frmEditProduct = new frmProductAddEdit();
                frmEditProduct.xNewProduct         = false;
                frmEditProduct.txbProductID.Text   = prd.ProductId.ToString();
                frmEditProduct.txbProductName.Text = prd.ProdName;
                if (frmEditProduct.ShowDialog() == DialogResult.OK)
                {
                    RefreshProducts();      // Refresh the Product List and the TreeView Node
                    frmMain.DisplayMessage("The product has been modified successfully.");
                }
                break;

            case "rootSuppliers":       // open AddEditSupplier form with related Supplier object in Edit mode
                Supplier             sp = frmMain.supplierList[frmMain.supplierList.FindIndex(s => s.SupName == uxTreeView.SelectedNode.Name)];
                frmAddModifySupplier frmEditSupplier = new frmAddModifySupplier();
                frmEditSupplier.add             = false;
                frmEditSupplier.supplierContact = SupplierContactsDB.GetSupplierbySupID(sp.SupplierId);
                if (frmEditSupplier.ShowDialog() == DialogResult.OK)
                {
                    RefreshSuppliers();      // Refresh the Supplier List and the TreeView Node
                    frmMain.DisplayMessage("The supplier information have been modified successfully.");
                }
                break;

            default:
                break;
            }
        }
コード例 #2
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());
                    }
                }
            }
        }
コード例 #3
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;
            }
        }
コード例 #4
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());
                }
            }
        }