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

  • 相关阅读:
    JDK7与JDK8环境共存与切换:先安装jdk7,配置好环境变量后再安装jdk8
    Maven环境配置
    JDK的安装
    Access2010打开系统表MSysObjects的控制权限
    Spring aop 简单示例
    redis集群搭建
    springmvc中拦截器与springmvc全局异常处理器的问题
    自定义springmvc统一异常处理器(实现HandlerExceptionResolver接口)不起作用的一种情况
    一句SQL实现MYSQL的递归查询
    2002年的决战坦克,重新玩一遍。qq群号:1035127306
  • 原文地址:https://www.cnblogs.com/liangwei/p/3468318.html
Copyright © 2011-2022 走看看