예제 #1
0
        /// <summary>
        /// Adds a new forum.
        /// </summary>
        /// <param name="forum">A Forum object instance that defines the variables for the new forum to
        /// be added.  The Forum object properties used to create the new forum are: Name, Description,
        /// Moderated, and DaysToView.</param>
        public void AddForum(Forum forum)
        {
            // Create Instance of Connection and Command Object
            SqlConnection myConnection = new SqlConnection(Globals.DatabaseConnectionString);
            SqlCommand myCommand = new SqlCommand("dbo.forums_AddForum", myConnection);

            // Mark the Command as a SPROC
            myCommand.CommandType = CommandType.StoredProcedure;

            // Add Parameters to SPROC
            SqlParameter parameterForumName = new SqlParameter("@Name", SqlDbType.NVarChar, 100);
            parameterForumName.Value = forum.Name;
            myCommand.Parameters.Add(parameterForumName);

            SqlParameter parameterForumDesc = new SqlParameter("@Description", SqlDbType.NVarChar, 3000);
            parameterForumDesc.Value = forum.Description;
            myCommand.Parameters.Add(parameterForumDesc);

            // Execute the command
            myConnection.Open();
            myCommand.ExecuteNonQuery();
            myConnection.Close();
        }
예제 #2
0
        /// <summary>
        /// Handles the click event for the button when creating a new forum.
        /// </summary>
        private void CreateUpdateForum_Click(Object sender, EventArgs e)
        {
            Control form;
            Forum forum;

            // if the page is invalid, simply exit the function
            if (!Page.IsValid)
                return;

            // Get the Edit Form
            form = FindControl("CreateEditForm");

            // Create a new forum
            forum = new Forum();

            forum.Name = ((TextBox)form.FindControl("ForumName")).Text;
            forum.Description = ((TextBox)form.FindControl("Description")).Text;

            // Set special properties if this is a new forum
            if (Mode == CreateEditForumMode.CreateForum)
            {
                forum.DateCreated = DateTime.Now;
                Forums.AddForum(forum);
                ((TextBox)form.FindControl("ForumName")).Text = "";
                ((TextBox)form.FindControl("Description")).Text = "";

            }
            else
            {
                // we need to update the forum
                forum.ForumID = ForumID;
                Forums.UpdateForum(forum);
                Context.Response.Redirect(this.RedirectUrl);
            }
        }
예제 #3
0
        // *********************************************************************
        //  Initializeskin
        //
        /// <summary>
        /// Initializes the user control loaded in CreateChildControls. Initialization
        /// consists of finding well known control names and wiring up any necessary events.
        /// </summary>
        /// 
        // ********************************************************************/
        protected override void InitializeSkin(Control skin)
        {
            // Images
            HyperLink link;
            OrderBy = (DropDownList)skin.FindControl("OrderBy");
            OrderType = (DropDownList)skin.FindControl("OrderTyp");

            if (null != ForumUser)
                username = ForumUser.Username;

            // Ensure we have a valid forum
            try
            {
                forum = Forums.GetForumInfo(ForumID);
            }
            catch (Components.ForumNotFoundException)
            {
                Page.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.UnknownForum));
                Page.Response.End();
            }

            // Find the label that we use when there are no threads available
            noThreads = (Label)skin.FindControl("NoThreads");
            noPostsDueToFilter = (Label)skin.FindControl("NoPostsDueToFilter");

            // Find the forum name
            forumName = (HyperLink)skin.FindControl("ForumName");
            if (forumName != null)
            {
                forumName.Text = forum.Name;
                forumName.NavigateUrl = Globals.UrlShowForum + ForumID;
            }

            // Find the forum Description
            forumDescription = (Label)skin.FindControl("ForumDescription");
            if (forumDescription != null)
                forumDescription.Text = forum.Description;

            // Find the thread list
            threadList = (ThreadList)skin.FindControl("ThreadList");

            // Find the link button to mark all as read
            markAllRead = (LinkButton)skin.FindControl("MarkAllRead");
            if (markAllRead != null)
            {
                if (username != null)
                {
                    markAllRead.Visible = true;
                    markAllRead.Click += new System.EventHandler(MarkAllRead_Click);
                }
                else
                {
                    markAllRead.Visible = false;
                }
            }

            // Find the search text box
            search = (TextBox)skin.FindControl("Search");

            // Find the search button
            searchButton = (Button)skin.FindControl("SearchButton");
            if (searchButton != null)
            {
                searchButton.Click += new System.EventHandler(Search_Click);
            }

            // This allows the user to control the total number of threads displayed
            daysToDisplay = (DropDownList)skin.FindControl("DisplayByDays");
            if (daysToDisplay != null)
            {
                daysToDisplay.SelectedIndexChanged += new System.EventHandler(SelectedDays_Changed);
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "All").ToString(), "0"));
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "Today").ToString(), "1"));
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "3 Days").ToString(), "3"));
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "Week").ToString(), "7"));
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "2 Weeks").ToString(), "14"));
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "Month").ToString(), "30"));
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "3 Moths").ToString(), "90"));
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "6 Months").ToString(), "180"));
                daysToDisplay.Items.Add(new ListItem(HttpContext.GetLocalResourceObject(Globals.SkinsDir + "ThreadView", "Year").ToString(), "360"));
                daysToDisplay.AutoPostBack = true;
            }
            DropDownList ddlOrderBy = (DropDownList)skin.FindControl("OrderBy");
            if (ddlOrderBy != null)
            {
                foreach (ListItem i in ddlOrderBy.Items)
                    i.Text = HttpContext.GetLocalResourceObject(Globals.SkinsDir + "skin-showforum.ascx", "SortBy" + i.Value).ToString();

            }

            // Find the new thread button(s)
            newThreadTop = (System.Web.UI.WebControls.Image)skin.FindControl("NewThreadImageTop");
            if (newThreadTop != null)
                newThreadTop.ImageUrl = Globals.ApplicationVRoot + Globals.ForumsDirectory + "/Skins/" + SkinName + "/images"+ Globals.LangDir +"post.gif";

            // Set the anchor
            link = (HyperLink)skin.FindControl("NewThreadLinkTop");
            if (link != null)
                if (HttpContext.Current.User.Identity.IsAuthenticated && Users.GetLoggedOnUser().IsApproved)
                    link.NavigateUrl = Globals.UrlAddNewPost + ForumID;

            link = (HyperLink)skin.FindControl("NewThreadLinkBottom");
            if (link != null)
                if (HttpContext.Current.User.Identity.IsAuthenticated && Users.GetLoggedOnUser().IsApproved)
                    link.NavigateUrl = Globals.UrlAddNewPost + ForumID;

            // Find the pager
            pager = (Paging)skin.FindControl("Pager");
            // Get the total records used in the pager
            if (ForumUser != null)
            {
                if (!Page.IsPostBack)
                    pager.TotalRecords = Forums.GetTotalThreadsInForum(ForumID, threadMaxValue, CalculateDateTimeFilter());
                else
                    pager.TotalRecords = Forums.GetTotalThreadsInForum(ForumID, threadMaxValue, CalculateDateTimeFilter());
            }
            else
            {
                pager.TotalRecords = Forums.GetTotalThreadsInForum(ForumID, threadMaxValue, CalculateDateTimeFilter());
            }
        }
예제 #4
0
        /// <summary>
        /// Builds and returns an instance of the Forum class based on the current row of an
        /// aptly populated SqlDataReader object.
        /// </summary>
        /// <param name="dr">The SqlDataReader object that contains, at minimum, the following
        /// columns: ForumID, DateCreated, Description, Name, Moderated, and DaysToView.</param>
        /// <returns>An instance of the Forum class that represents the current row of the passed 
        /// in SqlDataReader, dr.</returns>
        private Forum PopulateForumFromSqlDataReader(SqlDataReader dr)
        {
            Forum forum = new Forum();
            forum.ForumID = Convert.ToInt32(dr["ForumID"]);
            forum.DateCreated = Convert.ToDateTime(dr["DateCreated"]);
            forum.Description = Convert.ToString(dr["Description"]);
            forum.Name = Convert.ToString(dr["Name"]);

            return forum;
        }
예제 #5
0
        // *********************************************************************
        //  PostView
        //
        /// <summary>
        /// Class contructor - read in the PostId that was sent via the
        /// QueryString or Post body of the request
        /// </summary>
        /// 
        // ********************************************************************/
        public PostView()
        {
            // If we have an instance of context, let's attempt to
            // get the ForumID so we can save the user from writing
            // the code
            if (null != Context)
            {

                try
                {
                    if (null != Context.Request.QueryString["PostID"])
                    {
                        string postID = Context.Request.QueryString["PostID"];

                        // Contains a #
                        if (postID.IndexOf("#") > 0)
                            postID = postID.Substring(0, postID.IndexOf("#"));

                        this.PostID = Convert.ToInt32(postID);
                    }
                    else if (null != Context.Request.Form["PostId"])
                    {
                        this.PostID = Convert.ToInt32(Context.Request.Form["PostID"]);
                    }
                }
                catch (Exception)
                {
                    HttpContext.Current.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.PostDoesNotExist));
                    HttpContext.Current.Response.End();
                }

                // Was a view option passed in via the querystring?
                if (null != Context.Request.QueryString["View"])
                    if (Context.Request.QueryString["View"] == "Threaded")

                        // Was a threshhold value passed in
                        if (null != Context.Request.QueryString["ThreshHold"])
                            threshHold = Convert.ToInt32(Context.Request.QueryString["ThreshHold"]);

            }

            // Populate get details about the forum we are in
            try
            {
                forum = Forums.GetForumInfoByPostID(PostID);
            }
            catch (Components.ForumNotFoundException)
            {
                HttpContext.Current.Response.Redirect(Globals.UrlMessage + Convert.ToInt32(Messages.UnknownForum));
                HttpContext.Current.Response.End();
            }
        }