예제 #1
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());
            }
        }
예제 #2
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());
            }
            // ----------------------------
        }