SQL数据库抽像工厂类,相关特性的定义

  1 /// <summary>
  2     /// 权限验证
  3     /// </summary>
  4     public sealed class ResultAttribute : Attribute
  5     {
  6         /// <summary>
  7         /// 类属于哪个页面
  8         /// </summary>
  9         public string Referfer { get; set; }
 10         /// <summary>
 11         /// 是否进行验证
 12         /// </summary>
 13         public bool RoleCheck { get; set; }
 14     }
 15     /// <summary>
 16     /// 类、属性或方法特性
 17     /// </summary>
 18     [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
 19     public sealed class CommandAttribute : Attribute
 20     {
 21         /// <summary>
 22         /// 类、属性或方法特性
 23         /// </summary>
 24         /// <param name="_cmdname">类,方法或属性名称</param>
 25         /// <param name="_author">作者或修订人</param>
 26         /// <param name="_creation">创建或修订时间</param>
 27         /// <param name="_remark">创建或修订内容</param>
 28         public CommandAttribute(string _cmdname, string _author, string _creation, string _remark)
 29         {
 30             this.CommandName = _cmdname;
 31             this.Author = _author;
 32             this.Creation = _creation;
 33             this.Remark = _remark;
 34         }
 35         /// <summary>
 36         /// 类,方法或属性名称
 37         /// </summary>
 38         public string CommandName { get; set; }
 39         /// <summary>
 40         /// 作者或修订人
 41         /// </summary>
 42         public string Author { get; set; }
 43         /// <summary>
 44         /// 创建或修订时间
 45         /// </summary>
 46         public string Creation { get; set; }
 47         /// <summary>
 48         /// 创建或修订内容
 49         /// </summary>
 50         public string Remark { get; set; }
 51     }
 52 
 53     /// <summary>
 54     /// 数据表列名映射
 55     /// </summary>
 56     [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
 57     public sealed class ColumnMap : Attribute
 58     {
 59         /// <summary>
 60         /// 映射字段
 61         /// </summary>
 62         /// <param name="_ColumnName">列字段名</param>
 63         /// <param name="_ColumnLen">长度</param>
 64         /// <param name="_DataType">数据类型</param>
 65         /// <param name="_Remark">字段说明</param>
 66         /// <param name="_IsNull">是否允许空值</param>
 67         /// <param name="_PrimaryKey">是否为主键</param>
 68         /// <param name="_Mark">是否为自增或默认值,True:则不对此列进行Insert与Update操作</param>
 69         public ColumnMap(string _ColumnName, string _ColumnLen, object _DataType, string _Remark, bool _IsNull, bool _PrimaryKey, bool _Mark)
 70         {
 71             this.ColumnName = _ColumnName;
 72             this.ColumnLen = _ColumnLen;
 73             this.DataType = _DataType;
 74             this.Remark = _Remark;
 75             this.IsNull = _IsNull;
 76             this.PrimaryKey = _PrimaryKey;
 77             this.Mark = _Mark;
 78             this.IsSetValue = true;
 79             this.ValueTp = ValueType.Null;
 80             this.IsValueTemp = false;
 81         }
 82         /// <summary>
 83         /// 映射字段
 84         /// </summary>
 85         /// <param name="_ValueType">子表查询的返回类型</param>
 86         /// <param name="_ValueTableName">子表表名和对应的实体类名</param> 
 87         /// <param name="_KeyCol">子表条件字段名</param>
 88         /// <param name="_ParentCol">父表关联字段名</param>
 89         /// <param name="_ReadValueCols">查询的列</param>
 90         public ColumnMap( ValueType _ValueType, string _ValueTableName, string _KeyCol, string _ParentCol, string _ReadValueCols)
 91         {
 92             this.IsSetValue = false;
 93             this.ValueTp = _ValueType;
 94             this.ValueTableName = _ValueTableName;
 95             this.KeyCol = _KeyCol;
 96             this.ParentCol = _ParentCol;
 97             this.IsOrderBy = false;
 98             this.ReadValueCols = _ReadValueCols;
 99             this.IsValueTemp = false;
100         }
101         /// <summary>
102         /// 映射字段
103         /// </summary>
104         /// <param name="_ValueType">子表查询的返回类型</param>
105         /// <param name="_ValueTableName">子表表名和对应的实体类名</param> 
106         /// <param name="_KeyCol">子表条件字段名,多个用|分隔</param>
107         /// <param name="_ParentCol">父表关联字段名或条件值(值不能与字段名相同),多个用|分隔</param>
108         /// <param name="_OrderByKey">排序列</param>
109         /// <param name="_OrderBy">排序方式</param>
110         /// <param name="_ReadValueCols">查询的列</param>
111         public ColumnMap(ValueType _ValueType, string _ValueTableName, string _KeyCol, string _ParentCol, string _OrderByKey, OrderBy _OrderBy, string _ReadValueCols)
112         {
113             this.IsSetValue = false;
114             this.ValueTp = _ValueType;
115             this.ValueTableName = _ValueTableName;
116             this.KeyCol = _KeyCol;
117             this.ParentCol = _ParentCol;
118             this.OrderByKey = _OrderByKey;
119             this.OrderBy = _OrderBy;
120             this.IsOrderBy = true;
121             this.ReadValueCols = _ReadValueCols;
122             this.IsValueTemp = false;
123         }
124         /// <summary>
125         /// 映射临时存储单位,只能为TRUE
126         /// </summary>
127         /// <param name="_IsValueTemp"></param>
128         public ColumnMap(bool _IsValueTemp, string _ValueTempName)
129         {
130             this.IsSetValue = false;
131             this.IsValueTemp = true;
132             this.ValueTempName = _ValueTempName;
133         }
134         /// <summary>
135         /// 列字段名
136         /// </summary>
137         public string ColumnName { get; set; }
138         /// <summary>
139         /// 长度
140         /// </summary>
141         public string ColumnLen { get; set; }
142         /// <summary>
143         /// 数据类型
144         /// </summary>
145         public object DataType { get; set; }
146         /// <summary>
147         /// 字段说明
148         /// </summary>
149         public string Remark { get; set; }
150         /// <summary>
151         /// 是否允许空值
152         /// </summary>
153         public bool IsNull { get; set; }
154         /// <summary>
155         /// 是否为主键
156         /// </summary>
157         public bool PrimaryKey { get; set; }
158         /// <summary>
159         /// 是否为自增或默认值,True则不对此列进行INSERT和UPDATE
160         /// </summary>
161         public bool Mark { get; set; }
162         /// <summary>
163         /// 是否在允许在此类直接附值,应用于多表查询带子实体表内容的,此项主要应用于查询
164         /// </summary>
165         public bool IsSetValue { get; set; }
166         /// <summary>
167         /// 是否为临时存储对象,应用于子实体类关联查询时的临时储值对象,对List作用
168         /// </summary>
169         public bool IsValueTemp { get; set; }
170         /// <summary>
171         /// 当存在临时存储对象时,临时对象对应的属性名称
172         /// </summary>
173         public string ValueTempName { get; set; }
174         /// <summary>
175         /// 子表查询的返回类型
176         /// </summary>
177         public ValueType ValueTp { get; set; }
178         /// <summary>
179         /// 子表表名和对应的实体类名
180         /// </summary>
181         public string ValueTableName { get; set; }
182         /// <summary>
183         /// 查询要返回的列
184         /// </summary>
185         public string ReadValueCols { get; set; }
186         /// <summary>
187         /// 子表条件字段名,多个用|分隔,并用必须与父表关联字段对应
188         /// </summary>
189         public string KeyCol { get; set; }
190         /// <summary>
191         /// 父表关联字段名,多个用|分隔,或查询条件值
192         /// </summary>
193         public string ParentCol { get; set; }
194         /// <summary>
195         /// 子查询是否排序
196         /// </summary>
197         public bool IsOrderBy { get; set; }
198         /// <summary>
199         /// 排序列
200         /// </summary>
201         public string OrderByKey { get; set; }
202         /// <summary>
203         /// 排序方式
204         /// </summary>
205         public OrderBy OrderBy { get; set; }
206     }
207     public enum ValueType{
208           List,
209           Row,
210           Scalar,
211           Null
212     }
213     /// <summary>
214     /// 数据表列名映射
215     /// </summary>
216     [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
217     public sealed class TableMap : Attribute
218     {
219         /// <summary>
220         /// 映射数据库表
221         /// </summary>
222         /// <param name="_DataName">数据库名</param>
223         /// <param name="_TableName">表名</param>
224         public TableMap(string _DataName, string _TableName)
225         {
226             this.TableName = _TableName;
227             this.DataName = _DataName;
228         }
229         /// <summary>
230         /// 映射表名
231         /// </summary>
232         public string TableName { get; set; }
233         /// <summary>
234         /// 所属数据库名
235         /// </summary>
236         public string DataName { get; set; }
237     }
238 
239     /// <summary>
240     /// 获取指定属性对象的特性
241     /// </summary>
242     /// <typeparam name="T"></typeparam>
243     public sealed class AttributeProperty<T> where T : class
244     {
245         public static T GetTableMapAttribute(PropertyInfo t)
246         {
247             T Map = default(T);
248             T[] MapAttributes = t.GetCustomAttributes(typeof(T), true) as T[];
249             if (MapAttributes.Length > 0)
250             {
251                 Map = MapAttributes[0];
252             }
253             return Map;
254         }
255     }
256     /// <summary>
257     /// 获取指定类对象的特性
258     /// </summary>
259     public sealed class AttributeTag<T, A>
260         where T : class
261         where A : class
262     {
263         /// <summary>
264         /// 获取表所映射的特性
265         /// </summary>
266         /// <param name="t">对象</param>
267         /// <returns></returns>
268         public static A GetTableMapAttribute(T t)
269         {
270             A Map = default(A);
271             Type MapType = t.GetType();
272             A[] MapAttributes = MapType.GetCustomAttributes(typeof(A), true) as A[];
273             if (MapAttributes.Length > 0)
274             {
275                 Map = MapAttributes[0];
276             }
277             return Map;
278         }
279     }
280     public sealed class ModelAttributeTag<A>
281         where A : class
282     {
283         /// <summary>
284         /// 获取表所映射的特性
285         /// </summary>
286         /// <param name="t">对象</param>
287         /// <returns></returns>
288         public static A GetTableMapAttribute(Type MapType)
289         {
290             A Map = default(A);
291 
292             A[] MapAttributes = MapType.GetCustomAttributes(typeof(A), true) as A[];
293             if (MapAttributes.Length > 0)
294             {
295                 Map = MapAttributes[0];
296             }
297             return Map;
298         }
299     }

 

posted on 2013-03-22 22:44  FLASHFYZ  阅读(193)  评论(0编辑  收藏  举报

导航