// delete button to delete a package
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Delete " + package.PkgName + "?",
                                                  "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    if (!PackageDB.DeletePackage(package)) // optimistic concurrency violation
                    {
                        MessageBox.Show("Another user has updated or deleted " +
                                        "that package.", "Database Error");
                        this.GetPackage(package.PackageId);
                        if (package != null)
                        {
                            this.DisplayPackage();
                        }
                        else
                        {
                            this.ClearControls();
                        }
                    }
                    else // successful delete
                    {
                        this.ClearControls();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Example #2
0
        // Deletes the currently selected package
        private void btnPkgDelete_Click(object sender, EventArgs e)
        {
            //Delete Package
            DialogResult confirmation = DialogResult.No;

            confirmation = MessageBox.Show("Are you sure you want to delete the package '" +
                                           selectedPackage.Name + "'?", "Confirm Delete", MessageBoxButtons.YesNo,
                                           MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
            if (confirmation != DialogResult.Yes)
            {
                return;
            }

            int rowsDeleted = 0;

            try
            {
                rowsDeleted = PackageDB.Delete(selectedPackage);
                if (rowsDeleted > 0)
                {
                    //package deleted. Refill combo box and display result
                    FillPackageComboBox(btnPkgDelete, EventArgs.Empty);
                    lblPkgStatus.Text = "Package deleted";
                    MessageBox.Show("Package deleted");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Deleting Package");
            }
        }
Example #3
0
        /// <summary>
        /// Update accepted
        /// </summary>
        private void btnAccept_Click(object sender, EventArgs e)
        {
            newPkg = Validation();
            if (newPkg == null)
            {
                return;
            }
            try
            {
                int success = PackageDB.UpdatePackage(oldPkg, newPkg);

                if (success == 1)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else if (success == 0) // there was a concurrency issue
                {
                    this.DialogResult = DialogResult.Abort;
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while editing package.\n" + ex.Message,
                                ex.GetType().ToString());
            }
        }
Example #4
0
        //Delete Package
        private void btnPkgDelete_Click(object sender, EventArgs e)
        {
            int getPkgId = 0;

            if (pkgDataGrid.SelectedCells.Count > 0)
            {
                int             selectedrowindex = pkgDataGrid.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow      = pkgDataGrid.Rows[selectedrowindex];
                getPkgId = Convert.ToInt32(selectedRow.Cells["PackageId"].Value);
                Package_AddProduct_DB pkgDeleteObj = new Package_AddProduct_DB();
                string            message          = "Do you want to delete this Record?";
                string            caption          = "Delete Info";
                MessageBoxButtons buttons          = MessageBoxButtons.YesNo;
                DialogResult      result;
                // Displays the MessageBox.
                result = MessageBox.Show(message, caption, buttons);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    pkgDeleteObj.Pkg_Products_Delete(getPkgId);

                    if (pkgDeleteObj.DeletePackage(getPkgId))
                    {
                        MessageBox.Show("Package Deleted");
                    }
                    PackageDB ObjDeletePkg = new PackageDB();
                    if (ObjDeletePkg.FillDataGrid())
                    {
                        pkgDataGrid.DataSource = ObjDeletePkg.dt;
                    }
                    Load_PkgProducts();
                    cmbProducts.SelectedIndex = -1;
                }
            }
        }
Example #5
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 #6
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;
            }
        }
