Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["loggedIn"] == "true" && Session["userType"] == "user" && Session["status"] == "normal")
            {
                currUser       = fetchUserObject(Session["userID"].ToString());
                nameLabel.Text = "Hello " + currUser.getName();

                // Check if page refresh was due to a successful action
                if (Session["success"] == "giveRating")
                {
                    general_dialog.InnerHtml = "You have successfully rated the user";
                    general_dialog.Visible   = true;
                    Session["success"]       = "";
                }

                else if (Session["success"] == "msgSent")
                {
                    general_dialog.InnerHtml = "You have successfully sent a message";
                    general_dialog.Visible   = true;
                    Session["success"]       = "";
                }

                else if (Session["success"] == "tourEdited")
                {
                    general_dialog.InnerHtml = "You have successfully edited the tour";
                    general_dialog.Visible   = true;
                    Session["success"]       = "";
                }

                else if (Session["success"] == "tourCreated")
                {
                    general_dialog.InnerHtml = "You have successfully created the tour";
                    general_dialog.Visible   = true;
                    Session["success"]       = "";
                }

                else if (Session["success"] == "editProfile")
                {
                    general_dialog.InnerHtml = "You have successfully edited your profile";
                    general_dialog.Visible   = true;
                    Session["success"]       = "";
                }

                SqlConnection conn   = null;
                SqlCommand    cmd    = null;
                SqlDataReader reader = null;


                conn = new SqlConnection(ConfigurationManager.ConnectionStrings["vetoTours"].ToString());

                conn.Open();

                // Pull Tour Guides Created Tours
                currUser.getCreatedTours(createdToursView);
                conn.Close();



                // Fetch available Tours
                List <tour> availableTours = new List <tour>();
                availableTours = fetchTours();

                if (Session["filterType"] == "Price" && Session["criteria"] == "Ascending")
                {
                    availableTours.Sort((x, y) => x.getPrice().CompareTo(y.getPrice()));
                }

                else if (Session["filterType"] == "Price" && Session["criteria"] == "Descending")
                {
                    availableTours.Sort((x, y) => - 1 * x.getPrice().CompareTo(y.getPrice()));
                }

                else if (Session["filterType"] == "Rating" && Session["criteria"] == "Ascending")
                {
                    availableTours.Sort((x, y) => x.fetchTourGuideRating().CompareTo(y.fetchTourGuideRating()));
                }

                else if (Session["filterType"] == "Rating" && Session["criteria"] == "Descending")
                {
                    availableTours.Sort((x, y) => - 1 * x.fetchTourGuideRating().CompareTo(y.fetchTourGuideRating()));
                }

                var _bind = from a in availableTours
                            select new
                {
                    Tour_ID          = a.getTourID(),
                    Created_By       = a.getUserID(),
                    Rating           = a.fetchTourGuideRating(),
                    Tour_Name        = a.getTourName(),
                    Tour_Capacity    = a.getCapacity(),
                    Tour_Location    = a.getLocation(),
                    Tour_Description = a.getTourDescription(),
                    Start_Date       = a.getStartDate(),
                    End_Date         = a.getEndDate(),
                    Price            = a.getPrice(),
                    Status           = a.getStatus()
                };



                availableToursView.DataSource = _bind;
                availableToursView.DataBind();



                // Pull all booked tours that have yet to start
                currUser.getUpcomingBookings(bookedToursView);

                // Pull booking history where the events have ended
                currUser.getBookingHistory(bookingHistoryView);

                // Pull User Profile Information
                currUser.getProfileDetails(myProfileView);

                // Fetch user Inbox
                List <chat> allMessages = new List <chat>();
                allMessages       = fetchMessages();
                pmInbox.InnerHtml = "";

                foreach (chat msg in allMessages)
                {
                    pmInbox.InnerHtml += ("Sender: " + msg.getSender() + "<br/>" + "Time Sent:" + msg.getDateTime().ToString() + "<br/> Subject: " + msg.getSubject() + "<br/>" + "Message: " + "<br />" + "<textarea rows=\"4\" cols=\"50\" readonly>" + msg.getMessage() + "</textarea>" + "<br/> <hr> <br/>");
                }
            }

            else if (Session["loggedIn"] == "true" && Session["userType"] == "user" && Session["status"] == "suspended")
            {
            }


            else if (Session["loggedIn"] == "true" && Session["userType"] == "admin")
            {
                currAdmin = fetchAdminObject(Session["userID"].ToString());
                if (Session["success"] == "adminEditUser")
                {
                    adminDialog.InnerHtml = "You have successfully edited the user";
                    adminDialog.Visible   = true;
                    Session["success"]    = "";
                }

                if (Session["success"] == "adminCreateUser")
                {
                    adminDialog.InnerHtml = "You have successfully created the user";
                    adminDialog.Visible   = true;
                    Session["success"]    = "";
                }

                if (Session["success"] == "adminSuspendUser")
                {
                    adminDialog.InnerHtml = "You have successfully suspended the user";
                    adminDialog.Visible   = true;
                    Session["success"]    = "";
                }


                // Fetch all currently registered users
                List <user> allUsers = new List <user>();
                allUsers = fetchUsers();

                var _bind = from a in allUsers
                            select new
                {
                    User_ID              = a.getUserID(),
                    Name                 = a.getName(),
                    Email                = a.getEmail(),
                    Phone_Number         = a.getPhoneNumber(),
                    Personal_Description = a.getPersonalDescription(),
                    status               = a.getStatus()
                };
                foreach (GridViewRow row in this.editUserView.Rows)
                {
                    row.Style["color"]             = "White";
                    row.Style[" background-color"] = "Black";
                    break;
                }
                editUserView.DataSource = _bind;
                editUserView.DataBind();
            }
        }