1
Entity: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_ID17

{18

get
{ return this._USER_ID; }19

set
{ this._USER_ID = value; }20
}21
[DataField("USER_NAME")]22
public String USER_NAME23

{24

get
{ return this._USER_NAME; }25

set
{ this._USER_NAME = value; }26
}27
[DataField("SHIFT_ID")]28
public String SHIFT_ID29

{30

get
{ return this._SHIFT_ID; }31

set
{ this._SHIFT_ID = value; }32
}33
[DataField("DEPARTMENT_ID")]34
public String DEPARTMENT_ID35

{36

get
{ return this._DEPARTMENT_ID; }37

set
{ this._DEPARTMENT_ID = value; }38
}39
[DataField("USER_REMARK")]40
public String USER_REMARK41

{42

get
{ return this._USER_REMARK; }43

set
{ this._USER_REMARK = value; }44
}45
[DataField("CREATE_TIME")]46
public DateTime CREATE_TIME47

{48

get
{ return this._CREATE_TIME; }49

set
{ this._CREATE_TIME = value; }50
}51
[DataField("CREATE_USER")]52
public String CREATE_USER53

{54

get
{ return this._CREATE_USER; }55

set
{ this._CREATE_USER = value; }56
}57
[DataField("USER_STATE")]58
public Decimal USER_STATE59

{60

get
{ return this._USER_STATE; }61

set
{ this._USER_STATE = value; }62
}63
[DataField("USER_PWD")]64
public String USER_PWD65

{66

get
{ return this._USER_PWD; }67

set
{ this._USER_PWD = value; }68
}69
}70

71
DataTableAttribute:72
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class)]73
public class DataTableAttribute : Attribute74

{75
// Fields76
private string tableName;77

78
// Methods79
public DataTableAttribute(string tableName)80

{81
this.tableName = tableName;82
}83

84
// Properties85
public string TableName86

{87
get88

{89
return this.tableName;90
}91
set92

{93
this.tableName = value;94
}95
}96
}97

98
BaseFieldAttribute:99
[AttributeUsage(AttributeTargets.Property)]100
public abstract class BaseFieldAttribute : Attribute101

{102
// Fields103
private string columnName;104
private int length;105
private string tableName;106

107
// Methods108
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
// Properties121
public int ColumnLength122

{123
get124

{125
return this.length;126
}127
set128

{129
this.length = value;130
}131
}132

133
public string ColumnName134

{135
get136

{137
return this.columnName;138
}139
set140

{141
this.columnName = value;142
}143
}144

145
public string TableName146

{147
get148

{149
return this.tableName;150
}151
set152

{153
this.tableName = value;154
}155
}156
}157

158
DataFieldAttribute:159
[AttributeUsage(AttributeTargets.Property)]160
public class DataFieldAttribute : BaseFieldAttribute161

{162
// Fields163
private DbType dbType;164
private CallbackHandler handler;165

166
// Methods167
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
// Properties190
public CallbackHandler CallbackHandler191

{192
get193

{194
return this.handler;195
}196
}197

198
public DbType Type199

{200
get201

{202
return this.dbType;203
}204
set205

{206
this.dbType = value;207
}208
}209
}210

211
ColumnInfo:212
public enum CallbackHandler213

{214
BlobArray = 0,215
ClobString = 1,216
None = -1217
}218

219
public class ColumnInfo220

{221
// Fields222
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
// Methods231
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
// Properties240
public string Alias241

{242
get243

{244
return this.alias;245
}246
set247

{248
this.alias = value;249
}250
}251

252
public CallbackHandler CallbackHandler253

{254
get255

{256
return this.handler;257
}258
set259

{260
this.handler = value;261
}262
}263

264
public int ColumnLength265

{266
get267

{268
return this.length;269
}270
set271

{272
this.length = value;273
}274
}275

276
public string ColumnName277

{278
get279

{280
return this.name;281
}282
set283

{284
this.name = value;285
}286
}287

288
public Type ColumnType289

{290
get291

{292
return this.columnType;293
}294
set295

{296
this.columnType = value;297
}298
}299

300
public string PropertyName301

{302
get303

{304
return this.propertyName;305
}306
set307

{308
this.propertyName = value;309
}310
}311

312
public object Value313

{314
get315

{316
return this.columnValue;317
}318
set319

{320
this.columnValue = value;321
}322
}323
}324

325
EntityOperator:326
public class EntityOperator327

{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
else396

{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
// Properties409
//public ArrayList CallbackColumns410
//{411
// get412
// {413
// return this.callbackColumns;414
// }415
//}416

417
public ArrayList Columns418

{419
get420

{421
return this.columns;422
}423
set424

{425
this.columns = value;426
}427
}428

429
public string DataSource430

{431
get432

{433
return this.resultTableName;434
}435
}436

437
}438


浙公网安备 33010602011771号