Example #7
0
        //add packages, based on the criteria
        private void btnAddPackage_Click_1(object sender, EventArgs e)
        {
            if (validaterClass.isProvided(txtPkgName, "Package Name can not be null") &&
                (validaterClass.validateDate(Convert.ToDateTime(dtPkgStartDate.Text), Convert.ToDateTime(dtPkgEndDate.Text)) &&
                 (validaterClass.isProvided(txtPkgDesc, "Package Description can not be null")) &&
                 (validaterClass.isProvided(txtPkgBasePrice, "Package Base Price can not be null")) &&
                 (validaterClass.isNonNegativeDoub(txtPkgBasePrice, "Package Price must be a Positive Whole number")) &&
                 (validaterClass.isProvided(txtPkgComision, "Agency Comm can not be null")) &&
                 (validaterClass.isNonNegativeDoub(txtPkgComision, "Agency Comm must be a positive whole number") &&
                  (validaterClass.isValidateComm(txtPkgBasePrice, txtPkgComision)))))
            {
                try
                {
                    PackageDB addPkgObj     = new PackageDB();
                    string    pkgName       = Convert.ToString(txtPkgName.Text);
                    DateTime  pkgStartDate  = Convert.ToDateTime(dtPkgStartDate.Text);
                    DateTime  pkgEndDate    = Convert.ToDateTime(dtPkgEndDate.Text);
                    string    pkgDesc       = Convert.ToString(txtPkgDesc.Text);
                    decimal   pkgBasePrice  = Convert.ToDecimal(txtPkgBasePrice.Text);
                    decimal   pkgAgencyComm = Convert.ToDecimal(txtPkgComision.Text);

                    addPkgObj.addPackage(pkgName, pkgStartDate, pkgEndDate, pkgDesc, pkgBasePrice, pkgAgencyComm);
                    if (addPkgObj.FillDataGrid())
                    {
                        pkgDataGrid.DataSource = addPkgObj.dt;
                    }
                }
                catch (OverflowException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                Clear_Form();
            }
        }
Example #8
0
        /// <summary>
        /// Adding new package accepted
        /// </summary>
        private void btnAccept_Click(object sender, EventArgs e)
        {
            Package newPkg = Validation();

            if (newPkg == null) // validation failed
            {
                return;
            }

            try
            {
                bool success = PackageDB.AddPackage(newPkg);
                if (success)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while adding package.\n" + ex.Message,
                                ex.GetType().ToString());
            }
        }
Example #9
0
        /// <summary>
        /// Sets the start date of the package
        /// </summary>
        /// <param name="dateTimePicker"></param>
        /// <param name="removeDate"></param>
        private void SetStartDate(DateTimePicker dateTimePicker, bool removeDate = false)
        {
            //update display date and DB
            if (!removeDate)
            {
                dateTimePicker.CustomFormat = DateTimePickerFormat;

                DateTime date = dateTimePicker.Value;
                PackageSelected.PkgStartDate = date;

                PackageDB.UpdatePropertyById(nameof(Package.PkgStartDate), PackageSelected);

                //enable editing end date;
                dtpPkgEndDate.Enabled = true;
            }
            else   //date field is cleared, display it as such and update DB, also remove end date
            {
                //clear start date field and End Date Field and updated db
                PackageSelected.PkgStartDate = null;
                dateTimePicker.CustomFormat  = " ";
                PackageDB.UpdatePropertyById(nameof(Package.PkgStartDate), PackageSelected);

                SetEndDate(dtpPkgEndDate, true);

                //disable editing of end date
                dtpPkgEndDate.Enabled = false;
            }
        }
Example #10
0
        //On combo box selected index changed event populate data into list box
        private void cmbProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
            PackageDB supplierObj = new PackageDB();
            int       getPkgId    = 0;

            if (pkgDataGrid.SelectedCells.Count > 0)
            {
                int selectedrowindex = pkgDataGrid.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = pkgDataGrid.Rows[selectedrowindex];

                getPkgId = Convert.ToInt32(selectedRow.Cells["PackageId"].Value);
                Package_AddProduct_DB getSupIdobj = new Package_AddProduct_DB();
                getSupIdobj.GetSupplierId(getPkgId);
                pkgProductGrid.DataSource = getSupIdobj.getPackageProduct();
            }
            if (supplierObj.FetchSuppliers(Convert.ToString(cmbProducts.Text), getPkgId))
            {
                lstSuppliers.Items.Clear();
                while (supplierObj.reader.Read())
                {
                    lstSuppliers.Items.Add(supplierObj.reader.GetValue(0));
                }
                supplierObj.reader.Close();
            }
        }
