功能很单一,也不是很完善~~,虚心听各位的教诲*^_^*
代码如下:
using System;
using System.Data;
using System.Xml;
using System.Text;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.IO;
using System.ComponentModel;
namespace htmldemo
{
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:生成静态页面
/// </summary>
public class xmlhtml:IDisposable
{
public string strXmlName_;
public string strHTMLName_;
public string strXSLTName_;
public int intPageSize_;
public DataTable dts_;
private int _intCx=0;
private bool disposed = false;
private Component component = new Component();
private IntPtr handle;
public xmlhtml()
{
}
public xmlhtml(DataTable dt,string XmlFileName,string HtmlFileName,string XsltFileName)
{
strXmlName_=XmlFileName;
strHTMLName_=HtmlFileName;
strXSLTName_=XsltFileName;
dts_=dt;
_intCx=2;
}
public xmlhtml(DataTable dt,string XmlFileName,string HtmlFileName,string XsltFileName,int PageSize)
{
strXmlName_=XmlFileName;
strHTMLName_=HtmlFileName;
strXSLTName_=XsltFileName;
intPageSize_=PageSize;
dts_=dt;
_intCx=1;
}
public xmlhtml(IntPtr handle)
{
this.handle = handle;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if(!this.disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if(disposing)
{
// Dispose managed resources.
component.Dispose();
}
// Call the appropriate methods to clean up
// unmanaged resources here.
// If disposing is false,
// only the following code is executed.
CloseHandle(handle);
handle = IntPtr.Zero;
}
disposed = true;
}
[System.Runtime.InteropServices.DllImport("Kernel32")]
private extern static Boolean CloseHandle(IntPtr handle);
~xmlhtml()
{
// Do not re-create Dispose clean-up code here.
// Calling Dispose(false) is optimal in terms of
// readability and maintainability.
Dispose(false);
}
public bool StaticHtml()
{
if(_intCx==0)
{
return false;
}
else if(_intCx==1)
{
return StaticHtml(dts_,strXmlName_,strHTMLName_,strXSLTName_,intPageSize_);
}
else if(_intCx==2)
{
return StaticHtml(dts_,strXmlName_,strHTMLName_,strXSLTName_);
}
else
{
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:根据sql语句和xslt样式表生成静态html页面,分页控制
/// </summary>
/// <param name="dt">生成xml的DataTable</param>
/// <param name="strSql">数据表的sql语句</param>
/// <param name="strXmlName">中间生成的xml的路径</param>
/// <param name="strHTMLName">生成的静态html的路径</param>
/// <param name="strXSLTName">样式表xslt的路径</param>
/// <param name="pagesize">分页尺寸</param>
/// <returns>成功true</returns>
public bool StaticHtml(DataTable dt,string strXmlName,string strHTMLName,string strXSLTName,int pagesize)
{
if(dt!=null && strXmlName!=null && strHTMLName!=null && strXSLTName!=null && strXmlName!="" && strHTMLName!="" && strHTMLName!="")
{
processDirectory(strXmlName);
processDirectory(strHTMLName);
//processDirectory(strXSLTName);
int temp=TransformDTIntoXML(dt,strXmlName,pagesize);
if(temp!=-1)
{
if(TransformXMLIntoHtml(strXmlName,strHTMLName,strXSLTName,temp)==true)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:根据sql语句和xslt样式表生成静态html页面
/// </summary>
/// <param name="strSql">数据表的sql语句</param>
/// <param name="strXmlName">中间生成的xml的路径</param>
/// <param name="strHTMLName">生成的静态html的路径</param>
/// <param name="strXSLTName">样式表xslt的路径</param>
/// <returns>成功true</returns>
public bool StaticHtml(DataTable dt,string strXmlName,string strHTMLName,string strXSLTName)
{
if(dt!=null && strXmlName!=null && strHTMLName!=null && strXSLTName!=null && strXmlName!="" && strHTMLName!="" && strHTMLName!="")
{
processDirectory(strXmlName);
processDirectory(strHTMLName);
//processDirectory(strXSLTName);
if(TransformDTIntoXML(dt,strXmlName)==true)
{
if(TransformXMLIntoHtml(strXmlName,strHTMLName,strXSLTName)==true)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:将xml转换成html
/// </summary>
/// <param name="strHtmlName">要生成的html路径</param>
/// <param name="strXMLName">要转换的xml路径</param>
/// <param name="strXSLTName">样式表路径</param>
/// <returns>成功true</returns>
private bool TransformXMLIntoHtml(string strXMLName,string strHtmlName,string strXSLTName)
{
try
{
string filename=strXMLName;
string stylesheet=strXSLTName;
string html=strHtmlName;
XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);
XPathDocument xpathdocument = new XPathDocument(filename);
XmlTextWriter writer = new XmlTextWriter(html,Encoding.UTF8);
xslt.Transform(xpathdocument, null, writer, null);
writer.Close();
return true;
}
catch(Exception e)
{
e=null;
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:将xml转换成html,支持分页
/// </summary>
/// <param name="strHtmlName">要生成的html路径</param>
/// <param name="strXMLName">要转换的xml路径</param>
/// <param name="strXSLTName">样式表路径</param>
/// <returns>成功true</returns>
private bool TransformXMLIntoHtml(string strXMLName,string strHtmlName,string strXSLTName,int pagecount)
{
try
{
for(int i=0;i<pagecount;i++)
{
string filename=processFileName(i,strXMLName);
string stylesheet=strXSLTName;
string html=processFileNameHtml(i,strHtmlName);
XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);
XPathDocument xpathdocument = new XPathDocument(filename);
XmlTextWriter writer = new XmlTextWriter(html,Encoding.UTF8);
xslt.Transform(xpathdocument, null, writer, null);
writer.Close();
}
return true;
}
catch(Exception e)
{
e=null;
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:将DataTable转换成Xml文件,支持分页
/// </summary>
/// <param name="dt">要转换的DataTable</param>
/// <param name="strXMLName">生成xml的路径</param>
/// <param name="intPageSize">分页页面尺寸</param>
/// <returns>成功true</returns>
private int TransformDTIntoXML(DataTable dt,string strXMLName,int intPageSize)
{
try
{
int pno=dt.Rows.Count/intPageSize;
if(dt.Rows.Count%intPageSize>0)
{
pno++;
}
int countstart=0;
int countend=dt.Rows.Count;
int nowcount = dt.Rows.Count;
for(int k=0;k<pno;k++)
{
XmlTextWriter xtw=new XmlTextWriter(processFileName(k,strXMLName),null);
int page=k+1;
if(page * intPageSize<nowcount)
{
countstart =(page-1) * intPageSize;
countend = page * intPageSize;
}
else if((page==1)&&(page * intPageSize>nowcount))
{
countstart =0;
countend =nowcount;
}
else
{
countstart = (page-1)*intPageSize;
countend = nowcount;
}
xtw.WriteStartDocument();
xtw.WriteStartElement("records");
for(int i=countstart;i<countend;i++)
{
xtw.WriteStartElement("record");
for(int j=0;j<dt.Columns.Count;j++)
{
xtw.WriteStartElement(dt.Columns[j].ColumnName);
xtw.WriteString(dt.Rows[i][j].ToString());
xtw.WriteEndElement();
}
xtw.WriteEndElement();
}
xtw.WriteStartElement("pagecontrol");
xtw.WriteStartElement("recordcount");
xtw.WriteString(Convert.ToString(nowcount));
xtw.WriteEndElement();
xtw.WriteStartElement("firstpage");
xtw.WriteString(strXMLName.Replace(".xml",".html"));
xtw.WriteEndElement();
xtw.WriteStartElement("previouspage");
xtw.WriteString(previousFileName(k,strXMLName));
xtw.WriteEndElement();
xtw.WriteStartElement("nextpage");
xtw.WriteString(nextFileName(k,strXMLName,pno));
xtw.WriteEndElement();
xtw.WriteStartElement("lastpage");
xtw.WriteString(processFileNameHtml(pno-1,strXMLName.Replace(".xml",".html")));
xtw.WriteEndElement();
xtw.WriteStartElement("nowpage");
xtw.WriteString(Convert.ToString(k+1));
xtw.WriteEndElement();
xtw.WriteStartElement("current");
xtw.WriteString(processFileNameHtml(k,strXMLName.Replace(".xml",".html")));
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.Close();
}
return pno;
}
catch(Exception e)
{
e=null;
return -1;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:将DataTable转换成Xml文件
/// </summary>
/// <param name="dt">要转换的DataTable</param>
/// <param name="strXMLName">生成xml的路径</param>
/// <returns>成功true</returns>
private bool TransformDTIntoXML(DataTable dt,string strXMLName)
{
try
{
XmlTextWriter xtw=new XmlTextWriter(strXMLName,null);
xtw.WriteStartDocument();
xtw.WriteStartElement("records");
for(int i=0;i<dt.Rows.Count;i++)
{
xtw.WriteStartElement("record");
for(int j=0;j<dt.Columns.Count;j++)
{
xtw.WriteStartElement(dt.Columns[j].ColumnName);
xtw.WriteString(dt.Rows[i][j].ToString());
xtw.WriteEndElement();
}
xtw.WriteEndElement();
}
xtw.WriteEndElement();
xtw.Close();
return true;
}
catch(Exception e)
{
e=null;
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:处理文件的路径,如果目录不存在,则建立目录
/// </summary>
/// <param name="filename">需要处理的文件路径</param>
private void processDirectory(string filename)
{
if(Directory.Exists(getpath(filename))==false)
{
Directory.CreateDirectory(getpath(filename));
}
}
private string getpath(string filename)
{
if(filename!=null && filename !="")
{
return filename.Substring(0,filename.LastIndexOf("\\"));
}
else
{
return "";
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-17||功能:处理分页文件名
/// </summary>
/// <param name="pagenumber"></param>
/// <param name="filename"></param>
/// <returns></returns>
private string processFileName(int pagenumber,string filename)
{
if(pagenumber==0)
{
return filename;
}
else
{
string strTemp=filename.Replace(".xml","_"+Convert.ToString(pagenumber)+".xml");
return strTemp;
}
}
private string processFileNameHtml(int pagenumber,string filename)
{
if(pagenumber==0)
{
return filename;
}
else
{
string strTemp=filename.Replace(".html","_"+Convert.ToString(pagenumber)+".html");
return strTemp;
}
}
private string previousFileName(int pagenumber,string filename)
{
pagenumber--;
if(pagenumber==0 || pagenumber<0)
{
return filename.Replace(".xml",".html");
}
else
{
string strTemp=filename.Replace(".xml","_"+Convert.ToString(pagenumber)+".html");
return strTemp;
}
}
private string nextFileName(int pagenumber,string filename,int pagecount)
{
pagenumber++;
if(pagenumber<pagecount)
{
string strTemp=filename.Replace(".xml","_"+Convert.ToString(pagenumber)+".html");
return strTemp;
}
else
{
return filename.Replace(".xml","_"+Convert.ToString(pagenumber-1)+".html");
}
}
}
}
有两种使用方法。
第一种:实例化时初始化数据,例:
xmlhtml sh=new xmlhtml(dt,strXmlname,strHtmlname,strXSLTname,100)
dt是提供数据源的datatable,strXmlname是中间生成的xml文件的路径,strHtmlname是生成的静态html页面路径,strXSLTname是xslt样式表的路径,100是分页后每页代码显示的记录行数。
注:最后的页面尺寸参数可以不加,默认整个数据表显示到一个页面。
第二种:实例化后直接使用StaticHtml方法。最后三行为
demo下载
代码如下:
using System;
using System.Data;
using System.Xml;
using System.Text;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.IO;
using System.ComponentModel;
namespace htmldemo
{
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:生成静态页面
/// </summary>
public class xmlhtml:IDisposable
{
public string strXmlName_;
public string strHTMLName_;
public string strXSLTName_;
public int intPageSize_;
public DataTable dts_;
private int _intCx=0;
private bool disposed = false;
private Component component = new Component();
private IntPtr handle;
public xmlhtml()
{
}
public xmlhtml(DataTable dt,string XmlFileName,string HtmlFileName,string XsltFileName)
{
strXmlName_=XmlFileName;
strHTMLName_=HtmlFileName;
strXSLTName_=XsltFileName;
dts_=dt;
_intCx=2;
}
public xmlhtml(DataTable dt,string XmlFileName,string HtmlFileName,string XsltFileName,int PageSize)
{
strXmlName_=XmlFileName;
strHTMLName_=HtmlFileName;
strXSLTName_=XsltFileName;
intPageSize_=PageSize;
dts_=dt;
_intCx=1;
}
public xmlhtml(IntPtr handle)
{
this.handle = handle;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if(!this.disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if(disposing)
{
// Dispose managed resources.
component.Dispose();
}
// Call the appropriate methods to clean up
// unmanaged resources here.
// If disposing is false,
// only the following code is executed.
CloseHandle(handle);
handle = IntPtr.Zero;
}
disposed = true;
}
[System.Runtime.InteropServices.DllImport("Kernel32")]
private extern static Boolean CloseHandle(IntPtr handle);
~xmlhtml()
{
// Do not re-create Dispose clean-up code here.
// Calling Dispose(false) is optimal in terms of
// readability and maintainability.
Dispose(false);
}
public bool StaticHtml()
{
if(_intCx==0)
{
return false;
}
else if(_intCx==1)
{
return StaticHtml(dts_,strXmlName_,strHTMLName_,strXSLTName_,intPageSize_);
}
else if(_intCx==2)
{
return StaticHtml(dts_,strXmlName_,strHTMLName_,strXSLTName_);
}
else
{
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:根据sql语句和xslt样式表生成静态html页面,分页控制
/// </summary>
/// <param name="dt">生成xml的DataTable</param>
/// <param name="strSql">数据表的sql语句</param>
/// <param name="strXmlName">中间生成的xml的路径</param>
/// <param name="strHTMLName">生成的静态html的路径</param>
/// <param name="strXSLTName">样式表xslt的路径</param>
/// <param name="pagesize">分页尺寸</param>
/// <returns>成功true</returns>
public bool StaticHtml(DataTable dt,string strXmlName,string strHTMLName,string strXSLTName,int pagesize)
{
if(dt!=null && strXmlName!=null && strHTMLName!=null && strXSLTName!=null && strXmlName!="" && strHTMLName!="" && strHTMLName!="")
{
processDirectory(strXmlName);
processDirectory(strHTMLName);
//processDirectory(strXSLTName);
int temp=TransformDTIntoXML(dt,strXmlName,pagesize);
if(temp!=-1)
{
if(TransformXMLIntoHtml(strXmlName,strHTMLName,strXSLTName,temp)==true)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:根据sql语句和xslt样式表生成静态html页面
/// </summary>
/// <param name="strSql">数据表的sql语句</param>
/// <param name="strXmlName">中间生成的xml的路径</param>
/// <param name="strHTMLName">生成的静态html的路径</param>
/// <param name="strXSLTName">样式表xslt的路径</param>
/// <returns>成功true</returns>
public bool StaticHtml(DataTable dt,string strXmlName,string strHTMLName,string strXSLTName)
{
if(dt!=null && strXmlName!=null && strHTMLName!=null && strXSLTName!=null && strXmlName!="" && strHTMLName!="" && strHTMLName!="")
{
processDirectory(strXmlName);
processDirectory(strHTMLName);
//processDirectory(strXSLTName);
if(TransformDTIntoXML(dt,strXmlName)==true)
{
if(TransformXMLIntoHtml(strXmlName,strHTMLName,strXSLTName)==true)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:将xml转换成html
/// </summary>
/// <param name="strHtmlName">要生成的html路径</param>
/// <param name="strXMLName">要转换的xml路径</param>
/// <param name="strXSLTName">样式表路径</param>
/// <returns>成功true</returns>
private bool TransformXMLIntoHtml(string strXMLName,string strHtmlName,string strXSLTName)
{
try
{
string filename=strXMLName;
string stylesheet=strXSLTName;
string html=strHtmlName;
XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);
XPathDocument xpathdocument = new XPathDocument(filename);
XmlTextWriter writer = new XmlTextWriter(html,Encoding.UTF8);
xslt.Transform(xpathdocument, null, writer, null);
writer.Close();
return true;
}
catch(Exception e)
{
e=null;
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:将xml转换成html,支持分页
/// </summary>
/// <param name="strHtmlName">要生成的html路径</param>
/// <param name="strXMLName">要转换的xml路径</param>
/// <param name="strXSLTName">样式表路径</param>
/// <returns>成功true</returns>
private bool TransformXMLIntoHtml(string strXMLName,string strHtmlName,string strXSLTName,int pagecount)
{
try
{
for(int i=0;i<pagecount;i++)
{
string filename=processFileName(i,strXMLName);
string stylesheet=strXSLTName;
string html=processFileNameHtml(i,strHtmlName);
XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);
XPathDocument xpathdocument = new XPathDocument(filename);
XmlTextWriter writer = new XmlTextWriter(html,Encoding.UTF8);
xslt.Transform(xpathdocument, null, writer, null);
writer.Close();
}
return true;
}
catch(Exception e)
{
e=null;
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:将DataTable转换成Xml文件,支持分页
/// </summary>
/// <param name="dt">要转换的DataTable</param>
/// <param name="strXMLName">生成xml的路径</param>
/// <param name="intPageSize">分页页面尺寸</param>
/// <returns>成功true</returns>
private int TransformDTIntoXML(DataTable dt,string strXMLName,int intPageSize)
{
try
{
int pno=dt.Rows.Count/intPageSize;
if(dt.Rows.Count%intPageSize>0)
{
pno++;
}
int countstart=0;
int countend=dt.Rows.Count;
int nowcount = dt.Rows.Count;
for(int k=0;k<pno;k++)
{
XmlTextWriter xtw=new XmlTextWriter(processFileName(k,strXMLName),null);
int page=k+1;
if(page * intPageSize<nowcount)
{
countstart =(page-1) * intPageSize;
countend = page * intPageSize;
}
else if((page==1)&&(page * intPageSize>nowcount))
{
countstart =0;
countend =nowcount;
}
else
{
countstart = (page-1)*intPageSize;
countend = nowcount;
}
xtw.WriteStartDocument();
xtw.WriteStartElement("records");
for(int i=countstart;i<countend;i++)
{
xtw.WriteStartElement("record");
for(int j=0;j<dt.Columns.Count;j++)
{
xtw.WriteStartElement(dt.Columns[j].ColumnName);
xtw.WriteString(dt.Rows[i][j].ToString());
xtw.WriteEndElement();
}
xtw.WriteEndElement();
}
xtw.WriteStartElement("pagecontrol");
xtw.WriteStartElement("recordcount");
xtw.WriteString(Convert.ToString(nowcount));
xtw.WriteEndElement();
xtw.WriteStartElement("firstpage");
xtw.WriteString(strXMLName.Replace(".xml",".html"));
xtw.WriteEndElement();
xtw.WriteStartElement("previouspage");
xtw.WriteString(previousFileName(k,strXMLName));
xtw.WriteEndElement();
xtw.WriteStartElement("nextpage");
xtw.WriteString(nextFileName(k,strXMLName,pno));
xtw.WriteEndElement();
xtw.WriteStartElement("lastpage");
xtw.WriteString(processFileNameHtml(pno-1,strXMLName.Replace(".xml",".html")));
xtw.WriteEndElement();
xtw.WriteStartElement("nowpage");
xtw.WriteString(Convert.ToString(k+1));
xtw.WriteEndElement();
xtw.WriteStartElement("current");
xtw.WriteString(processFileNameHtml(k,strXMLName.Replace(".xml",".html")));
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.Close();
}
return pno;
}
catch(Exception e)
{
e=null;
return -1;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:将DataTable转换成Xml文件
/// </summary>
/// <param name="dt">要转换的DataTable</param>
/// <param name="strXMLName">生成xml的路径</param>
/// <returns>成功true</returns>
private bool TransformDTIntoXML(DataTable dt,string strXMLName)
{
try
{
XmlTextWriter xtw=new XmlTextWriter(strXMLName,null);
xtw.WriteStartDocument();
xtw.WriteStartElement("records");
for(int i=0;i<dt.Rows.Count;i++)
{
xtw.WriteStartElement("record");
for(int j=0;j<dt.Columns.Count;j++)
{
xtw.WriteStartElement(dt.Columns[j].ColumnName);
xtw.WriteString(dt.Rows[i][j].ToString());
xtw.WriteEndElement();
}
xtw.WriteEndElement();
}
xtw.WriteEndElement();
xtw.Close();
return true;
}
catch(Exception e)
{
e=null;
return false;
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-16||功能:处理文件的路径,如果目录不存在,则建立目录
/// </summary>
/// <param name="filename">需要处理的文件路径</param>
private void processDirectory(string filename)
{
if(Directory.Exists(getpath(filename))==false)
{
Directory.CreateDirectory(getpath(filename));
}
}
private string getpath(string filename)
{
if(filename!=null && filename !="")
{
return filename.Substring(0,filename.LastIndexOf("\\"));
}
else
{
return "";
}
}
/**//// <summary>
/// 创建者:齐明||时间:2007-5-17||功能:处理分页文件名
/// </summary>
/// <param name="pagenumber"></param>
/// <param name="filename"></param>
/// <returns></returns>
private string processFileName(int pagenumber,string filename)
{
if(pagenumber==0)
{
return filename;
}
else
{
string strTemp=filename.Replace(".xml","_"+Convert.ToString(pagenumber)+".xml");
return strTemp;
}
}
private string processFileNameHtml(int pagenumber,string filename)
{
if(pagenumber==0)
{
return filename;
}
else
{
string strTemp=filename.Replace(".html","_"+Convert.ToString(pagenumber)+".html");
return strTemp;
}
}
private string previousFileName(int pagenumber,string filename)
{
pagenumber--;
if(pagenumber==0 || pagenumber<0)
{
return filename.Replace(".xml",".html");
}
else
{
string strTemp=filename.Replace(".xml","_"+Convert.ToString(pagenumber)+".html");
return strTemp;
}
}
private string nextFileName(int pagenumber,string filename,int pagecount)
{
pagenumber++;
if(pagenumber<pagecount)
{
string strTemp=filename.Replace(".xml","_"+Convert.ToString(pagenumber)+".html");
return strTemp;
}
else
{
return filename.Replace(".xml","_"+Convert.ToString(pagenumber-1)+".html");
}
}
}
}
有两种使用方法。
第一种:实例化时初始化数据,例:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strSql="Select c.CRM_ID,c.crm_cn,c.CRM_TYPE_ID login_name From crm c Where c.status='0'";
OracleDb conn=new OracleDb();
DataTable dt=new DataTable();
dt=conn.GetDtRecorder(strSql);
string strAPath=Request.PhysicalApplicationPath;
string strXmlname=strAPath+"xsltdemo\\crm.xml";
string strHtmlname=strAPath+"xsltdemo\\crm.html";
string strXSLTname=strAPath+"xsltdemo\\crm.xslt";
xmlhtml sh=new xmlhtml(dt,strXmlname,strHtmlname,strXSLTname,100);
sh.StaticHtml();
sh.Dispose();
}
代码{
// 在此处放置用户代码以初始化页面
string strSql="Select c.CRM_ID,c.crm_cn,c.CRM_TYPE_ID login_name From crm c Where c.status='0'";
OracleDb conn=new OracleDb();
DataTable dt=new DataTable();
dt=conn.GetDtRecorder(strSql);
string strAPath=Request.PhysicalApplicationPath;
string strXmlname=strAPath+"xsltdemo\\crm.xml";
string strHtmlname=strAPath+"xsltdemo\\crm.html";
string strXSLTname=strAPath+"xsltdemo\\crm.xslt";
xmlhtml sh=new xmlhtml(dt,strXmlname,strHtmlname,strXSLTname,100);
sh.StaticHtml();
sh.Dispose();
}
xmlhtml sh=new xmlhtml(dt,strXmlname,strHtmlname,strXSLTname,100)
dt是提供数据源的datatable,strXmlname是中间生成的xml文件的路径,strHtmlname是生成的静态html页面路径,strXSLTname是xslt样式表的路径,100是分页后每页代码显示的记录行数。
注:最后的页面尺寸参数可以不加,默认整个数据表显示到一个页面。
第二种:实例化后直接使用StaticHtml方法。最后三行为
xmlhtml sh=new xmlhtml();
sh.StaticHtml(dt,strXmlname,strHtmlname,strXSLTname,100);
sh.Dispose();
sh.StaticHtml(dt,strXmlname,strHtmlname,strXSLTname,100);
sh.Dispose();
demo下载