private void btnAdd_Click(object sender, EventArgs e)
        {
            if (lstProdSup.SelectedIndex < 0) // no selection
            {
                MessageBox.Show("Please select product supplier to add");
            }
            else
            {
                Packages currentPackage = PackagesDB.GetPackageById((int)id);
                string   i         = lstProdSup.SelectedItem.ToString();
                string[] s         = i.Split('|');
                int      prodSupId = Int32.Parse(s[0].Trim());

                Products_Suppliers selectedProductSupplier = Products_SuppliersDB.GetProductSupplierById(prodSupId);

                try
                {
                    if (!Packages_Products_SuppliersDB.AddPackageProductSupplier(currentPackage.PackageId, selectedProductSupplier.ProductSupplierId))
                    {
                        MessageBox.Show("Product added", "Success!");
                        this.DialogResult = DialogResult.OK;
                        DisplayPackage();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Example #2
0
 private void GetDetails()
 {
     if (Int32.TryParse(packageIdTextBox.Text, out int pkgId))
     {
         dgvPackage.DataSource = PackagesDB.DisplayProductsSuppliers(pkgId);
     }
 }
        private void btnAddPackage_Click(object sender, EventArgs e)
        {
            package = new Packages();
            bool currentDates = IsValidShippedDate();

            if (Validator.IsPresent(txtPkgName) &&
                Validator.IsPresent(txtPkgDesc) &&
                Validator.IsDecimal(txtBasePrice) &&
                Validator.IsDecimal(txtCommission) &&
                currentDates == true)
            {
                this.PutPackageData(package);
                try
                {
                    package.PackageId = PackagesDB.AddPackage(package);
                    MessageBox.Show("Package added", "Success!");
                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }

            else if (package.PkgName == null ||
                     package.PkgDesc == null
                     )
            {
                MessageBox.Show("Fill in name and description before adding package", "Please check");
                this.DialogResult = DialogResult.OK;
            }
            this.Close();
        }
Example #4
0
 private void btnAccept_Click_1(object sender, EventArgs e)
 {
     if (addPackage)
     {
         pack = new Packages();
         putPackageData(pack);
         int Id = PackagesDB.AddPackage(pack);
         MessageBox.Show("New Package with Id of" + Id + " was added");
         this.DialogResult = DialogResult.OK;
     }
     else
     {
         Packages newPackage = new Packages();
         newPackage.PackageId = modifyPack.PackageId;
         this.putPackageData(newPackage);
         try
         {
             if (!PackagesDB.UpdatePackage(modifyPack, newPackage))
             {
                 MessageBox.Show("Another user has updated or " +
                                 "deleted that customer.", "Database Error");
                 this.DialogResult = DialogResult.Retry;
             }
             else
             {
                 modifyPack        = newPackage;
                 this.DialogResult = DialogResult.OK;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
 }
Example #5
0
 private void RefreshPackages()
 {
     frmMain.packageList = null;
     frmMain.packageList = PackagesDB.GetAll();
     PopulateTreeNode("rootPackages");
     PopulateViewer("rootPackages");
 }
Example #6
0
        private void DeletePackage(Package pkg)
        {
            DialogResult result = MessageBox.Show("Delete the Package " + pkg.PkgName + "?", "Confirm Delete",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                // creates the other table objects
                List <Packages_Products_Suppliers> newpack_prod_sup = new List <Packages_Products_Suppliers>();
                try              // tries to delete the table records
                {
                    // gets the data for the tasble records that need to be deleted
                    newpack_prod_sup = Packages_Products_SuppliersDB.GetList(pkg.PackageId);
                    // deletes each productsuppliers table record
                    foreach (Packages_Products_Suppliers ps in newpack_prod_sup)
                    {
                        Packages_Products_SuppliersDB.DeletePackProdSup(ps);
                    }
                    // deletes the suppliercontacts record
                    PackagesDB.DeletePackage(pkg);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
                RefreshPackages();
            }
        }
Example #7
0
 private void mainForm_Load(object sender, EventArgs e)
 {
     packageList          = PackagesDB.GetAll();
     productList          = ProductsDB.GetAll();
     supplierList         = SupplierDB.ListSupplier();
     suppliersContactList = SupplierContactsDB.listSuppliers();
 }
Example #8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            addModifyForm addCustomerForm = new addModifyForm();

            addCustomerForm.addPackage = true;
            DialogResult result = addCustomerForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                dataGridView1.DataSource = PackagesDB.GetPackages();
            }
        }
Example #9
0
 // loads the form
 private void frmPackages_Load(object sender, EventArgs e)
 {
     try
     {
         packages = PackagesDB.GetAll();
         refreshDGV();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
     }
 }
        // button the add the data to the DB
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (isValid())
            {
                if (add)
                {
                    package = this.createPackageObjects();
                    try
                    {
                        package.PackageId = PackagesDB.AddPackage(package);


                        foreach (Packages_Products_Suppliers ps in pack_prod_sup)
                        {
                            ps.PackageId = package.PackageId;
                            Packages_Products_SuppliersDB.AddPackProdSupp(ps);
                        }

                        this.DialogResult = DialogResult.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
                else
                {
                    Package newPackage = new Package();
                    newPackage = this.createPackageObjects();

                    try
                    {
                        if (!PackagesDB.UpdatePackage(package, newPackage))
                        {
                            MessageBox.Show("That Package has been updated or deleted already.", "Database Error");
                            this.DialogResult = DialogResult.Retry;
                        }
                        else
                        {
                            package           = newPackage;
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
Example #11
0
 private void DisplayPackages()
 {
     packages = PackagesDB.GetPackages();
     if (packages != null)      // if we have product suppliers to display
     {
         lstView.Items.Clear(); //start with empty list box
         foreach (Packages pkg in packages)
         {
             lstView.Items.Add(pkg);
         }
     }
     else // null this product does not exist - need to refresh combo box
     {
         packageIds = PackagesDB.GetPackageIds();
     }
 }
Example #12
0
        // button to delete a package from the DB
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvPackages.SelectedRows.Count > 0)
            {
                // sets the object to delete
                int index = dgvPackages.SelectedRows[0].Index;
                package = packages[index];

                // asks user if they are sure
                DialogResult result = MessageBox.Show("Delete the Package " + package.PkgName + "?", "Confirm Delete",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    // creates the other table objects
                    List <Packages_Products_Suppliers> newpack_prod_sup = new List <Packages_Products_Suppliers>();
                    try              // tries to delete the table records
                    {
                        // gets the data for the tasble records that need to be deleted
                        newpack_prod_sup = Packages_Products_SuppliersDB.GetList(package.PackageId);
                        // deletes each productsuppliers table record
                        foreach (Packages_Products_Suppliers ps in newpack_prod_sup)
                        {
                            Packages_Products_SuppliersDB.DeletePackProdSup(ps);
                        }

                        // deltes the suppliercontacts record
                        PackagesDB.DeletePackage(package);

                        // deltes the supplier record

                        // redisplays the dgv
                        packages = PackagesDB.GetAll();

                        refreshDGV();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }

            else
            {
                MessageBox.Show("Please select a Product");
            }
        }
Example #13
0
 // display packages after getting list by DB method
 public void DisplayPackages()
 {
     packagesList = PackagesDB.GetPackages();
     if (packagesList != null)  // if we have product suppliers to display
     {
         lstView.Items.Clear(); //start with empty list box
         foreach (Packages pkg in packagesList)
         {
             lstView.Items.Add(pkg);
             lstView.Refresh();
         }
     }
     else // null this package does not exist - need to refresh combo box
     {
         MessageBox.Show("There is no package to display.");
     }
 }
Example #14
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            var    cells           = dataGridView1.CurrentRow.Cells;
            string rowId           = cells[0].Value.ToString();
            var    selectedPackage = PackagesDB.GetPackage(rowId);

            addModifyForm modifyPackageForm = new addModifyForm();

            modifyPackageForm.addPackage = false;
            modifyPackageForm.modifyPack = selectedPackage;
            DialogResult result = modifyPackageForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                dataGridView1.DataSource = PackagesDB.GetPackages();
            }
        }
        private void btnAcceptEdit_Click(object sender, EventArgs e)
        {
            Packages currentPackage = PackagesDB.GetPackageById((int)id);
            Packages newPackage     = new Packages();
            bool     currentDates   = IsValidShippedDate();

            if (currentPackage.PkgName == null ||
                currentPackage.PkgDesc == null
                )
            {
                MessageBox.Show("Fill in name and description before adding package", "Please check");

                this.DialogResult = DialogResult.OK;
            }

            else if (Validator.IsPresent(txtPkgName) &&
                     Validator.IsPresent(txtPkgDesc) &&
                     Validator.IsDecimal(txtBasePrice) &&
                     Validator.IsDecimal(txtCommission) &&
                     currentDates == true)
            {
                newPackage.PackageId = currentPackage.PackageId;
                this.PutPackageData(newPackage);
                try
                {
                    if (!PackagesDB.UpdatePackage(currentPackage, newPackage))
                    {
                        MessageBox.Show("Another user has updated or " +
                                        "deleted that package.", "Database Error");
                        this.DialogResult = DialogResult.Retry;
                    }
                    else
                    {
                        package = newPackage;
                        MessageBox.Show("Package updated", "Success!");
                        this.DialogResult = DialogResult.OK;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
                this.Close();
            }
        }
Example #16
0
        private void BtnAdd_Click(object sender, EventArgs e)
        { /*Add Button code added by Shanice Talan. Validation by Kai Feng.
           * Create a new Package object then get data from textboxes to be passed as args. */
            Packages pkg = new Packages();

            try
            {
                if (Validator.IsPresent(pkgNameTextBox) && Validator.IsPresent(pkgDescTextBox))
                {
                    if (pkgEndDateDateTimePicker.Value.Date.CompareTo(pkgStartDateDateTimePicker.Value.Date) <= 0)
                    {
                        MessageBox.Show("Start Date must be less than End Date", "Date Selection Error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        pkg.PackageID    = Convert.ToInt32(packageIdTextBox.Text);
                        pkg.PkgName      = pkgNameTextBox.Text;
                        pkg.PkgStartDate = pkgStartDateDateTimePicker.Value;
                        pkg.PkgEndDate   = pkgEndDateDateTimePicker.Value;
                        pkg.PkgDesc      = pkgDescTextBox.Text;
                        Decimal.TryParse(pkgBasePriceTextBox.Text, out decimal baseprice);
                        Decimal.TryParse(pkgAgencyCommissionTextBox.Text, out decimal commision);
                        if (baseprice < commision)
                        {
                            MessageBox.Show("Commission can not be larger than Base Price!");
                        }
                        else
                        {
                            pkg.PkgBasePrice        = baseprice;
                            pkg.PkgAgencyCommission = commision;
                        }
                        PackagesDB.PackageAdd(pkg);
                    }
                }
                else
                {
                    MessageBox.Show("Please enter Package Name and Description.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #17
0
 private void btnAccept_Click(object sender, EventArgs e)
 {
     if (addPackage)
     {
         package = new Packages();
         this.PutPackageData(package);
         try
         {
             package.PackageId = PackagesDB.AddPackage(package);
             this.DialogResult = DialogResult.OK;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
     else
     {
         Packages newPackage = new Packages();
         newPackage.PackageId = package.PackageId;
         this.PutPackageData(newPackage);
         try
         {
             if (!PackagesDB.UpdatePackage(package, newPackage))
             {
                 MessageBox.Show("Another user has updated or " +
                                 "deleted that package.", "Database Error");
                 this.DialogResult = DialogResult.Retry;
             }
             else
             {
                 package           = newPackage;
                 this.DialogResult = DialogResult.OK;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, ex.GetType().ToString());
         }
     }
 }
        private void DisplayPackage()
        {
            currentProductSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds((int)id);
            Packages currentPackage = PackagesDB.GetPackageById((int)id);

            txtPackageId.Text = currentPackage.PackageId.ToString();
            txtPkgName.Text   = currentPackage.PkgName;
            txtPkgDesc.Text   = currentPackage.PkgDesc;
            txtBasePrice.Text = currentPackage.PkgBasePrice.ToString();

            DisplayCurrentPackageProductSupplierData();

            if (currentPackage.PkgStartDate == null)
            {
                dtpStartDate.Text = "";
            }
            else
            {
                DateTime startDate = (DateTime)currentPackage.PkgStartDate;
                dtpStartDate.Text = startDate.ToShortDateString();
            }

            if (currentPackage.PkgEndDate == null)
            {
                dtpEndDate.Text = "";
            }
            else
            {
                DateTime endDate = (DateTime)currentPackage.PkgEndDate;
                dtpEndDate.Text = endDate.ToShortDateString();
            }

            if (currentPackage.PkgAgencyCommission.Equals(null))
            {
                txtCommission.Text = "";
            }
            else
            {
                txtCommission.Text = Convert.ToDecimal(currentPackage.PkgAgencyCommission).ToString();
            }
        }
Example #19
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());
                }
            }
        }
Example #20
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());
                }
            }
        }
Example #21
0
 private void Form1_Load(object sender, EventArgs e)
 {
     dataGridView1.DataSource       = PackagesDB.GetPackages();
     dataGridView1.Rows[0].Selected = true;
 }
Example #22
0
        // delete item button based on which radio button and item is selected
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (radPackages.Checked == false && radProducts.Checked == false && radSuppliers.Checked == false)
            {
                MessageBox.Show("Please select a database to delete from.", "Select a Database");
            }
            else if (radPackages.Checked)
            {
                string   i            = lstView.SelectedItem.ToString();
                string[] s            = i.Split('|');
                int      packageId    = Int32.Parse(s[0].Trim());
                string   nameSelected = s[1].Trim();

                currentPackage = PackagesDB.GetPackageById(packageId);

                DialogResult result = MessageBox.Show("Delete Packages " + nameSelected + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!PackagesDB.DeletePackage(currentPackage))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                            currentPackage = PackagesDB.GetPackageById(packageId);
                        }
                        else
                        {
                            this.DisplayPackages();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (radProducts.Checked)
            {
                string   i            = lstView.SelectedItem.ToString();
                string[] s            = i.Split('|');
                int      productId    = Int32.Parse(s[0].Trim());
                string   nameSelected = s[1].Trim();

                currentProduct = ProductsDB.GetProductById(productId);

                DialogResult result = MessageBox.Show("Delete Product " + nameSelected + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!ProductsDB.DeleteProduct(currentProduct))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                            currentProduct = ProductsDB.GetProductById(productId);
                        }
                        else
                        {
                            this.DisplayProducts();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (radSuppliers.Checked)
            {
                string   i            = lstView.SelectedItem.ToString();
                string[] s            = i.Split('|');
                int      supplierId   = Int32.Parse(s[0].Trim());
                string   nameSelected = s[1].Trim();

                currentSupplier = SuppliersDB.GetSupplierById(supplierId);

                DialogResult result = MessageBox.Show("Delete Supplier " + nameSelected + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!SuppliersDB.DeleteSupplier(currentSupplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                            currentSupplier = SuppliersDB.GetSupplierById(supplierId);
                        }
                        else
                        {
                            this.DisplaySuppliers();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
Example #23
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                DialogResult result = MessageBox.Show("Delete " + currentProd.ProdName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!ProductsDB.DeleteProduct(currentProd))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that product.", "Database Error");
                            currentProd = ProductsDB.GetProductById(currentProd.ProductId);
                            if (currentProd != null)
                            {
                                this.DisplayProductData();
                            }
                        }
                        else
                        {
                            this.DisplayProductData();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Suppliers")
            {
                DialogResult result = MessageBox.Show("Delete " + currentSupplier.SupName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!SuppliersDB.DeleteSupplier(currentSupplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that supplier.", "Database Error");
                            currentSupplier = SuppliersDB.GetSupplierById(currentSupplier.SupplierId);
                            if (currentSupplier != null)
                            {
                                this.DisplaySupplierData();
                            }
                        }
                        else
                        {
                            this.DisplaySupplierData();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Products_Suppliers")
            {
                DialogResult result = MessageBox.Show("Delete Product Supplier " + currentProductSupplier.ProductSupplierId + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!Products_SuppliersDB.DeleteProductSupplier(currentProductSupplier))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that product_supplier.", "Database Error");
                            currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId);
                            if (currentProductSupplier != null)
                            {
                                this.DisplayCurrentProductSupplierData();
                            }
                            this.DisplayProductSupplierData();
                        }
                        else
                        {
                            this.DisplayCurrentProductSupplierData();
                        }
                        this.DisplayProductSupplierData();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
            else if (tableName == "Packages")
            {
                DialogResult result = MessageBox.Show("Delete Packages " + currentPackage.PkgName + "?",
                                                      "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        if (!PackagesDB.DeletePackage(currentPackage))
                        {
                            MessageBox.Show("Another user has updated or deleted " +
                                            "that package.", "Database Error");
                            currentPackage = PackagesDB.GetPackageById(currentPackage.PackageId);
                            if (currentPackage != null)
                            {
                                //this.DisplayCurrentProductSupplierData();
                                this.DisplayProductSupplierData();
                            }
                        }
                        else
                        {
                            //this.DisplayCurrentProductSupplierData();
                            this.DisplayPackages();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
Example #24
0
        private void cboTableNames_SelectedIndexChanged(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                pnlName.Visible  = true;
                pnlName2.Visible = false;
                lblId.Text       = "Product Id";
                productIds       = ProductsDB.GetProductsIds();

                if (productIds.Count > 0) // if there are prodcuts
                {
                    cboId.DataSource    = productIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no products. " +
                                    "Add some products in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
                DisplayProductData();
            }
            else if (tableName == "Suppliers")
            {
                lblId.Text       = "Supplier Id";
                supplierIds      = SuppliersDB.GetSuppliersIds();
                pnlName.Visible  = true;
                pnlName2.Visible = false;
                if (supplierIds.Count > 0) // if there are suppliers
                {
                    cboId.DataSource    = supplierIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no suppliers. " +
                                    "Add some supplier in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
                DisplaySupplierData();
            }
            else if (tableName == "Products_Suppliers")
            {
                lblId.Text         = "ProductSupplier Id";
                lblName.Text       = "Product Name";
                lblName2.Text      = "Supplier Name";
                pnlName.Visible    = true;
                pnlName2.Visible   = true;
                productSupplierIds = Products_SuppliersDB.GetProductSupplierIds();

                if (productSupplierIds.Count > 0) // if there are suppliers
                {
                    cboId.DataSource    = productSupplierIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no product_suppliers. " +
                                    "Add some product_supplier in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
                DisplayProductSupplierData();
            }
            else if (tableName == "Packages_Products_Suppliers")
            {
                lblId.Text       = "Package Id";
                packageIds       = Packages_Products_SuppliersDB.GetPackageIds();
                pnlName.Visible  = false;
                pnlName2.Visible = false;

                if (packageIds.Count > 0) // if there are packages
                {
                    cboId.DataSource    = packageIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no packages with products_suppliers. " +
                                    "Add some packages with product_supplier in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
            }
            else if (tableName == "Packages")
            {
                lblId.Text       = "Package Id";
                pnlName.Visible  = true;
                pnlName2.Visible = false;
                packageIds       = PackagesDB.GetPackageIds();
                DisplayPackages();
                if (packageIds.Count > 0) // if there are suppliers
                {
                    cboId.DataSource    = packageIds;
                    cboId.SelectedIndex = 0; // triggers SelectedIndexChanged
                }
                else // no members
                {
                    MessageBox.Show("There are no packages. " +
                                    "Add some packages in the database, and restart the application ", "Empty Load");
                    Application.Exit();
                }
            }
        }
Example #25
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                frmAddUpdateProducts updateProductForm = new frmAddUpdateProducts();
                updateProductForm.addProduct = false;
                updateProductForm.product    = currentProd;
                DialogResult result = updateProductForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    currentProd = updateProductForm.product;
                    this.DisplayProductData();
                }
                else if (result == DialogResult.Retry)
                {
                    currentProd = ProductsDB.GetProductById(currentProd.ProductId);
                    if (currentProd != null)
                    {
                        this.DisplayProductData();
                    }
                }
            }
            else if (tableName == "Suppliers")
            {
                frmAddUpdateSuppliers updateSupplierForm = new frmAddUpdateSuppliers();
                updateSupplierForm.addSupplier = false;
                updateSupplierForm.supplier    = currentSupplier;
                DialogResult result = updateSupplierForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    currentSupplier = updateSupplierForm.supplier;
                    this.DisplaySupplierData();
                }
                else if (result == DialogResult.Retry)
                {
                    currentSupplier = SuppliersDB.GetSupplierById(currentSupplier.SupplierId);
                    if (currentSupplier != null)
                    {
                        this.DisplaySupplierData();
                    }
                }
            }
            else if (tableName == "Products_Suppliers")
            {
                frmAddUpdateProductSupplier updateProductSupplierForm = new frmAddUpdateProductSupplier();
                updateProductSupplierForm.addProductSupplier = false;
                updateProductSupplierForm.productSupplier    = currentProductSupplier;
                DialogResult result = updateProductSupplierForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    this.DisplayCurrentProductSupplierData();
                    this.DisplayProductSupplierData();
                }
                else if (result == DialogResult.Retry)
                {
                    currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(currentProductSupplier.ProductSupplierId);
                    if (currentProductSupplier != null)
                    {
                        this.DisplayCurrentProductSupplierData();
                    }
                    this.DisplayProductSupplierData();
                }
            }
            else if (tableName == "Packages")
            {
                frmAddUpdatePackages updatePackageForm = new frmAddUpdatePackages();
                updatePackageForm.addPackage = false;
                updatePackageForm.package    = currentPackage;
                updatePackageForm.currentProductSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(currentPackage.PackageId);
                DialogResult result = updatePackageForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    this.DisplayPackages();
                    DisplayCurrentPackageProductSupplierData();
                }
                else if (result == DialogResult.Retry)
                {
                    currentPackage = PackagesDB.GetPackageById(currentPackage.PackageId);
                    if (currentPackage != null)
                    {
                        DisplayCurrentPackageProductSupplierData();
                    }
                    this.DisplayPackages();
                }
            }
        }
Example #26
0
        private void cboId_SelectedIndexChanged(object sender, EventArgs e)
        {
            string tableName = cboTableNames.SelectedValue.ToString();

            if (tableName == "Products")
            {
                int selectedID = (int)cboId.SelectedValue;
                lblName.Text = "Product Name";
                try
                {
                    currentProd = ProductsDB.GetProductById(selectedID);
                    DisplayCurrentProductData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving product with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else if (tableName == "Suppliers")
            {
                int selectedID = (int)cboId.SelectedValue;
                lblName.Text = "Supplier Name";
                try
                {
                    currentSupplier = SuppliersDB.GetSupplierById(selectedID);
                    DisplayCurrentSupplierData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving supplier with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else if (tableName == "Products_Suppliers")
            {
                int selectedID = (int)cboId.SelectedValue;
                try
                {
                    currentProductSupplier = Products_SuppliersDB.GetProductSupplierById(selectedID);
                    DisplayCurrentProductSupplierData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving product supplier with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else if (tableName == "Packages_Products_Suppliers")
            {
                int selectedID = (int)cboId.SelectedValue;
                try
                {
                    productSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(selectedID);
                    DisplayCurrentPackageProductSupplierData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving package product supplier with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else if (tableName == "Packages")
            {
                int selectedID = (int)cboId.SelectedValue;
                lblName.Text = "Package Name";
                try
                {
                    productSupplierIds = Packages_Products_SuppliersDB.GetProductSupplierIds(selectedID);
                    DisplayCurrentPackageProductSupplierData();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving package product supplier with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
                try
                {
                    currentPackage = PackagesDB.GetPackageById(selectedID);
                    txtName.Text   = currentPackage.PkgName;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while retrieving package with selected ID: " + ex.Message,
                                    ex.GetType().ToString());
                }
            }
        }
Example #27
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox7.Text))
            {
                MessageBox.Show("Please Enter a Package Name !", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (dateTimePicker1.Value >= dateTimePicker2.Value)
            {
                MessageBox.Show("Package End Date must be later than Package Start Date !",
                                "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox9.Text))
            {
                MessageBox.Show("Please Enter Package Description !",
                                "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (string.IsNullOrWhiteSpace(textBox11.Text))
            {
                MessageBox.Show("Please Enter Base Price !",
                                "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (string.IsNullOrWhiteSpace(textBox10.Text))
            {
                MessageBox.Show("Please Enter Agency Commission !",
                                "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (Convert.ToInt32(textBox10.Text) > Convert.ToInt32(textBox11.Text))
            {
                MessageBox.Show("Agency Commission cannot be greater than the Base Price !",
                                "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (list3_ToDB.Count == 0)
            {
                MessageBox.Show("Please choose products for this package !",
                                "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }


            int newID = PackagesDB.AddPackageForForm2(textBox7.Text,
                                                      dateTimePicker1.Value, dateTimePicker2.Value,
                                                      textBox9.Text,
                                                      Convert.ToDecimal(textBox11.Text.ToString()),
                                                      Convert.ToDecimal(textBox10.Text.ToString()));

            if (newID == -1)
            {
                MessageBox.Show("Error adding Package.");
            }
            else
            {
                foreach (var ps in list3_ToDB)
                {
                    int psid = Products_SuppliersDB.GetPSID_By_P_SID(ps.ProductId, ps.SupplierId);
                    if (!Packages_Products_SuppliersDB.AddPPS(newID, psid))
                    {
                        MessageBox.Show("Error adding Packages_Products_Suppliers.");
                    }
                }
            }
            listBox3.DataSource = null;
            list3.Clear();
            list3_ToDB.Clear();

            textBox7.Text  = "";
            textBox9.Text  = "";
            textBox11.Text = "";
            textBox10.Text = "";
        }