Example #11
0
        private void dgvPackages_Selected(object sender, EventArgs e)
        {
            dgvProductsSuppliers.Rows.Clear();

            int     index           = dgvPackages.CurrentCell.RowIndex;             //get the the user selection
            Package selectedPackage = packages[index];                              //get the package details

            this.DisplayPackage(selectedPackage);                                   //display package details

            List <Product>  productList  = PackageDB.GetProducts(selectedPackage.PackageID);
            List <Supplier> supplierList = PackageDB.GetSuppliers(selectedPackage.PackageID);

            //add rows to the dTgrid view
            for (int i = 0; i < productList.Count; i++)
            {
                dgvProductsSuppliers.Rows.Add();
            }

            //add package data to the rows
            for (int i = 0; i <= productList.Count - 1; i++)
            {
                dgvProductsSuppliers.Rows[i].Cells[0].Value = productList[i].ProdName;
                dgvProductsSuppliers.Rows[i].Cells[1].Value = supplierList[i].SupName;
            }
        }
        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 #13
0
        /// <summary>
        /// Add selected product to package in detail view
        /// </summary>
        /// @author Harry
        private void btnAddProdToPkg_Click(object sender, EventArgs e)
        {
            if (cmboBoxSupsOfProd.SelectedIndex > -1) // selection required
            {
                // get product and supplier ids (to get ProductSupplierId)
                int prodId     = products[cmboBoxProducts.SelectedIndex].ProductID;
                int supplierId = suppliersOfProd[cmboBoxSupsOfProd.SelectedIndex].SupplierId;

                try
                {
                    // get product supplier id
                    int prodSuppId = ProductSupplierDB.GetId(prodId, supplierId);

                    // create new package product supplier object to enter into package products suppliers table
                    PackageProductSupplier newPkgProdSup = new PackageProductSupplier();
                    newPkgProdSup.PackageId         = Convert.ToInt32(packageIdTextBox.Text);
                    newPkgProdSup.ProductSupplierId = prodSuppId;

                    // update packages product supplier table
                    bool success = PackageProductSupplierDB.AddNewPkgProdSupp(newPkgProdSup);

                    if (success)
                    {
                        // clear combo boxes
                        cmboBoxProducts.Items.Clear();
                        cmboBoxSupsOfProd.Items.Clear();

                        // show updated version of products associated with package
                        List <string> pkgProducts;
                        List <string> pkgProdSupps;

                        // access products and suppliers associated with current package
                        PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps);
                        ShowPkgProducts(pkgProducts, pkgProdSupps);
                        ShowAllProducts();
                        cmboBoxSupsOfProd.Text = "";
                        cmboBoxProducts.Text   = "";
                        cmboBoxSupsOfProd.Items.Clear();
                        MessageBox.Show("Added product successfully.", "Success");
                    }
                    else
                    {
                        // clear combo boxes
                        cmboBoxProducts.Items.Clear();
                        cmboBoxSupsOfProd.Items.Clear();
                        MessageBox.Show("Error occured while adding product.", "Failure");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while adding product to package\n" + ex.Message,
                                    ex.GetType().ToString());
                }
            }
            else
            {
                MessageBox.Show("Please select a product and its supplier.", "Select Error");
            }
        }
Example #14
0
 /// <summary>
 /// Fills the package ComboBox.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The instance containing the event data.</param>
 private void FillPackageComboBox(object sender, EventArgs e)
 {
     //Fills the selection box with package items
     cmbPackageID.Items.Clear();
     cmbPackageID.Items.AddRange(PackageDB.GetTravelPackages().ToArray());
     cmbPackageID.SelectedIndex = 0;
     accessMode = AccessMode.Read;
 }
        private void btnAddRemoveProduct_Click(object sender, EventArgs e)
        {
            pkgId = selected.PackageId;
            frmAddProductToPackage viewProductsForPackage = new frmAddProductToPackage();

            viewProductsForPackage.selected = PackageDB.GetPackageById(pkgId);
            DialogResult result = viewProductsForPackage.ShowDialog();
        }
 private void reloadData()
 {
     packageList     = PackageDB.GetAllPackages();
     productsList    = ProductDB.GetProducts();
     suppliersList   = SupplierDB.GetSuppliers();
     prodSuppList    = ProductsSupplierDB.GetAllProductsSuppliers();
     pkgProdSuppList = PackagesProductsSuppliersDB.GetPackagesProductsSuppliers();
 }
