예제 #1
0
        private void BtnAdd_Click(object sender, EventArgs e)
        { /*Add Button code added by Shanice Talan. Validation by Kai Feng.
           * Create a new Package object then get data from textboxes to be passed as args. */
            Packages pkg = new Packages();

            try
            {
                if (Validator.IsPresent(pkgNameTextBox) && Validator.IsPresent(pkgDescTextBox))
                {
                    if (pkgEndDateDateTimePicker.Value.Date.CompareTo(pkgStartDateDateTimePicker.Value.Date) <= 0)
                    {
                        MessageBox.Show("Start Date must be less than End Date", "Date Selection Error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        pkg.PackageID    = Convert.ToInt32(packageIdTextBox.Text);
                        pkg.PkgName      = pkgNameTextBox.Text;
                        pkg.PkgStartDate = pkgStartDateDateTimePicker.Value;
                        pkg.PkgEndDate   = pkgEndDateDateTimePicker.Value;
                        pkg.PkgDesc      = pkgDescTextBox.Text;
                        Decimal.TryParse(pkgBasePriceTextBox.Text, out decimal baseprice);
                        Decimal.TryParse(pkgAgencyCommissionTextBox.Text, out decimal commision);
                        if (baseprice < commision)
                        {
                            MessageBox.Show("Commission can not be larger than Base Price!");
                        }
                        else
                        {
                            pkg.PkgBasePrice        = baseprice;
                            pkg.PkgAgencyCommission = commision;
                        }
                        PackagesDB.PackageAdd(pkg);
                    }
                }
                else
                {
                    MessageBox.Show("Please enter Package Name and Description.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }