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

  • 相关阅读:
    “猫癣”集团借IE7新漏洞再掀风浪 狼人:
    研究人员在黑帽安全大会演示SSL攻击 狼人:
    猫癣病毒“躲猫猫” 移师广东东莞月入百万 狼人:
    Adobe两款软件存在缺陷 黑客可控制用户PC 狼人:
    安全观点:遭遇数据泄露破坏 损失的不只是金钱 狼人:
    McAfee报告称七成手机制造商认为手机安全至关重要 狼人:
    微软表示本月将发布五个Windows 7更新 狼人:
    Gmail电子邮件曝全球性故障 谷歌向用户道歉 狼人:
    Google Talk被黑客利用 发动钓鱼攻击 狼人:
    谷歌GMail邮件服务出现故障 部分服务已恢复 狼人:
  • 原文地址:https://www.cnblogs.com/liangwei/p/3468318.html
Copyright © 2011-2022 走看看