Example #1
0
        private void DisplayPackages()
        {
            int     rows;
            decimal basePrice, agencyCom;
            decimal subTotal = 0;

            try
            {
                packageList = PackageDB.GetPackages();
                packageDataGridView.DataSource = packageList;   // bind the grid view to the Package list
                rows = packageList.Count;
                for (int i = 0; i < rows; i++)
                {
                    basePrice = (decimal)packageDataGridView.Rows[i].Cells["dataGridViewTextBoxColumn6"].Value;
                    agencyCom = (decimal)packageDataGridView.Rows[i].Cells["dataGridViewTextBoxColumn7"].Value;
                    subTotal  = basePrice + agencyCom;
                    packageDataGridView.Rows[i].Cells["PkgSubTotal"].Value = subTotal;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error while retrieving packages: " + ex.Message,
                                ex.GetType().ToString());
            }
        }
Example #2
0
        /// <summary>
        /// Show edit form
        /// </summary>
        /// @author Harry
        private void btnEdit_Click(object sender, EventArgs e)
        {
            // get a copy of the current order
            Package oldPkg = packages[pkgPos].Clone();

            frmEditPkg updatePkg = new frmEditPkg();

            // set new and old packages on update form
            updatePkg.oldPkg = oldPkg;
            updatePkg.newPkg = packages[pkgPos];

            // show package edit form
            DialogResult editPkgResult = updatePkg.ShowDialog();

            if (editPkgResult == DialogResult.OK) // edit accepted
            {
                // re-gather packages from DB
                packages = PackageDB.GetPackages();
                ShowPackages();
            }
            else if (editPkgResult == DialogResult.Abort) // concurrency issue
            {
                packages[pkgPos] = oldPkg;
                MessageBox.Show("Edit aborted. Another user has modified or deleted that package.", "Edit Abort");
            }
            else // edit cancelled
            {
                // set back to un-edited package
                packages[pkgPos] = oldPkg;
            }
        }
        private void btnAddPackage_Click(object sender, EventArgs e)
        {
            DialogResult result = new DialogResult();

            if (txtDesc.Text == "")
            {
                MessageBox.Show("Package Description is a required field. Please fill in.");
                result = DialogResult.Retry;
            }
            if (txtPrice.Text == "" || txtCommission.Text == "" || Convert.ToDouble(txtPrice.Text) < Convert.ToDouble(txtCommission.Text))
            {
                MessageBox.Show("The Agency Commission cannot be larger than the Base Price of the package.");
                result = DialogResult.Retry;
            }
            if (txtStart.Text == "" || txtCommission.Text == "" || Convert.ToDateTime(txtStart.Text) >= Convert.ToDateTime(txtEnd.Text))
            {
                MessageBox.Show("The Start Date must be an earlier date than the End Date.");
                result = DialogResult.Retry;
            }
            if (result != DialogResult.Retry)
            {
                Package pkg = new Package();
                pkg.PkgAgencyCommission = Convert.ToDouble(txtCommission.Text);
                pkg.PkgBasePrice        = Convert.ToDouble(txtPrice.Text);
                pkg.PkgDesc             = txtDesc.Text.ToString();
                pkg.PkgEndDate          = Convert.ToDateTime(txtEnd.Text);
                pkg.PkgName             = txtPackageName.Text.ToString();
                pkg.PkgStartDate        = Convert.ToDateTime(txtStart.Text);
                TravelExpertData.PackageDB.AddPackage(pkg);
                lblAddPkg.Text = "Package Added Successfully";
                packageDataGridView.DataSource = PackageDB.GetPackages();
            }
        }
Example #4
0
        private void GetHomePageInfo()
        {
            List <int>     duration = new List <int>();
            List <decimal> subCost = new List <decimal>();
            int            rows, rowDuration, minDuration, maxDuration;
            decimal        minBasePrice, maxBasePrice, rowSubCost;

            subTotalChecked = checkBox1.Checked;

            packageList          = PackageDB.GetPackages();
            rows                 = packageList.Count;
            txtPackageCount.Text = rows.ToString();

            if (subTotalChecked)
            {
                for (int i = 0; i < rows; i++)
                {
                    rowSubCost = (decimal)packageList[i].PkgBasePrice + (decimal)packageList[i].PkgAgencyCommission;
                    subCost.Add(rowSubCost);
                }

                minBasePrice         = subCost.Min();
                txtMinBasePrice.Text = minBasePrice.ToString("c");
                maxBasePrice         = subCost.Max();
                txtMaxBasePrice.Text = maxBasePrice.ToString("c");
            }
            else
            {
                minBasePrice         = packageList.Min(r => r.PkgBasePrice);
                txtMinBasePrice.Text = minBasePrice.ToString("c");
                maxBasePrice         = packageList.Max(r => r.PkgBasePrice);
                txtMaxBasePrice.Text = maxBasePrice.ToString("c");
            }

            for (int i = 0; i < rows; i++)
            {
                rowDuration = (int)((DateTime)packageList[i].PkgEndDate - (DateTime)packageList[i].PkgStartDate).TotalDays;
                duration.Add(rowDuration);
            }

            minDuration         = duration.Min();
            txtMinDuration.Text = minDuration.ToString();
            maxDuration         = duration.Max();
            txtMaxDuration.Text = maxDuration.ToString();

            supplierList = SupplierDB.GetSuppliers();
            txtTotalNumSuppliers.Text = supplierList.Count.ToString();

            engagedSuppliers         = SupplierDB.GetEngagedSuppliers();
            txtEngagedSuppliers.Text = engagedSuppliers.Count.ToString();

            productList = ProductDB.GetProducts();
            txtTotalNumProducts.Text = productList.Count.ToString();

            engagedProducts         = ProductDB.GetEngagedProducts();
            txtEngagedProducts.Text = engagedProducts.Count.ToString();
        }
