我发现我错怪了M$ m$正在以一种极端激进的方式改变我们的数据访问模式
在.net 1.1框架下编写自己的数据访问类时 我曾经抱怨过 如果M$的dataset 能够像组件一样 可以把各种各样的 DataAdepter捆绑进去该多好啊 这样数据储存器和数据I/O就可以一起发布了 编写也方便,何苦要建立DataAccess工程阿
现在的Dataset 基本上满足了我幻想初步的一切需求: 拖拽数据表、 生成数据结构和填充器(TableAdapter) 、对每个填充器强类型化(编写程序的时候可以通过vs IDE提示来减少工作量 改写和阅读也更清晰)、每个填充器捆绑若干种强类型化select查询限定(以前每次都要自己写where 混乱不说 每个dataadapter 修改了selectcommand以后就成了巨大的废物)。。。。。种种功能都是我那被废弃的数据访问费尽千辛万苦达到了的或费尽千辛万苦也没能达到的。。
于是我开始利用这个构架疯狂的升级了我手头所有的工程!
作为纪念 把我曾经的心血贴出来 里面很多功能和现在的dataset 从思想根源是一致的
这个数据访问类是以dataset为存储核心 使用的时候 把这个组件拖到有dataadpter 和dataadapter生成数据集的地方(窗体 组件 服务皆可) 然后用MountDataAdepters()方法把dataadpters 全都引用就可以使用了
永别了~曾经的数据访问类
1Imports WayneWorks
2Imports WayneWorks.Toolkits
3Imports System.Data
4Imports System.Data.SqlClient
5Imports System.Data.OleDb
6Imports System.Data.Odbc
7Imports System.Data.OracleClient
8
9Public Class DataAccessComponent1_1Class DataAccessComponent1_1
10 '基础据访问类
11 '用例 在继承的新类 New()函数中指定 dsAllTables 和 DBConnection
12 '并且将所有拖拽得到的 IDataAdepter 放入list
13 'DA2List(Me.SqlDataAdapter1, DACols)
14 'DA2List(Me.SqlDataAdapter2, DACols)
15 'DA2List(Me.SqlDataAdapter3, DACols)
16 'DA2List(Me.SqlDataAdapter4, DACols)
17 'DA2List(Me.SqlDataAdapter5, DACols)
18 'DA2List(Me.SqlDataAdapter6, DACols)
19 'DA2List(Me.SqlDataAdapter7, DACols)
20 'DA2List(Me.SqlDataAdapter8, DACols)
21
22 Inherits System.ComponentModel.Component
23
24
25
26自定义的全局量#Region " 自定义的全局量 "
27
28
29
30 Protected DACols As New SortedList '所有的DA列表
31 Protected WithEvents DsAllTables As DataSet '全局的数据集
32 Protected DBConnection As IDbConnection
33 Protected ConstStr As String
34 Protected ConstArray() As String '除了cst开头的表 所有常量表名
35
36
37#End Region
38
39组件设计器生成的代码#Region " 组件设计器生成的代码 "
40
41
42
43 Public Sub New()Sub New(ByVal Container As System.ComponentModel.IContainer)
44 MyClass.New()
45
46
47 'Windows.Forms 类撰写设计器支持所必需的
48 Container.Add(Me)
49 End Sub
50
51 Public Sub New()Sub New()
52 MyBase.New()
53
54 '该调用是组件设计器所必需的。
55 'InitializeComponent()
56
57 ''在 InitializeComponent() 调用之后添加任何初始化
58 '' Dim ConstString As String = "" ' "ADD_Roles,ADD_RolePowers,ADD_RoleList"
59 'Dim ViewString As String = "" '"CardMountsCardCount,vwProcessCount,vwProcessSameCount,vwServerUserCount"
60 ' ConstArray = Split(ConstString, ",")
61
62
63
64 'DA2List()
65
66 'Me.DACols.Clear()
67
68 'DA2List(Me.SqlDataAdapter1, DACols)
69 'DA2List(Me.SqlDataAdapter2, DACols)
70 'DA2List(Me.SqlDataAdapter3, DACols)
71 'DA2List(Me.SqlDataAdapter4, DACols)
72 'DA2List(Me.SqlDataAdapter5, DACols)
73 'DA2List(Me.SqlDataAdapter6, DACols)
74 'DA2List(Me.SqlDataAdapter7, DACols)
75 'DA2List(Me.SqlDataAdapter8, DACols)
76 'DA2List(Me.SqlDataAdapter9, DACols)
77 'DA2List(Me.SqlDataAdapter10, DACols)
78 'DA2List(Me.SqlDataAdapter11, DACols)
79 'DA2List(Me.SqlDataAdapter12, DACols)
80 'DA2List(Me.SqlDataAdapter13, DACols)
81 'DA2List(Me.SqlDataAdapter14, DACols)
82 'DA2List(Me.SqlDataAdapter15, DACols)
83 'DA2List(Me.SqlDataAdapter16, DACols)
84 'DA2List(Me.SqlDataAdapter17, DACols)
85 'DA2List(Me.SqlDataAdapter18, DACols)
86 'DA2List(Me.SqlDataAdapter19, DACols)
87 'DA2List(Me.SqlDataAdapter20, DACols)
88 'DA2List(Me.SqlDataAdapter21, DACols)
89 'DA2List(Me.SqlDataAdapter22, DACols)
90 'DA2List(Me.SqlDataAdapter23, DACols)
91 'DA2List(Me.SqlDataAdapter24, DACols)
92 'DA2List(Me.SqlDataAdapter25, DACols)
93 'DA2List(Me.SqlDataAdapter26, DACols)
94 'DA2List(Me.SqlDataAdapter27, DACols)
95 'DA2List(Me.SqlDataAdapter28, DACols)
96 'DA2List(Me.SqlDataAdapter29, DACols)
97 ' DA2List(Me.SqlDataAdapter30, DACols)
98 ' DA2List(Me.SqlDataAdapter31, DACols)
99 End Sub
100
101
102
103
104 '组件重写 dispose 以清理组件列表。
105 Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
106 If disposing Then
107 If Not (components Is Nothing) Then
108 components.Dispose()
109 End If
110 End If
111 MyBase.Dispose(disposing)
112 End Sub
113
114 '组件设计器所必需的
115 Protected components As System.ComponentModel.IContainer
116
117 '注意: 以下过程是组件设计器所必需的
118 '可以使用组件设计器修改此过程。
119 '不要使用代码编辑器修改它。
120
121
122
123
124#End Region
125
126
127
128
129功能实现代码#Region "功能实现代码"
130
131
132 '分析一组DA确定它的表名
133 Public Sub MountDataAdepters()Sub MountDataAdepters(ByVal ParamArray DataAdepters() As Object)
134 Me.DACols.Clear()
135
136 For Each da As Object In DataAdepters
137
138 Dim ms As ITableMappingCollection = da.TableMappings
139 Dim m As ITableMapping = ms(0)
140 DACols.Add(m.DataSetTable, da)
141 Next
142
143 End Sub
144
145 Public Overridable Property ConstTableName()Property ConstTableName() As String()
146 Get
147 Return ConstArray
148 End Get
149
150 Set(ByVal Array As String())
151 ConstArray = Array
152
153
154 End Set
155
156 End Property
157
158
159 Public Overridable Property BaseDataSet()Property BaseDataSet() As DataSet
160
161 Get
162 Return DsAllTables
163 End Get
164 Set(ByVal Value As DataSet)
165 DsAllTables = Value
166 End Set
167 End Property
168
169 Public Overridable Property DBConn()Property DBConn() As Data.IDbConnection
170
171 Get
172 Return DBConnection
173 End Get
174 Set(ByVal Value As Data.IDbConnection)
175 Me.DBConnection = Value
176 End Set
177 End Property
178
179 Public Overridable ReadOnly Property ConstTables()Property ConstTables() As System.Collections.SortedList
180 Get
181 Dim r As New SortedList
182 For Each s As String In ConstArray
183 r.Add(s, DsAllTables.Tables(s))
184
185 Next
186 For Each t As DataTable In Me.DsAllTables.Tables
187 If t.TableName.StartsWith("cst") Then
188 r.Add(t.TableName, t)
189 End If
190
191 Next
192 Return r
193
194 End Get
195 End Property
196
197
198
199
200
201 Public Overridable Sub RefreshConst()Sub RefreshConst()
202 Dim tmpda As IDataAdapter
203 For Each v As Collections.DictionaryEntry In Me.DataAdepterList
204 If CStr(v.Key).StartsWith("cst") Then
205 DsAllTables.Tables(v.Key).Clear()
206 tmpda = v.Value
207 tmpda.Fill(Me.DsAllTables)
208 End If
209
210 Next
211
212
213 For Each s As String In Me.ConstArray
214
215 If DACols.ContainsKey(s) Then
216 DsAllTables.Tables(s).Clear()
217 tmpda = DACols(s)
218 tmpda.Fill(Me.DsAllTables)
219 End If
220 Next
221
222 End Sub
223
224
225
226 Sub LoadConst()Sub LoadConst(ByVal xml As String)
227 Dim sr As System.IO.StringReader = New System.IO.StringReader(xml)
228 BaseDataSet.ReadXml(sr)
229 BaseDataSet.AcceptChanges()
230 End Sub
231
232 Public Overridable Sub Update()Sub Update()
233 Dim tmpda As IDataAdapter
234 For Each s As String In DACols.Keys
235 'If Array.IndexOf(Me.ConstArray, s) <> -1 Then
236 tmpda = DACols(s)
237 tmpda.Update(Me.DsAllTables)
238
239 ' End If
240 Next
241
242 End Sub
243 Public Overridable Sub Update()Sub Update(ByVal tbName As String)
244 Dim tmpda As IDataAdapter
245
246 'If Array.IndexOf(Me.ConstArray, s) <> -1 Then
247 tmpda = DACols(tbName)
248 tmpda.Update(Me.DsAllTables)
249
250 ' End If
251
252
253 End Sub
254
255
256
257
258 Public Overridable Property DataAdepterList()Property DataAdepterList() As System.Collections.SortedList
259
260 Get
261 Return Me.DACols
262 End Get
263 Set(ByVal value As System.Collections.SortedList)
264 Me.DACols = value
265 End Set
266 End Property
267
268
269
270 Public Overridable Property ConstValues()Property ConstValues(ByVal TableName As String, ByVal ConstName As String, Optional ByVal Field As String = "Value", Optional ByVal Do_UPDATE As Boolean = False) As Object
271
272 Get
273
274
275 Dim table As DataTable = Me.BaseDataSet.Tables(TableName)
276 Dim rs() As DataRow
277 rs = (table.Select("Name='" & ConstName & "'"))
278 If rs.Length = 0 Then
279 Throw New Exception("本常量表没有此常量")
280 Else
281 Dim r As DataRow = rs(0)
282
283 Return r(Field)
284
285
286 End If
287
288
289 End Get
290 Set(ByVal Value As Object)
291
292 Dim table As DataTable = Me.ConstTables(TableName)
293 Dim rs() As DataRow
294 rs = (table.Select("Name='" & ConstName & "'"))
295 If rs.Length = 0 Then
296 Throw New Exception("本常量表没有此常量")
297 Else
298 Dim r As DataRow = rs(0)
299 r(Field) = Value
300 If Do_UPDATE Then Me.UpdateSingleRow(r)
301
302
303 End If
304
305 End Set
306 End Property
307
308
309
310
311
312
313 Public Overridable Property ConstValues()Property ConstValues(ByVal TableName As String, ByVal ConstID As Long, Optional ByVal Field As String = "Value", Optional ByVal Do_UPDATE As Boolean = False) As Object
314
315 Get
316
317
318 Dim table As DataTable = Me.BaseDataSet.Tables(TableName)
319 Dim rs() As DataRow
320 rs = (table.Select("ID=" & ConstID & ""))
321 If rs.Length = 0 Then
322 Throw New Exception("本常量表没有此常量")
323 Else
324 Try
325 Dim r As DataRow = rs(0)
326
327 Return r(Field)
328 Catch e As Exception
329 Return Nothing
330 End Try
331
332
333 End If
334
335
336 End Get
337 Set(ByVal Value As Object)
338
339 Dim table As DataTable = Me.ConstTables(TableName)
340 Dim rs() As DataRow
341 rs = (table.Select("ID='" & ConstID & "'"))
342 If rs.Length = 0 Then
343 Throw New Exception("本常量表没有此常量")
344 Else
345 Dim r As DataRow = rs(0)
346 r(Field) = Value
347 If Do_UPDATE Then Me.UpdateSingleRow(r)
348
349
350 End If
351
352 End Set
353 End Property
354
355
356
357
358
359 Public Overridable Function UpdateSingleRow()Function UpdateSingleRow(ByVal row As DataRow) As DataRow
360
361 Dim r(0) As DataRow
362 r(0) = row
363 Dim s() As String = Me.DataAdepterList(row.Table.TableName).GetType.ToString.Split(".")
364
365 Select Case s(s.Length - 1)
366 Case "SqlDataAdapter"
367
368 CType(Me.DataAdepterList(row.Table.TableName), SqlDataAdapter).Update(r)
369
370 Case "OleDbDataAdapter"
371 CType(Me.DataAdepterList(row.Table.TableName), OleDbDataAdapter).Update(r)
372
373 Case "OdbcDataAdapter"
374 CType(Me.DataAdepterList(row.Table.TableName), OdbcDataAdapter).Update(r)
375
376 Case "OracleDataAdapter"
377 CType(Me.DataAdepterList(row.Table.TableName), OracleDataAdapter).Update(r)
378
379 End Select
380
381
382
383 Return r(0)
384
385 End Function
386
387
388 Public Overridable Function UpdateRows()Function UpdateRows(ByVal rows As DataRow()) As DataRow()
389 Dim s() As String = Me.DataAdepterList(rows(0).Table.TableName).GetType.ToString.Split(".")
390
391 Select Case s(s.Length - 1)
392 Case "SqlDataAdapter"
393 CType(Me.DataAdepterList(rows(0).Table.TableName), SqlDataAdapter).Update(rows)
394
395
396 Case "OleDbDataAdapter"
397 CType(Me.DataAdepterList(rows(0).Table.TableName), OleDbDataAdapter).Update(rows)
398
399
400 Case "OdbcDataAdapter"
401 CType(Me.DataAdepterList(rows(0).Table.TableName), OdbcDataAdapter).Update(rows)
402
403
404 Case "OracleDataAdapter"
405 CType(Me.DataAdepterList(rows(0).Table.TableName), OdbcDataAdapter).Update(rows)
406
407 End Select
408 Return rows
409
410
411
412
413 End Function
414
415 Public Overridable Function BeginTransaction()Function BeginTransaction() As IDbTransaction
416
417 Dim t As Data.IDbTransaction = Me.DBConnection.BeginTransaction()
418
419 For Each dao As Object In Me.DataAdepterList.Values
420 Dim s() As String = dao.GetType.ToString.Split(".")
421
422 Select Case s(s.Length - 1)
423 Case "SqlDataAdapter"
424 Dim da As SqlDataAdapter = dao
425 If Not da.InsertCommand Is Nothing Then da.InsertCommand.Transaction = t
426 If Not da.DeleteCommand Is Nothing Then da.DeleteCommand.Transaction = t
427 If Not da.UpdateCommand Is Nothing Then da.UpdateCommand.Transaction = t
428 If Not da.SelectCommand Is Nothing Then da.SelectCommand.Transaction = t
429
430 Case "OleDbDataAdapter"
431 Dim da As OleDbDataAdapter = dao
432 If Not da.InsertCommand Is Nothing Then da.InsertCommand.Transaction = t
433 If Not da.DeleteCommand Is Nothing Then da.DeleteCommand.Transaction = t
434 If Not da.UpdateCommand Is Nothing Then da.UpdateCommand.Transaction = t
435 If Not da.SelectCommand Is Nothing Then da.SelectCommand.Transaction = t
436
437 Case "OdbcDataAdapter"
438
439 Dim da As OdbcDataAdapter = dao
440 If Not da.InsertCommand Is Nothing Then da.InsertCommand.Transaction = t
441 If Not da.DeleteCommand Is Nothing Then da.DeleteCommand.Transaction = t
442 If Not da.UpdateCommand Is Nothing Then da.UpdateCommand.Transaction = t
443 If Not da.SelectCommand Is Nothing Then da.SelectCommand.Transaction = t
444
445 Case "OracleDataAdapter"
446 Dim da As OracleDataAdapter = dao
447 If Not da.InsertCommand Is Nothing Then da.InsertCommand.Transaction = t
448 If Not da.DeleteCommand Is Nothing Then da.DeleteCommand.Transaction = t
449 If Not da.UpdateCommand Is Nothing Then da.UpdateCommand.Transaction = t
450 If Not da.SelectCommand Is Nothing Then da.SelectCommand.Transaction = t
451 End Select
452
453
454
455 Next
456 Return t
457 End Function
458
459
460
461 Public Function XmlText()Function XmlText() As String
462 Dim sw As System.IO.StringWriter = New System.IO.StringWriter
463 BaseDataSet.WriteXml(sw)
464
465 Return sw.ToString
466 End Function
467
468
469#End Region
470
471
472
473
474
475
476End Class
477
478
1Imports WayneWorks
2Imports WayneWorks.Toolkits
3Imports System.Data
4Imports System.Data.SqlClient
5Imports System.Data.OleDb
6Imports System.Data.Odbc
7Imports System.Data.OracleClient
8
9Public Class DataAccessComponent1_1Class DataAccessComponent1_1
10 '基础据访问类
11 '用例 在继承的新类 New()函数中指定 dsAllTables 和 DBConnection
12 '并且将所有拖拽得到的 IDataAdepter 放入list
13 'DA2List(Me.SqlDataAdapter1, DACols)
14 'DA2List(Me.SqlDataAdapter2, DACols)
15 'DA2List(Me.SqlDataAdapter3, DACols)
16 'DA2List(Me.SqlDataAdapter4, DACols)
17 'DA2List(Me.SqlDataAdapter5, DACols)
18 'DA2List(Me.SqlDataAdapter6, DACols)
19 'DA2List(Me.SqlDataAdapter7, DACols)
20 'DA2List(Me.SqlDataAdapter8, DACols)
21
22 Inherits System.ComponentModel.Component
23
24
25
26自定义的全局量#Region " 自定义的全局量 "
27
28
29
30 Protected DACols As New SortedList '所有的DA列表
31 Protected WithEvents DsAllTables As DataSet '全局的数据集
32 Protected DBConnection As IDbConnection
33 Protected ConstStr As String
34 Protected ConstArray() As String '除了cst开头的表 所有常量表名
35
36
37#End Region
38
39组件设计器生成的代码#Region " 组件设计器生成的代码 "
40
41
42
43 Public Sub New()Sub New(ByVal Container As System.ComponentModel.IContainer)
44 MyClass.New()
45
46
47 'Windows.Forms 类撰写设计器支持所必需的
48 Container.Add(Me)
49 End Sub
50
51 Public Sub New()Sub New()
52 MyBase.New()
53
54 '该调用是组件设计器所必需的。
55 'InitializeComponent()
56
57 ''在 InitializeComponent() 调用之后添加任何初始化
58 '' Dim ConstString As String = "" ' "ADD_Roles,ADD_RolePowers,ADD_RoleList"
59 'Dim ViewString As String = "" '"CardMountsCardCount,vwProcessCount,vwProcessSameCount,vwServerUserCount"
60 ' ConstArray = Split(ConstString, ",")
61
62
63
64 'DA2List()
65
66 'Me.DACols.Clear()
67
68 'DA2List(Me.SqlDataAdapter1, DACols)
69 'DA2List(Me.SqlDataAdapter2, DACols)
70 'DA2List(Me.SqlDataAdapter3, DACols)
71 'DA2List(Me.SqlDataAdapter4, DACols)
72 'DA2List(Me.SqlDataAdapter5, DACols)
73 'DA2List(Me.SqlDataAdapter6, DACols)
74 'DA2List(Me.SqlDataAdapter7, DACols)
75 'DA2List(Me.SqlDataAdapter8, DACols)
76 'DA2List(Me.SqlDataAdapter9, DACols)
77 'DA2List(Me.SqlDataAdapter10, DACols)
78 'DA2List(Me.SqlDataAdapter11, DACols)
79 'DA2List(Me.SqlDataAdapter12, DACols)
80 'DA2List(Me.SqlDataAdapter13, DACols)
81 'DA2List(Me.SqlDataAdapter14, DACols)
82 'DA2List(Me.SqlDataAdapter15, DACols)
83 'DA2List(Me.SqlDataAdapter16, DACols)
84 'DA2List(Me.SqlDataAdapter17, DACols)
85 'DA2List(Me.SqlDataAdapter18, DACols)
86 'DA2List(Me.SqlDataAdapter19, DACols)
87 'DA2List(Me.SqlDataAdapter20, DACols)
88 'DA2List(Me.SqlDataAdapter21, DACols)
89 'DA2List(Me.SqlDataAdapter22, DACols)
90 'DA2List(Me.SqlDataAdapter23, DACols)
91 'DA2List(Me.SqlDataAdapter24, DACols)
92 'DA2List(Me.SqlDataAdapter25, DACols)
93 'DA2List(Me.SqlDataAdapter26, DACols)
94 'DA2List(Me.SqlDataAdapter27, DACols)
95 'DA2List(Me.SqlDataAdapter28, DACols)
96 'DA2List(Me.SqlDataAdapter29, DACols)
97 ' DA2List(Me.SqlDataAdapter30, DACols)
98 ' DA2List(Me.SqlDataAdapter31, DACols)
99 End Sub
100
101
102
103
104 '组件重写 dispose 以清理组件列表。
105 Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
106 If disposing Then
107 If Not (components Is Nothing) Then
108 components.Dispose()
109 End If
110 End If
111 MyBase.Dispose(disposing)
112 End Sub
113
114 '组件设计器所必需的
115 Protected components As System.ComponentModel.IContainer
116
117 '注意: 以下过程是组件设计器所必需的
118 '可以使用组件设计器修改此过程。
119 '不要使用代码编辑器修改它。
120
121
122
123
124#End Region
125
126
127
128
129功能实现代码#Region "功能实现代码"
130
131
132 '分析一组DA确定它的表名
133 Public Sub MountDataAdepters()Sub MountDataAdepters(ByVal ParamArray DataAdepters() As Object)
134 Me.DACols.Clear()
135
136 For Each da As Object In DataAdepters
137
138 Dim ms As ITableMappingCollection = da.TableMappings
139 Dim m As ITableMapping = ms(0)
140 DACols.Add(m.DataSetTable, da)
141 Next
142
143 End Sub
144
145 Public Overridable Property ConstTableName()Property ConstTableName() As String()
146 Get
147 Return ConstArray
148 End Get
149
150 Set(ByVal Array As String())
151 ConstArray = Array
152
153
154 End Set
155
156 End Property
157
158
159 Public Overridable Property BaseDataSet()Property BaseDataSet() As DataSet
160
161 Get
162 Return DsAllTables
163 End Get
164 Set(ByVal Value As DataSet)
165 DsAllTables = Value
166 End Set
167 End Property
168
169 Public Overridable Property DBConn()Property DBConn() As Data.IDbConnection
170
171 Get
172 Return DBConnection
173 End Get
174 Set(ByVal Value As Data.IDbConnection)
175 Me.DBConnection = Value
176 End Set
177 End Property
178
179 Public Overridable ReadOnly Property ConstTables()Property ConstTables() As System.Collections.SortedList
180 Get
181 Dim r As New SortedList
182 For Each s As String In ConstArray
183 r.Add(s, DsAllTables.Tables(s))
184
185 Next
186 For Each t As DataTable In Me.DsAllTables.Tables
187 If t.TableName.StartsWith("cst") Then
188 r.Add(t.TableName, t)
189 End If
190
191 Next
192 Return r
193
194 End Get
195 End Property
196
197
198
199
200
201 Public Overridable Sub RefreshConst()Sub RefreshConst()
202 Dim tmpda As IDataAdapter
203 For Each v As Collections.DictionaryEntry In Me.DataAdepterList
204 If CStr(v.Key).StartsWith("cst") Then
205 DsAllTables.Tables(v.Key).Clear()
206 tmpda = v.Value
207 tmpda.Fill(Me.DsAllTables)
208 End If
209
210 Next
211
212
213 For Each s As String In Me.ConstArray
214
215 If DACols.ContainsKey(s) Then
216 DsAllTables.Tables(s).Clear()
217 tmpda = DACols(s)
218 tmpda.Fill(Me.DsAllTables)
219 End If
220 Next
221
222 End Sub
223
224
225
226 Sub LoadConst()Sub LoadConst(ByVal xml As String)
227 Dim sr As System.IO.StringReader = New System.IO.StringReader(xml)
228 BaseDataSet.ReadXml(sr)
229 BaseDataSet.AcceptChanges()
230 End Sub
231
232 Public Overridable Sub Update()Sub Update()
233 Dim tmpda As IDataAdapter
234 For Each s As String In DACols.Keys
235 'If Array.IndexOf(Me.ConstArray, s) <> -1 Then
236 tmpda = DACols(s)
237 tmpda.Update(Me.DsAllTables)
238
239 ' End If
240 Next
241
242 End Sub
243 Public Overridable Sub Update()Sub Update(ByVal tbName As String)
244 Dim tmpda As IDataAdapter
245
246 'If Array.IndexOf(Me.ConstArray, s) <> -1 Then
247 tmpda = DACols(tbName)
248 tmpda.Update(Me.DsAllTables)
249
250 ' End If
251
252
253 End Sub
254
255
256
257
258 Public Overridable Property DataAdepterList()Property DataAdepterList() As System.Collections.SortedList
259
260 Get
261 Return Me.DACols
262 End Get
263 Set(ByVal value As System.Collections.SortedList)
264 Me.DACols = value
265 End Set
266 End Property
267
268
269
270 Public Overridable Property ConstValues()Property ConstValues(ByVal TableName As String, ByVal ConstName As String, Optional ByVal Field As String = "Value", Optional ByVal Do_UPDATE As Boolean = False) As Object
271
272 Get
273
274
275 Dim table As DataTable = Me.BaseDataSet.Tables(TableName)
276 Dim rs() As DataRow
277 rs = (table.Select("Name='" & ConstName & "'"))
278 If rs.Length = 0 Then
279 Throw New Exception("本常量表没有此常量")
280 Else
281 Dim r As DataRow = rs(0)
282
283 Return r(Field)
284
285
286 End If
287
288
289 End Get
290 Set(ByVal Value As Object)
291
292 Dim table As DataTable = Me.ConstTables(TableName)
293 Dim rs() As DataRow
294 rs = (table.Select("Name='" & ConstName & "'"))
295 If rs.Length = 0 Then
296 Throw New Exception("本常量表没有此常量")
297 Else
298 Dim r As DataRow = rs(0)
299 r(Field) = Value
300 If Do_UPDATE Then Me.UpdateSingleRow(r)
301
302
303 End If
304
305 End Set
306 End Property
307
308
309
310
311
312
313 Public Overridable Property ConstValues()Property ConstValues(ByVal TableName As String, ByVal ConstID As Long, Optional ByVal Field As String = "Value", Optional ByVal Do_UPDATE As Boolean = False) As Object
314
315 Get
316
317
318 Dim table As DataTable = Me.BaseDataSet.Tables(TableName)
319 Dim rs() As DataRow
320 rs = (table.Select("ID=" & ConstID & ""))
321 If rs.Length = 0 Then
322 Throw New Exception("本常量表没有此常量")
323 Else
324 Try
325 Dim r As DataRow = rs(0)
326
327 Return r(Field)
328 Catch e As Exception
329 Return Nothing
330 End Try
331
332
333 End If
334
335
336 End Get
337 Set(ByVal Value As Object)
338
339 Dim table As DataTable = Me.ConstTables(TableName)
340 Dim rs() As DataRow
341 rs = (table.Select("ID='" & ConstID & "'"))
342 If rs.Length = 0 Then
343 Throw New Exception("本常量表没有此常量")
344 Else
345 Dim r As DataRow = rs(0)
346 r(Field) = Value
347 If Do_UPDATE Then Me.UpdateSingleRow(r)
348
349
350 End If
351
352 End Set
353 End Property
354
355
356
357
358
359 Public Overridable Function UpdateSingleRow()Function UpdateSingleRow(ByVal row As DataRow) As DataRow
360
361 Dim r(0) As DataRow
362 r(0) = row
363 Dim s() As String = Me.DataAdepterList(row.Table.TableName).GetType.ToString.Split(".")
364
365 Select Case s(s.Length - 1)
366 Case "SqlDataAdapter"
367
368 CType(Me.DataAdepterList(row.Table.TableName), SqlDataAdapter).Update(r)
369
370 Case "OleDbDataAdapter"
371 CType(Me.DataAdepterList(row.Table.TableName), OleDbDataAdapter).Update(r)
372
373 Case "OdbcDataAdapter"
374 CType(Me.DataAdepterList(row.Table.TableName), OdbcDataAdapter).Update(r)
375
376 Case "OracleDataAdapter"
377 CType(Me.DataAdepterList(row.Table.TableName), OracleDataAdapter).Update(r)
378
379 End Select
380
381
382
383 Return r(0)
384
385 End Function
386
387
388 Public Overridable Function UpdateRows()Function UpdateRows(ByVal rows As DataRow()) As DataRow()
389 Dim s() As String = Me.DataAdepterList(rows(0).Table.TableName).GetType.ToString.Split(".")
390
391 Select Case s(s.Length - 1)
392 Case "SqlDataAdapter"
393 CType(Me.DataAdepterList(rows(0).Table.TableName), SqlDataAdapter).Update(rows)
394
395
396 Case "OleDbDataAdapter"
397 CType(Me.DataAdepterList(rows(0).Table.TableName), OleDbDataAdapter).Update(rows)
398
399
400 Case "OdbcDataAdapter"
401 CType(Me.DataAdepterList(rows(0).Table.TableName), OdbcDataAdapter).Update(rows)
402
403
404 Case "OracleDataAdapter"
405 CType(Me.DataAdepterList(rows(0).Table.TableName), OdbcDataAdapter).Update(rows)
406
407 End Select
408 Return rows
409
410
411
412
413 End Function
414
415 Public Overridable Function BeginTransaction()Function BeginTransaction() As IDbTransaction
416
417 Dim t As Data.IDbTransaction = Me.DBConnection.BeginTransaction()
418
419 For Each dao As Object In Me.DataAdepterList.Values
420 Dim s() As String = dao.GetType.ToString.Split(".")
421
422 Select Case s(s.Length - 1)
423 Case "SqlDataAdapter"
424 Dim da As SqlDataAdapter = dao
425 If Not da.InsertCommand Is Nothing Then da.InsertCommand.Transaction = t
426 If Not da.DeleteCommand Is Nothing Then da.DeleteCommand.Transaction = t
427 If Not da.UpdateCommand Is Nothing Then da.UpdateCommand.Transaction = t
428 If Not da.SelectCommand Is Nothing Then da.SelectCommand.Transaction = t
429
430 Case "OleDbDataAdapter"
431 Dim da As OleDbDataAdapter = dao
432 If Not da.InsertCommand Is Nothing Then da.InsertCommand.Transaction = t
433 If Not da.DeleteCommand Is Nothing Then da.DeleteCommand.Transaction = t
434 If Not da.UpdateCommand Is Nothing Then da.UpdateCommand.Transaction = t
435 If Not da.SelectCommand Is Nothing Then da.SelectCommand.Transaction = t
436
437 Case "OdbcDataAdapter"
438
439 Dim da As OdbcDataAdapter = dao
440 If Not da.InsertCommand Is Nothing Then da.InsertCommand.Transaction = t
441 If Not da.DeleteCommand Is Nothing Then da.DeleteCommand.Transaction = t
442 If Not da.UpdateCommand Is Nothing Then da.UpdateCommand.Transaction = t
443 If Not da.SelectCommand Is Nothing Then da.SelectCommand.Transaction = t
444
445 Case "OracleDataAdapter"
446 Dim da As OracleDataAdapter = dao
447 If Not da.InsertCommand Is Nothing Then da.InsertCommand.Transaction = t
448 If Not da.DeleteCommand Is Nothing Then da.DeleteCommand.Transaction = t
449 If Not da.UpdateCommand Is Nothing Then da.UpdateCommand.Transaction = t
450 If Not da.SelectCommand Is Nothing Then da.SelectCommand.Transaction = t
451 End Select
452
453
454
455 Next
456 Return t
457 End Function
458
459
460
461 Public Function XmlText()Function XmlText() As String
462 Dim sw As System.IO.StringWriter = New System.IO.StringWriter
463 BaseDataSet.WriteXml(sw)
464
465 Return sw.ToString
466 End Function
467
468
469#End Region
470
471
472
473
474
475
476End Class
477
478