예제 #1
0
        protected string getHeader()
        {
            string header = "";

            connect.Open();
            SqlCommand cmd = connect.CreateCommand();

            //Check if the ID exists in the database:
            cmd.CommandText = "select count(*) from topics where topicId = '" + topicId + "' ";
            int countTopic = Convert.ToInt32(cmd.ExecuteScalar());

            if (countTopic > 0)//if ID exists, countTopic = 1
            {
                //Get topic_createdBy:
                cmd.CommandText = "select topic_createdBy from [Topics] where [topicId] = '" + topicId + "' ";
                string topic_createdBy = cmd.ExecuteScalar().ToString();
                //Get creator's email:
                cmd.CommandText = "select user_email from users where userId = '" + topic_createdBy + "' ";
                string email = cmd.ExecuteScalar().ToString();
                //Get creator's fullname:
                cmd.CommandText = "select user_firstname from users where userId = '" + topic_createdBy + "' ";
                string creator = cmd.ExecuteScalar().ToString();
                cmd.CommandText = "select user_lastname from users where userId = '" + topic_createdBy + "' ";
                creator         = creator + " " + cmd.ExecuteScalar().ToString();
                //Get topic_type:
                cmd.CommandText = "select topic_type from [Topics] where [topicId] = '" + topicId + "' ";
                string topic_type = cmd.ExecuteScalar().ToString();
                //Get topic_title:
                cmd.CommandText = "select topic_title from [Topics] where [topicId] = '" + topicId + "' ";
                string topic_title = cmd.ExecuteScalar().ToString();
                //Get topic_time:
                cmd.CommandText = "select topic_time from [Topics] where [topicId] = '" + topicId + "' ";
                string topic_time = cmd.ExecuteScalar().ToString();
                //Get topic_description:
                cmd.CommandText = "select topic_description from [Topics] where [topicId] = '" + topicId + "' ";
                string topic_description = cmd.ExecuteScalar().ToString();
                //Get "Yes" or "No" for topic_hasImage:
                cmd.CommandText = "select topic_hasImage from [Topics] where [topicId] = '" + topicId + "' ";
                int topic_hasImage = Convert.ToInt32(cmd.ExecuteScalar());

                //Get topic_isDeleted ?:
                cmd.CommandText = "select topic_isDeleted from [Topics] where [topicId] = '" + topicId + "' ";
                int int_topic_isDeleted = Convert.ToInt32(cmd.ExecuteScalar());

                //Get topic_isApproved ?:
                cmd.CommandText = "select topic_isApproved from [Topics] where [topicId] = '" + topicId + "' ";
                int int_topic_isApproved = Convert.ToInt32(cmd.ExecuteScalar());

                //Get topic_isDenied ?:
                cmd.CommandText = "select topic_isDenied from [Topics] where [topicId] = '" + topicId + "' ";
                int int_topic_isDenied = Convert.ToInt32(cmd.ExecuteScalar());

                //Get topic_isTerminated ?:
                cmd.CommandText = "select topic_isTerminated from [Topics] where [topicId] = '" + topicId + "' ";
                int int_topic_isTerminated = Convert.ToInt32(cmd.ExecuteScalar());

                //Get tags:
                string tagNames = "";
                cmd.CommandText = "select count(*) from TagsForTopics where topicId = '" + topicId + "' ";
                int totalTags = Convert.ToInt32(cmd.ExecuteScalar());
                if (totalTags == 0)
                {
                    tagNames = "There are no tags for the selected topic";
                }
                for (int i = 1; i <= totalTags; i++)
                {
                    cmd.CommandText = "select [tagId] from(SELECT rowNum = ROW_NUMBER() OVER(ORDER BY tagId ASC), * FROM [TagsForTopics] where topicId = '" + topicId + "') as t where rowNum = '" + i + "'";
                    string tagId = cmd.ExecuteScalar().ToString();
                    cmd.CommandText = "select tag_name from Tags where tagId = '" + tagId + "' ";
                    if (totalTags == 1)
                    {
                        tagNames = cmd.ExecuteScalar().ToString();
                    }
                    else if (totalTags > 1)
                    {
                        if (i == 0)
                        {
                            tagNames = cmd.ExecuteScalar().ToString();
                        }
                        else
                        {
                            tagNames = tagNames + ", " + cmd.ExecuteScalar().ToString();
                        }
                    }
                }
                //Create an informative message containing all information for the selected user:
                string imagesHTML = "";
                if (topic_hasImage == 1)
                {
                    cmd.CommandText = "select count(*) from ImagesForTopics where topicId = '" + topicId + "' ";
                    int totalImages = Convert.ToInt32(cmd.ExecuteScalar());
                    for (int i = 1; i <= totalImages; i++)
                    {
                        cmd.CommandText = "select [imageId] from(SELECT rowNum = ROW_NUMBER() OVER(ORDER BY imageId ASC), * FROM [ImagesForTopics] where topicId = '" + topicId + "') as t where rowNum = '" + i + "'";
                        string imageId = cmd.ExecuteScalar().ToString();
                        cmd.CommandText = "select image_name from Images where imageId = '" + imageId + "' ";
                        string image_name = cmd.ExecuteScalar().ToString();
                        imagesHTML = imagesHTML + "<img src='../../images/" + image_name + "'></img> <br />";
                    }
                }
                //Get userId of current user viewing:
                cmd.CommandText = "select userId from Users where loginId = '" + loginId + "' ";
                string userId = cmd.ExecuteScalar().ToString();
                header = Layouts.postHeader(creator, topic_type, topic_title, topic_time, topic_description, imagesHTML, roleId, userId, topicId, topic_createdBy);
            }
            else
            {
                addSession();
                Response.Redirect("Home");
            }
            connect.Close();
            return(header);
        }