CommonUtility.cs
1using System;
2using System.Text;
3using CodeSmith.Engine;
4using SchemaExplorer;
5using System.ComponentModel;
6using System.Data;
7
8namespace Common.Data
9{
10 /// <summary>
11 /// TemplateRule
12 /// </summary>
13 public class CommonUtility
14 {
15
16 //get Columns info by TableName
17 public ColumnSchemaCollection GetColumnCollectionByTable(TableSchema table)
18 {
19 ColumnSchemaCollection columns=new ColumnSchemaCollection(table.Columns);
20 return columns;
21 }
22
23 //Get camelcase name,such as Customer,
24 public string GetCamelCaseName(string str)
25 {
26 return str.Substring(0,1).ToUpper()+str.Substring(1);
27 }
28
29 //Get ,user,private const String USER_FIELD = "User"
30 public string GetMemberConstantDeclarationStatement(ColumnSchema column)
31 {
32 return GetMemberConstantDeclarationStatement("public const String ",column);
33 }
34
35 //such as public const String USER_TABLE = "User"
36 public string GetTableConstantDeclarationStatement(TableSchema table)
37 {
38 return GetMemberConstantDeclarationStatement("public const String ",table);
39 }
40 //suck as USER_TABLE
41 public string GetUpperStatement(TableSchema table)
42 {
43 return table.Name.ToUpper()+"_TABLE";
44 }
45 //suck as USER_FIELD
46 public string GetUpperStatement(ColumnSchema column)
47 {
48 return column.Name.ToUpper()+"_FIELD";
49 }
50
51 // such as USER_TABLE = "User"
52 public string GetMemberConstantDeclarationStatement(string protectionLevel,TableSchema table)
53 {
54 return protectionLevel+GetUpperStatement(table)+" = \""+GetCamelCaseName(table.Name)+"\"";
55 }
56
57 //such as USERID_FIELD = "Userid"
58 public string GetMemberConstantDeclarationStatement(string protectionLevel,ColumnSchema column)
59 {
60 return protectionLevel+GetUpperStatement(column)+" = \""+GetCamelCaseName(column.Name)+"\"";
61 }
62
63 public string GetCSharpVariableType(ColumnSchema column)
64 {
65 switch(column.DataType)
66 {
67 case DbType.AnsiString: return "string";
68 case DbType.AnsiStringFixedLength: return "string";
69 case DbType.Binary: return "byte[]";
70 case DbType.Boolean: return "bool";
71 case DbType.Byte: return "int";
72 case DbType.Currency: return "decimal";
73 case DbType.Date: return "DataTime";
74 case DbType.DateTime: return "DateTime";
75 case DbType.Decimal: return "decimal";
76 case DbType.Double: return "double";
77 case DbType.Guid: return "Guid";
78 case DbType.Int16: return "short";
79 case DbType.Int32: return "int";
80 case DbType.Int64: return "long";
81 case DbType.Object: return "object";
82 case DbType.SByte: return "sbyte";
83 case DbType.Single: return "float";
84 case DbType.String: return "string";
85 case DbType.StringFixedLength: return "string";
86 case DbType.Time: return "TimeSpan";
87 case DbType.UInt16: return "ushort";
88 case DbType.UInt32: return "uint";
89 case DbType.UInt64: return "ulong";
90 case DbType.VarNumeric: return "decimal";
91 }
92
93 return null;
94 }
95
96 public string GetCSharpBaseType(ColumnSchema column)
97 {
98 switch(column.DataType)
99 {
100 case DbType.AnsiString: return "System.String";
101 case DbType.AnsiStringFixedLength: return "System.String";
102 case DbType.Binary: return "System.Byte[]";
103 case DbType.Boolean: return "System.Boolean";
104 case DbType.Byte: return "System.Int32";
105 case DbType.Currency: return "System.Decimal";
106 case DbType.Date: return "System.DataTime";
107 case DbType.DateTime: return "System.DataTime";
108 case DbType.Decimal: return "System.Decimal";
109 case DbType.Double: return "System.Double";
110 case DbType.Guid: return "System.Guid";
111 case DbType.Int16: return "System.Int16";
112 case DbType.Int32: return "System.Int32";
113 case DbType.Int64: return "System.Int64";
114 case DbType.Object: return "System.Object";
115 case DbType.SByte: return "System.SByte";
116 case DbType.Single: return "System.Single";
117 case DbType.String: return "System.String";
118 case DbType.StringFixedLength: return "System.String";
119 case DbType.Time: return "System.TimeSpan";
120 case DbType.UInt16: return "System.UInt16";
121 case DbType.UInt32: return "System.UInt32";
122 case DbType.UInt64: return "System.UInt64";
123 case DbType.VarNumeric: return "System.Decimal";
124 }
125 return null;
126 }
127 }
128}
129
130
131
132
2using System.Text;
3using CodeSmith.Engine;
4using SchemaExplorer;
5using System.ComponentModel;
6using System.Data;
7
8namespace Common.Data
9{
10 /// <summary>
11 /// TemplateRule
12 /// </summary>
13 public class CommonUtility
14 {
15
16 //get Columns info by TableName
17 public ColumnSchemaCollection GetColumnCollectionByTable(TableSchema table)
18 {
19 ColumnSchemaCollection columns=new ColumnSchemaCollection(table.Columns);
20 return columns;
21 }
22
23 //Get camelcase name,such as Customer,
24 public string GetCamelCaseName(string str)
25 {
26 return str.Substring(0,1).ToUpper()+str.Substring(1);
27 }
28
29 //Get ,user,private const String USER_FIELD = "User"
30 public string GetMemberConstantDeclarationStatement(ColumnSchema column)
31 {
32 return GetMemberConstantDeclarationStatement("public const String ",column);
33 }
34
35 //such as public const String USER_TABLE = "User"
36 public string GetTableConstantDeclarationStatement(TableSchema table)
37 {
38 return GetMemberConstantDeclarationStatement("public const String ",table);
39 }
40 //suck as USER_TABLE
41 public string GetUpperStatement(TableSchema table)
42 {
43 return table.Name.ToUpper()+"_TABLE";
44 }
45 //suck as USER_FIELD
46 public string GetUpperStatement(ColumnSchema column)
47 {
48 return column.Name.ToUpper()+"_FIELD";
49 }
50
51 // such as USER_TABLE = "User"
52 public string GetMemberConstantDeclarationStatement(string protectionLevel,TableSchema table)
53 {
54 return protectionLevel+GetUpperStatement(table)+" = \""+GetCamelCaseName(table.Name)+"\"";
55 }
56
57 //such as USERID_FIELD = "Userid"
58 public string GetMemberConstantDeclarationStatement(string protectionLevel,ColumnSchema column)
59 {
60 return protectionLevel+GetUpperStatement(column)+" = \""+GetCamelCaseName(column.Name)+"\"";
61 }
62
63 public string GetCSharpVariableType(ColumnSchema column)
64 {
65 switch(column.DataType)
66 {
67 case DbType.AnsiString: return "string";
68 case DbType.AnsiStringFixedLength: return "string";
69 case DbType.Binary: return "byte[]";
70 case DbType.Boolean: return "bool";
71 case DbType.Byte: return "int";
72 case DbType.Currency: return "decimal";
73 case DbType.Date: return "DataTime";
74 case DbType.DateTime: return "DateTime";
75 case DbType.Decimal: return "decimal";
76 case DbType.Double: return "double";
77 case DbType.Guid: return "Guid";
78 case DbType.Int16: return "short";
79 case DbType.Int32: return "int";
80 case DbType.Int64: return "long";
81 case DbType.Object: return "object";
82 case DbType.SByte: return "sbyte";
83 case DbType.Single: return "float";
84 case DbType.String: return "string";
85 case DbType.StringFixedLength: return "string";
86 case DbType.Time: return "TimeSpan";
87 case DbType.UInt16: return "ushort";
88 case DbType.UInt32: return "uint";
89 case DbType.UInt64: return "ulong";
90 case DbType.VarNumeric: return "decimal";
91 }
92
93 return null;
94 }
95
96 public string GetCSharpBaseType(ColumnSchema column)
97 {
98 switch(column.DataType)
99 {
100 case DbType.AnsiString: return "System.String";
101 case DbType.AnsiStringFixedLength: return "System.String";
102 case DbType.Binary: return "System.Byte[]";
103 case DbType.Boolean: return "System.Boolean";
104 case DbType.Byte: return "System.Int32";
105 case DbType.Currency: return "System.Decimal";
106 case DbType.Date: return "System.DataTime";
107 case DbType.DateTime: return "System.DataTime";
108 case DbType.Decimal: return "System.Decimal";
109 case DbType.Double: return "System.Double";
110 case DbType.Guid: return "System.Guid";
111 case DbType.Int16: return "System.Int16";
112 case DbType.Int32: return "System.Int32";
113 case DbType.Int64: return "System.Int64";
114 case DbType.Object: return "System.Object";
115 case DbType.SByte: return "System.SByte";
116 case DbType.Single: return "System.Single";
117 case DbType.String: return "System.String";
118 case DbType.StringFixedLength: return "System.String";
119 case DbType.Time: return "System.TimeSpan";
120 case DbType.UInt16: return "System.UInt16";
121 case DbType.UInt32: return "System.UInt32";
122 case DbType.UInt64: return "System.UInt64";
123 case DbType.VarNumeric: return "System.Decimal";
124 }
125 return null;
126 }
127 }
128}
129
130
131
132