/// <summary> /// Update method updates the Packages table with the modified data from the form. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdatePkg_Click(object sender, EventArgs e) { Package newPackage = new Package();//Created new package object which is empty for now try { if (txtPackageId.Text != "") { if (Validator.IsPresent(txtPkgName) && (Validator.IsPresent(txtPkgBasePrice)) && (Validator.isNonNegative(txtPkgBasePrice, "Base Price"))) { 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 { PutPackageData(newPackage); // calls the putpackagedata() method to populate rest of the properties newPackage.PackageId = int.Parse(txtPackageId.Text); //populates the PackageID property of the object bool success = PackageDB.PackageUpdate(package, newPackage); if (success) { MessageBox.Show("Package Updated Successfully", "Package Update"); Refresh(); packages = PackageDB.DisplayPackagesInGrid(); packageDataGridView.DataSource = packages; //packages is the list to hold the list of packages } } } else { PutPackageData(newPackage); // calls the putpackagedata() method to populate rest of the properties newPackage.PackageId = int.Parse(txtPackageId.Text); //populates the PackageID property of the object bool success = PackageDB.PackageUpdate(package, newPackage); if (success) { MessageBox.Show("Package Updated Successfully", "Package Update"); Refresh(); packages = PackageDB.DisplayPackagesInGrid(); packageDataGridView.DataSource = packages; //packages is the list to hold the list of packages } } } else { MessageBox.Show("Package Name & Base Price have to entered"); } } else { MessageBox.Show("please select a record from the grid to update", "selection error"); } } catch (SqlException ex) { MessageBox.Show(ex.ToString()); } catch (Exception ex) { //MessageBox.Show(ex.GetType().ToString() + ex.Message); MessageBox.Show("Can't update the record now as it is beeing accessed by someone else", "Update Error"); } }