Example #17
0
        /// <summary>
        /// Event after validating commission field
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbxPkgCommission_Validated(object sender, EventArgs e)
        {
            string commission = (sender as TextBox).Text;

            PackageSelected.PkgAgencyCommission = (commission != null) ? Convert.ToDecimal(commission) : (decimal?)null;

            PackageDB.UpdatePropertyById(nameof(Package.PkgAgencyCommission), PackageSelected);
        }
Example #18
0
        /// <summary>
        /// event occurs when descript has been validated
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbxPkgDesc_Validated(object sender, EventArgs e)
        {
            string desc = (sender as TextBox).Text;

            PackageSelected.PkgDesc = desc;

            PackageDB.UpdatePropertyById(nameof(Package.PkgDesc), PackageSelected);
        }
Example #19
0
        /// <summary>
        /// Updates the Package Fields displayed on the form
        /// </summary>
        /// <param name="package"></param>
        private bool DisplayPackage(int packageId)
        {
            //the package displayed is the same as the package selected from the drop down... do not redisplay.
            if (!Object.Equals(PackageSelected, null) && packageId == PackageSelected.PackageId && PackageSelected.PkgName == lblPackageName.Text)
            {
                return(false);
            }

            //get the package data
            PackageSelected = PackageDB.GetById(packageId);

            //Update non-nullable properties

            tbxPkgName.Text  = PackageSelected.PkgName.ToString();
            tbxPkgPrice.Text = Decimal.Round(PackageSelected.PkgBasePrice, 2).ToString();

            //Update nullable properties
            tbxPkgCommission.Text =
                (PackageSelected.PkgAgencyCommission.HasValue) ?
                Decimal.Round((decimal)PackageSelected.PkgAgencyCommission, 2).ToString() : String.Empty;

            tbxPkgDesc.Text = PackageSelected.PkgDesc.ToString();

            //start date is null, remove format
            if (Object.Equals(PackageSelected.PkgStartDate, null))
            {
                dtpPkgStartDate.CustomFormat = " ";
            }
            else
            {
                dtpPkgStartDate.CustomFormat = DateTimePickerFormat;
                dtpPkgStartDate.Text         = PackageSelected.PkgStartDate.ToString();
            }

            //end date is null, remove format
            if (Object.Equals(PackageSelected.PkgEndDate, null))
            {
                dtpPkgEndDate.CustomFormat = " ";
            }
            else
            {
                dtpPkgEndDate.CustomFormat = DateTimePickerFormat;
                dtpPkgEndDate.Text         = PackageSelected.PkgEndDate.ToString();
            }

            //update char count labels
            DisplayCharCount(tbxPkgDesc, lblDescCharCount);
            DisplayCharCount(tbxPkgName, lblNameCharCount);

            //If package name is updated, update controls
            if (PackageSelected.PkgName != lblPackageName.Text)
            {
                lblPackageName.Text = PackageSelected.PkgName.ToString();
                GetBindedPackageIds();
            }

            return(true);
        }
