示例#1
0
        /// <summary>
        /// 根据cat_ctrl,cat_id获得新闻列表
        /// </summary>
        /// <returns></returns>
        public static List <NewsInfo> News_SelectPaged(string cat_ctrl, string cat_id, string page, string pagesize)
        {
            page     = (int.Parse(page) < 1) ? "1" : page;
            pagesize = (int.Parse(pagesize) > 30) ? "30" : pagesize;

            NewsCateInfo   cate     = CacheMarker.GetNewsCatesBycat_id(cat_id);
            NewsSearchInfo search   = new NewsSearchInfo();
            int            rowcount = 0;

            using (var access = new DataAccess_QzNews(Constants.QZNewSite_News_Db_Key))
            {
                search.n_state = 1;

                if (cate != null && cate.cat_inheritAll && !cate.cat_isLast)
                {
                    search.cat_inheritPath = cate.cat_path;
                }
                else
                {
                    search.n_cat_id = cate.cat_id;
                }

                string whereString = search.ToWhereString();

                // 图集
                if ("photo" == cat_ctrl)
                {
                    whereString += " and n_type='images'";
                }

                return(access.News_SelectPaged(GetNewsTable(cate.cat_tableIndex), "*", whereString, search.DefOrder, int.Parse(page), int.Parse(pagesize), out rowcount));
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pg_uid">"Corp_Page_News"</param>
        /// <param name="blk_name">"Focus"</param>
        /// <param name="topn">"5"</param>
        /// <returns></returns>
        public Stream CMSItems_SelectPaged(string pg_uid, string blk_name, string topn)
        {
            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            // 设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            string json = "";

            CMSBlocksInfo block = CacheMarker.GetCMSBlocksInfo(pg_uid, blk_name);

            if (block == null)
            {
                return(null);
            }
            // 获得发布过的前topn条数据
            List <CMSItemsInfo> cmsItems = new List <CMSItemsInfo>();

            cmsItems = DataAccess_News.CMSItems_SelectTopN2(block.blk_id, int.Parse(topn), "" /*" and n_publish = 1"*/);

            var jsonSerialiser = new JavaScriptSerializer();

            json = string.Format("{{\"AppTop\":{0}}}", jsonSerialiser.Serialize(cmsItems));

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
示例#3
0
        /// <summary>
        /// 获取热门评论
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public Stream RecommendComments_SelectPaged(string sourceId, string page, string limit)
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json; charset=utf-8";

            string json = CacheMarker.GetRecommendComments(sourceId.ToSafety(), page, limit);

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
示例#4
0
        /// <summary>
        /// 加载个人评论(个人中心:我的跟帖)
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public Stream LoadUserContent(string userId, string page, string pagesize)
        {
            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            // 设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            string json = "";

            // 根据条件获得评论
            List <CommentInfo> cmtLst = DataAccess_News.Comments_SelectPaged(userId, page, pagesize);

            // 在评论里加上作者、发表时间、以及文章标题
            List <CommentInfoApp> cmtLst2 = new List <CommentInfoApp>();

            if (cmtLst != null)
            {
                for (int i = 0; i < cmtLst.Count; i++)
                {
                    var item    = cmtLst[i];
                    var infoApp = new CommentInfoApp();
                    infoApp.cmt_content      = item.cmt_content;
                    infoApp.cmt_id           = item.cmt_id;
                    infoApp.cmt_sourceId     = item.cmt_sourceId;
                    infoApp.cmt_sourceType   = item.cmt_sourceType;
                    infoApp.cmt_uid          = item.cmt_uid;
                    infoApp.cmt_sourceCateId = item.cmt_sourceCateId;

                    int catId = 0;
                    if (!int.TryParse(item.cmt_sourceCateId, out catId))
                    {
                        continue;
                    }

                    var cate = CacheMarker.GetNewsCatesBycat_id(catId.ToString());
                    if (cate == null)
                    {
                        continue;
                    }
                    NewsInfo news = CacheMarker.News_Selectbyn_gid(item.cmt_sourceId, "News_" + cate.cat_tableIndex.ToString());
                    if (news != null)
                    {
                        infoApp.n_authors = news.n_authors;
                        infoApp.n_date    = news.n_date;
                        infoApp.n_title   = news.n_title;
                    }

                    cmtLst2.Add(infoApp);
                }
            }
            var jsonSerialiser = new JavaScriptSerializer();

            json = "{\"list\":" + jsonSerialiser.Serialize(cmtLst2) + "}";
            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
示例#5
0
        /// <summary>
        /// 获取热门评论
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public Stream RecommendComments_SelectPaged2(string sourceId, string page, string limit)
        {
            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            //设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";

            string json = CacheMarker.GetRecommendComments2(sourceId.ToSafety(), page, limit);

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
示例#6
0
        /// <summary>
        /// 获得某条新闻的详细内容
        /// </summary>
        /// <param name="rData"></param>
        /// <returns></returns>
        public Stream NewsContent_Selectbync_n_gid(NewsContentInfo_RD rData)
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json;charset=utf-8";
            string json = "";
            // 获取某条新闻的详细内容
            List <NewsContentInfo> list = DataAccess_News.GetNewsContent(rData.n_gid);

            if (list.Count == 0)
            {
                json = string.Format("{{\"contents\":{0},\"shareUrl\":\"{1}\",\"imgs\":{2}}}", string.Empty,
                                     string.Empty, string.Empty);
            }
            else
            {
                string       shareUrl = ""; // 分享文章的地址
                NewsCateInfo cateInfo = null;
                string       n_gid    = "";
                // 获取文章分类的相关字段信息,并拼接得到文章分享地址
                if (list != null && list.Count > 0)
                {
                    // 分类ID
                    string cat_id = rData.vl_cateId.ToSafety();
                    // 根据分类ID获取分类信息
                    cateInfo = CacheMarker.GetNewsCatesBycat_id(cat_id);

                    string cat_ctrl = (cateInfo != null) ? cateInfo.cat_ctrl : "";
                    n_gid    = list[0].nc_n_gid;
                    shareUrl = "http://qiye.qianzhan.com/show/detail/" + rData.n_gid + ".html";
                    //ServiceHandler.GetDetailURL(cat_ctrl, cat_id, n_gid, 1, false);
                }

                // 存放图片数据
                List <ImgsInfo> imgs = new List <ImgsInfo>();
                // 自定义文章内容
                list = CustomContent(list, n_gid, "News_" + cateInfo.cat_tableIndex, out imgs, rData.vl_screenSize);

                // 插入浏览记录
                int logIndex = VisitLog_Insert(rData, shareUrl);
                if (logIndex == -1)
                {
                    return(null);
                }

                var jsonSerialiser = new JavaScriptSerializer();
                json = string.Format("{{\"contents\":{0},\"shareUrl\":\"{1}\",\"imgs\":{2}}}", jsonSerialiser.Serialize(list), shareUrl, jsonSerialiser.Serialize(imgs));
            }

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
示例#7
0
        public static Response Process_Index_Pics()
        {
            var pics_mb = CacheMarker.GetCMSBlocksInfo("App_Header_Pic", "Focus").ToMaybe()     // get info of the block with a path of 'App_Header_Pic.Focus'. Refer to behind website for more details
                          .Select(block => DataAccess_News.CMSItems_SelectTopN2(block.blk_id, 5, "").ToMaybe())
                          .Select(items => items.Select(item => new Index_Pic()
            {
                href = item.n_linkUrl, img_src = item.n_imageUrl, title = item.n_title
            }).ToList().ToMaybe());

            var body     = pics_mb.HasValue ? pics_mb.Value.ToJson() : new List <Index_Pic>().ToJson();
            var response = Util.Normal_Resp_Create(body, EncryptType.PT);

            return(response);
        }
示例#8
0
        /// <summary>
        /// 根据cat_ctrl获得新闻列表
        /// 指定某一个新闻分类,然后获取这个分类下的处于正常状态的新闻列表
        /// </summary>
        /// <returns></returns>
        public static List <NewsInfo> News_SelectPaged(string cat_ctrl, string page, string pagesize)
        {
            page     = (int.Parse(page) < 1) ? "1" : page;
            pagesize = (int.Parse(pagesize) > 30) ? "30" : pagesize;

            // 根据指定的cat_ctrl获取某一新闻分类信息
            NewsCateInfo cate = CacheMarker.GetNewsCateByCtrl(cat_ctrl);

            if (cate == null)
            {
                return(new List <NewsInfo>());
            }
            NewsSearchInfo search   = new NewsSearchInfo();
            int            rowcount = 0;

            using (var access = new DataAccess_QzNews(Constants.QZNewSite_News_Db_Key))
            {
                try
                {
                    search.n_state = 1;

                    if (cate.cat_inheritAll && !cate.cat_isLast)
                    {
                        search.cat_inheritPath = cate.cat_path;
                    }
                    else
                    {
                        search.n_cat_id = cate.cat_id;
                    }

                    string whereString = search.ToWhereString();

                    // 图集
                    if ("photo" == cat_ctrl)
                    {
                        whereString += " and n_type='images'";
                    }

                    return(access.News_SelectPaged(GetNewsTable(cate.cat_tableIndex), "*", whereString, search.DefOrder, int.Parse(page), int.Parse(pagesize), out rowcount));
                }
                catch (Exception e)
                {
                    #region debug
                    Util.Log_Info(nameof(News_SelectPaged), Location.Internal, e.Message, "database error");
                    #endregion
                    return(new List <NewsInfo>());
                }
            }
        }
示例#9
0
        public static List <NewsInfo> News_Page_Select(string catId, string page, string pagesize)
        {
            page     = (int.Parse(page) < 1) ? "1" : page;
            pagesize = (int.Parse(pagesize) > 30) ? "30" : pagesize;

            // 根据指定的cat_ctrl获取某一新闻分类信息
            NewsCateInfo cate = CacheMarker.NewsCates_FromId_Get(catId);

            if (cate == null)
            {
                return(new List <NewsInfo>());
            }
            NewsSearchInfo search   = new NewsSearchInfo();
            int            rowcount = 0;

            using (var access = new DataAccess_QzNews(Constants.QZNewSite_News_Db_Key))
            {
                try
                {
                    search.n_state = 1;

                    if (cate.cat_inheritAll && !cate.cat_isLast)
                    {
                        search.cat_inheritPath = cate.cat_path;
                    }
                    else
                    {
                        search.n_cat_id = cate.cat_id;
                    }

                    string whereString = search.ToWhereString();

                    //// 图集
                    //if ("photo" == cat_ctrl)
                    //{
                    //    whereString += " and n_type='images'";
                    //}

                    var res = access.News_SelectPaged(GetNewsTable(cate.cat_tableIndex), "*", whereString, search.DefOrder, int.Parse(page), int.Parse(pagesize), out rowcount);
                    return(res);
                }
                catch (Exception e)
                {
                    return(new List <NewsInfo>());
                }
            }
        }
示例#10
0
        /// <summary>
        /// 获取某一分类下最新新闻
        /// </summary>
        /// <param name="cat_ctrl"></param>
        /// <returns></returns>
        public static NewsInfo LastNews_Select(string cat_ctrl)
        {
            // 根据指定的cat_ctrl获取某一新闻分类信息
            NewsCateInfo cate = CacheMarker.GetNewsCateByCtrl(cat_ctrl);

            if (cate == null)
            {
                return(null);
            }
            NewsSearchInfo search   = new NewsSearchInfo();
            int            rowcount = 0;

            using (var access = new DataAccess_QzNews(Constants.QZNewSite_News_Db_Key))
            {
                search.n_state = 1;

                if (cate.cat_inheritAll && !cate.cat_isLast)
                {
                    search.cat_inheritPath = cate.cat_path;
                }
                else
                {
                    search.n_cat_id = cate.cat_id;
                }

                string whereString = search.ToWhereString();

                // 图集
                if ("photo" == cat_ctrl)
                {
                    whereString += " and n_type='images'";
                }

                var list = access.News_SelectPaged(GetNewsTable(cate.cat_tableIndex), "*",
                                                   whereString, search.DefOrder, 1, 1, out rowcount);
                if (list != null && list.Count > 0)
                {
                    return(list[0]);
                }
                return(null);
            }
        }
示例#11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="list"></param>
        /// <param name="n_gid"></param>
        /// <param name="tableName"></param>
        /// <param name="imgs"></param>
        /// <param name="screen_resolution"></param>
        /// <returns></returns>
        private List <NewsContentInfo> CustomContent(List <NewsContentInfo> list, string n_gid, string tableName,
                                                     out List <ImgsInfo> imgs, string screen_resolution = "")
        {
            // 样式
            string tableStyle = "border-collapse:collapse;text-align:left;";
            string pStyle     = "font-size:18px;font-family:'Helvetica Neue','Helvetica','Heiti SC Regular',stheititc,sans-serif;font-color:#000;line-height:1.6;margin-top:19px;padding:0 6.5px"; //text-align:justify;

            if ((screen_resolution == "750x1334") || (screen_resolution == "1080x1920"))                                                                                                           // 6、6s
            {
                pStyle = "font-size:20px;font-family:'Helvetica Neue','Helvetica','Heiti SC Regular',stheititc,sans-serif;font-color:#000;line-height:1.6;margin-top:25px;padding:0 7.5px";        //text-align:justify;
            }
            string titleStyle  = "font-size:25px;font-weight:bold;line-height:1.25;font-family:'Helvetica Neue','Helvetica','Heiti SC',stheititc,sans-serif;color:#333;padding:0;margin:0;";
            string authorStyle = "font-size:12px;font-weight:400;font-family:'Helvetica Neue','Helvetica','Heiti SC',stheititc,sans-serif;color:#bbb;padding:0;margin:0;line-height:1.25;";

            // 获取文章题名,作者与时间
            string   html     = "";
            NewsInfo newsInfo = CacheMarker.News_Selectbyn_gid(n_gid, tableName); //DataAccess_News.News_Selectbyn_gid(n_gid, tableName);

            if (newsInfo != null)                                                 // 图集不需要将文章标题加入内容中
            {
                if (newsInfo.n_type != "images")
                {
                    string title  = newsInfo.n_title;
                    string author = string.IsNullOrEmpty(newsInfo.n_authors.Trim()) ? newsInfo.n_source : newsInfo.n_authors;
                    string date   = newsInfo.n_date;
                    html = string.Format("<p style=\"{0}\">{1}</p><p style=\"{2}\">{3} {4}</p>", titleStyle, title, authorStyle, date, author);
                }
                else
                {
                    list.RemoveAll(t => t.nc_order == -1);
                }
            }

            // 存放图片数据
            imgs = new List <ImgsInfo>();
            int first = 0;

            if (list != null)
            {
                foreach (var info in list)
                {
                    // 对新闻内容特殊字符做处理
                    info.nc_content = HtmlHelper.DecodeHTMLString(info.nc_content, false);

                    using (HtmlParser hp = new HtmlParser(string.Format("<q>{0}</q>", info.nc_content)))
                    {
                        hp.Parse();
                        // 链接集合
                        List <HtmlTag> anchorList = hp.HtmlElemnt.GetElementsByTagName("a");
                        foreach (var anchor in anchorList)
                        {
                            anchor.RemoveTagButKeepChildrenAndValue();  // 去掉新闻内容中的a标签
                        }
                        // 图片集合
                        List <HtmlTag> imgList = hp.HtmlElemnt.GetElementsByTagName("img");
                        foreach (var img in imgList)
                        {
                            img.SetAttribute("style", "width:100%;height:auto"); // 设置新闻内容的图片样式
                            img.RemoveAttribute("width");                        // 去除原来的width属性
                            img.RemoveAttribute("height");                       // 去除原来的height属性

                            string   src   = img.GetAttribute("src");
                            string   alt   = img.GetAttribute("alt");
                            ImgsInfo _info = new ImgsInfo();
                            _info.src = src;
                            _info.alt = alt;
                            imgs.Add(_info);
                        }
                        List <HtmlTag> pTags = hp.HtmlElemnt.GetElementsByTagName("p");
                        foreach (var p in pTags)
                        {
                            p.SetAttribute("style", pStyle); // 设置文章段落
                            foreach (var strong in p.GetElementsByTagName("strong"))
                            {
                                strong.SetAttribute("style", "color:#333");
                            }
                        }
                        // 设置表格样式
                        List <HtmlTag> tTags = hp.HtmlElemnt.GetElementsByTagName("table");
                        foreach (var table in tTags)
                        {
                            // 删除文章中的相关推荐
                            if (table.GetAttribute("style") == "float:right;margin-left:5px;border: 1px solid #C4D6EC;")
                            {
                                table.RemoveTag();
                                continue;
                            }

                            table.SetAttribute("style", tableStyle);
                        }

                        if (++first == 1)// 有些文章分成几篇,会出现多个标题情况
                        {
                            if (newsInfo != null && newsInfo.n_type != "images")
                            {
                                info.nc_content = html + hp.HtmlElemnt.InnerHTMLReBuild + "<br />"; // 重新组装新闻内容
                            }
                            else
                            {
                                info.nc_content = html + hp.HtmlElemnt.InnerHTMLReBuild;
                            }
                        }
                        else
                        {
                            if (newsInfo != null && newsInfo.n_type != "images")
                            {
                                info.nc_content = hp.HtmlElemnt.InnerHTMLReBuild + "<br />"; // 重新组装新闻内容
                            }
                            else
                            {
                                info.nc_content = hp.HtmlElemnt.InnerHTMLReBuild;
                            }
                        }
                    }
                }
            }
            return(list);
        }