private void btnDelete_Click(object sender, EventArgs e)
        {
            //delete the package
            if (rdbPackage.Checked)
            {
                int row = this.dgvMainPage.CurrentCell.RowIndex;
                int col = 0;

                DialogResult result =
                    MessageBox.Show("Do you want to delete "
                                    + dgvMainPage.SelectedRows[0].Cells[1].Value.ToString() + "?",
                                    "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    int pkgid = (int)dgvMainPage.Rows[row].Cells[col].Value;
                    if (PackageDB.DeletePackage(pkgid))
                    {
                        MessageBox.Show("Package was deleted");
                        SearchFor();
                    }
                    else
                    {
                        MessageBox.Show("Failed deleting Package");
                    }
                }
            }
        }
        // User clicks FILTER button
        private void filterButton_Click(object sender, EventArgs e)
        {
            PackFilter packFilter = new PackFilter(nameContains, startDateBegin, startDateFinish,
                                                   endDateBegin, endDateFinish);

            if (packFilter.ShowDialog() == DialogResult.Yes)
            {
                nameContains = packFilter.txtNameCont.Text;
                // Check START DATE BEGIN
                if (DateTime.Compare(packFilter.dtpStartDateBegin.Value.Date, Constants.MINDATE.Date) == 0)
                {
                    startDateBegin = null;
                }
                else
                {
                    startDateBegin = packFilter.dtpStartDateBegin.Value;
                }
                // Check START DATE FINISH
                if (DateTime.Compare(packFilter.dtpStartDateFinish.Value.Date, Constants.MAXDATE.Date) == 0)
                {
                    startDateFinish = null;
                }
                else
                {
                    startDateFinish = packFilter.dtpStartDateFinish.Value;
                }
                // Check END DATE BEGIN
                if (DateTime.Compare(packFilter.dtpEndDateBegin.Value.Date, Constants.MINDATE.Date) == 0)
                {
                    endDateBegin = null;
                }
                else
                {
                    endDateBegin = packFilter.dtpEndDateBegin.Value;
                }
                // Check END DATE FINISH
                if (DateTime.Compare(packFilter.dtpEndDateFinish.Value.Date, Constants.MAXDATE.Date) == 0)
                {
                    endDateFinish = null;
                }
                else
                {
                    endDateFinish = packFilter.dtpEndDateFinish.Value;
                }

                // Check if at least ONE out of FIVE conditions is not null make CANCEL FILTER button enable
                if (nameContains != "" || startDateBegin != null || startDateFinish != null ||
                    endDateBegin != null || endDateFinish != null)
                {
                    cancelFilter.Enabled = true;
                }

                // Display updated List of Packages
                dgvPackageList.DataSource = PackageDB.getPackageList(nameContains, startDateBegin, startDateFinish,
                                                                     endDateBegin, endDateFinish);
            }
        }
        //**************************************************************************
        //*** SAVE AND CANCEL BUTTONS
        //**************************************************************************

        // SAVE BUTTON CLICK
        private void btnSave_Click(object sender, EventArgs e)
        {
            // First check if all text boxes and grid view are filled properly
            if (PackFormValidator.checkTextFields(txtName, txtDesc) &&
                PackFormValidator.checkCommission(txtBasePrice, txtAgComm) &&
                PackFormValidator.checkDates(tpStartDate, tpEndDate) &&
                PackFormValidator.dgvIsNotEmpty(dgvPackProdSuppl) &&
                PackFormValidator.dgvIsFilled(dgvPackProdSuppl))
            {
                // Set this bool variable to true so app won't try to save data twice
                useSaveButton = true;

                // Create an instance of Package class from the form
                Package pack = new Package();
                pack.PackName            = txtName.Text;
                pack.PackStartDate       = Convert.ToDateTime(tpStartDate.Text);
                pack.PackEndDate         = Convert.ToDateTime(tpEndDate.Text);
                pack.PackDesc            = txtDesc.Text;
                pack.PackBasePrice       = Convert.ToDecimal(txtBasePrice.Text);
                pack.PackAgncyCommission = Convert.ToDecimal(txtAgComm.Text);
                pack.PkgImage            = imgDescription.Text;

                // Create a list of innstances of PackIdProdSupId
                List <PackIdProdSupId> pps = new List <PackIdProdSupId>();
                for (int i = 0; i < dgvPackProdSuppl.Rows.Count; i++)
                {
                    PackIdProdSupId item = new PackIdProdSupId(Convert.ToInt32(txtId.Text),
                                                               Convert.ToInt32(dgvPackProdSuppl.Rows[i].Cells[4].Value));
                    pps.Add(item);
                }

                // If it is a new form just insert gatherd values into DB
                if (itIsNewForm == true)
                {
                    // Insert data into Package Table
                    PackageDB.insertPackages(pack);

                    // Insert data into Packages_Products_Suppliers
                    PackProdSupplierDB.insertPackages_Products_Suppliers(pps);

                    FormHandler.upDatePackList(Convert.ToInt32(txtId.Text));
                    this.Close();
                }
                else
                {
                    // Update data in Package Table
                    PackageDB.updatePackages(pack, Convert.ToInt32(txtId.Text));

                    // Update data in Packages_Products_Suppliers Table
                    PackProdSupplierDB.updatePackages_Products_Suppliers(pps, prodSuppliersIdForUpDate);

                    FormHandler.upDatePackList(Convert.ToInt32(txtId.Text));
                    this.Close();
                }
            }
        }
