Пример #1
0
        // form load
        private void Form1_Load(object sender, EventArgs e)
        {
            btnDashboard_Click(sender, e);
            // display all packages in data grid view
            var _sortablePackages = new SortableBindingList <Package>(packages);

            packageBindingSource.DataSource = _sortablePackages;
            grdProductList.Columns[2].DefaultCellStyle.Format = "d";
            grdProductList.Columns[3].DefaultCellStyle.Format = "d";
            grdProductList.Columns[5].DefaultCellStyle.Format = "c";
            grdProductList.Columns[6].DefaultCellStyle.Format = "c";


            // add products supliers to new package
            List <ProductsInPackage> productsIncluded;

            productsIncluded = ProductsInPackageDB.GetProducts();
            newProductPackageBindingSource.DataSource = productsIncluded;

            // display products included in selected package
            if (cmbPackageId.Text == "")
            {
                return;
            }
            int packageID = Convert.ToInt32(cmbPackageId.Text);

            List <ProductsInPackage> products = ProductsInPackageDB.GetProductsFromPackage(packageID);

            productsInPackageBindingSource.DataSource = products;
        }
Пример #2
0
        // details view - display list of products included in selected package
        private void packageBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            if (cmbPackageId.Text == "")
            {
                return;
            }
            int packageID = Convert.ToInt32(cmbPackageId.Text);

            List <ProductsInPackage> products = ProductsInPackageDB.GetProductsFromPackage(packageID);

            productsInPackageBindingSource.DataSource = products;
        }
Пример #3
0
        // view detail or modify
        private void btnViewDetail_Click(object sender, EventArgs e)
        {
            tabPackageList.SelectedIndex = 1;
            if (cmbPackageId.Text == "")
            {
                return;
            }
            int packageID = Convert.ToInt32(cmbPackageId.Text);

            List <ProductsInPackage> products = ProductsInPackageDB.GetProductsFromPackage(packageID);

            productsInPackageBindingSource.DataSource = products;
        }
Пример #4
0
        // go to details of selected package on double click
        private void grdProductList_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            tabPackageList.SelectedIndex = 1;
            if (cmbPackageId.Text == "")
            {
                return;
            }
            int packageID = Convert.ToInt32(cmbPackageId.Text);

            List <ProductsInPackage> products = ProductsInPackageDB.GetProductsFromPackage(packageID);

            productsInPackageBindingSource.DataSource = products;
        }
Пример #5
0
        // delete Package
        private void btnDeletePackage_Click(object sender, EventArgs e)
        {
            // get selected package
            int            packageId   = Convert.ToInt32(cmbPackageId.Text);
            List <Package> packageList = PackageDB.GetPackages(packageId);
            Package        package     = packageList.First();

            // confirm to delete
            DialogResult result = MessageBox.Show("Delete Package " + package.PackageId + "?",
                                                  "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    // get current product suppliers
                    List <int> productSupplierIds = new List <int>();
                    foreach (var product in ProductsInPackageDB.GetProductsFromPackage(packageId))
                    {
                        productSupplierIds.Remove(product.ProductSupplierId);
                    }

                    // delete products suppliers linked to package
                    Packages_products_suppliersDB.Delete(packageId);

                    foreach (DataGridViewRow item in this.grdProductList.SelectedRows)
                    {
                        grdProductList.Rows.RemoveAt(item.Index);
                    }

                    // delete package
                    PackageDB.DeletePackage(package);
                    MessageBox.Show("Package " + packageId + " deleted successfully");
                    tabPackageList.SelectTab(0); // go back to list view
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #6
0
        // update Package
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            // check all input values
            if (IsValidData())
            {
                // check if package end date is greater than start date
                if (txtPkgStart.Value > txtPkgEnd.Value || txtPkgStart.Value == txtPkgEnd.Value)
                {
                    MessageBox.Show("End Date should be greater than Start Date. Please choose a valid date.", "Input Error");
                }
                else
                {
                    // check if price is greater than commission
                    if (Convert.ToDouble(txtPkgCommission.Text) > Convert.ToDouble(txtPkgPrice.Text))
                    {
                        MessageBox.Show("Commission cannot be greater than the Base Price. Please enter a valid amount.", "Input Error");
                    }
                    else
                    {
                        // get current package from database
                        if (cmbPackageId.Text == "")
                        {
                            return;
                        }

                        int            packageId      = Convert.ToInt32(cmbPackageId.Text);
                        List <Package> oldPackageList = PackageDB.GetPackages(packageId);
                        Package        oldPackage     = oldPackageList.First();

                        // set new values
                        Package newPackage = new Package();
                        newPackage.PackageId = packageId;
                        this.PutPackageData(newPackage);


                        // save package
                        try
                        {
                            package = newPackage;
                            PackageDB.UpdatePackage(oldPackage, newPackage);

                            // get current product suppliers
                            List <int> productSupplierIds = new List <int>();
                            foreach (var product in ProductsInPackageDB.GetProductsFromPackage(packageId))
                            {
                                productSupplierIds.Add(product.ProductSupplierId);
                            }

                            // delete products suppliers linked to package
                            Packages_products_suppliersDB.Delete(packageId);

                            // add products supliers to package
                            List <ProductsInPackage> productsInPackages = (List <ProductsInPackage>)productsInPackageBindingSource.DataSource;
                            foreach (var productsInPackage in productsInPackages)
                            {
                                Packages_products_suppliersDB.Add(packageId, productsInPackage.ProductSupplierId);
                            }

                            MessageBox.Show("Changes saved for Package ID " + packageId);
                            tabPackageList.SelectTab(0); // go back to list view
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }