62,041
社区成员
发帖
与我相关
我的任务
分享
SQL> insert into TB_ATICLE(title,article, articledatetime,articlesgroup_parent_id,articledescription
)
2 select title,article, articledatetime,articlesgroup_parent_id,articledescription from tb_aticle
;
已创建448行。
SQL> commit;
模板页:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Index</title>
</head>
<body>
<div> $htmlformat[0]</div>
<br />
<div> $htmlformat[0]</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title> $htmlformat[0]</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="style.css" type="text/css" rel="stylesheet"/>
<style type="text/css">
<!--
body { margin:0px; font-size:12px;
}
p{text-indent:24px; text-align:left;}
.browser{ border-collapse:collapse; text-align:center; width:95%;}
.PPT{border:1px solid #64b7d7; padding:0px 0px; word-wrap: break-word; word-break:break-all;}
-->
</style>
<!-- 式样表自己制作 -->
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" style="width:800px;">
<tr><!--文章导航 -->
<td align="left" class="PPT" style="height:30px"> $htmlformat[4]</td>
</tr>
<tr><!--文章的标题 -->
<td align="center" class="PPT" style="height:30px" > $htmlformat[0]</td>
</tr>
<tr><!--发表时间 -->
<td align="center"class="PPT" style="height:30px"> $htmlformat[5] $htmlformat[1]</td>
</tr>
<tr><!--文章概述 -->
<td align="left" class="PPT" style="height:60px" valign="top"> $htmlformat[6]<br/>$htmlformat[2]</td>
</tr>
<tr><!--文章内容 -->
<td class="PPT" style="height:200px" valign="top"> $htmlformat[3]</td>
</tr>
</table>
</body>
</html>
数据库:
Article表
create table Aticle
(
Articles_id number(20) primary key,/*自增*/
title varchar2(50) not null,
Article varchar2(3500) not null,
Articledatetime date default sysdate,
Articlesgroup_parent_id number(6),
Articledescription varchar2(500) not null
)
创建自动增长序列
CREATE SEQUENCE newsID_Sequence
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
NOCACHE -- 不建缓冲区
创建触发器
CREATE TRIGGER newsID_Increase BEFORE
insert ON Aticle FOR EACH ROW
begin
select newsID_Sequence.nextval into:New.Articles_id from dual;
end;
提交
commit;
Articlesgroup表
create table Articlesgroup(
Articlesgroup_id number(6),
Groupname varchar2(100) not null,
Articlesgroup_parent_id number(6),
Groupdescription varchar2(500) not null
)
insert into Articlesgroup(Articlesgroup_id,Groupname,Articlesgroup_parent_id,Groupdescription)
values(11,'ASP.NET',1,'IT专区');
insert into Articlesgroup(Articlesgroup_id,Groupname,Articlesgroup_parent_id,Groupdescription)
values(12,'Oracle数据库',1,'IT专区');
insert into Articlesgroup(Articlesgroup_id,Groupname,Articlesgroup_parent_id,Groupdescription)
values(13,'J2EE',1,'IT专区');
ALTER TABLE Aticle RENAME TO tb_Aticle;
insert into tb_Aticle(title,Article,Articlesgroup_parent_id,Articledescription)
values('','',11,'')
//现在问题是 我每次显示100条, 而得到的结果是 WebForm1.aspx页面 是显示100条 但是分页的超链接按钮 没有了?也不现实
/*
using (StreamReader sr = new StreamReader(Server.MapPath("WebForm2.aspx")))
....
string pageStr = "<div>页码:<asp:Label ID='Label2' runat='server' Text=''></asp:Label>"
+"<asp:LinkButton ID='LinkButton3' runat='server' OnClick='LinkButton1_Click'>下一页</asp:LinkButton>"
+"<asp:LinkButton ID='LinkButton4' runat='server' OnClick='LinkButton2_Click'>上一页</asp:LinkButton></div>";
htmltext.Replace("$htmlformat[0]", pageStr);
htmltext.Replace("$htmlformat[1]", format[0]);
我改了一下这个页面 将模板页换成WebForm2.aspx 基本上也是和原来的模板也一样的
报错:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。
分析器错误消息: ID“Label1”已被其他控件使用。
*/
protected void LinkButton1_Click(object sender, EventArgs e)
{
index = index+ 1;
Response.Redirect("WebForm1.aspx?pageIndex=" + index);
}
protected void Page_Load(object sender, EventArgs e)
{
//if (!IsPostBack)
//{
index=1;
//Response.Redirect("WebForm1.aspx?pageIndex=3");
if (Request.QueryString["pageIndex"] != null)
{
int i = Convert.ToInt32(Request.QueryString["pageIndex"].ToString());
index = i;
}
total = getCount();
int page = 100;
int pagecount = Convert.ToInt32((total / page));
NewMethod(page, index);
//现在问题是 我每次显示100条, 而得到的结果是 WebForm1.aspx页面 是显示100条 但是分页的超链接按钮 没有了?也不现实
/*
using (StreamReader sr = new StreamReader(Server.MapPath("WebForm2.aspx")))
....
string pageStr = "<div>页码:<asp:Label ID='Label2' runat='server' Text=''></asp:Label>"
+"<asp:LinkButton ID='LinkButton3' runat='server' OnClick='LinkButton1_Click'>下一页</asp:LinkButton>"
+"<asp:LinkButton ID='LinkButton4' runat='server' OnClick='LinkButton2_Click'>上一页</asp:LinkButton></div>";
htmltext.Replace("$htmlformat[0]", pageStr);
htmltext.Replace("$htmlformat[1]", format[0]);
我改了一下这个页面 将模板页换成WebForm2.aspx 基本上也是和原来的模板也一样的
报错:
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。
分析器错误消息: ID“Label1”已被其他控件使用。
*/
if (index == 1)
{ LinkButton2.Enabled = false; }
else { LinkButton2.Enabled = true; }
if (index == pagecount)
{ LinkButton1.Enabled = false; }
else { LinkButton1.Enabled = true; }
// }
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
index = index - 1;
Response.Redirect("WebForm1.aspx?pageIndex="+index);
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
index = index+ 1;
Response.Redirect("WebForm1.aspx?pageIndex=" + index);
}
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;
using System.Text;
using System.IO;
namespace CreatHtml_DEMO
{
public partial class _Default : System.Web.UI.Page
{
string conStr = "Data Source=orcl;Persist Security Info=True;User ID=store;Password=store;Unicode=True";
public string title = "", content = "", datetime = "", desc = "", pages = "", nowPosition = "", positionlist = null, forindex = "";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
NewMethod();
Response.Redirect("index.html");
}
private void NewMethod()
{
int count = getCount();
for (int i = 1; i <= count; i++)
{
this.Createhtml(i.ToString());
string[] format = new string[1];//定义和htmlyem标记数目一致的数组
StringBuilder htmltext = new StringBuilder();
try
{
using (StreamReader sr = new StreamReader(Server.MapPath("index_tmp.htm")))
{
String line;
while ((line = sr.ReadLine()) != null)
{
htmltext.Append(line);
}
sr.Close();
}
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
//Response.Write("<Script>alert('读取文件错误')</Script>");
}
////---------------------给标记数组赋值------------
format[0] = forindex;
/////----------替换htm里的标记为你想加的内容
htmltext.Replace("$htmlformat[0]", format[0]);
////----------生成htm文件------------------――
try
{
using (StreamWriter sw = new StreamWriter(Server.MapPath("index.html"), false, System.Text.Encoding.GetEncoding("GB2312")))
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
}
}
catch (Exception exp)
{
throw new Exception(exp.ToString());
}
}
//try
//{
// StringBuilder htmltext = new StringBuilder();
// using (StreamReader sr = new StreamReader(Server.MapPath("index.html")))
// {
// String line;
// while ((line = sr.ReadLine()) != null)
// {
// htmltext.Append(line);
// }
// sr.Close();
// }
// string tt = htmltext.ToString();
//}
//catch (Exception ex)
//{
// throw new Exception(ex.ToString());
// //Response.Write("<Script>alert('读取文件错误')</Script>");
//}
}
private void Createhtml(string article_id)
{
this.GetArticle(article_id);
if (title != "" && content != "")
{//防止生成空数据的页面
string[] format = new string[7];//定义和htmlyem标记数目一致的数组
StringBuilder htmltext = new StringBuilder();
try
{
string tmpHtml = Server.MapPath("temp.htm");
using (StreamReader sr = new StreamReader(tmpHtml))
{
String line;
while ((line = sr.ReadLine()) != null)
{
htmltext.Append(line);
}
sr.Close();
}
}
catch (Exception e)
{
throw new Exception(e.ToString());
}
////---------------------给标记数组赋值------------
format[0] = title;
format[1] = datetime;
format[2] = desc;
format[3] = content;
format[4] = nowPosition;
format[5] = "作者:Admin";
format[6] = "文章简介:";
////----------替换htm里的标记为你想加的内容
for (int i = 0; i < 7; i++)
{
htmltext.Replace("$htmlformat[" + i + "]", format[i]);
}
//----------生成htm文件------------------――
try
{
using (StreamWriter sw = new StreamWriter(Server.MapPath("article" + article_id + ".html"), false, System.Text.Encoding.GetEncoding("GB2312")))//"html/article" + article_id + ".html"
{
sw.WriteLine(htmltext);
sw.Flush();
sw.Close();
}
}
catch (Exception e)
{
throw new Exception(e.ToString());
}
}
}
private void GetArticle(string article_id)
{
int articles_id = Convert.ToInt32(article_id);
OracleConnection conn = new OracleConnection(conStr);
string sql = "select * from tb_Aticle where articles_id=" + articles_id;
OracleCommand cmd = new OracleCommand(sql, conn);
try
{
conn.Open();
}
catch (Exception e)
{
throw new Exception(e.ToString());
}
OracleDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
nowPosition = this.GetPosition(sdr["articlesgroup_parent_id"].ToString(), positionlist);
title = sdr["title"].ToString();
content = Server.HtmlDecode(sdr["article"].ToString());
desc = sdr["articledescription"].ToString();
datetime = sdr["articledatetime"].ToString();
forindex += "<a href='article" + articles_id + ".html' target='_blank'>" + sdr["title"] + "</a><br />";
}
else
{
title = "";
content = "";
desc = "";
datetime = "";
}
conn.Close();
}
private string GetPosition(string articlesgroup_id, string positionlist)
{
string articlesgroup_parent_id = "";
string groupname = "";
string NowPosition = "";
if (articlesgroup_id == "")
articlesgroup_id = "0";
string sql = "select articlesgroup_parent_id, groupname from articlesgroup where articlesgroup_id = " + articlesgroup_id + "";
OracleConnection conn = new OracleConnection(conStr);
OracleCommand cmd =new OracleCommand(sql,conn) ;
cmd.CommandType = CommandType.Text;
try
{
conn.Open();
OracleDataReader sdr;
sdr = cmd.ExecuteReader();
if (!sdr.Read())
{
NowPosition = "Current Location:<a href=categorylist.aspx target='_blank'>Base</a>";
}
else
{
articlesgroup_parent_id = sdr["articlesgroup_parent_id"].ToString();
groupname = sdr["groupname"].ToString();
if (groupname != "")
NowPosition = GetPosition(articlesgroup_parent_id, groupname);
}
sdr.Close();
conn.Close();
if (articlesgroup_id != "0")
NowPosition = NowPosition + " -> <a href=categorylist.aspx?viewcatagorie_id=" + articlesgroup_id + " target='_blank'>" + groupname + "</a>";
}
catch (Exception e)
{
throw new Exception(e.ToString());
}
return NowPosition;
}
private int getCount()
{
OracleConnection con = new OracleConnection(conStr);
OracleCommand cmd = new OracleCommand("select max(Articles_id) from tb_aticle", con);//("select count(1) from tb_Aticle", con);//最大编号???? count不行
con.Open();
int kk = Convert.ToInt32(cmd.ExecuteScalar().ToString());
return kk;
}
}
}