protected void AddBookButton_Click(object sender, EventArgs e) { try { //Create service reference object Assignment5ServiceRefs.Service1Client serviceRef = new Assignment5ServiceRefs.Service1Client(); //Check if any of the fields are empty if (TitleTb.Text.Equals("") || IsbnTb.Text.Equals("") || DescriptionTb.Text.Equals("")) { ErrorLbl.Text = "All the fields are required."; } else { //Call the AddBooks operation from the service string status = serviceRef.AddBooks(IsbnTb.Text, TitleTb.Text, DescriptionTb.Text); if (status.Equals("true")) { ErrorLbl.Text = "Book added succesfully"; } else { ErrorLbl.Text = "Unexpected error occured!"; } } } catch { ErrorLbl.Text = "Unexpected error occured!"; } }
protected void LoginButton_Click(object sender, EventArgs e) { try { CryptoClass crypto = new CryptoClass(); String id = userIdTb.Text; String password = crypto.Encrypt(PasswordTb.Text); Assignment5ServiceRefs.Service1Client serviceRef = new Assignment5ServiceRefs.Service1Client(); if (serviceRef.checkUserCredentials(id, password)) { HttpCookie userCookies = new HttpCookie("userInfo"); userCookies["id"] = userIdTb.Text; userCookies.Expires = DateTime.Now.AddMonths(6); Response.Cookies.Add(userCookies); FormsAuthentication.RedirectFromLoginPage(userIdTb.Text, Persistent.Checked); Session["type"] = "member"; userCookies["type"] = "member"; Response.Redirect("~/MemberPages/Member.aspx"); } else { LoginErrorLbl.Text = "Invalid credentials!"; } } catch { LoginErrorLbl.Text = "Invalid credentials!"; } }
//Add the current title to the book tag in the user.xml protected void BorrowButton_Click(object sender, EventArgs e) { try { //Create a service reference object Assignment5ServiceRefs.Service1Client client = new Assignment5ServiceRefs.Service1Client(); //Get the user id from the cookie HttpCookie userCookies = Request.Cookies["userInfo"]; String userId = ""; if (!(userCookies == null) && !(userCookies["id"] == "")) { userId = userCookies["id"]; String title = BookList.SelectedItem.Text; //call the opearation in the service to add the book tag if (client.addBorrowed(title, userId)) { BorrowStatusLbl.Text = "Book borrowed successfully!"; } else { BorrowStatusLbl.Text = "Unexpected Error Occured!"; } } else { BorrowStatusLbl.Text = "Unexpected Error Occured!"; } } catch { BorrowStatusLbl.Text = "Unexpected Error Occured!"; } }
protected void LogInButton_Click(object sender, EventArgs e) { try { //Create object of Crypto class CryptoClass crypto = new CryptoClass(); String id = UserNameTb.Text; //Encrypt the password String password = crypto.Encrypt(PasswordTb.Text); //Create object of reference class Assignment5ServiceRefs.Service1Client serviceRef = new Assignment5ServiceRefs.Service1Client(); //get the role from the Staff.xml string role = serviceRef.checkUserCredentialsForStaff(id, password); //if the role is not empty if (!role.Equals("")) { //Create a cookie and store the user id HttpCookie userCookies = new HttpCookie("userInfo"); userCookies["id"] = UserNameTb.Text; //Cookie expires in 6 months userCookies.Expires = DateTime.Now.AddMonths(6); Response.Cookies.Add(userCookies); //Redirect to the staff page after authentication FormsAuthentication.RedirectFromLoginPage(UserNameTb.Text, Persistent.Checked); //Store the role in the session Session["type"] = role; userCookies["type"] = role; //If the role is staff, redirect to the staff page if (role.Equals("staff")) { Response.Redirect("~/StaffPage2/StaffPage.aspx"); } //else if the role is admin, redirect to the admin page else if (role.Equals("admin")) { Response.Redirect("~/StaffPage1/AdminPage.aspx"); } //else redirect to the public default page else { Response.Redirect("~/Default.aspx"); } } //Print error message if the credentials are invalid else { LoginErrorLbl.Text = "Invalid credentials!"; } } catch { LoginErrorLbl.Text = "Invalid credentials!"; } }
protected void searchButton_Click(object sender, EventArgs e) { try { //Get the latitude and longitude from the given zipcode Assignment5ServiceRefs.Service1Client serviceRefs = new Assignment5ServiceRefs.Service1Client(); String zipCode = zipCodeTB.Text; String[] latLong = serviceRefs.getLatLong(zipCode); if (latLong[0].Equals("false")) { LibrariesLabel.Text = "Invalid Zipcode"; } else { //Get the place id of athe nearby libraries String locationIdQuery = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + latLong[0] + "," + latLong[1] + "&type=library&rankby=distance&key=" + API_KEY; //Create a web client for the http get operation WebClient client = new WebClient(); //Get the result in JSON format string response = client.DownloadString(locationIdQuery); StringBuilder addsb = new StringBuilder(); dynamic jsonReader = JObject.Parse(response); int length = jsonReader.results.Count < 5 ? jsonReader.results.Count : 5; //If the count is zero, theer are no libraries in the vicinity if (length == 0) { LibrariesLabel.Text = "No Libraries within 30 miles."; } else { for (int i = 0; i < length; i++) { //Get the store id from the JSON String placeId = jsonReader.results[i].place_id; //Construct a query to obtain the address from the place id string addressQuery = "https://maps.googleapis.com/maps/api/place/details/json?placeid=" + placeId + "&key=" + API_KEY; //Get the address in JSON format string addResponse = client.DownloadString(addressQuery); dynamic addJson = JObject.Parse(addResponse); String libraryName = jsonReader.results[i].name; addsb.Append(libraryName); addsb.Append(","); addsb.Append(addJson.result.adr_address); addsb.Append("<br/><br/>"); } LibrariesLabel.Text = addsb.ToString(); } } } catch (Exception exc) { LibrariesLabel.Text = exc.Message; } }
protected void signUpButton_Click(object sender, EventArgs e) { try { CryptoClass crypto = new CryptoClass(); Assignment5ServiceRefs.Service1Client serviceRef = new Assignment5ServiceRefs.Service1Client(); if (!UserIdTb.Text.ToString().Equals("") && !NameTb.Text.ToString().Equals("") && !PasswordTb.Text.ToString().Equals("") && !CardNoTb.Text.ToString().Equals("")) { String status = serviceRef.SignUpMembers(UserIdTb.Text, crypto.Encrypt(PasswordTb.Text), NameTb.Text, CardNoTb.Text); if (status.Equals("UserIdTaken")) { UserIdErrorLbl.Text = "User Id is already taken"; } else if (status.Equals("false")) { UserIdErrorLbl.Text = "An exception occured during sign up."; } else { Session["name"] = NameTb.Text; FormsAuthentication.RedirectFromLoginPage(NameTb.Text, true); Response.Redirect("~/MemberPages/Member"); } } else { if (UserIdTb.Text.ToString().Equals("")) { UserIdErrorLbl.Text = "User Id is required"; } if (NameTb.Text.ToString().Equals("")) { NameErrorLbl.Text = "Name is required"; } if (PasswordTb.Text.ToString().Equals("")) { PasswordErrorLbl.Text = "Password is required"; } if (CardNoTb.Text.ToString().Equals("")) { CardErrorLbl.Text = "Card Number is required"; } } } catch { UserIdErrorLbl.Text = "An exception occured during sign up."; } }
protected void DetailButton_Click(object sender, EventArgs e) { try { //Get the details of the book from the title Assignment5ServiceRefs.Service1Client client = new Assignment5ServiceRefs.Service1Client(); String name = BookList.SelectedItem.Text; String[] details = client.getBookDetails(name); TitleLbl.Text = name; IsbnLbl.Text = details[0]; DescLbl.Text = details[1]; } catch { TitleLbl.Text = "Unexpected error occured!"; } }
protected void Page_Load(object sender, EventArgs e) { //Check if the user id is present in the cookie try { HttpCookie userCookies = Request.Cookies["userInfo"]; String type = ""; //Get the role of the user from the session if (Session["type"] != null) { type = Session["type"].ToString(); } //If there are no cookies, then redirect to Login page if (userCookies == null || userCookies["id"] == "" || userCookies["type"] == "staff" || userCookies["type"] == "admin" || userCookies["type"] == "") { Response.Redirect("~/MembersLogin.aspx"); } //Redirect to login page if the user's role is admin or staff else if (type.Equals("staff") || type.Equals("admin")) { Response.Redirect("~/MembersLogin.aspx"); } else { if (!Page.IsPostBack) { if (!(userCookies == null) && !(userCookies["id"] == "")) { idLbl.Text = userCookies["id"]; } //Get all the books from the Books.xml Assignment5ServiceRefs.Service1Client client = new Assignment5ServiceRefs.Service1Client(); ArrayList bookList = new ArrayList(client.getAllBooks()); foreach (string title in bookList) { BookList.Items.Add(title); } } } } catch { } }
protected void Page_Load(object sender, EventArgs e) { try { //check if the user id is in the cookie HttpCookie userCookies = Request.Cookies["userInfo"]; //Get the role of the user from the cookie String type = ""; if (Session["type"] != null) { type = Session["type"].ToString(); } //Redirect to login page if the id is absent if (userCookies == null || userCookies["id"] == "" || userCookies["type"] == "member" || userCookies["type"] == "admin" || userCookies["type"] == "") { Response.Redirect("~/StaffLogin.aspx"); } //Redirect to login page if the role is incorrect else if (type.Equals("member") || type.Equals("admin")) { Response.Redirect("~/StaffLogin.aspx"); } else { if (!Page.IsPostBack) { if (!(userCookies == null) && !(userCookies["id"] == "")) { idLbl.Text = userCookies["id"]; } //Create an object of service reference Assignment5ServiceRefs.Service1Client client = new Assignment5ServiceRefs.Service1Client(); //Transform the user and the book xml files UsersInfoLbl.Text = client.transformationMembers(); BooksInfoLbl.Text = client.transformationBooks(); } } } catch {} }