Exemplo n.º 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;
            }
        }
Exemplo n.º 2
0
        // button to edit a package
        private void btnEdit_Click(object sender, EventArgs e)
        {
            //creates the form and sets the options
            int index = dgvPackages.SelectedRows[0].Index;
            frmAddModifyPackages editfrm = new frmAddModifyPackages();

            editfrm.add     = false;
            editfrm.package = packages[index];
            DialogResult result = editfrm.ShowDialog();

            if (result == DialogResult.OK)
            {
                try      // if the edit for good redisplay the dgv
                {
                    package  = editfrm.package;
                    packages = PackagesDB.GetAll();

                    refreshDGV();

                    // selects the edited record
                    int n = -1;
                    foreach (Package sc in packages)
                    {
                        if (sc.PackageId == package.PackageId)
                        {
                            n = packages.IndexOf(sc);
                            break;
                        }
                    }
                    dgvPackages.Rows[n].Selected = true;
                    dgvPackages.FirstDisplayedScrollingRowIndex = n;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 4
0
        // button to bring uo the add form
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // creates the new form and sets the options
            frmAddModifyPackages newaddfrm = new frmAddModifyPackages();

            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
                {
                    package  = newaddfrm.package;
                    packages = PackagesDB.GetAll();

                    refreshDGV();

                    // select the newly made record
                    int n = -1;
                    foreach (Package pack in packages)
                    {
                        if (pack.PackageId == package.PackageId)
                        {
                            n = packages.IndexOf(pack);
                            break;
                        }
                    }
                    dgvPackages.Rows[n].Selected = true;
                    dgvPackages.FirstDisplayedScrollingRowIndex = n;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }