コード例 #1
0
    protected void SubmitImgBtn_Click(object sender, ImageClickEventArgs e)
    {
        //This code updates the password of the user
        //Open a connection to the database
        UseDataBase usedb = new UseDataBase();

        usedb.ConnectDataBase();

        //Query the database to see if the record exists using the information provided by the user
        SqlDataReader userInfoReader = usedb.ExecuteQuery("SELECT * FROM [UserInformation] WHERE [UserEmail] = '" + EmailTxtb.Text.Replace("'", "") + "' AND [UserQuestion] = '" + SecurityQuestionDdl.SelectedValue.ToString() + "' AND [UserAnswer] = '" + AnswerTxtb.Text.Replace("'", "") + "'");

        if (userInfoReader != null && userInfoReader.HasRows)
        {
            //Close the datareader
            userInfoReader.Close();
            //Update the password of the user based on the information provided by the user
            usedb.ExecuteCommand("UPDATE [UserInformation] SET [UserPassword] = '" + NewPasswordTxtb.Text.Replace("'", "") + "' WHERE [UserEmail] = '" + EmailTxtb.Text.Replace("'", "") + "' AND [UserQuestion] = '" + SecurityQuestionDdl.SelectedValue.ToString() + "' AND [UserAnswer] = '" + AnswerTxtb.Text.Replace("'", "") + "'");

            //Indicate success
            ReportBackLble.Text = "Your password has successfully been updated";
        }
        else
        {
            //Close the datareader
            userInfoReader.Close();

            //Idicate the record does not exist
            ReportBackLble.Text = "The Email/Security question or answer is not correct.";
        }
    }
コード例 #2
0
    public void WriteLine(string bookTitle, string bookAuthor, string userId, int userRating)
    {
        //String used to store the users email address
        string userEmail = null;

        //Open a new instance of the database class to retrieve the user email
        UseDataBase usedb = new UseDataBase();

        //Connect to the database
        usedb.ConnectDataBase();
        //Query the database and store the dataset as a DataReader
        DataTableReader EmailReader = usedb.ExecuteQuery("SELECT [UserEmail] FROM [UserInformation] WHERE [UserId] = '" + userId.ToString() + "'").CreateDataReader();

        while (EmailReader.Read())
        {
            //Store the user email address
            userEmail = EmailReader.GetString(0);
        }

        //Instanate a new streamReader class to write the rating information to a log file
        StreamWriter sw = new StreamWriter("C:/Users/Thane_Acheron/Desktop/ThaneAcheron/CTI/Exercises PrePracs and Projects/C#/C# Advanced/C#/Exercieses/CTIQuestionOne/CTIQuestionOne/Features.txt");

        //Write to logfile
        sw.WriteLine("User E-mail: " + userEmail + ", Book Title: " + bookTitle + ", Book Author: " + bookAuthor + ", Rating: " + userRating.ToString() + "%" + ", Date/Time: " + DateTime.Now.ToString());

        //Clear up all resources
        //Close the stream reader
        sw.Close();
        //Close the connection to the database
        usedb.Close();
        //Close the dataReader
        EmailReader.Close();
    }
コード例 #3
0
ファイル: WriteToFile.cs プロジェクト: ThaneAcheron/BookWorm
    public void WriteLine(string bookTitle, string bookAuthor, string userId, int userRating)
    {
        //String used to store the users email address
        string userEmail = null;

        //Open a new instance of the database class to retrieve the user email
        UseDataBase usedb = new UseDataBase();

        //Connect to the database
        usedb.ConnectDataBase();
        //Query the database and store the dataset as a DataReader
        DataTableReader EmailReader = usedb.ExecuteQuery("SELECT [UserEmail] FROM [UserInformation] WHERE [UserId] = '" + userId.ToString() + "'").CreateDataReader();

        while (EmailReader.Read())
        {
            //Store the user email address
            userEmail = EmailReader.GetString(0);
        }

        //Instanate a new streamReader class to write the rating information to a log file
        StreamWriter sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + @"\log.txt", true);

        //Write to logfile
        sw.WriteLine("User E-mail: " + userEmail + ", Book Title: " + bookTitle + ", Book Author: " + bookAuthor + ", Rating: " + userRating.ToString() + "%" + ", Date/Time: " + DateTime.Now.ToString());

        //Clear up all resources
        //Close the stream reader
        sw.Close();
        //Close the connection to the database
        usedb.Close();
        //Close the dataReader
        EmailReader.Close();
    }