Exemple #4
0
        private void FillSupplierCombobox()
        {
            List <Supplier> suppliers;
            int             productID = ((Product)cbxProductList.SelectedItem).prodID;

            suppliers = PackageDB.GetSuppliers(productID.ToString());

            cbxSuppliers.DataSource = suppliers;
            //cbxSuppliers.ValueMember = "SupplierId";
            //cbxSuppliers.DisplayMember = "SupName";
        }
        public void PackagesForm_Load(object sender, EventArgs e)
        {
            // Call just data source for dataGridView
            // Source has to be DATA TABLE

            dgvPackageList.DataSource = PackageDB.getPackageList(nameContains, startDateBegin, startDateFinish,
                                                                 endDateBegin, endDateFinish);

            //HIDE ID COLUMN
            dgvPackageList.Columns[0].Visible = false;
            dgvPackageList.Columns[7].Visible = false;

            // EDIT APPEARANCE OF DATA GRID VIEW
            dgvPackageList.Columns[0].HeaderText = "ID";
            dgvPackageList.Columns[1].HeaderText = "Name";
            dgvPackageList.Columns[1].Width      = 130;
            dgvPackageList.Columns[2].HeaderText = "Start Date";
            dgvPackageList.Columns[2].Width      = 100;
            dgvPackageList.Columns[3].HeaderText = "End Date";
            dgvPackageList.Columns[3].Width      = 100;
            dgvPackageList.Columns[4].HeaderText = "Description";
            dgvPackageList.Columns[5].Width      = 310;
            dgvPackageList.Columns[5].HeaderText = "Base Price";
            dgvPackageList.Columns[5].Width      = 90;
            dgvPackageList.Columns[6].HeaderText = "Commission";
            dgvPackageList.Columns[6].Width      = 110;

            // SET BOLD FONT FOR COLUMN HEADERS
            dgvPackageList.Columns[1].HeaderCell.Style.Font = new Font("Microsoft Sans Serif", 10.75F, FontStyle.Bold);
            dgvPackageList.Columns[2].HeaderCell.Style.Font = new Font("Microsoft Sans Serif", 10.75F, FontStyle.Bold);
            dgvPackageList.Columns[3].HeaderCell.Style.Font = new Font("Microsoft Sans Serif", 10.75F, FontStyle.Bold);
            dgvPackageList.Columns[4].HeaderCell.Style.Font = new Font("Microsoft Sans Serif", 10.75F, FontStyle.Bold);
            dgvPackageList.Columns[5].HeaderCell.Style.Font = new Font("Microsoft Sans Serif", 10.75F, FontStyle.Bold);
            dgvPackageList.Columns[6].HeaderCell.Style.Font = new Font("Microsoft Sans Serif", 10.75F, FontStyle.Bold);

            // DATE FORMAT IN DATE COLUMNS
            dgvPackageList.Columns[2].DefaultCellStyle.Format = "dd-MMM-yyyy";
            dgvPackageList.Columns[3].DefaultCellStyle.Format = "dd-MMM-yyyy";

            // NUMBER FORMAT IN PRICE COLUMNS
            dgvPackageList.Columns[5].DefaultCellStyle.Format = "N2";
            dgvPackageList.Columns[6].DefaultCellStyle.Format = "N2";

            // SET READ ONLY TO CERTAIN COLUMNS
            dgvPackageList.Columns[1].ReadOnly = true;
            dgvPackageList.Columns[2].ReadOnly = true;
            dgvPackageList.Columns[3].ReadOnly = true;
            dgvPackageList.Columns[4].ReadOnly = true;
            dgvPackageList.Columns[5].ReadOnly = true;
            dgvPackageList.Columns[6].ReadOnly = true;

            dgvPackageList.CurrentCell = dgvPackageList.Rows[this.activeRow].Cells[1];
        }
        // User clicks CANCEL FILTER button
        private void cancelFilter_Click(object sender, EventArgs e)
        {
            // NUll down all conditions and display updated List of Packages
            nameContains              = null;
            startDateBegin            = null;
            startDateFinish           = null;
            endDateBegin              = null;
            endDateFinish             = null;
            dgvPackageList.DataSource = PackageDB.getPackageList(nameContains, startDateBegin, startDateFinish,
                                                                 endDateBegin, endDateFinish);

            // Disable this button
            cancelFilter.Enabled = false;
        }
