Beispiel #1
0
        public News(News news)
        {
            this.a_id = news.A_id;
            this.article_id = news.Article_id;
            this.article_author = news.Article_author;
            this.article_title = news.Article_title;
            this.article_content = news.Article_content;
            this.article_publish_date = news.Article_publish_date;
            this.article_isDeleted = news.Article_isDeleted;

            this.news_image = news.News_image;
            this.news_isOnIndex = news.News_isOnIndex;
        }
Beispiel #2
0
 public News ConvertNEWSToNews(NEWS news)
 {
     News ResultNews = new News();
     ResultNews.Article_title = news.news_title;
     ResultNews.Article_id = news.news_id;
     ResultNews.Article_content = news.news_content;
     ResultNews.Article_isDeleted = news.news_isDeleted;
     ResultNews.News_isOnIndex = news.news_isOnIndex;
     ResultNews.Article_publish_date = news.news_publish_date;
     ResultNews.Article_timestamp = news.news_timestamp;
     ResultNews.Article_author = news.news_author;
     ResultNews.News_click_count = news.news_click_count;
     ResultNews.News_image = news.news_image;
     return ResultNews;
 }
Beispiel #3
0
 public NEWS ConvertNewsToNEWS(News news)
 {
     NEWS ResultNEWS = new NEWS();
     ResultNEWS.news_title = news.Article_title;
     ResultNEWS.news_id = news.Article_id;
     ResultNEWS.news_content = news.Article_content;
     ResultNEWS.news_isDeleted = news.Article_isDeleted;
     ResultNEWS.news_isOnIndex = news.News_isOnIndex;
     ResultNEWS.news_publish_date = news.Article_publish_date;
     ResultNEWS.news_timestamp = news.Article_timestamp;
     ResultNEWS.news_author = news.Article_author;
     ResultNEWS.news_click_count = news.News_click_count;
     ResultNEWS.news_image = news.News_image;
     return ResultNEWS;
 }
Beispiel #4
0
 /// <summary>
 /// 根据给定新闻id删除新闻(UPDATE isDeleted = true),成功返回true,失败返回false
 /// </summary>
 /// <param name="news">要删除的新闻</param>
 /// <returns>成功返回true,失败返回false</returns>
 public Boolean DeleteNewsByID(News news)
 {
     Boolean result = false;
     //数据合法性检查
     if (news.Article_id != null)
     {
         INewsDAL newsDAL = DALFactory.CreateInstance<INewsDAL>("NewsDAL");
         result = newsDAL.DeleteNewsByID(news);
     }
     else
     {
         result = false;
     }
     return result;
 }