コード例 #4
0
    public void CalculateAndStoreAverage(int UserScore, string BookId, string UserId)
    {
        //Used to store the current average rating of the book
        int AverageRating = 0;
        int NumberOfRates = 0;
        int NewRating     = 0;

        //Connect to the database
        UseDataBase usedb = new UseDataBase();

        usedb.ConnectDataBase();

        //Retreive the number of people who have rated the book
        NumberOfRates = usedb.RecordNumber("SELECT * FROM [RatingInformation] WHERE [BookId] = '" + BookId.ToString() + "'") + 1;

        //Retrive the users ratings
        DataSet RatingsRead = usedb.ExecuteQuery("SELECT [Rating] FROM [RatingInformation] WHERE BookId = '" + BookId.ToString() + "'");

        //Convert the dataSet to a DataReader
        DataTableReader sqlReader = RatingsRead.CreateDataReader();

        if (sqlReader.HasRows)
        {
            //This variable is used to increment the loop
            int increment = 0;
            while (sqlReader.Read())
            {
                //Store the average rating
                AverageRating = AverageRating + sqlReader.GetInt32(increment);
                increment     = increment++;
            }
        }

        //Close the DataReader
        sqlReader.Close();

        //Calculate the new average using the old average plus the new user average devided by the number of people who have scored this book
        AverageRating = AverageRating + UserScore;
        NewRating     = AverageRating / NumberOfRates;

        //Store the new average in the BookInformation table
        usedb.ExecuteCommand("UPDATE [BookInformation] SET [BookAverageRating] = '" + NewRating + "' WHERE [BookId] = " + BookId.ToString());

        //Close the database
        usedb.Close();

        //Open a new connection
        UseDataBase storeRating = new UseDataBase();

        storeRating.ConnectDataBase();

        //Store the UsersScore in the RatingInformation table
        storeRating.ExecuteCommand("INSERT INTO [RatingInformation] ([BookId],[UserId],[Rating]) VALUES ('" + BookId.ToString() + "','" + UserId.ToString() + "','" + UserScore.ToString() + "');");

        //Close the connection
        storeRating.Close();
    }
コード例 #5
0
    protected void UpdateBtn_Click(object sender, ImageClickEventArgs e)
    {
        //This code updates the sql database based on the users input on the textboxs
        //Open the dataBase
        UseDataBase update = new UseDataBase();

        update.ConnectDataBase();

        //Update the datbase vid sqlCommand and store the result (bool) into a session variable
        Session["UpDateReport"] = update.ExecuteCommand("UPDATE [UserInformation] SET [UserName] = '" + UserNameTxtb.Text.Replace("'", "") + "', [UserEmail] = '" + this.EmailTxtb.Text.Replace("'", "") + "' ,[UserQuestion] = '" + this.SecurityQuestionDdl.Text.Replace("'", "") + "' ,[UserAnswer] = '" + this.SecurityAnswerTxtb.Text.Replace("'", "") + "' WHERE [UserId] = '" + Request.Cookies["LoggedInCookie"]["UserId"] + "'");

        //Close the database
        update.Close();

        //Refresh the page
        Response.Redirect("Account.aspx");
    }
コード例 #6
0
    protected void LoginBtn_Click(object sender, ImageClickEventArgs e)
    {
        //Create a new instance of the database class
        UseDataBase useDb = new UseDataBase();

        //Structure a query
        string queryString = "SELECT * FROM [UserInformation] WHERE UserEmail = '";

        queryString += UserEmailTxtb.Text + "' AND UserPassword = '******'; ";

        //Open a connect to the database
        useDb.ConnectDataBase();
        //Execute the query
        SqlDataReader sqlReader = useDb.ExecuteQuery(queryString);

        if (sqlReader != null && sqlReader.HasRows)
        {
            //Set up cookies if the userinformation exists.

            HttpCookie loggedInCookie = new HttpCookie("LoggedInCookie");
            loggedInCookie["LoggedIn"] = "true";
            while (sqlReader.Read())
            {
                loggedInCookie["UserId"] = sqlReader.GetInt32(0).ToString();
            }

            //If the user wishes to be kept logged in then set the expiration date
            if (KeepLoggedInChb.Checked == true)
            {
                loggedInCookie.Expires = System.DateTime.Now.AddDays(7);
            }

            Response.Cookies.Add(loggedInCookie);
            Response.Redirect("Books.aspx");
        }
        else
        {
            //Display the error message.
            ErrorLble.Visible = true;
        }

        sqlReader.Close();
        useDb.Close();
    }
コード例 #7
0
    protected void UpdateImgBtn_Click(object sender, ImageClickEventArgs e)
    {
        //Check to see if the oldpassword matches the password in the database
        UseDataBase usedb = new UseDataBase();

        usedb.ConnectDataBase();

        //Query the database to see if the password the user entered was correct
        SqlDataReader sqlReader = usedb.ExecuteQuery("SELECT [UserPassword] FROM [UserInformation] WHERE [UserId] = '" + Request.Cookies["LoggedInCookie"]["UserId"] + "' AND [UserPassword] = '" + OldPassTxtb.Text.Replace("'", "") + "'");

        if (sqlReader != null && sqlReader.HasRows)
        {
            //Close the dataReader
            sqlReader.Close();
            //Retreive the query result
            bool result = usedb.ExecuteCommand("UPDATE [UserInformation] SET [UserPassword] = '" + NewPassTxtb.Text.Replace("'", "") + "' WHERE [UserId] = '" + Request.Cookies["LoggedInCookie"]["UserId"] + "'");

            //Display a message weather the query executed successfully or not
            if (result == true)
            {
                UpdateResultLble.Text = "Your password has been updated";
            }
            else
            {
                UpdateResultLble.Text = "Something went wrong, try again in a few minuttes";
            }

            //Make sure no values are carried over
            OldPassWarningLble.Text = "";
        }
        else
        {
            //The password was incorrect, display a message to the user and close the DataReader
            sqlReader.Close();
            OldPassWarningLble.Text = "Incorrect password";
        }

        //Close the connection to the database
        usedb.Close();
    }
コード例 #8
0
    protected void SubmitImgBtn_Click(object sender, ImageClickEventArgs e)
    {
        //This code inserts a new record of user details into the UserInformation table in the database
        //Open a connection to the database
        UseDataBase insertUser = new UseDataBase();

        insertUser.ConnectDataBase();

        //Insert the new record details
        bool result = insertUser.ExecuteCommand("INSERT INTO [UserInformation] (UserName , UserEmail , UserPassword , UserQuestion , UserAnswer) VALUES ('" + UsernameTxtb.Text.Replace("'", "") + "','" + EmailTxtb.Text.Replace("'", "") + "','" + PasswordTxtb.Text.Replace("'", "") + "','" + SecurityDdl.SelectedValue.ToString() + "','" + SecurityTxtb.Text.Replace("'", "") + "')");

        //Display a report back message weather the account was sucessfully created or not
        if (result == true)
        {
            ReportBackLble.Text = "Your account was sucessfully created, enter your new login details in the login bar.";
        }
        else
        {
            ReportBackLble.Text = "Your account was not sucessfully created, please try again.";
        }

        //Close the connection to the database
        insertUser.Close();
    }
コード例 #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Check to see if the user is logged in else redirect them to the login page
        if (Request.Cookies["LoggedInCookie"] == null || (Request.Cookies["LoggedInCookie"] != null && Request.Cookies["LoggedInCookie"]["LoggedIn"] != "true"))
        {
            Response.Redirect("Register.aspx");
        }



        if (!IsPostBack)
        {
            //Set the button events
            logoutImgBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/LogoutMouseOver.png'");
            logoutImgBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/LogOutDefault.png'");

            PasswordImgBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/ChangePasswordMouseOver.jpg'");
            PasswordImgBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/ChangePasswordDefault.jpg'");

            SubmitImgBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/SubmitABookMouseOver.jpg'");
            SubmitImgBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/SubmitABookDefault.jpg'");

            UpdateBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/UpdateMouseOver.png'");
            UpdateBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/UpdateDefault.png'");

            RecoverPassImgBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/RecoverPasswordMouseOver.jpg'");
            RecoverPassImgBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/RecoverPasswordDefault.jpg'");

            //Databind the security question  to the drop down list
            //Create a new instance of the class containing the list of security questions: /App_code/ArrayCollections.cs
            ArrayList        SecurityQuestionsList = new ArrayList();
            ArrayCollections getlist = new ArrayCollections();
            SecurityQuestionsList = getlist.SecurityQuestions();

            //Set as the datasource
            SecurityQuestionDdl.DataSource = SecurityQuestionsList;

            //DataBind
            SecurityQuestionDdl.DataBind();

            //Set the textbox values to the userInfo from the database/Check to see the update report
            UseDataBase usedb = new UseDataBase();
            usedb.ConnectDataBase();

            //Data reader for the sql database
            SqlDataReader UserInfo = usedb.ExecuteQuery("SELECT [UserName],[UserPassword],[UserEmail],[UserAnswer],[UserQuestion] FROM [UserInformation] WHERE [UserId] = '" + Request.Cookies["LoggedInCookie"]["UserId"].ToString() + "'");

            //Read from the dataset and apply the values to the lables
            while (UserInfo.Read())
            {
                UserNameTxtb.Text                 = UserInfo.GetString(0);
                UserNameHeaderLble.Text           = UserInfo.GetString(0);
                EmailTxtb.Text                    = UserInfo.GetString(2);
                SecurityAnswerTxtb.Text           = UserInfo.GetString(3);
                SecurityQuestionDdl.SelectedValue = UserInfo.GetString(4);
            }

            //Close the connection to the database
            UserInfo.Close();

            //Close the datareader
            usedb.Close();
        }

        //Set the gridView to select all books containig the users Id
        SqlDataSource1.SelectCommand = "SELECT [BookImageUrl] , [BookId] , [BookName] FROM [BookInformation] WHERE [BookSubmiterId] = '" + Request.Cookies["LoggedInCookie"]["UserId"] + "'";

        // disply the report if the user has tried to update thier profile
        //Make sure no values are carried over
        UpdateReportLble.Text = "";

        if (Session["UpDateReport"] != null)
        {
            if (Session["UpDateReport"].ToString() == "True")
            {
                UpdateReportLble.Text = "Update Successful!";
            }
            else
            {
                UpdateReportLble.Text = "Something went wrong, try again in a few minuttes.";
            }
        }

        //Make sure no values are carried over
        Session["UpDateReport"] = null;
    }
コード例 #10
0
    protected void SubmitImgBtn_Click(object sender, ImageClickEventArgs e)
    {
        //Make sure the file is not larger than 800KB (File extention validation is done by a regular expression validator on the client side)
        double size = BookImageFileUpL.FileContent.Length;

        if (size > 819200)
        {
            UploadReportLble.Text = "The file is too large, it must be under 800KB.";
        }
        else
        {
            if (BookImageFileUpL.HasFile == true)
            {
                //Start a new instance of the resize class /AppCode/
                ResizeImage resize = new ResizeImage();

                //Create and store an new GUID for a unique image name
                string guid = System.Guid.NewGuid().ToString() + ".jpg";

                // Specify the upload directory
                string directory = Server.MapPath("Resources/BookImages/");

                //Store the image from the uploadFile control into memory
                Bitmap image = new Bitmap(BookImageFileUpL.FileContent);

                //Resize the image(used from the ResizeImage class) and store the resized image in a new bitmap
                Bitmap resizedImage = resize.Resize(image, 105, 150);

                // Save the new graphic file to the server
                resizedImage.Save(directory + guid);

                //Dispose the BitMaps
                image.Dispose();
                resizedImage.Dispose();

                //Set the ImgURL of the sampleImg control to display the uploaded image
                ImageSampleImg.ImageUrl = "Resources/BookImages/" + guid;

                //Show the book details panel
                BookDetailsPnl.Visible = true;
                //Apply the appropriate values to the lables
                NameValueLble.Text   = BookNameTxtb.Text;
                AuthorValueLble.Text = AuthorTxtb.Text;
                GenreValueLble.Text  = GenreDdl.SelectedValue.ToString();

                //Open a new connection to the database and insert the information entered by the user
                UseDataBase usedb = new UseDataBase();
                usedb.ConnectDataBase();
                //Insert command
                usedb.ExecuteCommand("INSERT INTO [BookInformation] (BookName , BookAuthor, BookSummary, BookGenre, BookImageUrl , BookSubmiterId , BookAverageRating) VALUES ('" + BookNameTxtb.Text.Replace("'", "") + "','" + AuthorTxtb.Text.Replace("'", "") + "','" + BookSummaryTxtb.Text.Replace("'", "") + "','" + GenreDdl.SelectedValue.ToString() + "','/Resources/BookImages/" + guid + "','" + Request.Cookies["LoggedInCookie"]["UserId"] + "' , '0' )");
                //Close the connection to the database
                usedb.Close();

                //Open a new connection to the database
                UseDataBase getName = new UseDataBase();
                getName.ConnectDataBase();

                //Store the select result in a datareader
                SqlDataReader UserName = getName.ExecuteQuery("SELECT [UserName] FROM [UserInformation] WHERE [UserId] = '" + Request.Cookies["LoggedInCookie"]["UserId"] + "'");

                //Set the submitterValueLble text to display the users name
                while (UserName.Read())
                {
                    SubmitterValueLble.Text = UserName.GetString(0);
                }

                //Close the connection to the database/DataReader
                getName.Close();
                UserName.Close();

                //Report back to the user
                UploadReportLble.Text = "Submittion successful, Thank you!";
            }
        }
    }
コード例 #11
0
    //Event used to load all the required infromation from the database to display the book details
    protected void Page_Load(object sender, EventArgs e)
    {
        //The following variable is used to store the userId from the BookInformation DataTable
        int userId = 0;

        //Check the cookies to see if the user is loggedin otherwise redirect to Register.aspx 
        if (Request.Cookies["LoggedInCookie"] == null || (Request.Cookies["LoggedInCookie"] != null && Request.Cookies["LoggedInCookie"]["LoggedIn"] != "true"))
        {
            Response.Redirect("Register.aspx");
        }

        //Check if the user has already rated the book if so; disable the stars to prevent the user from rating the book again
          //Create a connection to the database
        UseDataBase RatingCheck = new UseDataBase();
        RatingCheck.ConnectDataBase(); 
          
         //Query the datbase
        SqlDataReader rated = RatingCheck.ExecuteQuery("SELECT * FROM [RatingInformation] WHERE [BookID] = '" + (string)Session["BookId"] + "' AND [UserId] = '" + Request.Cookies["LoggedInCookie"]["UserId"] + "'");

        //Apply the appropriate values if the user has already scored the book 
        if(rated.HasRows && rated != null)
        {
            //Display a message that the user has already rated the book
            RateLble.Text = "You have already rated this book";

            //Disable the stars to prevent the user from rating the book again
            DisableStars();

            //display the value that the user scored the book on the stars
            while (rated.Read())
            {
                SetStars(rated.GetInt32(2));
            }
        }

        //Close the datareader
        rated.Close();
        RatingCheck.Close();

         //Unfortunatly I'm including some javascript for the star animations (sorry about this but there's no mouseover events for asp.net) 
           //The below code executes the star animations based on the onmouseover/onmouseout events.
        if (!Page.IsPostBack)
        {
           //Star Animations 
            //StarOne
            StarOneBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/StarMouseOver.png'");
            StarOneBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/StarDefault.png'");

            //StarTwoBtn  
            StarTwoBtn.Attributes.Add("onmouseover", "document.getElementById('StarOneBtn').src = 'Resources/Images/StarMouseOver.png'; this.src = 'Resources/Images/StarMouseOver.png'");
            StarTwoBtn.Attributes.Add("onmouseout", "document.getElementById('StarOneBtn').src = 'Resources/Images/StarDefault.png'; this.src = 'Resources/Images/StarDefault.png'");

            //StarThreeBtn
            StarThreeBtn.Attributes.Add("onmouseover", "document.getElementById('StarOneBtn').src = 'Resources/Images/StarMouseOver.png'; document.getElementById('StarTwoBtn').src = 'Resources/Images/StarMouseOver.png'; this.src = 'Resources/Images/StarMouseOver.png'");
            StarThreeBtn.Attributes.Add("onmouseout", "document.getElementById('StarOneBtn').src = 'Resources/Images/StarDefault.png'; document.getElementById('StarTwoBtn').src = 'Resources/Images/StarDefault.png'; this.src = 'Resources/Images/StarDefault.png'");

            //StarFourBtn 
            StarFourBtn.Attributes.Add("onmouseover", "document.getElementById('StarOneBtn').src = 'Resources/Images/StarMouseOver.png'; document.getElementById('StarTwoBtn').src = 'Resources/Images/StarMouseOver.png'; document.getElementById('StarThreeBtn').src = 'Resources/Images/StarMouseOver.png'; this.src = 'Resources/Images/StarMouseOver.png'");
            StarFourBtn.Attributes.Add("onmouseout", "document.getElementById('StarOneBtn').src = 'Resources/Images/StarDefault.png'; document.getElementById('StarTwoBtn').src = 'Resources/Images/StarDefault.png'; document.getElementById('StarThreeBtn').src = 'Resources/Images/StarDefault.png'; this.src = 'Resources/Images/StarDefault.png'");

            //StarFiveBtn 
            StarFiveBtn.Attributes.Add("onmouseover", "document.getElementById('StarOneBtn').src = 'Resources/Images/StarMouseOver.png'; document.getElementById('StarTwoBtn').src = 'Resources/Images/StarMouseOver.png'; document.getElementById('StarThreeBtn').src = 'Resources/Images/StarMouseOver.png'; document.getElementById('StarFourBtn').src = 'Resources/Images/StarMouseOver.png'; this.src = 'Resources/Images/StarMouseOver.png'");
            StarFiveBtn.Attributes.Add("onmouseout", "document.getElementById('StarOneBtn').src = 'Resources/Images/StarDefault.png'; document.getElementById('StarTwoBtn').src = 'Resources/Images/StarDefault.png'; document.getElementById('StarThreeBtn').src = 'Resources/Images/StarDefault.png'; document.getElementById('StarFourBtn').src = 'Resources/Images/StarDefault.png'; this.src = 'Resources/Images/StarDefault.png'");

            //MouseOver events for the other buttons 
            
            //GoBackBtn
            BackBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/ArrowBackMouseOver.jpg'");
            BackBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/ArrowBack.jpg'");

            //SubmitBtn 

            SubmitImgBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/SubmitMouseOver.png'");
            SubmitImgBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/SubmitDefault.png'");

        }

       //The following code sets the book details/lables to the appropriate values from the database 
        //Open a connection to the database 
        UseDataBase usedb = new UseDataBase();
        usedb.ConnectDataBase();

        //Query the database to retrieve the boook details 
        SqlDataReader result = usedb.ExecuteQuery("SELECT [BookName], [BookAuthor], [BookAverageRating], [BookSummary], [BookGenre], [BookImageUrl], [BookSubmiterId] FROM [BookInformation] WHERE [BookId] = '" + (string)Session["BookId"]+  "'");
        if (result.HasRows)
        {
            while (result.Read())
            {
                //Apply the values to the appropriate lables from the database based on the datakey selected on Books.apx
                TitleLble.Text = result.GetString(0).ToUpper();
                AuthorLble.Text = result.GetString(1);
                AverageLble.Text = result.GetInt32(2).ToString() + "%";
                SummaryLble.Text = result.GetString(3);
                GenreLble.Text = result.GetString(4); 
                BookImg.ImageUrl = result.GetString(5);
                userId = result.GetInt32(6);

                //Set the gridView query to select the top 4 rated similar books
                SqlDataSource1.SelectCommand = "SELECT TOP 4 [BookImageUrl] , [BookName] , [BookId] FROM [BookInformation] WHERE [BookId] != '" + (string)Session["BookId"] + "' AND [BookGenre] = '" + result.GetString(4) + "' OR [BookAuthor] = '" + result.GetString(4) + "' ORDER BY [BookAverageRating]";

                //Set the images for the stars based on the average percentage
                if (result.GetInt32(2) <= 20)
                {
                    AvgStarImg1.ImageUrl = "Resources/Images/StarMouseOver.png";
                }
                else if (result.GetInt32(2) > 20 & result.GetInt32(2) <= 40)
                {
                    AvgStarImg1.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg2.ImageUrl = "Resources/Images/StarMouseOver.png";
                }
                else if (result.GetInt32(2) > 40 & result.GetInt32(2) <= 60)
                {
                    AvgStarImg1.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg2.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg3.ImageUrl = "Resources/Images/StarMouseOver.png";
                }
                else if (result.GetInt32(2) > 60 & result.GetInt32(2) <= 80)
                {
                    AvgStarImg1.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg2.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg3.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg4.ImageUrl = "Resources/Images/StarMouseOver.png";
                }
                else if (result.GetInt32(2) > 80)
                {
                    AvgStarImg1.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg2.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg3.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg4.ImageUrl = "Resources/Images/StarMouseOver.png";
                    AvgStarImg5.ImageUrl = "Resources/Images/StarMouseOver.png";
                }
            }
            //Close the dataReader
            result.Close();

            //Query a new DataReader to retrieve the username of the person who submitted the book using the userId from the BookInformationTable
            SqlDataReader SubmittedBy = usedb.ExecuteQuery("SELECT [UserName] FROM [UserInformation] WHERE [UserId] = '" + userId + "'");

            //Read and assign the value
            while(SubmittedBy.Read())
            {
                UserNameLble.Text = SubmittedBy.GetString(0);
            }
            //Close the dataReader
            SubmittedBy.Close();
        }
        else
        {
            //Something went wrong with the database base (Redirect the user back to the books search page)
            Response.Redirect("Books.aspx");
        }

        //Recrord the number of time the book has been rated and assign the value to the label
        NumberRatedLble.Text = usedb.RecordNumber("SELECT * FROM [RatingInformation] WHERE [BookId] = '" + (string)Session["BookId"]+  "'").ToString();

        //Close the connection to the database
        usedb.Close();
        
   }
コード例 #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        #region EventScript

        if (!Page.IsPostBack)
        {
            //Add Events to the image buttons
            ConnectImgBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/ConnectWithUsMouseDown.jpg'");
            ConnectImgBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/ConnectWithUs.jpg'");

            UserIconImgBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/UserIconMouseOver.jpg'");
            UserIconImgBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/UserIconDefault.jpg'");

            LogOutImgBtn.Attributes.Add("onmouseover", "this.src = 'Resources/Images/LogOutHomeMouseOver.jpg'");
            LogOutImgBtn.Attributes.Add("onmouseout", "this.src = 'Resources/Images/LogOutHome.jpg'");
        }
        //Count the number of BookRecords ref. db_Bookworm_data>>BookInformation table.
        UseDataBase usedb = new UseDataBase();
        usedb.ConnectDataBase();

        //Apply the number of records to the appropriate label
        BooksNumberLble.Text = usedb.RecordNumber("SELECT * FROM BookInformation").ToString();
        //Count the number of UserRecords ref. db_Bookworm_data>>UserInformation table.
        UsersNumberLble.Text = usedb.RecordNumber("SELECT * FROM UserInformation").ToString();

        //Close the connection to the database
        usedb.Close();
        #endregion

        #region SidePanelLeftScript

        //Check to see if the user is logged in and show the appropriate controls
        if (Request.Cookies["LoggedInCookie"] != null && Request.Cookies["LoggedInCookie"]["LoggedIn"] == "true")
        {
            ConnectImgBtn.Visible  = false;
            UserIconImgBtn.Visible = true;
            LogOutImgBtn.Visible   = true;

            //Get and set UserName to the UserNameLble
            UseDataBase username = new UseDataBase();
            username.ConnectDataBase();

            //Query the database
            SqlDataReader getname = username.ExecuteQuery("SELECT [UserName] FROM [UserInformation] WHERE [UserId] = '" + Request.Cookies["LoggedInCookie"]["UserId"] + "'");

            //get the username
            while (getname.Read())
            {
                WellcomeBackLble.Text = getname.GetString(0);
            }

            //Close the connection to the database and the dataReader
            getname.Close();
            username.Close();
            WellcomeBackLble.Visible = true;
        }
        else
        {
            //if the user is not logged in
            ConnectImgBtn.Visible    = true;
            UserIconImgBtn.Visible   = false;
            WellcomeBackLble.Visible = false;
        }

        #endregion
    }