You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
3.5 KiB

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace Kenneth.DotNet.EntityTool
{
public class AppCommon
{
#region 转换SQL数据类型到C#数据类型...
/// <summary>
/// 转换SQL数据类型到C#数据类型
/// </summary>
/// <param name="sqlType">sql数据类型</param>
/// <returns>C#数据类型</returns>
///
public static string ConvertSqlType(string typecode)
{
SqlDbType cType = new SqlDbType();
typecode = typecode.Trim().ToLower();
if(typecode == TypeCode.Boolean.ToString().ToLower())
cType = SqlDbType.Bit;
else if (typecode == TypeCode.Byte.ToString().ToLower())
cType = SqlDbType.TinyInt;
else if (typecode == TypeCode.Char.ToString().ToLower())
cType = SqlDbType.Char;
else if (typecode == TypeCode.DateTime.ToString().ToLower())
cType = SqlDbType.DateTime;
else if (typecode == TypeCode.Decimal.ToString().ToLower())
cType = SqlDbType.Decimal;
else if (typecode == TypeCode.Double.ToString().ToLower())
cType = SqlDbType.Float;
else if (typecode == TypeCode.Int16.ToString().ToLower())
cType = SqlDbType.SmallInt;
else if (typecode == TypeCode.Int32.ToString().ToLower())
cType = SqlDbType.Int;
else if (typecode == TypeCode.Int64.ToString().ToLower())
cType = SqlDbType.BigInt;
else if (typecode == TypeCode.SByte.ToString().ToLower())
cType = SqlDbType.Binary;
else if (typecode == TypeCode.Single.ToString().ToLower())
cType = SqlDbType.Real;
else if (typecode == TypeCode.String.ToString().ToLower())
cType = SqlDbType.NVarChar;
else
cType = SqlDbType.VarChar;
return "SqlDbType." + cType.ToString();
}
public static string ConvertTypeName(Type type)
{
string name = "";
//string typecode = type.ToString().ToLower();
//if (typecode == "system." + TypeCode.Boolean.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.Byte.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.DateTime.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.Decimal.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.Double.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.Int16.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.Int32.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.Int64.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.SByte.ToString().ToLower())
// name = type.Name + "?";
//else if (typecode == "system." + TypeCode.Single.ToString().ToLower())
// name = type.Name + "?";
//else
name = type.Name;
return name;
}
#endregion
}
}