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;
            }
        }
    }

  • 相关阅读:
    Linux学习笔记(十四)磁盘管理(二):格式化、挂载以及Swap分区
    Linux学习笔记(十三)磁盘管理(一):磁盘分区
    Linux学习笔记(十二)VIM编辑器
    Linux学习笔记(十一)shell基础:管道符、通配符和其他特殊符号
    Linux学习笔记(十)shell基础:历史命令、命令补全、输出重定向、输出重定向
    Linux学习笔记(九)shell基础:echo、命令别名和常用快捷键
    Linux学习笔记(八)Linux常用命令:用户登录查看命令
    Linux学习笔记(七)Linux常用命令:挂载命令
    Linux学习笔记(六)Linux常用命令:关机、重启以及系统运行级别
    Python: 截屏
  • 原文地址:https://www.cnblogs.com/liangwei/p/3468318.html
Copyright © 2011-2022 走看看