protected void btnSubmit_Click(object sender, EventArgs e) { //initialize the random number generator Random r = new Random(); //set the new password from random number generator int newPw = r.Next(1, 100000); int result = 0; //initialze the result bool found = true; //initialize the boolean is true if (ddlCustOrg.SelectedItem.Text == "Customer") //when user choose to reset password for customer { //get the customer from database Customer c = CustomerDB.getACustomerByEmail(tbxEmail.Text); if (c != null) //if the customer is not null { c.Password = newPw.ToString(); //set the new password result = CustomerDB.updateCustomer(c); //update into customer database } else { found = false; //cannot find the customer from the database } } else if (ddlCustOrg.SelectedItem.Text == "Hotel Owner") //when user choose to reset password for hotel owner { Hotel h = HotelDB.getAHotelByEmail(tbxEmail.Text); //get the hotel owner from database if (h != null) //if the hotel is not null { h.Password = newPw.ToString(); //set the new password result = HotelDB.updateHotel(h); //update into hotel database } else { found = false; //cannot find the hotel owner from the database } } else if (ddlCustOrg.SelectedItem.Text == "Attraction Owner") //when user choose to reset password for attraction { Attraction a = AttractionDB.getAAttractionByEmail(tbxEmail.Text); //get the attraction owner from database if (a != null) //if the attraction is not null { //set the new password a.Password = newPw.ToString(); //update into attraction database result = AttractionDB.updateAttraction(a); } else { found = false; //canoot find the attraction from the database } } else if (ddlCustOrg.SelectedItem.Text == "Restaurant Owner") //when user choose to reset password for restaurant owner { Restaurant ra = RestaurantDB.getARestaurantByEmail(tbxEmail.Text); //get the restaurant owner from database if (ra != null) //if the restaurant is not null { //set the new password ra.Password = newPw.ToString(); //update into restaurant database result = RestaurantDB.updateRestaurant(ra); } else { found = false; //cannot find the restaurant from the database } } if (found) //if found { if (result > 0) //result cannot be zero { try //use try and catch to send an email to the organization and customer { SmtpClient client = new SmtpClient("smtp.gmail.com"); client.EnableSsl = true; client.Credentials = new NetworkCredential("*****@*****.**", "smart-travel1005"); MailMessage msg = new MailMessage("*****@*****.**", tbxEmail.Text); msg.Subject = "New Password"; msg.Body = "Your new password is: " + newPw.ToString() + "\r\n Please change your password again"; client.Send(msg); //send an email lblOutput.Text = "New Password has been sent to your email"; return; } catch (Exception ex) { lblOutput.Text = "Active internet connection needed!"; //show error message when user do not have internet connection return; } } else { lblOutput.Text = "Fails to update the password"; //show error message when user cannot update the password return; } } lblOutput.Text = "Account with this email address does not exist. Sign up for the account"; //if the account is not exist with our website }
protected void btnUpdate_Click(object sender, EventArgs e) { if (Session["user"] != null) { //calling member class to the session of user Customer c = (Customer)Session["user"]; c.Name = tbxName.Text; c.Gender = tbxGender.Text; c.DateOfBirth = Convert.ToDateTime(tbxDOB.Text); c.Address = tbxAddress.Text; c.PostalCode = tbxPostalCode.Text; c.PersonalID = tbxPID.Text; c.Nationality = tbxNationality.Text; c.PhoneNumber = Convert.ToInt32(tbxPhone.Text); c.CustEmail = tbxEmail.Text; c.Password = tbxPassword.Text; Session["user"] = c; int row = CustomerDB.updateCustomer(c); //display an output lblOutput.Text = "Update successfully!"; databindedCust(); } else if (Session["userAttraction"] != null) { Attraction a = (Attraction)Session["userAttraction"]; a.Name = tbxCName.Text; a.RegID = tbxRID.Text; a.Address = tbxCAddress.Text; a.PostalCode = tbxCPostalCode.Text; a.City = tbxCCity.Text; a.Country = tbxCCountry.Text; a.Password = tbxCpass.Text; a.ContactNo = tbxCPhone.Text; a.OrgEmail = tbxCEmail.Text; a.Password = tbxCPassword.Text; a.Description = tbxDesc.Text; a.OpeningHours = tbxOHour.Text; string imagefile = "notavailable"; if (FileUpload1.HasFile) { imagefile = FileUpload1.FileName; FileUpload1.SaveAs(Server.MapPath("../images/" + imagefile)); a.Photo = FileUpload1.FileName; imgProfile.ImageUrl = "../images/" + a.Photo; } Session["userAttraction"] = a; lblOutput.Text = "Update successfully!"; int row = AttractionDB.updateAttraction(a); databindedOrg(); } else if (Session["userRestaurant"] != null) { Restaurant r = (Restaurant)Session["userRestaurant"]; r.Name = tbxCName.Text; r.RegID = tbxRID.Text; r.Address = tbxCAddress.Text; r.PostalCode = tbxCPostalCode.Text; r.City = tbxCCity.Text; r.Country = tbxCCountry.Text; r.Password = tbxCpass.Text; r.ContactNo = tbxCPhone.Text; r.OrgEmail = tbxCEmail.Text; r.Password = tbxCPassword.Text; r.Description = tbxDesc.Text; r.OpeningHours = tbxOHour.Text; string imagefile = "notavailable"; if (FileUpload1.HasFile) { imagefile = FileUpload1.FileName; FileUpload1.SaveAs(Server.MapPath("../images/" + imagefile)); r.Photo = FileUpload1.FileName; imgProfile.ImageUrl = "../images/" + r.Photo; } r.License = tbxLicenseNo.Text; Session["userRestaurant"] = r; lblOutput.Text = "Update successfully!"; int row = RestaurantDB.updateRestaurant(r); databindedROrg(); } else if (Session["userHotel"] != null) { Hotel h = (Hotel)Session["userHotel"]; h.Name = tbxCName.Text; h.RegID = tbxRID.Text; h.Address = tbxCAddress.Text; h.PostalCode = tbxCPostalCode.Text; h.City = tbxCCity.Text; h.Country = tbxCCountry.Text; h.Password = tbxCpass.Text; h.ContactNo = tbxCPhone.Text; h.OrgEmail = tbxCEmail.Text; h.Password = tbxCPassword.Text; h.Description = tbxDesc.Text; string imagefile = "notavailable"; if (FileUpload1.HasFile) { imagefile = FileUpload1.FileName; FileUpload1.SaveAs(Server.MapPath("../images/" + imagefile)); h.Photo = FileUpload1.FileName; imgProfile.ImageUrl = "../images/" + h.Photo; } h.License = tbxOHour.Text; Session["userHotel"] = h; lblOutput.Text = "Update successfully!"; int row = HotelDB.updateHotel(h); databindedHOrg(); } }