Ejemplo n.º 1
0
        protected void btnaddpost_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(Request.QueryString["postId"]))
            {
                Posts_M post = new Posts_M();
                post.PostId = Convert.ToInt32(Request.QueryString["postId"]);
                post.Title = txtTitle.Text;
                post.TaxonomyId = Convert.ToInt32(ddlcate.Text);
                post.Post = postdesc.Text;
                if (Posts_B.updatePost(post))
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('修改成功');location.href='AdminPost.aspx';</script>");

                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('修改失败');</script>");

                }
            }
            else
            {
                Posts_M post = new Posts_M();
                post.Title = txtTitle.Text;
                post.TaxonomyId = Convert.ToInt32(ddlcate.Text);
                post.Post = postdesc.Text;
                if (Posts_B.addPost(post))
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('添加成功');</script>");
                    txtTitle.Text = "";
                    postdesc.Text = "";
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('添加失败');</script>");

                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 分页查询
 /// </summary>
 /// <param name="pageSize">页数大小</param>
 /// <param name="pageIndex">页码</param>
 /// <returns>返回集合</returns>
 public static List<Posts_M> PostListPager(string pageSize, string pageIndex)
 {
     List<Posts_M> list = new List<Posts_M>();
     string sql = string.Format("select top ({0}) *from Posts where PostId not in (select top (({1}-1)*{0}) PostId from Posts order by PostId) order by PostId", pageSize, pageIndex);
     SqlDataReader dr = SQLDBHelper.ExecuteReader(sql);
     if (dr.HasRows)
     {
         while (dr.Read())
         {
             Posts_M post = new Posts_M();
             if (dr["PostId"] != DBNull.Value)
             {
                 post.PostId = Convert.ToInt32(dr["PostId"]);
             }
             if (dr["TaxonomyId"] != DBNull.Value)
             {
                 post.TaxonomyId = Convert.ToInt32(dr["TaxonomyId"]);
             }
             if (dr["Title"] != DBNull.Value)
             {
                 post.Title = Convert.ToString(dr["Title"]);
             }
             if (dr["Post"] != DBNull.Value)
             {
                 post.Post = Convert.ToString(dr["Post"]);
             }
             if (dr["PublishTime"] != DBNull.Value)
             {
                 post.PublishTime = Convert.ToDateTime(dr["PublishTime"]);
             }
             list.Add(post);
         }
     }
     dr.Close();
     return list;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 查出所有帖子集合
 /// </summary>
 /// <returns>返回集合</returns>
 public static List<Posts_M> PostList()
 {
     List<Posts_M> list = new List<Posts_M>();
     string sql = "select * from Posts";
     SqlDataReader dr = SQLDBHelper.ExecuteReader(sql);
     if (dr.HasRows)
     {
         while (dr.Read())
         {
             Posts_M post = new Posts_M();
             if (dr["PostId"] != DBNull.Value)
             {
                 post.PostId = Convert.ToInt32(dr["PostId"]);
             }
             if (dr["TaxonomyId"] != DBNull.Value)
             {
                 post.TaxonomyId = Convert.ToInt32(dr["TaxonomyId"]);
             }
             if (dr["Title"] != DBNull.Value)
             {
                 post.Title = Convert.ToString(dr["Title"]);
             }
             if (dr["Post"] != DBNull.Value)
             {
                 post.Post = Convert.ToString(dr["Post"]);
             }
             if (dr["PublishTime"] != DBNull.Value)
             {
                 post.PublishTime = Convert.ToDateTime(dr["PublishTime"]);
             }
             list.Add(post);
         }
     }
     dr.Close();
     return list;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 修改帖子
 /// </summary>
 /// <param name="post">接收类</param>
 /// <returns>返回影响行数是否大于0</returns>
 public static bool updatePost(Posts_M post)
 {
     return Posts_D.updatePost(post);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 添加帖子
 /// </summary>
 /// <param name="post">接收类</param>
 /// <returns>返回影响行数是否大于0</returns>
 public static bool addPost(Posts_M post)
 {
     return Posts_D.addPost(post);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 修改帖子
 /// </summary>
 /// <param name="post">接收类</param>
 /// <returns>返回影响行数是否大于0</returns>
 public static bool updatePost(Posts_M post)
 {
     SqlParameter paramTaxID = new SqlParameter();
     paramTaxID.ParameterName = "@TaxonomyId";
     paramTaxID.DbType = DbType.String;
     paramTaxID.Value = post.TaxonomyId;
     SqlParameter paramTitle = new SqlParameter();
     paramTitle.ParameterName = "@Title";
     paramTitle.DbType = DbType.String;
     paramTitle.Value = post.Title;
     SqlParameter paramPost = new SqlParameter();
     paramPost.ParameterName = "@Post";
     paramPost.DbType = DbType.String;
     paramPost.Value = post.Post;
     SqlParameter paramPostID = new SqlParameter();
     paramPostID.ParameterName = "@PostId";
     paramPostID.DbType = DbType.String;
     paramPostID.Value = post.PostId;
     return SQLDBHelper.ExecuteNonQuery("proc_Update_Post",paramTaxID,paramTitle,paramPost,paramPostID);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 根据ID查找帖子
 /// </summary>
 /// <param name="PostID">获取PostID</param>
 /// <returns>返回一个对象</returns>
 public static Posts_M PostByID(string PostID)
 {
     Posts_M Post = new Posts_M();
     string sql = "select * from Posts where PostId=" + PostID;
     SqlDataReader dr = SQLDBHelper.ExecuteReader(sql);
     if (dr.HasRows)
     {
         dr.Read();
         if (dr["PostId"] != DBNull.Value)
         {
             Post.PostId = Convert.ToInt32(dr["PostId"]);
         }
         if (dr["TaxonomyId"] != DBNull.Value)
         {
             Post.TaxonomyId = Convert.ToInt32(dr["TaxonomyId"]);
         }
         if (dr["Title"] != DBNull.Value)
         {
             Post.Title = Convert.ToString(dr["Title"]);
         }
         if (dr["Post"] != DBNull.Value)
         {
             Post.Post = Convert.ToString(dr["Post"]);
         }
         if (dr["PublishTime"] != DBNull.Value)
         {
             Post.PublishTime = Convert.ToDateTime(dr["PublishTime"]);
         }
     }
     dr.Close();
     return Post;
 }