Int32 DisplaySuperHeros(string SearchParameter) { //clear the listbox lstDefaultDetails.Items.Clear(); //string variable to display "Super Speed" string SuperSpeed = ""; //string variable to display "Super Strength" string SuperStrength = ""; //string variable to display "Super Flight" string SuperFlight = ""; //string variable to display "Super Teleportation" string SuperTeleportation = ""; //string variable to display "Super Invisibility" string SuperInvisibility = ""; //string variable to display "Super Telekenisis" string SuperTelekenisis = ""; //string variable to display "Super Psychokenisis" string SuperPsychokenisis = ""; //variable to store the primary key Int32 SuperHeroID; //string variable for the Nickname String Nickname; //string variable for the Gender String Gender; //decimal variable to store Height_m Decimal Height; //integer variable to store Weight_kg Int32 Weight_kg; //DateTime variable to store birthdate DateTime BirthDate; //[27/02/2019] This line was added after the FormatDate function was created, so date can be displayed nicely in DD/MM/YYYY //string variable stores the formated date to be displayed String DisplayDate; //foreign key reference for City name in the SuperHeros Database (stored as a string value, thats why CityNo is a string) Int32 CityNo; //string variable to store the City name that will be retrieved from the City database using the CityNo string CityName; //Int32 Age; // variable for the Age is obscelete as the age is now calculated from the date //boolean value to store the boolean for speed in data base Boolean Speed; //boolean value to store the boolean for strength Boolean Strength; //boolean value to store the boolean for flight Boolean Flight; //boolean value to store the boolean for teleportation Boolean Teleportation; //boolean value to store the boolean for invisibility Boolean Invisibility; //boolean value to store the boolean for telekenisis Boolean Telekenisis; //boolean value to store the boolean for psychokenisis Boolean Psychokenisis; //integer variable to store age which will be calculated from the BirthDate and CurrentDate Int32 CurrentAge; //create an instance of the clsSuperHeroCollection class to give us access to data we need. ///The list is populated when we create an intsance of the class. ///create a SuperHeroCollection object, to get access to methods clsSuperHeroCollection newSuperHeroCollection = new clsSuperHeroCollection(); //execute the search method in the object, passing the search parameter //returns the number of records in newSuperHeroCollection and assigned to recordCount variable newSuperHeroCollection.SearchSuperHeros(SearchParameter); //declare integet to store the record count Int32 recordCount; recordCount = newSuperHeroCollection.Count; //initialise the Variable to store the index of the loop (used to point to SuperHero data we want) Int32 Pointer = 0; //declare a new instance of the newSuperHero so that we can use it to access functions for calculate age and format date clsSuperHero newSuperHero = new clsSuperHero(); //while loop that traverses the rows and gets the dat in each (named) column while (Pointer < recordCount) { /// obtain the desired data from the populated superHeroList from the instance of clsSuperHeroCollection /// newSuperHeroCollection is the instance of clsSuperHeroCollection to will //Get primary key from the data table SuperHeroID = newSuperHeroCollection.SuperHeroList[Pointer].SuperHeroID; //get Nickname from the data table Nickname = newSuperHeroCollection.SuperHeroList[Pointer].Nickname; //get Gender from the data table Gender = newSuperHeroCollection.SuperHeroList[Pointer].Gender; //get the weight from the data table Weight_kg = newSuperHeroCollection.SuperHeroList[Pointer].Weight_kg; //get the height from the datatable Height = newSuperHeroCollection.SuperHeroList[Pointer].Height_m; //get the birthdate from the data table BirthDate = newSuperHeroCollection.SuperHeroList[Pointer].BirthDate; //[27/01/2019] Formats and assigns date to the DisplayDate string. DisplayDate = newSuperHero.FormatDate(BirthDate); //[27/01/2019] Following code is obscelete as the age can be calculated directly //Age = newSuperHeroCollection.SuperHeroList[Pointer].Age; // get age //calculates the current age based on BirthDate and CurrentDate CurrentAge = newSuperHero.CalculateAge(BirthDate, DateTime.Today); //[02/02/2019] Adding the clsCityCollection and clsCity classes and having a seperate database for cities for the cities drop down list (in Profile.aspx) //meant SelectedValue for the Cities drop down list is passed to the database table for SuperHeros rather than the name. //the CityNo is being used as a foriegn key in the SuperHeros database and therefore when copied from the database a number appears in the listbox in Default.aspx. //However this number can be converted back to the city name by creating an instance of the clsCityCollection, which can then be used to copy city from the datatable. //Get the foreign key CityNo (now stored in City) from the SuperHeros database and convert it to an integer CityNo = newSuperHeroCollection.SuperHeroList[Pointer].CityNo; //create an instance of the clsCityCollection to work with clsCityCollection theCities = new clsCityCollection(); //Pass in the search parameter (to populate the the list array object called CitiesList) theCities.CitySearchParameter(CityNo); //Get the CityName to be displayed based on the CityNo CityName = theCities.CityList[0].CityName; //get the boolean value of speed thats in the datatable Speed = newSuperHeroCollection.SuperHeroList[Pointer].Speed; //if the value is true, assign some text, else assign nothing if (Speed == true) { SuperSpeed = ", Super Speed"; } else { SuperSpeed = ""; } //get the boolean value of Strength thats in the datatable Strength = newSuperHeroCollection.SuperHeroList[Pointer].Strength; //if the value is true, assign some text, else assign nothing if (Strength == true) { SuperStrength = ", Super Strength"; } else { SuperStrength = ""; } //get the boolean value of Flight thats in the datatable Flight = newSuperHeroCollection.SuperHeroList[Pointer].Flight; //if the value is true, assign some text, else assign nothing if (Flight == true) { SuperFlight = ", Flight"; } else { SuperFlight = ""; } //get the boolean value of Teleportation thats in the datatable Teleportation = newSuperHeroCollection.SuperHeroList[Pointer].Teleportation; //if the value is true, assign some text, else assign nothing if (Teleportation == true) { SuperTeleportation = ", Teleportation"; } else { SuperTeleportation = ""; } //get the boolean value of Invisibility thats in the datatable Invisibility = newSuperHeroCollection.SuperHeroList[Pointer].Invisibility; //if the value is true, assign some text, else assign nothing if (Invisibility == true) { SuperInvisibility = ", Invisibility"; } else { SuperInvisibility = ""; } //get the boolean value of Telekenisis thats in the datatable Telekenisis = newSuperHeroCollection.SuperHeroList[Pointer].Telekenisis; //if the value is true, assign some text, else assign nothing if (Telekenisis == true) { SuperTelekenisis = ", Telekenisis"; } else { SuperTelekenisis = ""; } //get the boolean value of Psychokenisis thats in the datatable Psychokenisis = newSuperHeroCollection.SuperHeroList[Pointer].Psychokenisis; //if the value is true, assign some text, else assign nothing if (Psychokenisis == true) { SuperPsychokenisis = ", Psychokenisis"; } else { SuperPsychokenisis = ""; } ///List item is defined: public ListItem (string text, string value); ///https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.listitem.-ctor?view=netframework-4.7.2#System_Web_UI_WebControls_ListItem__ctor ///Initialise a new instance of list item with the concatenated string of data we want to display as the first parameter in ListItem instance ///The value of list item is the primary key, we convert to string and add as the second parameter to ListItem instance ///Each List item will be displayed in the format Nickname, gender, age. ListItem newListItem = new ListItem("Superhero ID [" + SuperHeroID.ToString() + "] " + Nickname + ": " + Gender + ", " + Height.ToString() + "m tall" + ", " + Weight_kg + "kg" + ", " + "born " + DisplayDate + ", " + CurrentAge.ToString() + " years old, " + " lives in " + CityName + SuperFlight + SuperInvisibility + SuperSpeed + SuperStrength + SuperTelekenisis + SuperTeleportation + SuperPsychokenisis, SuperHeroID.ToString()); ///add the item to the list menu lstDefaultDetails.Items.Add(newListItem); /// increment pointer so it points to next superhero in the collection class Pointer++; } return(recordCount); }
//This function is used to populate the form using a SuperHeroID passed in as a parameter. //The parameter is then passed to the SelectSuperHero() function which resides in the clsSuperHero class. //The SelectSuperHero() function executes a Search and finds the superhero data and loads the properties // in the clsSuperHero class, these properties are then loaded in to the form by DisplaySuperHero void DisplaySuperHero(Int32 SuperHeroIDPassedIn) { clsSuperHero nSuperHero = new clsSuperHero(); nSuperHero.SelectSuperHero(SuperHeroIDPassedIn); //gets the SuperHeroID from the Data table converts to string and assigns to textbox on form lblProfileSuperHeroID.Text = Convert.ToString(nSuperHero.SuperHeroID); //gets the Nickname from the Data table converts to string and assigns to textbox on form tbxProfileName.Text = Convert.ToString(nSuperHero.Nickname); //gets the Gender from the Data table converts to string and assigns to Gender string variabl string GenderCheck = Convert.ToString(nSuperHero.Gender); //gets the Height from the Data table converts to string and assigns to textbox on form tbxProfileHeight.Text = Convert.ToString(nSuperHero.Height_m); //gets the Weight from the Data table converts to string and assigns to textbox on form tbxProfileWeight.Text = Convert.ToString(nSuperHero.Weight_kg); //Formats the date (using FormatDate function) and converts it to string then assigns to the BirthDate textbox tbxProfileBirthDate.Text = Convert.ToString(nSuperHero.FormatDate(nSuperHero.BirthDate)); //gets the City from the Data table converts to string and assigns to textbox on form ddlProfileCity.SelectedValue = Convert.ToString(nSuperHero.CityNo); //calculates age and assigns it to the label for Age lblProfileCalculatedAge.Text = Convert.ToString(nSuperHero.CalculateAge(nSuperHero.BirthDate, DateTime.Today)); //gets the boolean value of speed and assigns it (uses it to check or uncheck the checkbox) cbxProfileSpeed.Checked = Convert.ToBoolean(nSuperHero.Speed); //gets the boolean value of strength and assigns it (uses it to check or uncheck the checkbox) cbxProfileStrength.Checked = Convert.ToBoolean(nSuperHero.Strength); //gets the boolean value of flight and assigns it (uses it to check or uncheck the checkbox) cbxProfileFlight.Checked = Convert.ToBoolean(nSuperHero.Flight); //gets the boolean value of teleportation and assigns it (uses it to check or uncheck the checkbox) cbxProfileTeleportation.Checked = Convert.ToBoolean(nSuperHero.Teleportation); //gets the boolean value of invisibility and assigns it (uses it to check or uncheck the checkbox) cbxProfileInvisibility.Checked = Convert.ToBoolean(nSuperHero.Invisibility); //gets the boolean value of telekenisis and assigns it (uses it to check or uncheck the checkbox) cbxProfileTelekenisis.Checked = Convert.ToBoolean(nSuperHero.Telekenisis); //gets the boolean value of psychokenisis and assigns it (uses it to check or uncheck the checkbox) cbxProfilePsychokenesis.Checked = Convert.ToBoolean(nSuperHero.Psychokenisis); //Use if statements to check the gender and use selected Index of the drop down list to select it (what will be displayed when page loads) //if gender value returned is unassigned then to select this in the ddl selected index value must =0 if (GenderCheck == "Unassigned") { ddlProfileGender.SelectedIndex = 0; } //if gender value returned is Male then to select this in the ddl selected index value must =1 if (GenderCheck == "Male") { ddlProfileGender.SelectedIndex = 1; } //if gender value returned is Female then to select this in the ddl selected index value must =2 if (GenderCheck == "Female") { ddlProfileGender.SelectedIndex = 2; } //if gender value returned is Neutral then to select this in the ddl selected index value must =3 if (GenderCheck == "Neutral") { ddlProfileGender.SelectedIndex = 3; } //if gender value returned is Transgender then to select this in the ddl selected index value must =4 if (GenderCheck == "Transgender") { ddlProfileGender.SelectedIndex = 4; } //if gender value returned is Non-binary then to select this in the ddl selected index value must =5 if (GenderCheck == "Non-binary") { ddlProfileGender.SelectedIndex = 5; } }
//This function will find the superhero vehicle using the SuperHero primary key in the tblSuperHero, which is a foreign key in the tblSuperCars Boolean DisplaySuperHeroVehicle(Int32 ForeignSuperHeroIDKeyIn) { try { //declare a string to store the SuperVehicleID string SuperVehicleID = ""; //declare a string to store the SuperVehicleMake string SuperVehicleMake = ""; //declare a string to store the SuperVehicleModel string SuperVehicleModel = ""; //declare a string to store the SuperVehicleColor string SuperVehicleColor = ""; //declare a string to store the SuperVehicleLitreEngine string SuperVehicleLitreEngine = ""; //declare a string to store the SuperVehicleSunroof string SuperVehicleSunroof = ""; //declare a DateTime variable to store SuperVehicleRegistrationDateTime DateTime SuperVehicleRegistrationDateTime = Convert.ToDateTime("01 / 01 / 0001"); //declare a string to store the SuperVehicleRegistrationDate string SuperVehicleRegistrationDate = ""; //create the connection to access the database clsDataConnection mDatabase = new clsDataConnection(); //create an instance of the clsSuperVehicleCollection class to work with clsSuperVehicleCollection aVehicleCollection = new clsSuperVehicleCollection(); //invoke the function to get the vehicle data from the database and fill the SuperVehicleList object aVehicleCollection.VehicleSearchByParameter(ForeignSuperHeroIDKeyIn); //check the count of vehicles found in the database that match for the SuperHeroID is 1 //each superhero has only one vehicle so there should only be one SuperVehicle entry in the DataTable at index=0 //get the SuperVehicleID and store this in the SuperVehicleID string variable SuperVehicleID = Convert.ToString(aVehicleCollection.SuperVehicleList[0].VehicleID); //get the SuperVehicleMake and store this in the SuperVehicleMake string variable SuperVehicleMake = Convert.ToString(aVehicleCollection.SuperVehicleList[0].VehicleMake); //get the SuperVehicleModel and store this in the SuperVehicleModel string variable SuperVehicleModel = Convert.ToString(aVehicleCollection.SuperVehicleList[0].VehicleModel); //get the SuperVehicleColor and store this in the SuperVehicleColor string variable SuperVehicleColor = Convert.ToString(aVehicleCollection.SuperVehicleList[0].VehicleColor); //get the SuperVehicleLitreEngine and store this in the SuperVehicleLitreEngine string variable SuperVehicleLitreEngine = Convert.ToString(aVehicleCollection.SuperVehicleList[0].VehicleLitreEngine); //if the SuperVehicleSunroof boolean value is true then it has a Sunroof else sunroof is blank if (aVehicleCollection.SuperVehicleList[0].VehicleSunroof) { SuperVehicleSunroof = " with sunroof, "; } else { SuperVehicleSunroof = ", "; } //get the DateTime of the VehicleRegistrationDate SuperVehicleRegistrationDateTime = aVehicleCollection.SuperVehicleList[0].VehicleRegistrationDate; //convert the registration date to a suitable format and stores it back in SuperVehicleRegistration //the clsSuperHero class contains a method to format the date clsSuperHero dateSuperHero = new clsSuperHero(); //format the datetime variable and store it in the string variable SuperVehicleRegistrationDate = dateSuperHero.FormatDate(SuperVehicleRegistrationDateTime); //Concatenate the results and display the string in the lable lblDefaultSuperCarDetails.Text = "Vehicle ID [" + SuperVehicleID + "] " + "A " + SuperVehicleColor + ", " + SuperVehicleLitreEngine + "Litre, " + SuperVehicleMake + " " + SuperVehicleModel + SuperVehicleSunroof + "registered on " + SuperVehicleRegistrationDate; //return true the code works return(true); } catch { //if the code doesnt work return false return(false); } }
protected void btnProfileSave_Click(object sender, EventArgs e) { ///[--week10--]this function handles the click event of the Save button ///it create instance of the clsSuperHeroCollection class and calls it SuperHero clsSuperHeroCollection theSuperHeroCollection = new clsSuperHeroCollection(); //declares the variables to store the form data for new SuperHero string SuperHeroID = lblProfileSuperHeroID.Text; //get the nickname from forms textbox and store in associated string variable string Nickname = tbxProfileName.Text; //get the gender from forms dropdown list and store in associated string variable string Gender = ddlProfileGender.Text; //get the height from forms textbox and store it in the associated string variable string Height = tbxProfileHeight.Text; //get the weight from forms textbox and store it in the associated string variable string Weight = tbxProfileWeight.Text; //get the BirthDate from forms textbox and store it in associated string variable string BirthDate = tbxProfileBirthDate.Text; //get the City drop down list SelectedValue and store it in associated string variable Int32 CityNo = Convert.ToInt32(ddlProfileCity.SelectedValue); //get city name from ddl and assign it to the citName string variable string CityName = Convert.ToString(ddlProfileCity.SelectedItem); //string variable to store concatenated error messages string CheckNoValidationErrors = ""; //DateTime type variable declaration and initialisation to be used to store The BirthDate in DateTime format DateTime TheBirthDate = Convert.ToDateTime("01/01/0001"); //int type variable declaration and initialisation of variable to store calculated age (calculated using current age and date of birth) Int32 Age = 0; // int type variable declaration and initialisation of variable to store integer value of weight Int32 Weight_kg = 0; //Decimal variable to store the heights decimal value decimal Height_m = 0; //declaration of variables to store boolean value for speed Boolean Speed = cbxProfileSpeed.Checked; //declaration of variables to store boolean value for strength Boolean Strength = cbxProfileStrength.Checked; //declaration of variables to store boolean value for flight Boolean Flight = cbxProfileFlight.Checked; //declaration of variables to store boolean value for teleportation Boolean Teleportation = cbxProfileTeleportation.Checked; //declaration of variables to store boolean value for invisibility Boolean Invisibility = cbxProfileInvisibility.Checked; //declaration of variables to store boolean value for telekenisis Boolean Telekenisis = cbxProfileTelekenisis.Checked; //declaration of variables to store boolean value for pychokenisis Boolean Psychokenisis = cbxProfilePsychokenesis.Checked; //create and instance of the clsSuperHero clsSuperHero aSuperHero = new clsSuperHero(); /// validate the data from the form using the ValidateSuperHeroData function /// and returned validation error messages and store in CheckNoValidationErrors string CheckNoValidationErrors = aSuperHero.ValidateSuperheroData(SuperHeroID, Nickname, Height, Weight, BirthDate, CityName); //If theres no validation errors then do this section of code: if (CheckNoValidationErrors == "") { //If there are no validation errors then do some calculations or conversions that we need //find age using birthday and current date Age = aSuperHero.CalculateAge(Convert.ToDateTime(BirthDate), DateTime.Today); //Converts age from integer to string and displays the age as text lblProfileCalculatedAge.Text = Convert.ToString(Age); //convert the weight into integer and store in the weight_kg integer variable Weight_kg = Convert.ToInt32(Weight); //convert the height in to integer and store in height_m decimal variable Height_m = Convert.ToDecimal(Height); //convert the birth date into a datatime variable and store in TheBirthDate DateTime variable TheBirthDate = Convert.ToDateTime(BirthDate); //convert SuperHeroID in to an integer and store in integer variable theSuperHeroID Int32 theSuperHeroID = Convert.ToInt32(SuperHeroID); //Check the label for SuperHeroID has no entered number (==0). if (theSuperHeroID == 0) { //[03/02/2019] assign the values to the variables of the ThisSuperHero property. //No need to include the SuperHeroID as we are creating a new entry, the ID is automatically assigned in tblSuperHero //put the Nickname into the Nickname property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Nickname = Nickname; //put the Gender into the Gender property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Gender = Gender; //put the Height_m into the Height_m property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Height_m = Height_m; //put the Weight_kg into the Weight_kg property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Weight_kg = Weight_kg; //put the TheBirthDate into the TheBirthDate property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.BirthDate = TheBirthDate; //put the Age into the Age property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Age = Age; //put the CityNo into the CityNo property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.CityNo = CityNo; //put the Speed into the Speed property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Speed = Speed; //put the Strength into the Strength property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Strength = Strength; //put the Flight into the Flight property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Flight = Flight; //put the Teleportation into the Teleportation property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Teleportation = Teleportation; //put the Invisibility into the Invisibility property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Invisibility = Invisibility; //put the Telekenisis into the Telekenisis property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Telekenisis = Telekenisis; //put the Psychokenisis into the Psychokenisis property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Psychokenisis = Psychokenisis; try { //try this code to see if form fields have correct data type and no empty fields to cause errors //Following code creates a new entry in the database if no value SuperHeroID is in the textbox txtProfileSuperHeroID //Use onSuperHero ot invoke the Add() method of the object by passing it the data from the form, store return value in Sucess if the Boolean success = theSuperHeroCollection.Add(); //check if the above value is true if (success == true) { //[23/01/2019] //int count = 0; //while(count <= 10000000) ///this code was suppose to provide a delay but did not work in that way. //The idea was to display the message "saved successfully" for an instance so it could be seen by user before redirection. //{ //lblProfileMessage.Text = "Saved Successfully"; //MessageBox.Show("Saved successfully"); //this messagebox code did not work //} //if the superhero was added successfully then send to confirmation page Response.Redirect("SaveConfirmation.aspx"); } else { //if the superhero was not added then display an error lblProfileMessage.Text = "Error1:~ Save Failed.\n " + CheckNoValidationErrors; //[25/01/1029] had to add the ValidationErrors on the end; } } catch { //if the above try statement fails then sidplay an error lblProfileMessage.Text = "Error2:~ Failed to execute Add(). "; } } //[22/01/2019] if theSuperHeroID is not 0 then do this if (theSuperHeroID > 0) { //[03/02/2019] assign the values to the variables of the ThisSuperHero property, this time include the SuperHeroID, //this is used to select the row to update in the tblSuperHero table //put the SuperHeroID into the SuperHeroID property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.SuperHeroID = theSuperHeroID; //put the Nickname into the Nickname property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Nickname = Nickname; //put the Gender into the Gender property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Gender = Gender; //put the Height_m into the Height_m property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Height_m = Height_m; //put the Weight_kg into the Weight_kg property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Weight_kg = Weight_kg; //put the TheBirthDate into the TheBirthDate property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.BirthDate = TheBirthDate; //put the Age into the Age property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Age = Age; //put the CityNo into the CityNo property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.CityNo = CityNo; //put the Speed into the Speed property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Speed = Speed; //put the Strength into the Strength property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Strength = Strength; //put the Flight into the Flight property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Flight = Flight; //put the Teleportation into the Teleportation property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Teleportation = Teleportation; //put the Invisibility into the Invisibility property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Invisibility = Invisibility; //put the Telekenisis into the Telekenisis property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Telekenisis = Telekenisis; //put the Psychokenisis into the Psychokenisis property of the ThisSuperHero object theSuperHeroCollection.ThisSuperHero.Psychokenisis = Psychokenisis; try { ///[24/01/2019] This code is similar to the Add function. It has been ammended to update an entry. ///This time it uses Update funtion instead of Add Boolean success = theSuperHeroCollection.Update(); //check if the value of success is true if (success == true) { //[23/01/2019] //int count = 0; //while(count <= 10000000) ///this code was suppose to provide a delay but did not work in that way. //The idea was to display the message "saved successfully" for an instance so it could be seen by user before redirection. //{ //lblProfileMessage.Text = "Saved Successfully"; //MessageBox.Show("Saved successfully"); //this messagebox code did not work //} //since above did not work decided to send to confirm page Response.Redirect("SaveConfirmation.aspx"); } else { //if sucess is false the superheor wasnt updated the display an error lblProfileMessage.Text = "Error3:~ Save Failed.\n " + CheckNoValidationErrors; //[25/01/1029] had to add the ValidationErrors on the end } } catch { //if the try statement fails display an error lblProfileMessage.Text = "Error4:~ Failed to execute Update()."; } } else { //if SuperHeroID is less than 0 then display an error lblProfileMessage.Text = "Error5:~ Invalid SuperHero ID."; } } else { //if there are validation errors then display the errror messages lblProfileMessage.Text = CheckNoValidationErrors; } }