我的代码生成工具部分代码2,没办法本来发一篇文章的非要弄2次,非得出现500 Internal Server Error错误
来源:互联网 发布:股票高频数据下载 编辑:程序博客网 时间:2024/05/21 14:09
private static string getModelContent(string tableName)
{
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
StringBuilder sqlString = new StringBuilder();
sqlString.Append("select a.name,b.name as type from syscolumns ");
sqlString.Append("a join systypes b on a.xtype=b.xtype ");
sqlString.Append("where a.id=object_id( '"+tableName+" ') order by a.colorder ");
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.connString, CommandType.Text, sqlString.ToString()).Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
string columnName = dt.Rows[i]["name"].ToString();
string type = dt.Rows[i]["type"].ToString();
cSharpTypeMappingDBType cSharpType = getcSharpTypeFromMappingTypeList(type);
sb1.AppendLine(" private " + cSharpType.cSharpType + " _" + columnName + "=" + cSharpType .DefaultValue+ ";");
sb2.AppendLine(" public "+cSharpType.cSharpType+" "+columnName+"");
sb2.AppendLine(" {");
sb2.AppendLine(" set { _"+columnName+" = value; }");
sb2.AppendLine(" get { return _" + columnName + "; }");
sb2.AppendLine(" }");
}
return sb1.AppendLine(sb2.ToString()).ToString();
}
public static string getDalCSFile(string tableName)
{
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
StringBuilder sqlString = new StringBuilder();
sqlString.Append("select a.name,b.name as type from syscolumns ");
sqlString.Append("a join systypes b on a.xtype=b.xtype ");
sqlString.Append("where a.id=object_id( '" + tableName + " ') order by a.colorder ");
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.connString, CommandType.Text, sqlString.ToString()).Tables[0];
sb1.AppendLine("using System;");
sb1.AppendLine("using System.Collections.Generic;");
sb1.AppendLine("using System.Text;");
sb1.AppendLine("using System.Data;");
sb1.AppendLine("using System.Data.SqlClient;");
sb1.AppendLine("namespace Dal");
sb1.AppendLine("{");
sb1.AppendLine(" public class "+tableName);
sb1.AppendLine(" {");
sb1.AppendLine(getInsertSql(tableName));
sb1.AppendLine(getUpdateSql(tableName));
sb1.AppendLine(getModelSql(tableName));
sb1.AppendLine(getDeleteSql(tableName));
sb1.AppendLine(" }");
sb1.AppendLine("}");
return sb1.ToString();
}
static string getInsertSql(string tableName)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(" public bool Create(Model." + tableName + " model)");
sb.AppendLine(" {");
sb.AppendLine(" helper.Open();");
sb.AppendLine(" StringBuilder strSql = new StringBuilder();");
sb.AppendLine( getAllColumnNameFromTable(tableName, PrepareType.Insert));
sb.AppendLine(" SqlCommand m_Command = new SqlCommand(strSql.ToString());");
sb.AppendLine(getAllColumnNameFromTable(tableName, PrepareType.Param));
sb.AppendLine(" bool sReturn = false;");
sb.AppendLine(" sReturn = (int)helper.ExecuteNonQuery(m_Command) > 0 ? true : false;");
sb.AppendLine(" helper.Close();");
sb.AppendLine(" return sReturn;");
sb.AppendLine(" }");
return sb.ToString();
}
static string getUpdateSql(string tableName)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(" public bool Update(Model." + tableName + " model)");
sb.AppendLine(" {");
sb.AppendLine(" helper.Open();");
sb.AppendLine(" StringBuilder strSql = new StringBuilder();");
sb.AppendLine( getAllColumnNameFromTable(tableName, PrepareType.Update));
sb.AppendLine(" SqlCommand m_Command = new SqlCommand(strSql.ToString());");
sb.AppendLine(getAllColumnNameFromTable(tableName, PrepareType.Param));
sb.AppendLine(" bool sReturn = false;");
sb.AppendLine(" sReturn = (int)helper.ExecuteNonQuery(m_Command) > 0 ? true : false;");
sb.AppendLine(" helper.Close();");
sb.AppendLine(" return sReturn;");
sb.AppendLine(" }");
return sb.ToString();
}
//static string getListSql(string tableName)
//{
//}
static string getPKTypeAndColumnNameFromTableName(string tableName)
{
StringBuilder sb=new StringBuilder();
StringBuilder sb2 = new StringBuilder();
StringBuilder sqlString = new StringBuilder();
sqlString.Append("select a.name,b.name as type from syscolumns ");
sqlString.Append("a join systypes b on a.xtype=b.xtype ");
sqlString.Append("where a.id=object_id( '" + tableName + " ') order by a.colorder ");
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.connString, CommandType.Text, sqlString.ToString()).Tables[0];
string PK = getPK(tableName);
string PKColumnType = string.Empty;
bool isHasIncreaseColumn = false;
for (int i = 0; i < dt.Rows.Count; i++)
{
string columnName = dt.Rows[i]["name"].ToString();
if (getIncrease(columnName, tableName))
{
string type = dt.Rows[i]["type"].ToString();
cSharpTypeMappingDBType cSharpType = getcSharpTypeFromMappingTypeList(type);
sb.Append(cSharpType.cSharpType + " " + columnName);
isHasIncreaseColumn = true;
return sb.ToString();
}
if (PK.ToLower() == columnName.ToLower())
{
string type = dt.Rows[i]["type"].ToString();
cSharpTypeMappingDBType cSharpType = getcSharpTypeFromMappingTypeList(type);
sb2.Append(cSharpType.cSharpType + " " + columnName);
}
}
return sb2.ToString();
}
public static string getModelSql(string tableName)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(" public Model." + tableName + " getModel(" + getPKTypeAndColumnNameFromTableName(tableName) + ")");
sb.AppendLine(" {");
sb.AppendLine(" StringBuilder strSql = new StringBuilder();");
sb.AppendLine(getAllColumnNameFromTable(tableName, PrepareType.getModel));
sb.AppendLine(" helper.Open();");
sb.AppendLine(" SqlCommand m_Command = new SqlCommand(strSql.ToString());");
sb.AppendLine(getAllColumnNameFromTable(tableName, PrepareType.PK));
sb.AppendLine(" using (SqlDataReader dr = helper.ExecuteReader(m_Command))");
sb.AppendLine(" {");
sb.AppendLine(" if (dr.HasRows)");
sb.AppendLine(" {");
sb.AppendLine(" dr.Read();");
StringBuilder sqlString = new StringBuilder();
sqlString.Append("select a.name,b.name as type from syscolumns ");
sqlString.Append("a join systypes b on a.xtype=b.xtype ");
sqlString.Append("where a.id=object_id( '" + tableName + " ') order by a.colorder ");
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.connString, CommandType.Text, sqlString.ToString()).Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
string columnName = dt.Rows[i]["name"].ToString();
string type = dt.Rows[i]["type"].ToString();
cSharpTypeMappingDBType cSharpType = getcSharpTypeFromMappingTypeList(type);
sb.AppendLine(" model." + columnName + " = (" + cSharpType.cSharpType+ ")dr[/"" + columnName + "/"];");
}
sb.AppendLine("");
sb.AppendLine(" }");
sb.AppendLine(" }");
sb.AppendLine(" helper.Close();");
sb.AppendLine(" return model;");
sb.AppendLine(" }");
return sb.ToString();
}
public static string getDeleteSql(string tableName)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(" public bool Delete("+getPKTypeAndColumnNameFromTableName(tableName)+")");
sb.AppendLine(" {");
sb.AppendLine(" StringBuilder strSql = new StringBuilder();");
sb.AppendLine(getAllColumnNameFromTable(tableName, PrepareType.Delete));
sb.AppendLine(" helper.Open();");
sb.AppendLine(" SqlCommand m_Command = new SqlCommand(strSql.ToString());");
sb.AppendLine(getAllColumnNameFromTable(tableName, PrepareType.PK));
sb.AppendLine(" bool sReturn = false;");
sb.AppendLine(" sReturn = (int)helper.ExecuteNonQuery(m_Command) > 0 ? true : false;");
sb.AppendLine(" helper.Close();");
sb.AppendLine(" return sReturn;");
sb.AppendLine(" }");
return sb.ToString();
}
public static cSharpTypeMappingDBType getcSharpTypeFromMappingTypeList(string dbtype)
{
cSharpTypeMappingDBType cSharptype = new cSharpTypeMappingDBType();
foreach (cSharpTypeMappingDBType model in list)
{
if (model.dbType == dbtype)
{
cSharptype = model;
}
}
return cSharptype;
}
}
public class cSharpTypeMappingDBType
{
private string _cSharpType = string.Empty;
private string _dbType = string.Empty;
private string _defaultValue = string.Empty;
public string cSharpType
{
get { return _cSharpType; }
set { _cSharpType = value; }
}
public string dbType
{
get { return _dbType; }
set { _dbType = value; }
}
public cSharpTypeMappingDBType(string cSharpType, string dbType, string defaultValue)
{
this.cSharpType = cSharpType;
this.dbType = dbType;
this.DefaultValue = defaultValue;
}
public cSharpTypeMappingDBType()
{
}
public string DefaultValue
{
get { return _defaultValue; }
set { _defaultValue = value; }
}
}
- 我的代码生成工具部分代码2,没办法本来发一篇文章的非要弄2次,非得出现500 Internal Server Error错误
- 我的代码生成工具部分代码
- 500 Internal Server Error错误问题解决办法
- FCKeditor出现"XML request error: Internal Server Error(500)"错误的解决办法
- 出现Internal Server Error错误
- 500 Internal server error 部署ASP.NET项目时出现的错误
- 安装Destoon系统出现500 Internal Server Error错误的原因
- EBS 登录时出现500 Internal Server Error的解决方法
- Nginx出现 500 Internal Server Error的解决办法
- 关于安装wordpress出现500 Internal Server Error的解决方案
- wamp 的Internal Server Error错误解决方法
- PHP Yii gii自动生成的模块代码无法执行,报错:Internal Server Error include(Controller.php)
- nginx提示:500 Internal Server Error错误的解决方法
- [Nginx] nginx提示:500 Internal Server Error错误的解决方法
- nginx提示:500 Internal Server Error错误的解决方法
- 我的Java代码生成工具 AutoJCode
- apache出现 internal server error 500错误常见原因
- Axis2出现Internal server error错误
- 数学知识
- 各种字符编码详解(ascii,utf-8,unicode,gbk,gb2312,iso8859-1等)
- 用固定数据创建CvMat矩阵并打印
- SQL之性能优化
- 基于.NET的开源GIS项目
- 我的代码生成工具部分代码2,没办法本来发一篇文章的非要弄2次,非得出现500 Internal Server Error错误
- 希望对大家的学习有所帮助
- libxxx.so中加入printf语句输出
- 经典语录:
- 测试MapWindowGis控件
- 关于静态方法的覆盖
- Json 与 Object 相互转换的 gson-1.4.jar
- 【转】 基于RTSP协议流媒体服务器的实现
- iis6.0,HTTP服务器状态代码定义,web园--最大工作进程数