protected void Page_Load(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(SearchText))
        {
            Response.Redirect("~/");
        }

        using (DataProcess dp = new DataProcess())
        {
            try
            {
                dp.AddParameter("Content", SearchText);
                dp.ExecuteReader("SELECT * FROM Posts WHERE Type = 0 AND State = 1 AND (Content LIKE @Content + ' %' OR Content LIKE '% ' + @Content OR Content LIKE '% ' + @Content + ' %')");

                int p = 0;
                int.TryParse(Request["p"], out p);

                p = p == 0 ? 1 : p;

                IDataReader dr = dp.Return.Value as IDataReader;

                List <BSPost> posts = new List <BSPost>();

                while (dr.Read())
                {
                    BSPost post = new BSPost();
                    BSPost.FillPost(dr, post);
                    posts.Add(post);
                }

                if (posts.Count > 0)
                {
                    ltResult.Text = String.Format(Language.Get["SearchFoundedItemCount"], String.Format("<b>{0}</b>", posts.Count));
                }
                else
                {
                    ltResult.Text = Language.Get["SearchNotFound"];
                }

                ltPaging.Visible = posts.Count > 0;

                rpSearch.DataSource = Data.Paging(posts, p, ltPaging);
                rpSearch.DataBind();
            }
            catch (Exception)
            {
            }
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            List <BSPost> posts = new List <BSPost>();

            using (DataProcess dp = new DataProcess())
            {
                dp.AddParameter("PostID", BSPost.CurrentPost.PostID);
                dp.AddParameter("Title", BSPost.CurrentPost.Title);
                dp.ExecuteReader("SELECT TOP 5 * FROM Posts WHERE [PostID]<>@PostID AND [Type]=0 AND [State]=1 AND ([Title] Like '%'+@Title+'%' OR Content Like '%'+@Title+'%') ORDER BY [CreateDate] DESC");

                if (dp.Return.Status == DataProcessState.Success)
                {
                    using (IDataReader dr = dp.Return.Value as IDataReader)
                    {
                        while (dr.Read())
                        {
                            BSPost bsPost = new BSPost();
                            BSPost.FillPost(dr, bsPost);
                            posts.Add(bsPost);
                        }
                    }
                }
            }

            if (posts.Count > 0)
            {
                rpRelatedPosts.DataSource = posts;
                rpRelatedPosts.DataBind();
            }
            else
            {
                this.Visible = false;
            }
        }
        catch (System.Exception ex)
        {
        }
    }