gg

 

template.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
</head>
<body>

  
    $main
<br />
<div>$first&nbsp;&nbsp;&nbsp;$prev&nbsp;&nbsp;&nbsp;$info$next&nbsp;&nbsp;&nbsp;$last&nbsp;&nbsp;&nbsp;当前第$nowpage页&nbsp;&nbsp;共$total页</div>
</body>
</html>

 

CreateHtml.cs

 

 

 

 Service service = new Service();
    Common com = new Common();
    WhereDO where = new WhereDO();
    SystemsDO systemsDO = new SystemsDO();//网站信息
    private string sTemplatePath = System.Web.HttpContext.Current.Server.MapPath("template/");//模板路径
   
    private Encoding eCode = Encoding.GetEncoding("utf-8");//编码方式

    protected void Page_Load(object sender, EventArgs e)
    {


        GengerateHtmlList();
       

    }

    #region 判断文件夹是否存在 如果不存在,测创建
    /// <summary>
    /// 判断文件夹是否存在 如果不存在,测创建
    /// </summary>
    /// <param name="path"></param>
    private void DirIsExists(string path)
    {
        try
        {
            if (Directory.Exists(path))
            {

            }
            else
            {
                Directory.CreateDirectory(path);
            }
        }
        catch
        {
            Response.Write("<script>alert('路径不对或者没有写入权限,请联系管理员!')</script>");
        }

    }
     #endregion
    //获取总的页数
    public int GetAllPage()
    {
        int _allpage;
        WhereDO where = new WhereDO();
        where.Pagesize = 0;
        where.TableName = "news";
        where.Where=" siteId=3";

        DataSet ds = service.SelectByWhere(where);
        if (ds != null && ds.Tables[0].Rows.Count > 0)
        {
            if (ds.Tables[0].Rows.Count <= 100)
            {
                _allpage = 1;
            }
            else
            {
                _allpage = ds.Tables[0].Rows.Count / 100;
                if (ds.Tables[0].Rows.Count % 100 != 0)
                {
                    _allpage++;
                }
            }
        }
        else
        {
            return 1;
        }
        return _allpage;
    }
    //生成列表页面
    protected void GengerateHtmlList()
    {      

        where.Pagesize = 0;
        where.TableName = "Catalog";
        where.Where = "SiteId=3 and CataTypeId=3";
        DataSet dclass = service.SelectByWhere(where);
        if (dclass!=null&&dclass.Tables.Count>0)
        {
            for (int h = 0; h < dclass.Tables[0].Rows.Count; h++)
            {
                string filename = dclass.Tables[0].Rows[h]["Folder"].ToString();
                this.DirIsExists(System.Web.HttpContext.Current.Server.MapPath("sitemap"));

                string sFilePath = System.Web.HttpContext.Current.Server.MapPath("sitemap/");//生成路径
                string sHtmlFont = "$main";//需要替换的文字;
                for (int i = 1; i <= GetAllPage(); i++)
                {
                    DateTime dt = DateTime.Now;
                    string sHtml = null;//生成页面内容
                    StreamReader srHtml = null;
                    StreamWriter swHtml = null;
                    string sHtmlMain = "";//替换成的内容
                    srHtml = new StreamReader(sTemplatePath + "template.htm", eCode);
                    sHtml = srHtml.ReadToEnd();
                    srHtml.Close();
                    WhereDO where1 = new WhereDO();
                    DataSet ds = null;
                    if (i == 1)
                    {
                        where1.Pagesize = 100;
                        where1.TableName = "news";
                        where1.Where = " siteId=3 order by StartTime desc";

                        ds = service.SelectByWhere(where1);
                        for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                        {
                            sHtmlMain += "<li><a href=/"sitemap_" + ds.Tables[0].Rows[j]["Filename"] + ".html/" target=/"_blank/">" +filename+ ds.Tables[0].Rows[j]["Filename"] + "</a></li>";
                        }
                        sHtml = sHtml.Replace(sHtmlFont, sHtmlMain);
                        sHtml = sHtml.Replace("$prev", "上一页");
                        sHtml = sHtml.Replace("$next", "<a href='sitemap_" + (i + 1) + ".html'>下一页</a>");
                        sHtml = sHtml.Replace("$first", "首页");
                        sHtml = sHtml.Replace("$last", "<a href='sitemap_" + GetAllPage() + ".html'>末页</a>");
                        sHtml = sHtml.Replace("$total", GetAllPage().ToString());
                    }
                    else if (i == GetAllPage())
                    {
                        int not = (i - 1) * 100;
                        where1.Pagesize = 100;
                        where1.TableName = "news";
                        where1.Where = " siteId=3 and Id not in (select top " + not + " Id from News Order by StartTime desc)order by StartTime desc";


                        ds = service.SelectByWhere(where1);
                        for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                        {
                            sHtmlMain += "<li><a href=/"NewsInfo_" + ds.Tables[0].Rows[j]["Id"] + ".html/" target=/"_blank/">" + ds.Tables[0].Rows[j]["Filename"] + "</a></li>";
                        }
                        sHtml = sHtml.Replace(sHtmlFont, sHtmlMain);
                        sHtml = sHtml.Replace("$prev", "<a href='sitemap_" + (i - 1) + ".html'>上一页</a>");
                        sHtml = sHtml.Replace("$next", "下一页");
                        sHtml = sHtml.Replace("$first", "<a href='sitemap_1.html'>首页</a>");
                        sHtml = sHtml.Replace("$last", "末页");
                        sHtml = sHtml.Replace("$total", GetAllPage().ToString());
                    }
                    else
                    {
                        int not = (i - 1) * 100;
                        where1.Pagesize = 100;
                        where1.TableName = "news";
                        where1.Where = " siteId=3 and Id not in (select top " + not + " Id from News Order by StartTime desc)order by StartTime desc";

                        ds = service.SelectByWhere(where1);
                        for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                        {
                            sHtmlMain += "<li><a href=/"NewsInfo_" + ds.Tables[0].Rows[j]["Id"] + ".html/" target=/"_blank/">" + ds.Tables[0].Rows[j]["Filename"] + "</a></li>";
                        }
                        sHtml = sHtml.Replace(sHtmlFont, sHtmlMain);
                        sHtml = sHtml.Replace("$prev", "<a href='sitemap_" + (i - 1) + ".html'>上一页</a>");
                        sHtml = sHtml.Replace("$next", "<a href='sitemap_" + (i + 1) + ".html'>下一页</a>");
                        sHtml = sHtml.Replace("$first", "<a href='sitemap__1.html'>首页</a>");
                        sHtml = sHtml.Replace("$last", "<a href='sitemap_" + GetAllPage() + ".html'>末页</a>");
                        sHtml = sHtml.Replace("$total", GetAllPage().ToString());
                    }
                    string sAllPage = "";
                    for (int j = 1; j <= GetAllPage(); j++)
                    {
                        if (j == i)
                        {
                            sAllPage += "" + j + "&nbsp;&nbsp;&nbsp;";
                        }
                        else
                        {
                            sAllPage += "<a href='sitemap_" + j + ".html'>" + j + "</a>&nbsp;&nbsp;&nbsp;";
                        }
                    }
                    sHtml = sHtml.Replace("$nowpage", i.ToString());
                    sHtml = sHtml.Replace("$info", sAllPage);
                    swHtml = new StreamWriter(sFilePath + "sitemap_" + i + ".html", false, eCode);
                    swHtml.Write(sHtml);
                    swHtml.Flush();
                    swHtml.Close();
                    sHtmlMain = "";

 

                }


            } Response.Write("<script>alert('生成成功');</script>");
         
        }
     
    }

 

