Esempio n. 1
0
        public static void CreateNewsHtml(String newsId, String fileName, bool checkExists)
        {
            if ((!checkExists) || (!System.IO.File.Exists(fileName)))
            {
                var news = new BLL.news.V_NewsInfo().GetModel(Int64.Parse(newsId));
                if (news != null)
                {
                    // 读取模板文件
                    string temp    = HttpContext.Current.Server.MapPath("/home/news/template/news_template.html");
                    String newsStr = FileOperate.ReadFile(temp);
                    newsStr = newsStr.Replace("titlexxx", news.NI_Tile);
                    StringBuilder sb = new StringBuilder();
                    if (news.UI_RealName != "")
                    {
                        sb.Append("<span>发布者:").Append(news.UI_RealName).Append("</span>");
                    }
                    var isCampusCol = IsCampusCol(news.NCh_Id);
                    if (isCampusCol)
                    {
                        var newsChannel = new BLL.news.News_NewsChannel().GetModel(news.NCh_Id);
                        //content += "<p>来源:<a href='" + newsChannel.NCh_RssUrl + "'>" + newsChannel.NCh_Name + "</a></p>";
                        sb.Append("&nbsp;&nbsp;<span>来源:" + newsChannel.NCh_Name + "</span>");
                    }
                    sb.Append("&nbsp;&nbsp;");
                    sb.Append(news.CN_PubDate);
                    //sb.Append("&nbsp;&nbsp;").Append("阅读次数:").Append(news.NI_ReadNum);
                    newsStr = newsStr.Replace("desxxx", sb.ToString());
                    String content = HttpContext.Current.Server.HtmlDecode(news.NI_Content);

                    //newsStr = newsStr.Replace("contentxxx", content);
                    newsStr = newsStr.Replace("contentxxx", NewsHelper.SetHtmlImgWidth(content, "98%", ""));
                    sb.Clear();
                    var newsAttach = new BLL.news.News_NewsInfo().GetModel(Int64.Parse(newsId)).NewsAttach;
                    if (newsAttach != null && newsAttach.Count > 0)
                    {
                        sb.Append("<p class='attachTitle'>附件:</p>");
                        var itemCnt = 1;
                        foreach (var item in newsAttach)
                        {
                            sb.Append("<p class='attachItem'>(").Append(itemCnt).Append(")&nbsp;<a href='")
                            .Append("/home/news/Attach.aspx?id=").Append(DESEncrypt.Encrypt(item.NA_Id.ToString()))
                            .Append("&address=").Append(HttpUtility.UrlEncode(item.NA_Address))
                            .Append("&name=").Append(HttpUtility.UrlEncode(item.NA_Name))
                            .Append("' target='_blank' >")
                            .Append(item.NA_Name)
                            .Append("</a>")
                            .Append(OnlineViewHelper.GetOnlineViewWrapLink(item.NA_Address, item.NA_Name))
                            .Append("</p>");
                            itemCnt++;
                        }
                    }
                    newsStr = newsStr.Replace("attachxxx", sb.ToString());
                    //写文件
                    FileOperate.WriteNewFile(fileName, newsStr);
                }
            }
        }
Esempio n. 2
0
 public static void UpdateNewsReadNum(long newsId, long userId)
 {
     if (HttpContext.Current.Session[newsId.ToString()] == null)
     {
         var news = new BLL.news.News_NewsInfo().GetModel(newsId);
         news.NI_ReadNum++;
         new BLL.news.News_NewsInfo().Update(news);
         HttpContext.Current.Session[newsId.ToString()] = 1;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 获取新闻生成的日期目录
        /// </summary>
        /// <param name="newsId">新闻Id</param>
        private static string GetNewsDatePath(long newsId)
        {
            var m = new BLL.news.News_NewsInfo().GetModel(newsId);

            if (m.NI_Created == null)
            {
                return("");
            }
            //按年月/日存入不同的文件夹
            DateTime dt = Convert.ToDateTime(m.NI_Created);

            return(dt.ToString("yyyyMM") + "/" + dt.ToString("dd") + "/");
        }
Esempio n. 4
0
 /// <summary>
 /// 添加新闻阅读记录
 /// </summary>
 /// <param name="newsId">新闻Id</param>
 /// <param name="userId">用户登录Id</param>
 /// <param name="from">来源:app|web</param>
 public static void AddNewsReadRecord(long newsId, long userId, string from)
 {
     if (newsId != 0 && userId != 0)
     {
         var newsM = new BLL.news.News_NewsInfo().GetModel(newsId);
         if (newsM != null && newsM.NI_IsRecordRead == 1)
         {
             var bll = new BLL.news.News_NewsReader();
             //var ml = bll.GetModelList(" NI_Id=" + newsId + " and UserId=" + userId);
             //if (ml == null || ml.Count < 1)
             {
                 var model = new Model.news.News_NewsReader()
                 {
                     NI_Id   = newsId,
                     NR_From = from,
                     UserId  = userId,
                     NR_Time = DateTime.Now
                 };
                 bll.Add(model);
             }
         }
     }
 }