Example #20
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 #21
0
        static PackageDB CreatePackageLevel0DB(bool atOnce, bool?revert)
        {
            var db = new PackageDB();

            db = AddPackageLevel0(db, 0, atOnce, revert);
            db = AddPackageLevel0(db, 1, atOnce, revert);
            db = AddPackageLevel0(db, 2, atOnce, revert);
            db = AddPackageLevel0(db, 3, atOnce, revert);
            return(db);
        }
        private void btnDeletePkg_Click(object sender, EventArgs e)
        {
            if (loggedInAgt == null)
            {
                mainForm.btnSignIn_Click(null, null);
            }
            else
            {
                // Get Selected Package Id
                int pkgId = (int)pkgNameComboBox.SelectedValue;

                // Get Selected Package Object
                var selectedPkg = packageList.SingleOrDefault(p => p.PackageId == pkgId);

                // Get Data from datagridview
                int prodSuppId       = (int)productSupplierViewModelDataGridView.CurrentRow.Cells[0].Value;
                var selectedProdSupp = prodSuppList.SingleOrDefault(ps => ps.ProductSupplierId == prodSuppId);

                var selectedPkgProdSupp = pkgProdSuppList.SingleOrDefault(pps => pps.ProductSupplierId == prodSuppId &&
                                                                          pps.PackageId == pkgId);

                int pkgIdCount = pkgProdSuppList.Where(pps => pps.PackageId == pkgId).Count();
                if (pkgIdCount == 1)
                {
                    // If the packageId is the last one inside the Package_Products_Supplier table
                    // Then we delete that package in the Package Table
                    try {
                        deletePkgProdSupp(selectedPkgProdSupp);
                        if (!PackageDB.DeletePackage(selectedPkg))
                        {
                            MessageBox.Show("Another user has updated or " +
                                            "deleted that Package.", "Database Error");
                            // Refresh data
                            reloadData();
                            refreshComboBox();
                        }
                        else
                        {
                            int index = pkgNameComboBox.Items.IndexOf(selectedPkg);
                            packageList.Remove(selectedPkg);
                            pkgNameComboBox.SelectedIndex = index - 1;
                            refreshComboBox();
                        }
                    } catch (Exception ex) {
                        MessageBox.Show("Error: " + ex.Message, ex.GetType().ToString());
                    }
                }
                else
                {
                    deletePkgProdSupp(selectedPkgProdSupp);
                    // If there are 2 or more packageIds inside Package_Products_Supplier, only delete
                    // from the package_products_supplier table, not the Package table
                }
            }
        }
        /// <summary>

        /// Method responsible for creating BookingDetails accrording to the passed bookingId and class
        /// </summary>
        public static void CreateBookingDetailPckg(Booking newBooking, string Class)
        {
            List <Package>            selectedPckg = PackageDB.GetPackagesById((int)newBooking.PackageId);
            List <FlightsTable>       inclFlights  = FlightsTableDB.getFlightsById(selectedPckg[0].DepartureFlight, selectedPckg[0].ReturnFlight);
            List <Products_Suppliers> usedProds    = Products_SuppliersDB.GetProductsSuppliersIdFromPackageId((int)newBooking.PackageId);

            SqlConnection con             = UnversalDBControls.GetConnection();
            string        insertStatement = "ALTER TABLE BookingDetails " +
                                            "NOCHECK CONSTRAINT FK_BookingDetails_Bookings; " +
                                            "ALTER TABLE BookingDetails " +
                                            "NOCHECK CONSTRAINT FK_BookingDetails_Regions; " +
                                            "INSERT INTO BookingDetails (ItineraryNo, TripStart, TripEnd, Description, Destination, BasePrice, " +
                                            "AgencyCommission, BookingId, RegionId, ClassId, FeeId, ProductSupplierId, " +
                                            "DeparturePlnId, ReturnPlnId) " +
                                            "VALUES(@ItineraryNo, @TripStart, @TripEnd, @Description, @Destination, @BasePrice, " +
                                            "@AgencyCommission, @BookingId, @RegionId, @ClassId, @FeeId, @ProductSupplierId, " +
                                            "@DeparturePlnId, @ReturnPlnId)";
            SqlCommand cmd = new SqlCommand(insertStatement, con);

            cmd.Parameters.AddWithValue("@ItineraryNo", RandomString(6));
            cmd.Parameters.AddWithValue("@TripStart", inclFlights[0].FltDepart);
            cmd.Parameters.AddWithValue("@TripEnd", inclFlights[1].FltReturn);
            cmd.Parameters.AddWithValue("@Description", inclFlights[0].FltLocation + "/" + inclFlights[1].FltDestination + "/" + inclFlights[0].FltLocation);
            cmd.Parameters.AddWithValue("@Destination", inclFlights[1].FltDestination);
            cmd.Parameters.AddWithValue("@BasePrice", selectedPckg[0].PkgBasePrice);
            cmd.Parameters.AddWithValue("@AgencyCommission", selectedPckg[0].PkgAgencyCommission);
            cmd.Parameters.AddWithValue("@BookingId", newBooking.BookingId);
            cmd.Parameters.AddWithValue("@RegionId", inclFlights[1].RegionId);
            cmd.Parameters.AddWithValue("@ClassId", Class);
            if (newBooking.TravelerCount == 1)
            {
                cmd.Parameters.AddWithValue("@FeeId", "BK");
            }
            else if (newBooking.TravelerCount >= 2)
            {
                cmd.Parameters.AddWithValue("@FeeId", "GR");
            }
            cmd.Parameters.AddWithValue("@ProductSupplierId", usedProds[0].ProductSupplierId);
            cmd.Parameters.AddWithValue("@DeparturePlnId", inclFlights[0].FlightId);
            cmd.Parameters.AddWithValue("@ReturnPlnId", inclFlights[1].FlightId);

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }
        }// end of GetPackage button

        // GetPackage function to display the packageid information
        private void GetPackage(int packageId)
        {
            try
            {
                package = PackageDB.GetPackage(packageId);
            }
            catch (Exception ex)//show an error if catch any problem
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Example #25
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;
        }
 /// <summary>
 /// event occurs when descript has been validated
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tbxPkgDesc_Validated(object sender, EventArgs e)
 {
     PackageSelected.PkgDesc = (sender as TextBox).Text;
     try
     {
         PackageDB.UpdatePropertyById(nameof(Package.PkgDesc), PackageSelected);
     }
     catch (Exception f)
     {
         MessageBox.Show(f.Message, "Unable to update package description", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #27
0
        private void RegistPackageInfo(string[] args)
        {
            string new_package_name = null;
            string new_package_id   = null;

            while (true)
            {
                if (new_package_name == null)
                {
                    Console.Write("新しいパッケージ名: ");
                    new_package_name = Console.ReadLine();

                    if (new_package_name == null)
                    {
                        Console.WriteLine("新しいパッケージ名を入力してください。");
                        continue;
                    }
                }

                if (new_package_id == null)
                {
                    Console.Write("新しいパッケージID: ");
                    new_package_id = Console.ReadLine();

                    if (new_package_id == null)
                    {
                        Console.WriteLine("新しいパッケージIDを入力してください。");
                        continue;
                    }
                }

                break;
            }

            PackageDB   package_db   = new PackageDB();
            PackageInfo package_info = new PackageInfo()
            {
                PackageName = new_package_name,
                PackageId   = new_package_id
            };

            Console.WriteLine("-- 登録するパッケージ情報 --");
            Console.WriteLine($"パッケージ名: {package_info.PackageName}");
            Console.WriteLine($"パッケージID: {package_info.PackageId}");

            Console.WriteLine("----");
            Console.WriteLine("新しいパッケージ情報を登録しています…");

            package_db.RegisterPackageInfo(package_info);

            Console.WriteLine("完了");
            return;
        }
 /// <summary>
 /// event occures when price has been validated
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tbxPkgPrice_Validated(object sender, EventArgs e)
 {
     PackageSelected.PkgBasePrice = Convert.ToDecimal((sender as TextBox).Text);
     try
     {
         PackageDB.UpdatePropertyById(nameof(Package.PkgBasePrice), PackageSelected);
     }
     catch (Exception f)
     {
         MessageBox.Show(f.Message, "Unable to update package price", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #29
0
        private void SetPackageName(string packageName)
        {
            //name hasnt changed. return
            if (packageName == PackageSelected.PkgName)
            {
                return;
            }

            PackageIds.Remove(PackageSelected);
            PackageSelected.PkgName = packageName;

            PackageDB.UpdatePropertyById(nameof(Package.PkgName), PackageSelected);
        }
Example #30
0
 private void AddModifyPackages_Load(object sender, EventArgs e)
 {
     if (addPackage)                        //if addProduct is true then add button was picked
     {
         this.Text         = "Add Package"; //changed form title
         txtPackageId.Text = PackageDB.GetNextPackageID().ToString();
     }
     else //if modify button was picked
     {
         this.Text = "Modify Package";
         this.DisplayPackage();
     }
 }