Example #5
0
        // user typing in search bar
        private void txtSearchPackage_KeyUp(object sender, KeyEventArgs e)
        {
            // get search
            string search = txtSearchPackage.Text.Trim();

            // get products filtered by search
            int            packageId = 0;
            List <Package> packages  = PackageDB.GetPackages(packageId, search);

            // update binding source
            packageBindingSource.DataSource = packages;
        }
Example #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CustEmail"] == null || Session["CustFirstName"] == null)
            {
                Session.Clear();
                Response.Redirect("Login.aspx");
            }
            string CustEmail = Session["CustEmail"].ToString();

            if (!IsPostBack)
            {
                List <Packages> myPackageList = new List <Packages>();
                myPackageList        = PackageDB.GetPackages(CustEmail);
                GridView1.DataSource = myPackageList;
                GridView1.DataBind();
            }
        }
Example #7
0
        /// <summary>
        /// Show add form
        /// </summary>
        /// @author Harry
        private void btnAddPkg_Click(object sender, EventArgs e)
        {
            frmAddPkg addPkg = new frmAddPkg();

            // show add new package form
            DialogResult addPkgResult = addPkg.ShowDialog();

            if (addPkgResult == DialogResult.OK)
            {
                // set view to new package
                packages = PackageDB.GetPackages();
                pkgPos   = packages.Count - 1;
                ShowPackages();

                // access products and suppliers associated with current package
                PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps);
                ShowPkgProducts(pkgProducts, pkgProdSupps);
            }
        }
Example #8
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);
                }
            }
        }
Example #9
0
        // Load data for main form (first tab - Packages).
        private void loadMainFormData()
        {
            try
            {
                // access packages from db in thread (ASYNCHRONOUS) - Probably uneccessary

                /*Thread pkgWork = new Thread(() =>
                 * Thread pkgWork = new Thread(() =>
                 * {
                 *  packages = PackageDB.GetPackages();
                 * });
                 *
                 * // access all products from db in thread
                 * Thread prodWork = new Thread(() =>
                 * {
                 *  products = ProductsDB.GetAllProducts();
                 * });
                 *
                 * pkgWork.Start();
                 * prodWork.Start();
                 *
                 * pkgWork.Join();
                 * prodWork.Join();*/
                packages = PackageDB.GetPackages();
                products = ProductsDB.GetAllProducts();

                // access products and suppliers associated with current package
                PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps);

                ShowPackages();
                ShowAllProducts();
                ShowPkgProducts(pkgProducts, pkgProdSupps);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while loading data.\n\n" + ex.Message,
                                ex.GetType().ToString());
            }
        }
 // GET: Packages
 public ActionResult Packages()
 {
     packages = PackageDB.GetPackages();
     return(View(packages));
 }
 private void productsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == PRODUCT_EDIT)
     {
         productsDataGridView.DataSource = ProductDB.GetProducts();
         Products       oldProd    = prodList[e.RowIndex].CopyProduct();
         UpdateProducts updateForm = new UpdateProducts();
         updateForm.newProd = prodList[e.RowIndex];     //passing the current customer to the form
         updateForm.oldProd = oldProd;
         DialogResult result = updateForm.ShowDialog(); //display modal second form
         if (result == DialogResult.OK)                 //Update Accepted
         {
             //refresh the grid view
             CurrencyManager cm = (CurrencyManager)productsDataGridView.BindingContext[PackageDB.GetPackages()];
             cm.Refresh();
         }
         else//Update cancelled
         {
             prodList[e.RowIndex] = oldProd; //revert to old customer data
         }
     }
 }
 private void btnRefreshPack_Click(object sender, EventArgs e)
 {
     packageDataGridView.DataSource = PackageDB.GetPackages();
 }
        private void packageDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == EDIT_BUTTON)
            {
                Package       oldPack    = packList[e.RowIndex].CopyPackage();
                UpdatePackage updateForm = new UpdatePackage();
                //updateForm.newPack = packList[e.RowIndex]; //passing the current customer to the form
                //updateForm.oldPack = oldPack;

                updateForm.DataBindings.Add("dataMember", packList[e.RowIndex], "DepartureFltId", true);
                DialogResult result = updateForm.ShowDialog(); //display modal second form
                if (result == DialogResult.OK)                 //Update Accepted
                {
                    //refresh the grid view
                    CurrencyManager cm = (CurrencyManager)packageDataGridView.BindingContext[PackageDB.GetPackages()];
                    cm.Refresh();
                }
                else//Update cancelled
                {
                    packList[e.RowIndex] = oldPack; //revert to old customer data
                }
            }
        }
Example #14
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);
                        }
                    }
                }
            }
        }
Example #15
0
 // go back to list
 private void btnBackList_Click(object sender, EventArgs e)
 {
     tabPackageList.SelectTab(0);
     this.packages = PackageDB.GetPackages();
     packageBindingSource.DataSource = this.packages;
 }
Example #16
0
        public Package package; // current package


        public frmMain()
        {
            this.packages = PackageDB.GetPackages();
            InitializeComponent();
        }