zoukankan      html  css  js  c++  java
  • 新闻评论实体类及评论表操作类

    /*
     *  作者:张良伟
     *  创建时间:2013-12-10 10:00

     *  类说明:新闻评论实体类
     */
    namespace Model
    {
        /// <summary>
        /// 新闻评论实体类
        /// </summary>
        public class Comment
        {
            private string id;
            /// <summary>
            /// 主键,自增
            /// </summary>
            public string Id
            {
                get { return id; }
                set { id = value; }
            }

            private string content;
            /// <summary>
            /// 评论内容
            /// </summary>
            public string Content
            {
                get { return content; }
                set { content = value; }
            }

            private string userIp;
            /// <summary>
            /// 评论人IP
            /// </summary>
            public string UserIp
            {
                get { return userIp; }
                set { userIp = value; }
            }

            private string createTime;
            /// <summary>
            /// 评论发表时间
            /// </summary>
            public string CreateTime
            {
                get { return createTime; }
                set { createTime = value; }
            }

            private string newsId;
            /// <summary>
            /// 所属新闻ID
            /// </summary>
            public string NewsId
            {
                get { return newsId; }
                set { newsId = value; }
            }

            public Comment()
            { }

            public Comment(string content, string userIp, string newsId)
            {
                this.content = content;
                this.userIp = userIp;
                this.newsId = newsId;
            }
        }
    }

    /*
     * 创建人:张良伟
     * 创建时间:2013-12-10 10:00

    * 说明:评论表操作类
     * 版权所有:张良伟&www.tg029.com(众志网)
     */
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Data.SqlClient;
    using Model;

    namespace DAL
    {
        public class CommentDAO
        {
            private SQLHelper sqlhelper;
            public CommentDAO()
            {
                sqlhelper = new SQLHelper();
            }

            /// <summary>
            ///  根据新闻ID取出该新闻的所有评论
            /// </summary>
            /// <param name="newsId">新闻ID</param>
            /// <returns></returns>
            public DataTable SelectByNewsId(string newsId)
            {
                DataTable dt = new DataTable();
                string sql = "select * from comment where newsId=@newsId order by createTime desc";
                SqlParameter[] paras = new SqlParameter[] {
                new SqlParameter("@newsId", newsId)
               };
                dt = sqlhelper.ExecuteQuery(sql, paras, CommandType.Text);
                return dt;
            }

            /// <summary>
            ///  添加评论
            /// </summary>
            /// <param name="c">评论实体类</param>
            /// <returns></returns>
            public bool Insert(Comment c)
            {
                bool flag = false;
                string sql = "insert into comment([content],userIp, newsId) values(@content,@userIp,@newsId)";
                SqlParameter[] paras = new SqlParameter[] {
                new SqlParameter("@content", c.Content),
                new SqlParameter("@userIp", c.UserIp),
                new SqlParameter("@newsId", c.NewsId)
               };
                int res = sqlhelper.ExecuteNonQuery(sql, paras, CommandType.Text);
                if (res > 0)
                {
                    flag = true;
                }
                return flag;
            }

            /// <summary>
            ///  删除评论
            /// </summary>
            /// <param name="id">评论ID</param>
            /// <returns></returns>
            public bool Delete(string id)
            {
                bool flag = false;
                string sql = "delete comment where id=@id";
                SqlParameter[] paras = new SqlParameter[] {
                new SqlParameter("@id",id)
               };
                int res = sqlhelper.ExecuteNonQuery(sql, paras, CommandType.Text);
                if (res > 0)
                {
                    flag = true;
                }
                return flag;
            }
        }
    }

  • 相关阅读:
    数据结构(一)之HelloWord
    关于玩QQ消息导入导出功能的感想!
    关于java.lang.IllegalStateException
    Error querying database. Cause: java.sql.SQLException: ORA-01745: 无效的主机/绑定变量名
    关于SVN更新时文件加锁的小结
    项目中和时间相关的要注意的地方
    项目开发中遇到的小问题及小规范
    世界各国的谷歌网址
    非常不错的IT进阶站点
    CSS 垂直居中
  • 原文地址:https://www.cnblogs.com/liangwei/p/3468318.html
Copyright © 2011-2022 走看看