/// <summary> /// Add Package method adds the package into the package table, PackageID textbox on the form is disabled as it's auto-incremented /// in the database table. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddPkg_Click_1(object sender, EventArgs e) { Package pkgObj = new Package(); try { if (Validator.IsPresent(txtPkgName) && (Validator.IsPresent(txtPkgBasePrice) && (Validator.isNonNegative(txtPkgBasePrice, "Base Price")))) { var pkg = packages.SingleOrDefault(pk => pk.PkgName.ToLower() == txtPkgName.Text.ToLower()); //checks if same package name already exists in database. returns null if no duplicate found else returns >0 if (pkg == null) { if (pkrPkgStartDate.Checked == true && pkrPkgEndDate.Checked == true) { if (pkrPkgEndDate.Value.Date.CompareTo(pkrPkgStartDate.Value.Date) <= 0) { MessageBox.Show("Start Date should be less than End Date", "Date Selection Error", MessageBoxButtons.OK); } else { this.PutPackageData(pkgObj); PackageDB.PackageAdd(pkgObj); MessageBox.Show("Package Added Successfully"); Refresh(); // packageDataGridView.DataSource = PackageDB.DisplayPackagesInGrid(); packages = PackageDB.DisplayPackagesInGrid(); packageDataGridView.DataSource = packages; //packages is the list to hold the list of packagesckages } } else { this.PutPackageData(pkgObj); PackageDB.PackageAdd(pkgObj); MessageBox.Show("Package Added Successfully"); Refresh(); // packageDataGridView.DataSource = PackageDB.DisplayPackagesInGrid(); packages = PackageDB.DisplayPackagesInGrid(); packageDataGridView.DataSource = packages; //packages is the list to hold the list of packagesckages } } else { MessageBox.Show("Package Id: " + pkg.PackageId + "\nPackage Name: " + pkg.PkgName + " already Exsits"); txtPkgName.Text = ""; txtPkgName.SelectAll(); } } else { MessageBox.Show("Package Name & Base Price have to entered"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }