新闻管理系统(C#)

后台梳理


数据库(news)

1.新闻类别表Category
  • id(主键

  • name

2.新闻表News
  • id(主键

  • title

  • content

  • createTime

  • caID(类别表id外键

3.评论表Comment
  • id(主键

  • content

  • createTime

  • userID

  • newsID(新闻表id外键)

存储过程

  • news_delete(删除新闻

参数 (newsID=)id;

先删除该条新闻下的评论,再删除该新闻

  • news_insert(添加新闻

参数 title、content、caID

  • news_selectBycaId(根据类别查找新闻

参数(caID=)caid

  • news_selectByContent(根据内容查找新闻

参数content(varchar)

根据字符值匹配,取出最匹配的10条新闻按时间排列

  • news_selectById(根据id查找新闻)

参数id

  • news_selectByTitle(根据标题查找新闻

参数title(varchar)

根据字符值匹配,取出最匹配的10条新闻按时间排列

  • news_selectHotNews(根据评论次数查找新闻)

根据评论次数多,取出前五条新闻

  • news_seleteNewNews(根据创建时间查找新闻

取出前五条新闻,按时间顺序排列

  • news_update(修改新闻

参数id

重置该id下新闻的标题、内容或类别


数据访问层DAL

SQLHelper.cs
        private SqlConnection conn=null;
        private SqlCommand cmd = null;
        private SqlDataReader sdr = null;
  • SQLHelper():数据库连接

  • SqlConnection GetConn():打开与数据库的连接

  • 执行不带参数SQL查询语句

  • 执行不带参数存储过程

  • 执行带参数的查询语句

  • 执行带参数的存储过程

NewsDAO.cs(新闻表操作类)
        private SQLHelper sqlhelper;

        public NewsDAO()
        {
            sqlhelper = new SQLHelper();
        }
  • 选择全部新闻

  • 取出10条热点新闻

  • 根据类别ID取出新闻

  • 根据新闻ID取出该条新闻主题内容

  • 根据标题搜索新闻

  • 根据内容搜索新闻

  • 增加新闻

  • 修改新闻

  • 删除新闻

CommentDAO.cs(评论表操作类)
        private SQLHelper sqlhelper;

        public CommentDAO()
        {
            sqlhelper = new SQLHelper();
        }
  • 根据新闻ID取出该新闻的所有评论

  • 添加评论

  • 删除评论

CategoryDAO.cs(类别表操作类)
        private SQLHelper sqlhelper = null;

        public CategoryDAO()
        {
            sqlhelper = new SQLHelper();
        }

取出当前所有新闻分类

增加类别

修改类别

删除类别(包括新闻和评论)

判断类别是否存在


业务逻辑层BLL

NewsManager.cs
        private NewsDAO ndao = null;
        public NewsManager()
        {
            ndao = new NewsDAO();
        }
  • 选择全部新闻

  • 选择最新10条新闻

  • 选择10条热点新闻

  • 根据类别ID取出该类别下的所有新闻

  • 根据新闻ID取出新闻的主体内容

  • 根据标题搜索新闻

  • 根据内容搜索新闻

  • 增加新闻

  • 修改新闻

  • 删除新闻

LoginManager.cs

用户登录是否成功

        #region 用户登录是否成功
        /// <summary>
        /// 用户登录是否成功
        /// </summary>
        /// <param name="name">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public static  bool Login(string name,string pwd)
        {
            bool flag = false;
            //用户名,密码
            if ("Zhanghuixin"==name&& "E10ADC3949BA59ABBE56E057F20F883E"==pwd)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
CommentManager.cs
        private CommentDAO cdao = null;
        public CommentManager()
        {
            cdao = new CommentDAO();
        }
  • 根据新闻ID取出新闻所有评论

  • 添加评论

  • 删除评论

CategoryManager.cs
        private CategoryDAO cdao = null;
        public CategoryManager()
        {
            cdao = new CategoryDAO();
        }
  • 取出当前所有新闻分类

  • 增加类别名称

  • 修改类别

  • 删除类别(包括其下新闻和评论)

  • 判断类别是否存在


模型Model

News.cs
public  class News
    {
        private string id;
        public string Id
        {
            get { return id; }
            set { id = value; }
        }
        private string title;
        public string Title
        {
            get { return title; }
            set { title = value; }
        }
        private string content;
        public string Content
        {
            get { return content; }
            set { content = value; }
        }
        private string createTime;
        public string CreateTime
        {
            get { return createTime; }
            set { createTime = value; }
        }
        private string caId;
        public string CaId
        {
            get { return caId; }
            set { caId = value; }
        }

        public News() { }
        public News(string title,string content,string caid)
        {
            this.title = title;
            this.content = content;
            this.caId = caid;
        }
        public News(string id, string title, string content, string caid)
        {
            this.id = id;
            this.title = title;
            this.content = content;
            this.caId = caid;
        }

        }
Comment.cs
 public class Comment
    {
        private string newsId;
        /// <summary>
        /// 主键,自增
        /// </summary>
     public string NewsId
        {
            get { return newsId; }
            set { newsId = value; }
        }
        private string content;
        /// <summary>
        /// 评论内容
        /// </summary>
        public string Content
        {
            get { return content; }
            set { content = value; }
        }
        private string userIp;
        /// <summary>
        /// userIp
        /// </summary>
        public string UserIp
        {
            get { return userIp; }
            set { userIp = value; }
        }
        public Comment() { }
        public Comment(string content, string userIp, string newsId)
        {
            this.userIp = userIp;
            this.content = content;
            this.newsId = newsId;
        }

    }
Category.cs
public class Category
    {
        private string id;
        public string Id
        {
            get { return id; }
            set { id = value; }
        }
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public Category(string id, string name)
        {
            this.id = id;
            this.name = name;
        }
    }

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值