本站首页    管理页面    写新日志    退出


«may 2026»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
================

注会练习软件
http://www.cpasoft.com.cn
我的注会软件官网

http://blog.163.com/abc7105@126/

 

 


哈哈,热爱快“过气”的DELPHI


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:注册会计师(注会)练习软件
日志总数:398
评论数量:116
留言数量:27
访问次数:3309304
建立时间:2005年6月6日




续:前
软件技术

吕向阳 发表于 2006/9/7 17:12:28

CodeTemplateRule.cs using System;using System.Text;using System.ComponentModel;using CodeSmith.Engine;using System.Data;using SchemaExplorer; namespace CodeTemplateRule{    /**//// <summary>    /// CodeSmith自动生成代码所用到的函数    /// </summary>    public class CodeTemplateRule    {        /**//// <summary>        /// 获取所有列的集合        /// </summary>        /// <param name="dataBase">数据库Schema</param>        /// <param name="tableName">表名</param>        /// <returns>Columns Schema</returns>        public ColumnSchemaCollection GetColumnCollection(DatabaseSchema dataBase,string tableName)        {            TableSchemaCollection tables = new TableSchemaCollection(dataBase.Tables);            ColumnSchemaCollection columns=null;            for(int i=0;i<tables.Count;i++)            {                if(tables[i].Name.ToUpper()==tableName.ToUpper())                {                    TableSchema ts=tables[i];                    columns=new ColumnSchemaCollection(ts.Columns);                }            }            return columns;        }                /**//// <summary>        /// 获取处理后的表名 例如:ORG_Person,返回Person        /// </summary>        /// <param name="tableName">表名</param>        /// <returns>返回处理后的表名</returns>        public string GetTableName(string tableName)        {            int i=tableName.IndexOf("_");            return tableName.Substring(i+1,tableName.Length-(i+1));        }                /**//// <summary>        /// 获取唯一号的变量名,第一个字母小写        /// </summary>        /// <param name="guidColumn">唯一号列名</param>        /// <returns>唯一号的变量名</returns>        public string GetGuidColumnVar(string guidColumn)        {            string guid;            guid=guidColumn.Substring(0,1).ToLower()+guidColumn.Substring(1,guidColumn.Length-1);            return guid;            }                        /**//// <summary>        /// 获取c#变量类型        /// </summary>        /// <param name="column">列</param>        /// <returns>c#变量类型</returns>        public string GetType(ColumnSchema column)        {            if (column.Name.EndsWith("TypeCode")) return column.Name;                        switch (column.DataType)            {                case DbType.AnsiString: return "string";                case DbType.AnsiStringFixedLength: return "string";                case DbType.Binary: return "byte[]";                case DbType.Boolean: return "bool";                case DbType.Byte: return "int";                case DbType.Currency: return "decimal";                case DbType.Date: return "DateTime";                case DbType.DateTime: return "DateTime";                case DbType.Decimal: return "decimal";                case DbType.Double: return "double";                case DbType.Guid: return "Guid";                case DbType.Int16: return "short";                case DbType.Int32: return "int";                case DbType.Int64: return "long";                case DbType.Object: return "object";                case DbType.SByte: return "sbyte";                case DbType.Single: return "float";                case DbType.String: return "string";                case DbType.StringFixedLength: return "string";                case DbType.Time: return "TimeSpan";                case DbType.UInt16: return "ushort";                case DbType.UInt32: return "uint";                case DbType.UInt64: return "ulong";                case DbType.VarNumeric: return "decimal";                default:                {                    return "__UNKNOWN__" + column.NativeType;                }            }        }         /**//// <summary>        /// 获取c#变量类型默认值        /// </summary>        /// <param name="column">列</param>        /// <returns>c#变量类型默认值</returns>        public string GetDefaultValue(ColumnSchema column)        {            if (column.Name.EndsWith("TypeCode")) return column.Name;                        switch (column.DataType)            {                case DbType.AnsiString: return "\"\"";                case DbType.AnsiStringFixedLength: return "\"\"";                case DbType.Binary: return "null";                case DbType.Boolean: return "false";                case DbType.Byte: return "0";                case DbType.Currency: return "0";                case DbType.Date: return "DateTime.Parse(\"1900-1-1\")";                case DbType.DateTime: return "DateTime.Parse(\"1900-1-1\")";                case DbType.Decimal: return "0";                case DbType.Double: return "0";                case DbType.Guid: return "Guid.NewGuid().ToString()";                case DbType.Int16: return "0";                case DbType.Int32: return "0";                case DbType.Int64: return "0";                case DbType.Object: return "\"\"";                case DbType.SByte: return "0";                case DbType.Single: return "0";                case DbType.String: return "\"\"";                case DbType.StringFixedLength: return "";                case DbType.Time: return "DateTime.Parse(\"1900-1-1\")";                case DbType.UInt16: return "0";                case DbType.UInt32: return "0";                case DbType.UInt64: return "0";                case DbType.VarNumeric: return "0";                default:                {                    return "__UNKNOWN__" + column.NativeType;                }            }        }         /**//// <summary>        /// 获取c#变量类型默认值        /// </summary>        /// <param name="column">列</param>        /// <returns>c#变量类型默认值</returns>        public string GetConvert(ColumnSchema column)        {            if (column.Name.EndsWith("TypeCode")) return column.Name;                        switch (column.DataType)            {                case DbType.AnsiString: return "Convert.ToString";                case DbType.AnsiStringFixedLength: return "Convert.ToString";                case DbType.Binary: return "Convert.ToByte";                case DbType.Boolean: return "Convert.ToBoolean";                case DbType.Byte: return "Convert.ToInt32";                case DbType.Currency: return "Convert.ToDecimal";                case DbType.Date: return "Convert.DateTime";                case DbType.DateTime: return "Convert.DateTime";                case DbType.Decimal: return "Convert.ToDecimal";                case DbType.Double: return "Convert.ToDouble";                case DbType.Guid: return "Convert.ToString";                case DbType.Int16: return "Convert.ToInt16";                case DbType.Int32: return "Convert.ToInt32";                case DbType.Int64: return "Convert.ToInt64";                case DbType.Object: return "Convert.ToString";                case DbType.SByte: return "Convert.ToByte";                case DbType.Single: return "Convert.ToInt32";                case DbType.String: return "Convert.ToString";                case DbType.StringFixedLength: return "Convert.ToString";                case DbType.Time: return "Convert.DateTime";                case DbType.UInt16: return "Convert.ToUInt16";                case DbType.UInt32: return "Convert.ToUInt32";                case DbType.UInt64: return "Convert.ToUInt64";                case DbType.VarNumeric: return "Convert.ToDecimal";                default:                {                    return "__UNKNOWN__" + column.NativeType;                }            }        }    }}


阅读全文(1436) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144852232 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号