Beispiel #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     INewsBLL newsBLL = BLLFactory.CreateInstance<INewsBLL>("NewsBLL");
     if (Request.QueryString["news_id"] != null)
     {
         Guid news_id = new Guid(Request.QueryString["news_id"].ToString());
         News toFindNews = new News();
         toFindNews.Article_id =  news_id;
         News entireNews = newsBLL.GetNewsByID(toFindNews);
         if ( entireNews != null )
         {
             entireNews.News_click_count += 1;
             newsBLL.UpdateNewsInfo(entireNews);
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// 根据ID来获得完整新闻对应的的News类,其中参数的article_id必填
 /// 获取到了返回News对象,否则返回Null
 /// </summary>
 /// <param name="news">要获取的News类</param>
 /// <returns>包含完整信息的news类,若找不到或者失败,返回null</returns>
 public News GetNewsByID(News news)
 {
     News ResultNews = null;
     /* 数据合法性检查 */
     if (news.Article_id == null
         )
     {
         ResultNews = null;
     }
     else
     {
         INewsDAL newsDAL = DALFactory.CreateInstance<INewsDAL>("NewsDAL");
         ResultNews = newsDAL.GetNewsByID(news);
     }
     return ResultNews;
 }
Beispiel #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     INewsBLL newsBLL = BLLFactory.CreateInstance<INewsBLL>("NewsBLL");
     IAdminBLL adminBLL = BLLFactory.CreateInstance<IAdminBLL>("AdminBLL");
     Admin loggedAdmin = adminBLL.isLogged(Request);
     if ( loggedAdmin == null )
     {
         //未登录
         //未登录
         lblLoginStatus.Text = "您未登录或已经登录过期,请重新登录,3秒后转回管理员登录页。";
         lblLoginStatus.Visible = true;
         AdminLoggedForm.Visible = false;
         //重定向
         HtmlMeta RedirectMeta = new HtmlMeta(); //重定向用Meta标签
         RedirectMeta.HttpEquiv = "refresh"; //指定行为为跳转
         RedirectMeta.Content = "3;url=admin_login.aspx"; //时间为三秒,跳转到首页
         this.Page.Header.Controls.Add(RedirectMeta);
     }
     else
     {
         //已登录
         if (Request.QueryString["news_id"] != null)
         {
             //新闻id不为空
             News deleteNews = new News();
             deleteNews.Article_id = new Guid(Request.QueryString["news_id"]);
             if ( newsBLL.DeleteNewsByID(deleteNews) )
             {
                 lblDeleteStatus.Text = "删除成功,3秒后转向新闻管理首页";
                 HtmlMeta RedirectMeta = new HtmlMeta(); //重定向用Meta标签
                 RedirectMeta.HttpEquiv = "refresh"; //指定行为为跳转
                 RedirectMeta.Content = "3;url=news_manage_index.aspx"; //时间为三秒,跳转到首页
                 this.Page.Header.Controls.Add(RedirectMeta);
             }
             else
             {
                 lblDeleteStatus.Text = "删除失败";
             }
         }
         else
         {
             //新闻id为空
             lblDeleteStatus.Text = "新闻不存在";
         }
     }
 }
Beispiel #8
0
 /// <summary>
 /// 插入新闻,成功返回true,失败返回false
 /// </summary>
 /// <param name="news">要插入的新闻类</param>
 /// <returns>成功true,失败false</returns>
 public Boolean CreateNews(News news)
 {
     Boolean result = true;
     avfunEntities DataEntity = DataEntityManager.GetDataEntity();
     try
     {
         NEWS newNEWS = ConvertNewsToNEWS(news);
         DataEntity.NEWS.AddObject(newNEWS);
         DataEntity.SaveChanges();
         result = true;
     }
     catch
     {
         result = false;
     }
     return result;
 }
Beispiel #9
0
 /// <summary>
 /// 发布新闻
 /// </summary>
 /// <param name="news">要发布的新闻类</param>
 /// <param name="author">作者</param>
 /// <returns>成功返回true,失败返回false</returns>
 public Boolean CreateNews(News news, Admin author)
 {
     Boolean result = true;
     IAdminBLL adminBLL = BLLFactory.CreateInstance<IAdminBLL>("AdminBLL");
     if (!isLegalNews(news) || !adminBLL.isLegalNewAdmin(author))
     {
         //数据合法性检查未通过
         result = false;
     }
     else
     {
         news.Article_author = author.User_id;
         INewsDAL newsDAL = DALFactory.CreateInstance<INewsDAL>("NewsDAL");
         result = newsDAL.CreateNews(news);
     }
     return result;
 }
Beispiel #10
0
 /// <summary>
 /// 根据给定的news_id将NEWS表中的对应新闻列isDeleted设为true
 /// </summary>
 /// <param name="news">填写了news_id的news类</param>
 /// <returns>成功返回true,失败返回false</returns>
 public Boolean DeleteNewsByID(News news)
 {
     avfunEntities DataEntity = DataEntityManager.GetDataEntity();
     Boolean result = false;
     try
     {
         NEWS destNews = (from d_news in DataEntity.NEWS
                          where d_news.news_id == news.Article_id
                          select d_news).Single();
         destNews.news_isDeleted = true;
         DataEntity.SaveChanges();
         result = true;
     }
     catch
     {
         result = false;
     }
     return result;
 }
Beispiel #11
0
 /// <summary>
 /// 根据参数的article_id返回包含完整信息的News类,失败返回null
 /// </summary>
 /// <param name="news">包含了news的ID的News对象</param>
 /// <returns>成功返回包含完整信息的News对象,否则返回Null</returns>
 public News GetNewsByID(News news)
 {
     avfunEntities DataEntity = DataEntityManager.GetDataEntity();
     News result = null;
     try
     {
         NEWS ResultNEWS = (from destNews in DataEntity.NEWS
                  where
                  destNews.news_id == news.Article_id
                                select destNews).Single();
         result = ConvertNEWSToNews(ResultNEWS);
     }
     catch
     {
         result = null;
     }
     return result;
 }
Beispiel #12
0
        /// <summary>
        /// 更新新闻信息,成功返回true,失败返回false
        /// </summary>
        /// <param name="news">要更新的news类</param>
        /// <returns>成功返回true,失败返回false</returns>
        public Boolean UpdateNewsInfo(News news)
        {
            avfunEntities DataEntity = DataEntityManager.GetDataEntity();
            Boolean result = false;
            try
            {
                NEWS ResultNEWS = (from destNews in DataEntity.NEWS
                                  where destNews.news_id == news.Article_id
                                  && destNews.news_timestamp == news.Article_timestamp
                                       select destNews ).Single();

                ResultNEWS.news_title = news.Article_title;
                ResultNEWS.news_id = news.Article_id;
                ResultNEWS.news_content = news.Article_content;
                ResultNEWS.news_isDeleted = news.Article_isDeleted;
                ResultNEWS.news_isOnIndex = news.News_isOnIndex;
                ResultNEWS.news_publish_date = news.Article_publish_date;
                ResultNEWS.news_timestamp = news.Article_timestamp;
                ResultNEWS.news_author = news.Article_author;
                ResultNEWS.news_click_count = news.News_click_count;
                ResultNEWS.news_image = news.News_image;

                DataEntity.SaveChanges();

                result = true;
            }
            catch
            {
                result = false;
            }
            return result;
        }
Beispiel #13
0
 /// <summary>
 /// 检查新闻类的数据规范
 /// </summary>
 /// <param name="news">要检查的新闻类</param>
 /// <returns>合格返回true,否则返回false</returns>
 public Boolean isLegalNews(News news)
 {
     Boolean result = true;
     //文章标题检查
     if (news.Article_title.Length > 128
         || news.Article_title.Length < 1
         || news.Article_title.Equals("")
         || news.Article_title == null)
     {
         result = false;
     }
     if (news.Article_content.Length < 1
         || news.Article_content.Equals("")
         || news.Article_content == null
        )
     {
         result = false;
     }
     if (news.Article_publish_date == null)
     {
         result = false;
     }
     if (news.Article_author == null)
     {
         result = false;
     }
     if (news.News_image == null
         || news.News_image.Equals("")
         || news.News_image.Length > 256
         || news.News_image.Length < 1)
     {
         result = false;
     }
     if (news.News_click_count < 0)
     {
         result = false;
     }
     return result;
 }
Beispiel #14
0
        /// <summary>
        /// 更新新闻信息,成功返回true,否则返回false
        /// </summary>
        /// <param name="news">要更新的新闻类,必须含有新闻的完整信息。</param>
        /// <returns>成功返回true,失败返回false</returns>
        public Boolean UpdateNewsInfo(News news)
        {
            Boolean result = false;
            if (!isLegalNews(news))
            {
                result = false;
            }
            else
            {
                INewsDAL newsDAL = DALFactory.CreateInstance<INewsDAL>("NewsDAL");

                result = newsDAL.UpdateNewsInfo(news);
            }
            return result;
        }
Beispiel #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            IAdminBLL adminBLL = BLLFactory.CreateInstance<IAdminBLL>("AdminBLL");
            INewsBLL newsBLL = BLLFactory.CreateInstance<INewsBLL>("NewsBLL");
            Admin loggedAdmin = adminBLL.isLogged(Request);
            if (loggedAdmin == null)
            {
                //未登录
                lblLoginStatus.Text = "您未登录或已经登录过期,请重新登录";
                lblLoginStatus.Visible = true;
                loginForm.Visible = false;
            }
            else
            {
                //已经登录
                if (!Page.IsPostBack)
                {
                    //未提交
                    //这里分两个功能:①、修改。②、添加
                    // QueryString什么都没有,就是增加,反之,参数为news_id的时候,就是修改
                    if (Request.QueryString["news_id"] != null)
                    {
                        //修改文章
                        News destNews = new News();
                        destNews.Article_id = new Guid(Request.QueryString["news_id"]);
                        News entireNews = newsBLL.GetNewsByID(destNews);
                        if (entireNews != null)
                        {
                            //找到了
                            txtNewsContent.Text = entireNews.Article_content;
                            txtNewsTitle.Text = entireNews.Article_title;
                            imgHeadImage.ImageUrl = entireNews.News_image;
                            Boolean isOnIndex = entireNews.News_isOnIndex;
                            chkboxIsOnIndex.Checked = isOnIndex;
                        }
                        else
                        {
                            //没找到,给出提示信息
                            lblLoginStatus.Text = "文章不存在";
                            lblLoginStatus.Visible = true;
                            loginForm.Visible = false;
                        }

                    }
                }
                else
                {
                    ///提交回来了
                    if (Request.QueryString["news_id"] == null)
                    {
                        //增加用
                        String newsTitle = Request.Form[txtNewsTitle.ID];
                        String newsContent = Request.Form[txtNewsContent.ID];
                        String newsHeadImage = null;
                        if (Request.Cookies["newsHeadImage"] != null)
                        {
                            //如果填了题头图片,分配图片地址
                            newsHeadImage = Request.Cookies["newsHeadImage"].Value.Replace("%2F","/");
                            //释放Cookies
                            HttpCookie newsHeadImageCookie = new HttpCookie("newsHeadImage");
                            //这句不加清除不掉
                            newsHeadImageCookie.Path = "/admin";
                            newsHeadImageCookie.Expires = DateTime.Now.AddDays(-1d);
                            Response.Cookies.Add(newsHeadImageCookie);
                        }
                        else
                        {
                            newsHeadImage = "/news_image/default.jpg";
                        }
                        DateTime news_publish_date = DateTime.Now;
                        Boolean news_isDeleted = false;
                        Boolean news_isOnIndex = chkboxIsOnIndex.Checked;
                        int news_click_count = 0;
                        Guid news_author = loggedAdmin.User_id;
                        Guid news_id = System.Guid.NewGuid();
                        News newNews = new News();

                        newNews.Article_id = news_id;
                        newNews.Article_content = newsContent;
                        newNews.Article_title = newsTitle;
                        newNews.Article_author = news_author;
                        newNews.Article_publish_date = news_publish_date;
                        newNews.Article_isDeleted = news_isDeleted;
                        newNews.News_isOnIndex = news_isOnIndex;
                        //去空格否则bug
                        newNews.News_image = newsHeadImage.Trim();
                        newNews.News_click_count = news_click_count;

                        if (newsBLL.CreateNews(newNews, loggedAdmin))
                        {
                            //创建成功
                            loginForm.Visible = true;
                            lblLoginStatus.Text = "添加新闻成功";
                            lblLoginStatus.Visible = true;
                        }
                        else
                        {
                            lblLoginStatus.Text = "添加新闻失败,请检查各项是否已经填写";
                            lblLoginStatus.Visible = true;
                            loginForm.Visible = true;
                        }
                    }
                    else
                    {
                        //修改用
                        Guid news_id = new Guid(Request.QueryString["news_id"].ToString());
                        News destNews = new News();
                        destNews.Article_id = news_id;
                        News updateNews = newsBLL.GetNewsByID(destNews);
                        if ( updateNews != null )
                        {
                            String news_title = Request.Form[txtNewsTitle.ID];
                            String news_content = Request.Form[txtNewsContent.ID];
                            String news_head = imgHeadImage.ImageUrl;
                            //修改了题头图片!
                            if (Request.Cookies["newsHeadImage"] != null)
                            {
                                //如果填了题头图片,分配图片地址
                                news_head = Request.Cookies["newsHeadImage"].Value.Replace("%2F","/");
                                //释放Cookies
                                HttpCookie newsHeadImageCookie = new HttpCookie("newsHeadImage");
                                newsHeadImageCookie.Expires = DateTime.Now.AddDays(-1d);
                                //这句不加清不掉
                                newsHeadImageCookie.Path = "/admin";
                                Response.Cookies.Add(newsHeadImageCookie);
                            }
                            Boolean isOnIndex = chkboxIsOnIndex.Checked;

                            //开始更新
                            updateNews.Article_title = news_title;
                            updateNews.Article_content = news_content;
                            updateNews.News_image = news_head;
                            updateNews.News_isOnIndex = isOnIndex;

                            if ( newsBLL.UpdateNewsInfo(updateNews) )
                            {
                                lblLoginStatus.Text= "修改成功,若更改题头图片,请重新进入本页方能查看修改效果";
                                lblLoginStatus.Visible = true;
                            }
                            else
                            {
                                lblLoginStatus.Text = "修改失败";
                                lblLoginStatus.Visible = true;
                            }
                        }
                        else
                        {
                            lblLoginStatus.Text = "您要修改的新闻不存在";
                            lblLoginStatus.Visible = true;
                            loginForm.Visible = false;
                        }
                    }
                }
            }
        }