Code
1Entity:
2 [DataTable("BI_USER")]
3 public class Entity
4 {
5 String _USER_ID;
6 String _USER_NAME;
7 String _SHIFT_ID;
8 String _DEPARTMENT_ID;
9 String _USER_REMARK;
10 DateTime _CREATE_TIME;
11 String _CREATE_USER;
12 Decimal _USER_STATE;
13 String _USER_PWD;
14
15 [DataField("USER_ID")]
16 public String USER_ID
17 {
18 get { return this._USER_ID; }
19 set { this._USER_ID = value; }
20 }
21 [DataField("USER_NAME")]
22 public String USER_NAME
23 {
24 get { return this._USER_NAME; }
25 set { this._USER_NAME = value; }
26 }
27 [DataField("SHIFT_ID")]
28 public String SHIFT_ID
29 {
30 get { return this._SHIFT_ID; }
31 set { this._SHIFT_ID = value; }
32 }
33 [DataField("DEPARTMENT_ID")]
34 public String DEPARTMENT_ID
35 {
36 get { return this._DEPARTMENT_ID; }
37 set { this._DEPARTMENT_ID = value; }
38 }
39 [DataField("USER_REMARK")]
40 public String USER_REMARK
41 {
42 get { return this._USER_REMARK; }
43 set { this._USER_REMARK = value; }
44 }
45 [DataField("CREATE_TIME")]
46 public DateTime CREATE_TIME
47 {
48 get { return this._CREATE_TIME; }
49 set { this._CREATE_TIME = value; }
50 }
51 [DataField("CREATE_USER")]
52 public String CREATE_USER
53 {
54 get { return this._CREATE_USER; }
55 set { this._CREATE_USER = value; }
56 }
57 [DataField("USER_STATE")]
58 public Decimal USER_STATE
59 {
60 get { return this._USER_STATE; }
61 set { this._USER_STATE = value; }
62 }
63 [DataField("USER_PWD")]
64 public String USER_PWD
65 {
66 get { return this._USER_PWD; }
67 set { this._USER_PWD = value; }
68 }
69 }
70
71DataTableAttribute:
72 [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class)]
73 public class DataTableAttribute : Attribute
74 {
75 // Fields
76 private string tableName;
77
78 // Methods
79 public DataTableAttribute(string tableName)
80 {
81 this.tableName = tableName;
82 }
83
84 // Properties
85 public string TableName
86 {
87 get
88 {
89 return this.tableName;
90 }
91 set
92 {
93 this.tableName = value;
94 }
95 }
96 }
97
98BaseFieldAttribute:
99 [AttributeUsage(AttributeTargets.Property)]
100 public abstract class BaseFieldAttribute : Attribute
101 {
102 // Fields
103 private string columnName;
104 private int length;
105 private string tableName;
106
107 // Methods
108 public BaseFieldAttribute(string columnName)
109 : this(columnName, 0)
110 {
111
112 }
113
114 public BaseFieldAttribute(string columnName, int length)
115 {
116 this.columnName = columnName;
117 this.length = length;
118 }
119
120 // Properties
121 public int ColumnLength
122 {
123 get
124 {
125 return this.length;
126 }
127 set
128 {
129 this.length = value;
130 }
131 }
132
133 public string ColumnName
134 {
135 get
136 {
137 return this.columnName;
138 }
139 set
140 {
141 this.columnName = value;
142 }
143 }
144
145 public string TableName
146 {
147 get
148 {
149 return this.tableName;
150 }
151 set
152 {
153 this.tableName = value;
154 }
155 }
156 }
157
158DataFieldAttribute:
159 [AttributeUsage(AttributeTargets.Property)]
160 public class DataFieldAttribute : BaseFieldAttribute
161 {
162 // Fields
163 private DbType dbType;
164 private CallbackHandler handler;
165
166 // Methods
167 public DataFieldAttribute(string columnName)
168 : base(columnName)
169 {
170 this.handler = CallbackHandler.None;
171 this.dbType = DbType.String;
172 }
173
174 public DataFieldAttribute(string columnName, CallbackHandler callbackHandler)
175 : base(columnName)
176 {
177 this.handler = CallbackHandler.None;
178 this.dbType = DbType.String;
179 this.handler = callbackHandler;
180 }
181
182 public DataFieldAttribute(string columnName, int length)
183 : base(columnName, length)
184 {
185 this.handler = CallbackHandler.None;
186 this.dbType = DbType.String;
187 }
188
189 // Properties
190 public CallbackHandler CallbackHandler
191 {
192 get
193 {
194 return this.handler;
195 }
196 }
197
198 public DbType Type
199 {
200 get
201 {
202 return this.dbType;
203 }
204 set
205 {
206 this.dbType = value;
207 }
208 }
209 }
210
211ColumnInfo:
212 public enum CallbackHandler
213 {
214 BlobArray = 0,
215 ClobString = 1,
216 None = -1
217 }
218
219 public class ColumnInfo
220 {
221 // Fields
222 private string alias;
223 private Type columnType;
224 private object columnValue = DBNull.Value;
225 private CallbackHandler handler;
226 private int length;
227 private string name;
228 private string propertyName;
229
230 // Methods
231 public ColumnInfo(string name, string alias, Type type, string propertyName)
232 {
233 this.ColumnName = name;
234 this.Alias = alias;
235 this.ColumnType = type;
236 this.PropertyName = propertyName;
237 }
238
239 // Properties
240 public string Alias
241 {
242 get
243 {
244 return this.alias;
245 }
246 set
247 {
248 this.alias = value;
249 }
250 }
251
252 public CallbackHandler CallbackHandler
253 {
254 get
255 {
256 return this.handler;
257 }
258 set
259 {
260 this.handler = value;
261 }
262 }
263
264 public int ColumnLength
265 {
266 get
267 {
268 return this.length;
269 }
270 set
271 {
272 this.length = value;
273 }
274 }
275
276 public string ColumnName
277 {
278 get
279 {
280 return this.name;
281 }
282 set
283 {
284 this.name = value;
285 }
286 }
287
288 public Type ColumnType
289 {
290 get
291 {
292 return this.columnType;
293 }
294 set
295 {
296 this.columnType = value;
297 }
298 }
299
300 public string PropertyName
301 {
302 get
303 {
304 return this.propertyName;
305 }
306 set
307 {
308 this.propertyName = value;
309 }
310 }
311
312 public object Value
313 {
314 get
315 {
316 return this.columnValue;
317 }
318 set
319 {
320 this.columnValue = value;
321 }
322 }
323 }
324
325EntityOperator:
326 public class EntityOperator
327 {
328 private string resultTableName;
329 // private ArrayList callbackColumns;
330 private ArrayList columns;
331
332 public void InsertSqlBuild(object o)
333 {
334 RetrieveProperties(o.GetType());
335 BuildInsertSql(o);
336 }
337
338 private void RetrieveProperties(Type objectType)
339 {
340 PropertyInfo[] properties;
341 int num;
342 BaseFieldAttribute[] attributeArray3;
343 this.columns = new ArrayList();
344 DataTableAttribute[] customAttributes = (DataTableAttribute[])objectType.GetCustomAttributes(typeof(DataTableAttribute), true);
345 if (customAttributes.Length > 0)
346 {
347 this.resultTableName = customAttributes[0].TableName;
348 properties = objectType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
349 for (num = 0; num < properties.Length; num++)
350 {
351 attributeArray3 = (BaseFieldAttribute[])properties[num].GetCustomAttributes(typeof(BaseFieldAttribute), true);
352 if (attributeArray3.Length > 0)
353 {
354 ColumnInfo info = new ColumnInfo(attributeArray3[0].ColumnName, attributeArray3[0].TableName, properties[num].PropertyType, properties[num].Name);
355 //if (attributeArray3[0] is DataFieldAttribute)
356 //{
357 // info.CallbackHandler = ((DataFieldAttribute)attributeArray3[0]).CallbackHandler;
358 // if (info.CallbackHandler != CallbackHandler.None)
359 // {
360 // this.callbackColumns.Add(info);
361 // }
362 //}
363 this.Columns.Add(info);
364 }
365 }
366 }
367 }
368
369 public string BuildInsertSql(object o)
370 {
371 StringBuilder builder = new StringBuilder();
372 StringBuilder builder2 = new StringBuilder(" VALUES ");
373 object[] args = new object[] { "INSERT ", " INTO ", this.DataSource, " ", "(" };
374 builder.AppendFormat("{0}{1}{2}{3}{4}", args);
375 builder2.Append("(");
376 int num = 0;
377 object parameterValue = null;
378 foreach (ColumnInfo info2 in Columns)
379 {
380 if (num > 0)
381 {
382 builder.Append(",");
383 builder2.Append(",");
384 }
385 builder.Append(info2.ColumnName);
386
387
388 if (info2.ColumnType.FullName == "System.String")
389 {
390 builder2.Append("'");
391 parameterValue = o.GetType().GetProperty(info2.ColumnName).GetValue(o, null);
392 builder2.Append(parameterValue);
393 builder2.Append("'");
394 }
395 else
396 {
397 parameterValue = o.GetType().GetProperty(info2.ColumnName).GetValue(o, null);
398 builder2.Append(parameterValue);
399 }
400
401 num++;
402 }
403 builder2.Append(")");
404 builder.AppendFormat("{0}{1}", ")", builder2.ToString());
405 return builder.ToString();
406 }
407
408 // Properties
409 //public ArrayList CallbackColumns
410 //{
411 // get
412 // {
413 // return this.callbackColumns;
414 // }
415 //}
416
417 public ArrayList Columns
418 {
419 get
420 {
421 return this.columns;
422 }
423 set
424 {
425 this.columns = value;
426 }
427 }
428
429 public string DataSource
430 {
431 get
432 {
433 return this.resultTableName;
434 }
435 }
436
437 }
438
1Entity:
2 [DataTable("BI_USER")]
3 public class Entity
4 {
5 String _USER_ID;
6 String _USER_NAME;
7 String _SHIFT_ID;
8 String _DEPARTMENT_ID;
9 String _USER_REMARK;
10 DateTime _CREATE_TIME;
11 String _CREATE_USER;
12 Decimal _USER_STATE;
13 String _USER_PWD;
14
15 [DataField("USER_ID")]
16 public String USER_ID
17 {
18 get { return this._USER_ID; }
19 set { this._USER_ID = value; }
20 }
21 [DataField("USER_NAME")]
22 public String USER_NAME
23 {
24 get { return this._USER_NAME; }
25 set { this._USER_NAME = value; }
26 }
27 [DataField("SHIFT_ID")]
28 public String SHIFT_ID
29 {
30 get { return this._SHIFT_ID; }
31 set { this._SHIFT_ID = value; }
32 }
33 [DataField("DEPARTMENT_ID")]
34 public String DEPARTMENT_ID
35 {
36 get { return this._DEPARTMENT_ID; }
37 set { this._DEPARTMENT_ID = value; }
38 }
39 [DataField("USER_REMARK")]
40 public String USER_REMARK
41 {
42 get { return this._USER_REMARK; }
43 set { this._USER_REMARK = value; }
44 }
45 [DataField("CREATE_TIME")]
46 public DateTime CREATE_TIME
47 {
48 get { return this._CREATE_TIME; }
49 set { this._CREATE_TIME = value; }
50 }
51 [DataField("CREATE_USER")]
52 public String CREATE_USER
53 {
54 get { return this._CREATE_USER; }
55 set { this._CREATE_USER = value; }
56 }
57 [DataField("USER_STATE")]
58 public Decimal USER_STATE
59 {
60 get { return this._USER_STATE; }
61 set { this._USER_STATE = value; }
62 }
63 [DataField("USER_PWD")]
64 public String USER_PWD
65 {
66 get { return this._USER_PWD; }
67 set { this._USER_PWD = value; }
68 }
69 }
70
71DataTableAttribute:
72 [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class)]
73 public class DataTableAttribute : Attribute
74 {
75 // Fields
76 private string tableName;
77
78 // Methods
79 public DataTableAttribute(string tableName)
80 {
81 this.tableName = tableName;
82 }
83
84 // Properties
85 public string TableName
86 {
87 get
88 {
89 return this.tableName;
90 }
91 set
92 {
93 this.tableName = value;
94 }
95 }
96 }
97
98BaseFieldAttribute:
99 [AttributeUsage(AttributeTargets.Property)]
100 public abstract class BaseFieldAttribute : Attribute
101 {
102 // Fields
103 private string columnName;
104 private int length;
105 private string tableName;
106
107 // Methods
108 public BaseFieldAttribute(string columnName)
109 : this(columnName, 0)
110 {
111
112 }
113
114 public BaseFieldAttribute(string columnName, int length)
115 {
116 this.columnName = columnName;
117 this.length = length;
118 }
119
120 // Properties
121 public int ColumnLength
122 {
123 get
124 {
125 return this.length;
126 }
127 set
128 {
129 this.length = value;
130 }
131 }
132
133 public string ColumnName
134 {
135 get
136 {
137 return this.columnName;
138 }
139 set
140 {
141 this.columnName = value;
142 }
143 }
144
145 public string TableName
146 {
147 get
148 {
149 return this.tableName;
150 }
151 set
152 {
153 this.tableName = value;
154 }
155 }
156 }
157
158DataFieldAttribute:
159 [AttributeUsage(AttributeTargets.Property)]
160 public class DataFieldAttribute : BaseFieldAttribute
161 {
162 // Fields
163 private DbType dbType;
164 private CallbackHandler handler;
165
166 // Methods
167 public DataFieldAttribute(string columnName)
168 : base(columnName)
169 {
170 this.handler = CallbackHandler.None;
171 this.dbType = DbType.String;
172 }
173
174 public DataFieldAttribute(string columnName, CallbackHandler callbackHandler)
175 : base(columnName)
176 {
177 this.handler = CallbackHandler.None;
178 this.dbType = DbType.String;
179 this.handler = callbackHandler;
180 }
181
182 public DataFieldAttribute(string columnName, int length)
183 : base(columnName, length)
184 {
185 this.handler = CallbackHandler.None;
186 this.dbType = DbType.String;
187 }
188
189 // Properties
190 public CallbackHandler CallbackHandler
191 {
192 get
193 {
194 return this.handler;
195 }
196 }
197
198 public DbType Type
199 {
200 get
201 {
202 return this.dbType;
203 }
204 set
205 {
206 this.dbType = value;
207 }
208 }
209 }
210
211ColumnInfo:
212 public enum CallbackHandler
213 {
214 BlobArray = 0,
215 ClobString = 1,
216 None = -1
217 }
218
219 public class ColumnInfo
220 {
221 // Fields
222 private string alias;
223 private Type columnType;
224 private object columnValue = DBNull.Value;
225 private CallbackHandler handler;
226 private int length;
227 private string name;
228 private string propertyName;
229
230 // Methods
231 public ColumnInfo(string name, string alias, Type type, string propertyName)
232 {
233 this.ColumnName = name;
234 this.Alias = alias;
235 this.ColumnType = type;
236 this.PropertyName = propertyName;
237 }
238
239 // Properties
240 public string Alias
241 {
242 get
243 {
244 return this.alias;
245 }
246 set
247 {
248 this.alias = value;
249 }
250 }
251
252 public CallbackHandler CallbackHandler
253 {
254 get
255 {
256 return this.handler;
257 }
258 set
259 {
260 this.handler = value;
261 }
262 }
263
264 public int ColumnLength
265 {
266 get
267 {
268 return this.length;
269 }
270 set
271 {
272 this.length = value;
273 }
274 }
275
276 public string ColumnName
277 {
278 get
279 {
280 return this.name;
281 }
282 set
283 {
284 this.name = value;
285 }
286 }
287
288 public Type ColumnType
289 {
290 get
291 {
292 return this.columnType;
293 }
294 set
295 {
296 this.columnType = value;
297 }
298 }
299
300 public string PropertyName
301 {
302 get
303 {
304 return this.propertyName;
305 }
306 set
307 {
308 this.propertyName = value;
309 }
310 }
311
312 public object Value
313 {
314 get
315 {
316 return this.columnValue;
317 }
318 set
319 {
320 this.columnValue = value;
321 }
322 }
323 }
324
325EntityOperator:
326 public class EntityOperator
327 {
328 private string resultTableName;
329 // private ArrayList callbackColumns;
330 private ArrayList columns;
331
332 public void InsertSqlBuild(object o)
333 {
334 RetrieveProperties(o.GetType());
335 BuildInsertSql(o);
336 }
337
338 private void RetrieveProperties(Type objectType)
339 {
340 PropertyInfo[] properties;
341 int num;
342 BaseFieldAttribute[] attributeArray3;
343 this.columns = new ArrayList();
344 DataTableAttribute[] customAttributes = (DataTableAttribute[])objectType.GetCustomAttributes(typeof(DataTableAttribute), true);
345 if (customAttributes.Length > 0)
346 {
347 this.resultTableName = customAttributes[0].TableName;
348 properties = objectType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
349 for (num = 0; num < properties.Length; num++)
350 {
351 attributeArray3 = (BaseFieldAttribute[])properties[num].GetCustomAttributes(typeof(BaseFieldAttribute), true);
352 if (attributeArray3.Length > 0)
353 {
354 ColumnInfo info = new ColumnInfo(attributeArray3[0].ColumnName, attributeArray3[0].TableName, properties[num].PropertyType, properties[num].Name);
355 //if (attributeArray3[0] is DataFieldAttribute)
356 //{
357 // info.CallbackHandler = ((DataFieldAttribute)attributeArray3[0]).CallbackHandler;
358 // if (info.CallbackHandler != CallbackHandler.None)
359 // {
360 // this.callbackColumns.Add(info);
361 // }
362 //}
363 this.Columns.Add(info);
364 }
365 }
366 }
367 }
368
369 public string BuildInsertSql(object o)
370 {
371 StringBuilder builder = new StringBuilder();
372 StringBuilder builder2 = new StringBuilder(" VALUES ");
373 object[] args = new object[] { "INSERT ", " INTO ", this.DataSource, " ", "(" };
374 builder.AppendFormat("{0}{1}{2}{3}{4}", args);
375 builder2.Append("(");
376 int num = 0;
377 object parameterValue = null;
378 foreach (ColumnInfo info2 in Columns)
379 {
380 if (num > 0)
381 {
382 builder.Append(",");
383 builder2.Append(",");
384 }
385 builder.Append(info2.ColumnName);
386
387
388 if (info2.ColumnType.FullName == "System.String")
389 {
390 builder2.Append("'");
391 parameterValue = o.GetType().GetProperty(info2.ColumnName).GetValue(o, null);
392 builder2.Append(parameterValue);
393 builder2.Append("'");
394 }
395 else
396 {
397 parameterValue = o.GetType().GetProperty(info2.ColumnName).GetValue(o, null);
398 builder2.Append(parameterValue);
399 }
400
401 num++;
402 }
403 builder2.Append(")");
404 builder.AppendFormat("{0}{1}", ")", builder2.ToString());
405 return builder.ToString();
406 }
407
408 // Properties
409 //public ArrayList CallbackColumns
410 //{
411 // get
412 // {
413 // return this.callbackColumns;
414 // }
415 //}
416
417 public ArrayList Columns
418 {
419 get
420 {
421 return this.columns;
422 }
423 set
424 {
425 this.columns = value;
426 }
427 }
428
429 public string DataSource
430 {
431 get
432 {
433 return this.resultTableName;
434 }
435 }
436
437 }
438