Exemple #7
0
        //add data to the database
        private void btnAddPkg_Click(object sender, EventArgs e)
        {
            DateTime newStartDate = new DateTime();
            DateTime newEndDate   = new DateTime();
            decimal  newBasePrice;
            decimal  newCommission;

            // Check that the input data can be parsed
            if (!DateTime.TryParse(textBoxAddStartDate.Text, out newStartDate))
            {
                MessageBox.Show("Please enter a date for the start date", "Error");
            }
            if (!DateTime.TryParse(textBoxAddEndDate.Text, out newEndDate))
            {
                MessageBox.Show("Please enter a date for the end date", "Error");
            }

            if (!Decimal.TryParse(textBoxAddBasePrice.Text, out newBasePrice))
            {
                MessageBox.Show("Please enter a decimal value for the base price", "Error");
            }
            if (!Decimal.TryParse(textBoxAddComission.Text, out newCommission))
            {
                MessageBox.Show("Please enter a decimal value for the agency commission", "Error");
            }

            // Create the package object to be added
            Package newPkg = new Package(0, textBoxAddPkgName.Text, newStartDate, newEndDate, textBoxAddDesc.Text, newBasePrice, newCommission);

            // Validate the values of the input data.  If the input is valid, add the new package
            // to the Packages table in the database.
            try
            {
                if (PackageValidation.ValidatePackageData(newPkg))
                {
                    PackageDB.AddPackage(newPkg);
                }
                LoadUIforPackages();
                comboBoxPkgName.SelectedIndex = (packages.Count() - 1);

                panelDetailPkg.Visible    = true;
                panelAddPkg.Visible       = false;
                btnEditPkgClick.Enabled   = true;
                btnDeletePkgClick.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Exemple #8
0
        private void FillProductComboBox()
        {
            List <Product> products;

            products = PackageDB.GetProducts("");

            //foreach (Product p in products)
            //{
            //    cbxProductList.Items.Add(p);
            //}
            cbxProductList.DataSource = products;
            //cbxProductList.ValueMember = "prodID";
            //cbxProductList.DisplayMember = "prodName";
        }
Exemple #9
0
        //add product and supplier to package
        private void btnAddToPackage_Click(object sender, EventArgs e)
        {
            int    prodID   = ((Product)cbxProductList.SelectedItem).prodID;
            string prodName = ((Product)cbxProductList.SelectedItem).prodName;
            int    supID    = ((Supplier)cbxSuppliers.SelectedItem).SupplierId;
            string supName  = ((Supplier)cbxSuppliers.SelectedItem).SupName;

            //add to datagridview if no duplicate
            if (ProductSupplierIsNotIncluded(prodName, supName))
            {
                string[] record = PackageDB.GetProductSupplier(prodID, supID);

                //add row to datagridview
                dgvProductSuppliers.Rows.Add(record[0], record[1], record[2]);
            }
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            //edit package from main form
            if (rdbPackage.Checked)
            {
                //get selected package
                int row   = this.dgvMainPage.CurrentCell.RowIndex;
                int col   = 0;
                int pkgid = (int)dgvMainPage.Rows[row].Cells[col].Value;
                package = PackageDB.GetPackage(pkgid);

                //open modify form and pass selected package
                frmPackage   newForm = new frmPackage(package);
                DialogResult result  = newForm.ShowDialog();
                SearchFor();
            }
        }
        private void SearchFor()
        {
            bool isIncludeExpiredPackagesEnabled = false;

            dgvMainPage.DataSource = null;

            //search for Packages
            if (rdbPackage.Checked)
            {
                grpListOf.Text = "List Of Package";
                isIncludeExpiredPackagesEnabled = true;
                dgvMainPage.DataSource          = PackageDB.GetPackages(txtSearch.Text, chbIncludeExpiredPackages.Checked);
                hideColumn(5);
                hideColumn(6);
                dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            }
            //search for Products
            if (rdbProduct.Checked)
            {
                grpListOf.Text                  = "List Of Products";
                dgvMainPage.DataSource          = ProductDB.SearchProducts(txtSearch.Text);
                dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            //search for Suppliers
            if (rdbSupplier.Checked)
            {
                grpListOf.Text                  = "List Of Suppliers";
                dgvMainPage.DataSource          = SupplierDB.SearchSuppliers(txtSearch.Text);
                dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            //search for Agents
            if (rdbAgents.Checked)
            {
                grpListOf.Text                  = "List Of Agents";
                dgvMainPage.DataSource          = AgentDB.SearchAgents(txtSearch.Text);
                dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                hideColumn(8);
            }

            chbIncludeExpiredPackages.Enabled = isIncludeExpiredPackagesEnabled;//enable 'IncludeExpiredPackages' box or not
            this.Refresh();
            EnableDisableEditButton();

            //dgvMainPage.Columns[columNo].Visible = false;
        }
Exemple #12
0
        // Method called to load (or reload) the list of packages to the combo box in the
        // packages tab.  Also clears the gridviews and Detail Package panel.
        private void LoadUIforPackages()
        {
            packages = PackageDB.GetAllPackages();

            // First clear the combo box
            comboBoxPkgName.Items.Clear();

            // Next, loop through the list of packages and populate the combo box
            foreach (Package p in packages)
            {
                comboBoxPkgName.Items.Add(p.PackageName);
            }

            // Hide the panels
            panelDetailPkg.Visible = false;
            panelEditPkg.Visible   = false;
            panelAddPkg.Visible    = false;
        }
Exemple #13
0
        private void PopulateForm()
        {
            txtName.Text        = package.Name;
            txtDescription.Text = package.Description;
            txtPrice.Text       = package.Base_Price.ToString();
            txtCommission.Text  = package.Agency_Commission.ToString();
            dtpStart.Value      = package.Start_Date;
            dtpEnd.Value        = package.End_Date;

            //fill dgvProductSupplier
            List <string[]> listPkgProdSup = new List <string[]>();

            listPkgProdSup = PackageDB.GetPackageProductSupplier(package.ID);

            //add to datagridview if no duplicate
            foreach (string[] list in listPkgProdSup)
            {
                dgvProductSuppliers.Rows.Add(list[0], list[1], list[2]);
            }
        }
Exemple #14
0
        private void comboBoxPkgName_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Determine the package id from the selection in the combo box (i.e., if the nth
            // index is selected, the package Id can be obtained from the nth package in the
            // "packages" list).
            int pkgId = packages[comboBoxPkgName.SelectedIndex].PackageId;

            // Display the package details in the Detail Package panel
            panelDetailPkg.Visible = true;

            textBoxDetailPkgID.Text     = pkgId.ToString();
            textBoxDetailPkgName.Text   = packages[comboBoxPkgName.SelectedIndex].PackageName;
            textBoxDetailStartDate.Text = packages[comboBoxPkgName.SelectedIndex].PkgStartDate.ToString("yyyy-MM-dd");
            textBoxDetailEndDate.Text   = packages[comboBoxPkgName.SelectedIndex].PkgEndDate.ToString("yyyy-MM-dd");
            textBoxDetailDesc.Text      = packages[comboBoxPkgName.SelectedIndex].PkgDesc;
            textBoxDetailBasePrice.Text = packages[comboBoxPkgName.SelectedIndex].PkgBasePrice.ToString("0.00");
            textBoxDetailComission.Text = packages[comboBoxPkgName.SelectedIndex].PkgAgencyCommission.ToString("0.00");

            // Obtain all of the product/supplier combinations for this package
            List <ProductSupplier> ppsList = PackageDB.GetPackageProductSuppliers(pkgId);

            // Display the results in the first grid view
            gridViewPkgProduct.DataSource = ppsList;

            // Obtain all of the other availabe product/supplier combinations that are not yet
            // used by this package
            List <ProductSupplier> ppsOtherList = PackageDB.GetOtherProductSuppliers(pkgId);

            // Display the results in the first grid view
            gridViewOtherProduct.DataSource = ppsOtherList;

            // Ensure only the details panel is visible
            panelDetailPkg.Visible = true;
            panelEditPkg.Visible   = false;
            panelAddPkg.Visible    = false;

            // The ADD, EDIT and DELETE buttons should all be enabled
            btnAddPkgClick.Enabled    = true;
            btnEditPkgClick.Enabled   = true;
            btnDeletePkgClick.Enabled = true;
        }
Exemple #15
0
        private void btnDeletePkgClick_Click(object sender, EventArgs e)
        {
            // Return if no pacakge to delete
            if (comboBoxPkgName.SelectedIndex == -1)
            {
                return;
            }

            // Get the current package to delete.
            // If the nth index is selected in the combo box, the current package
            // is the nth entry in the "packages" list
            Package delPkg = packages[comboBoxPkgName.SelectedIndex];

            // Confirm with the user before proceeding
            DialogResult dr = MessageBox.Show("Delete the selected package from the database?",
                                              "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (dr == DialogResult.Yes)
            {
                // Delete the package from the database (note: cascading deletes have been
                // implemented in the Travel Experts database)
                try
                {
                    bool result = PackageDB.DeletePackage(delPkg);
                    if (result)
                    {
                        MessageBox.Show("The package was successfully deleted", "Information");
                        LoadUIforPackages();
                        comboBoxPkgName.SelectedIndex = 0;
                    }
                    else
                    {
                        MessageBox.Show("Error deleting package from database", "Error");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }
Exemple #16
0
        private void btnAddProdToPkg_Click(object sender, EventArgs e)
        {
            // Add the selected product/supplier to the package.  Multiselect has been set to
            // false for the data grid view so only one row can be selected at a time.

            // Return if no row selected
            if (gridViewOtherProduct.SelectedRows[0] == null)
            {
                return;
            }

            // Get the package ID of the current package
            int curCboSelIndex = comboBoxPkgName.SelectedIndex;
            int pkgId          = packages[curCboSelIndex].PackageId;

            // Obtain the ProductSupplierId from the datagridview
            int prodSupId = Convert.ToInt32(gridViewOtherProduct.SelectedRows[0].Cells[0].Value);

            // Then add a new record to the Packages_Products_Suppliers table
            try
            {
                if (PackageDB.AddProductToPackage(pkgId, prodSupId))
                {
                    MessageBox.Show("Product/Supplier successfully added to pacakge", "Information");
                    LoadUIforPackages();
                    comboBoxPkgName.SelectedIndex = curCboSelIndex;
                }
                else
                {
                    MessageBox.Show("Error adding Product/Supplier to pacakge", "Error");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Exemple #17
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //create package
            if (package == null)
            {
                if (ValidatePackageDataInput())
                {
                    //create package object
                    Package p = new Package();
                    p.Name              = txtName.Text;
                    p.Description       = txtDescription.Text;
                    p.Start_Date        = dtpStart.Value;
                    p.End_Date          = dtpEnd.Value;
                    p.Base_Price        = Convert.ToDecimal(txtPrice.Text);
                    p.Agency_Commission = Convert.ToDecimal(txtCommission.Text);

                    //insert package to DB
                    if (PackageDB.AddPackage(p)) //package was created
                    {
                        //get list of added products and suppliers
                        List <int> list = new List <int>();
                        foreach (DataGridViewRow item in dgvProductSuppliers.Rows)
                        {
                            int id = Convert.ToInt32(item.Cells[0].Value);
                            list.Add(id);
                        }
                        p.ID = PackageDB.GetMaxPackageID();
                        //insert products suppliers
                        foreach (int l in list)
                        {
                            PackageDB.AddPackageProductSupplier(p.ID, l);
                        }
                        MessageBox.Show("The Package was Added.",
                                        "Package was Added");
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Error Occured. Try Again",
                                        "Package was NOT Added");
                    }
                }
            }
            //update package
            else
            {
                if (ValidatePackageDataInput())
                {
                    //edit package class
                    package.Name              = txtName.Text;
                    package.Description       = txtDescription.Text;
                    package.Base_Price        = Convert.ToDecimal(txtPrice.Text);
                    package.Agency_Commission = Convert.ToDecimal(txtCommission.Text);
                    package.Start_Date        = dtpStart.Value;
                    package.End_Date          = dtpEnd.Value;

                    //update db
                    if (PackageDB.UpdatePackage(package))
                    {
                        //delete or add PackageProductSupplier Records
                        //get list of products and suppliers
                        List <int> list = new List <int>();
                        foreach (DataGridViewRow item in dgvProductSuppliers.Rows)
                        {
                            int prodSupID = Convert.ToInt32(item.Cells[0].Value);
                            list.Add(prodSupID);
                        }
                        //delete packageproductsupplier
                        if (PackageDB.DeletePackageProductSupplier(package.ID, list))
                        {
                        }
                        //insert packageproductsupplier
                        foreach (int l in list)
                        {
                            PackageDB.AddPackageProductSupplier(package.ID, l);
                        }
                        MessageBox.Show("The Package was Added.",
                                        "Package was Added");
                        Close();
                    }
                    else
                    {
                        MessageBox.Show("Error occured when saving package");
                    }
                }
            }
        }
Exemple #18
0
        //edit the selected package
        private void btnEditPkg_Click(object sender, EventArgs e)
        {
            // ------ Corinne Mullan ------
            // Obtain the original package data for the package currently selected in
            // the combo box.
            // If the nth index is selected in the combo box, the current package
            // is the nth entry in the "packages" list
            int     curCboIndex = comboBoxPkgName.SelectedIndex;
            Package currPkg     = packages[curCboIndex];

            // Next, obtain and verify the edited data entered by the user
            DateTime edStartDate = new DateTime();
            DateTime edEndDate   = new DateTime();
            decimal  edBasePrice;
            decimal  edCommission;

            // Check that the input data can be parsed
            if (!DateTime.TryParse(textBoxEditStartDate.Text, out edStartDate))
            {
                MessageBox.Show("Please enter a date for the start date", "Error");
            }
            if (!DateTime.TryParse(textBoxEditEndDate.Text, out edEndDate))
            {
                MessageBox.Show("Please enter a date for the end date", "Error");
            }

            if (!Decimal.TryParse(textBoxEditBasePrice.Text, out edBasePrice))
            {
                MessageBox.Show("Please enter a decimal value for the base price", "Error");
            }
            if (!Decimal.TryParse(textBoxEditComission.Text, out edCommission))
            {
                MessageBox.Show("Please enter a decimal value for the agency commission", "Error");
            }

            // Create the edited package object.  The package ID will be the same as the original
            // package.
            Package edPkg = new Package(currPkg.PackageId, textBoxEditPkgName.Text, edStartDate, edEndDate, textBoxEditDesc.Text, edBasePrice, edCommission);

            // Validate the values of the input data.  If the input is valid, add the new package
            // to the Packages table in the database.
            try
            {
                if (PackageValidation.ValidatePackageData(edPkg))
                {
                    PackageDB.UpdatePackage(currPkg, edPkg);
                }

                LoadUIforPackages();
                comboBoxPkgName.SelectedIndex = curCboIndex;

                panelDetailPkg.Visible    = true;
                panelEditPkg.Visible      = false;
                btnAddPkgClick.Enabled    = true;
                btnDeletePkgClick.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
            // ----------------------------
        }
        //*******************************************************************************//
        //  END OF CUSTOM USER CONTROL PART
        //*******************************************************************************//

        private void PackagesForm_Load(object sender, EventArgs e)
        {
            Constants.packageIsChanged = false;
            if (itIsNewForm == false)
            {
                // if form is opened in EDIT mode fill all exusting informartion

                // Create a DGV table
                FormHandler.createProdSupplTable(dgvPackProdSuppl);

                // Create a list of PackProdSuppl objects to popuplate Data Grid View with
                // existing data
                List <PackProdSupplier> packProdSupList = PackProdSupplierDB.getProdSuppliersForDGV(Convert.ToInt32(txtId.Text));

                // Loop through list generated from data table to populate DataGridView
                string[] splitLine = new string[5];

                foreach (PackProdSupplier line in packProdSupList)
                {
                    // variable to break list line into array
                    splitLine = line.PackProdSupplierToString().Split(',');

                    // Create a list of possiple values to populate a combox
                    List <Supplier> supplierIdPairs =
                        PackProdSupplier.createSupplierIdPairsList(Convert.ToInt32(splitLine[1]));

                    // Find index of right element
                    int indOfRightElement = supplierIdPairs.IndexOf(supplierIdPairs.Where(p =>
                                                                                          p.SupplierId == Convert.ToInt32(splitLine[3])).FirstOrDefault());

                    // Store values from DataTable
                    DataGridViewRow dgvRow = new DataGridViewRow();

                    dgvRow.Cells.Add(new DataGridViewTextBoxCell());
                    dgvRow.Cells.Add(new DataGridViewTextBoxCell());
                    dgvRow.Cells.Add(new DataGridViewComboBoxCell());
                    dgvRow.Cells.Add(new DataGridViewTextBoxCell());
                    dgvRow.Cells.Add(new DataGridViewTextBoxCell());

                    dgvRow.Cells[0].Value = splitLine[0];
                    dgvRow.Cells[1].Value = splitLine[1];
                    ((DataGridViewComboBoxCell)dgvRow.Cells[2]).FlatStyle     = FlatStyle.Flat;
                    ((DataGridViewComboBoxCell)dgvRow.Cells[2]).DataSource    = supplierIdPairs;
                    ((DataGridViewComboBoxCell)dgvRow.Cells[2]).DisplayMember = "SupName";
                    ((DataGridViewComboBoxCell)dgvRow.Cells[2]).ValueMember   = "SupplierId";
                    ((DataGridViewComboBoxCell)dgvRow.Cells[2]).Value         =
                        supplierIdPairs[indOfRightElement].SupplierId;
                    dgvRow.Cells[3].Value = splitLine[3];
                    dgvRow.Cells[4].Value = splitLine[4];

                    dgvPackProdSuppl.Rows.Add(dgvRow);

                    // add item to prodSuppliersIdForUpDate list
                    prodSuppliersIdForUpDate.Add(Convert.ToInt32(dgvRow.Cells[4].Value));
                }
            }
            else
            {
                // if it is a new form it is needed to generate new Package ID
                txtId.Text = Convert.ToString((PackageDB.getMaxPackIdValue() + 1));
            }

            //**************************************************************************
            //****** ADD CUSTOM BUTTON CONTROL
            //**************************************************************************

            this.txtbtn         = new TextAndButtonControlPackForm();
            this.txtbtn.Visible = false;
            this.dgvPackProdSuppl.Controls.Add(this.txtbtn);

            //Handle the cellbeginEdit event to show the usercontrol in the cell while editing
            this.dgvPackProdSuppl.CellBeginEdit += new DataGridViewCellCancelEventHandler(dgv_CellBeginEdit);

            //Handle the cellEndEdit event to update the cell value
            this.dgvPackProdSuppl.CellEndEdit += new DataGridViewCellEventHandler(dgv_CellEndEdit);
            //**************************************************************************
            //****** END OF CUSTOM BUTTON CONTROL
            //**************************************************************************

            FormHandler.captureChanges(this);

            rtxtHint.SelectionAlignment = HorizontalAlignment.Center;
        }