예제 #1
0
파일: App.aspx.cs 프로젝트: daonidedie/-
    ///<summary>
    /// 帮定分页数据
    ///</summary>
    ///
    void BindData(string key = null)
    {
        IEnumerable <书名表> ListSource = new List <书名表>();



        ListSource = Tygdb.书名表.Where(p => p.包含有效章节 != null && p.包含有效章节 > 0).OrderByDescending(p => p.最后更新时间);
        //ShowNews.DataSource = ListSource;
        //ShowNews.DataBind();
        //每一个分类取最新的一条记录
        var docs = Tygdb.ExecuteStoreQuery <NewDocItem>(@"
select d.ID,d.本记录GUID,d.GUID,d.书名 into #doc  from (
  select top 100 [GUID] from 书名表 where 包含有效章节 > 0    order by 最后更新时间 desc 
 ) as
 doctype
 left join 
 (
    SELECT *  from  文章表 
 )
 d
 on d.[GUID]=doctype.[GUID] 
select * from (select *,row=row_number()over(partition by [GUID] order by ID desc) from #doc)t where row=1 and t.id>0
drop table #doc ");

        decimal[] ids = docs.Select(p => p.ID).ToArray();
        //使用了in
        var topDocs = Tygdb.文章表.Where(p => ids.Contains(p.ID)).OrderByDescending(p => p.ID).ToList().Where(
            //确保章节是有效的
            p => string.Join("", System.Text.RegularExpressions.Regex.Matches(p.内容, @"[\u4e00-\u9fa5\d\w123456789~!!·#¥%……—*()——+/”》“‘’,;。、?,:…《]+[\u4e00-\u9fa5123456789~!!·#¥%……—*(!)——+/”》“‘,’\r\n;。、?,:…《]", System.Text.RegularExpressions.RegexOptions.Multiline)
                             .Cast <System.Text.RegularExpressions.Match>().Select(x => x.Value).ToArray()
                             ).Length > 200
            );


        topDocs = topDocs.ToList().Where(p => System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + p.GetHTMLFilePath())).ToList();


        Docs1.DataSource = topDocs.Take(6);
        Docs1.DataBind();
        Repeater1.DataSource = topDocs.Skip(6 * 1).Take(6);
        Repeater1.DataBind();

        Repeater2.DataSource = topDocs.Skip(6 * 2).Take(6);
        Repeater2.DataBind();

        Repeater3.DataSource = topDocs.Skip(6 * 3).Take(6);
        Repeater3.DataBind();

        Repeater4.DataSource = topDocs.Skip(6 * 4).Take(6);
        Repeater4.DataBind();

        Repeater5.DataSource = topDocs.Skip(6 * 5).Take(6);
        Repeater5.DataBind();

        BindTopBook();
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.IEnumerable <BookDoc> list = new List <BookDoc>();
        string guid = Request.QueryString["guid"];

        bool.TryParse(Request.QueryString["html"], out IsCresteHTMLPage);



        if (!string.IsNullOrEmpty(guid))
        {
            Guid guidx = Guid.Parse(guid);
            //susucong 生成静态页面
            if (QliliHelper.BaseSite.Contains("qlili.com") && System.Configuration.ConfigurationManager.AppSettings["启用Qlili获取数据"] != "0")
            {
                //使用url
                string result = QliliHelper.IndexBook();
                if (!string.IsNullOrEmpty(result))
                {
                    currentBook = Tygdb.书名表.Where(p => p.GUID == guidx).FirstOrDefault();
                    Response.Write(result);
                    currentBook.CreateStaticHTMLFile(result);
                    Response.End();
                    return;
                }
            }

            list = Tygdb.ExecuteStoreQuery <BookDoc>(string.Format(@"
SELECT  
		[ID]
      ,[章节名]
      ,[上一章]
      ,[本记录GUID]
      ,[下一章]
      
  FROM [Tyg].[dbo].[文章表]
  where [GUID]='{0}' order by 最后访问时间
", guid)).ToList();
            //Tygdb.文章表.Where(p => p.GUID == Guid.Parse(guid)).OrderBy(p => p.创建时间);
            currentBook = Tygdb.书名表.Where(p => p.GUID == guidx).FirstOrDefault();
            if (list.Count() > 0)
            {
                var item = list.First();
                BookName = currentBook.书名;
                Creater  = currentBook.作者名称;
                LastTime = currentBook.最后更新时间.ToString();
            }

            if (list.Count() > 2)
            {
                //循环数据
                list.Aggregate((c, n) =>
                {
                    n.一章 = c.本记录GUID;
                    c.一章 = n.本记录GUID;
                    return(n);
                });
                currentBook.包含有效章节 = list.Count();
            }
        }

        docList.EnableViewState = false;

        //System.Threading.Tasks.Task.Factory.StartNew(delegate
        //{
        //    System.Net.WebClient wc = new System.Net.WebClient();

        //    foreach (var item in list)
        //    {
        //        string url = item.GetHTMLFilePath();
        //        if (!System.IO.File.Exists(System.IO.Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + url)))
        //        {
        //            //生成静态页面
        //            string str = wc.DownloadString(new Uri(Request.Url, "BookIndex.aspx?guid=" + item.本记录GUID));

        //            item.CreateStaticHTMLFile(str);

        //        }
        //        // item.采集用的URL9 = url ? url : "BookIndex.aspx?guid=" + book.GUID;
        //    }
        //});
        docList.DataSource = list;
        docList.DataBind();
    }