CREATE TABLE [Catalog] (
 [Id] [int] IDENTITY (1, 1) NOT NULL ,
 [Title] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Fpath] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Folder] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Modelname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Conname] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Remark] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
 [Pic] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
 [Seotitle] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [Seokeywords] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
 [Seodesc] [nvarchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
 [ParentId] [int] NULL CONSTRAINT [DF_Catalog_ParentId] DEFAULT (0),
 [Sort] [int] NULL CONSTRAINT [DF_Catalog_Sort] DEFAULT (0),
 [Status] [int] NULL CONSTRAINT [DF_Catalog_Status] DEFAULT (0),
 [InfoNum] [int] NULL CONSTRAINT [DF_Catalog_InfoNum] DEFAULT (0),
 [TagName] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
 [CataTypeId] [int] NULL CONSTRAINT [DF_Catalog_CataTypeId] DEFAULT (0),
 [IsShow] [int] NULL CONSTRAINT [DF_Catalog_IsShow] DEFAULT (0),
 [SiteId] [int] NULL CONSTRAINT [DF_Catalog_SiteId] DEFAULT (0),
 [Starttime] [datetime] NULL CONSTRAINT [DF_Catalog_Starttime] DEFAULT (getdate()),
 [Content] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
 CONSTRAINT [PK_Catalog] PRIMARY KEY  CLUSTERED
 (
  [Id]
 )  ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值