C#分析数据库结构,使用XSL模板自动生成代码(一)

<html>
<head>
<TITLE>分析数据库结构,自动生成代码</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<frameset cols="237,767" rows="*">
<frame src="dbxml.aspx">
<frame name="code" src="about:blank">
</frameset>
</html>
########################### dbxml.aspx 文件内容,该文件没有C#代码文件 #############
<script language="C#" runat ="server">
System.Xml.XmlDocument myCfgXML = new System.Xml.XmlDocument();
// 获得系统配置字符串
string GetAppConfig(string strKey)
{
System.Xml.XmlElement cfgElement = myCfgXML.SelectSingleNode ("//setting[@key='" + strKey + "']" )
as System.Xml.XmlElement ;
if( cfgElement == null )
return "";
else
return cfgElement.InnerText ;
}

// 判断字符串是否是空白字符串
bool isBlankString(string strText )
{
if(strText != null)
{
int iCount;
for(iCount=0;iCount<strText.Length ;iCount++)
{
if(System.Char.IsWhiteSpace ( strText[iCount])==false)
return false;
}
}
return true;
}
void Page_Load(Object sender, EventArgs e)
{
// 加载系统配置文件
myCfgXML.Load(this.MapPath(".") + "//dbxmlcfg.xml");
string strType = this.Request["type"];
string strXSL = "main.xml";

if(strType == null)
strType = "querytable";
System.Xml.XmlDocument myDoc = new System.Xml.XmlDocument();
myDoc.LoadXml("<dbxml />");
string strConnection = GetAppConfig("conndbxml");
System.Text.Encoding myEncode = System.Text.Encoding.GetEncoding(936);

if(isBlankString(strConnection)==false)
{
using(System.Data.OleDb.OleDbConnection myConn = new System.Data.OleDb.OleDbConnection(strConnection))
{
myConn.Open();
if(myConn.State == System.Data.ConnectionState.Open )
{
string strSQL = GetAppConfig(strType + "_" + myConn.Provider);
if(isBlankString(strSQL)==false)
{
using(System.Data.OleDb.OleDbCommand myCmd = myConn.CreateCommand())
{
string strTableName = null;
if(strType.Equals("queryfield"))
{
// 修正SQL语句
string strTableList = this.Request.Form["tablelist"];
string []strTables = strTableList.Split(",".ToCharArray());
strXSL = System.Web.HttpUtility.UrlPathEncode(this.Request.Form["template"] ) + ".xml";
strTableList = null;
for(int iCount = 0 ; iCount < strTables.Length ; iCount ++ )
{
if(isBlankString(strTables[iCount])==false)
{
if(strTableList == null)
strTableList = "'" + strTables[iCount] + "'";
else
strTableList = strTableList + ",'" + strTables[iCount] + "'";
}
}
strSQL = strSQL.Replace("#tablelist", strTableList);
myCmd.CommandText = strSQL ;
string strLastTableName = null;
string strFieldName = null;
System.Xml.XmlElement TableElement = null;
System.Data.OleDb.OleDbDataReader myReader = myCmd.ExecuteReader();
while(myReader.Read())
{
strTableName = myReader[0].ToString().ToUpper();
if(strTableName.Equals(strLastTableName)==false)
{
// 填充表说明元素
strLastTableName = strTableName ;
TableElement = myDoc.CreateElement("table");
TableElement.SetAttribute("tablename", strTableName);
myDoc.Docume

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值