背景数据检索 [英] background data retrieval

查看:89
本文介绍了背景数据检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个具有数据访问类的应用程序。和用户界面

类别。


用于从一个系统接收采购订单数据并推送

处理的交易另一个系统。


系统通常运行良好。

目前用户界面要求每15分钟刷新一次数据

(可选)和数据访问类连接到数据库并检索结构化以适合应用程序的

数据。在检索过程中,它会显示

消息,通知用户各种下载。每个应用程序都有自己的数据访问类

。需要30秒到5分钟才能刷新数据取决于用户所在的位置


我被要求使刷新透明,以便用户没有

必须等待数据访问层获取其数据,因为某些站点有一个非常慢的网络连接。


我不确定如何实现这个新要求。

我以为我可以将数据访问类作为一个单独的应用程序

加载用户界面然后定期检索数据

并将其保存到本地数据库文件(mdb?)中,而不是保存到当前的

数据集中,然后异步使用用户界面连接到

本地数据库并更新其记录。


我将不胜感激。


问候


道格

Hi,
I have an application that has a "Data Access Class" and "User Interface
Class".

It is for receiving Purchase Order data from one system and pushing
processed transactions to another system.

The system generally works quite well.
Currently the User interface calls for a refresh of data every 15 minutes
(selectable) and the Data Access Class connects to the DB and retrieves the
data structured to suit the application. During the retrieval it displays
messages informing the User of the various downloads. Each application has
its own Data Access Class. It takes between 30 seconds and 5 minutes to
refresh the data dependant on where the User is located

I have been asked to make the refresh transparent so that the User does not
have to wait for the Data Access Layer to get its data as some site have a
very slow connections to the network.

I am not sure how to achieve this new requirement.
I thought that I could make the Data Access Class a separate application
that loads with the User interface and then periodically retrieves the data
and saves it into a local database file (mdb ?) rather than into the current
Data Set and then have the User Interface asynchronously connect to the
local database and update its records.

I would appreciate any oppinions.

Regards

Doug

推荐答案

嗨道格,


你可以execu在单独的线程上加载您的数据,以便

表单仍然响应用户,但是,您需要小心

没有UI元素在检索数据之前使用该数据。

加载数据后,您的数据访问类应该引发一个可以处理的事件,以便您可以调用该调用将调用封送到

UI线程的方法。这里是基本的想法(注意 - 这个例子使用SQL northwind

数据库):


Public Class Form1

继承System.Windows.Forms.Form

#Region" Windows窗体设计器生成的代码


Public Sub New()

MyBase.New()


' 'Windows窗体设计器需要此调用。

InitializeComponent()

''在InitializeComponent()调用后添加任何初始化
< br $>
结束子


''表格覆盖处理以清理组件列表。

受保护的重载覆盖子处理(ByVal处理为布尔)

如果处置那么

如果不是(组件什么都没有)那么

components.Dispose()

结束如果

结束如果

MyBase.Dispose(处置)

结束子


'' Windows窗体设计器要求

私有组件As System.ComponentModel.IContainer


''注意:Windows窗体设计器需要以下过程

''可以使用Windows窗体设计器修改它。

''不要莫使用代码编辑器来区分它。

Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents TextBox2 As System.Windows.Forms.TextBox

Friend WithEvents Button2 As System.Windows.Forms .Button

Friend WithEvents Button3 As System.Windows.Forms.Button

Friend WithEvents Button4 As System.Windows.Forms.Button

Friend WithEvents Button5 As System.Windows.Forms.Button

Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox

< System.Diagnostics.DebuggerStepThrough()> Private Sub

InitializeComponent()

Me.DataGrid1 = New System.Windows.Forms.DataGrid

Me.TextBox1 = New System.Windows。 Forms.TextBox

Me.Button1 = New System.Windows.Forms.Button

Me.TextBox2 = New System.Windows.Forms.TextBox

Me.Button2 = New System.Windows.Forms.Button

Me.Button3 = New System.Windows.Forms.Button

Me.Button4 = New System.Windows。 Forms.Button

Me.Button5 = New System.Windows.Forms.Button

Me.CheckBox1 = New System.Windows.Forms.CheckBox

CType(Me.DataGrid1,System.ComponentModel.ISupportInitialize).BeginIni t()

Me.SuspendLayout()

''

' 'DataGrid1

''

Me.DataGrid1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top或

系统.Windows.Forms.AnchorStyles.Bottom)_

或System.Windows.Forms.AnchorStyles.Left)_

或System.Windows.Forms.AnchorStyles.Right),

System.Windows.Forms.AnchorStyles)

Me.DataGrid1.DataMember =""

Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText

Me.DataGrid1.Location = New System.Drawing.Point(16,120)

Me.DataGrid1.Name =" DataGrid1"

Me .DataGrid1.Size = New System.Drawing.Size(472,208)

Me.DataGrid1.TabIndex = 0

''

' 'textBox1

''

Me.TextBox1.Location = New System.Drawing.Point(24,56)

Me.TextBox1.Name =" TextBox1"

Me.TextBox1.Size = New System.Drawing.Size(48,20)

Me.TextBox1.TabIndex = 1

Me.TextBox1.Text =" TextBox1"

''

''Button1

''

Me.Button1.Location = New System.Drawing.Point(24,88)

Me.Button1.Name =" Button1"

Me.Button1.TabIndex = 2

Me.Button1.Text =" Next"

''

''TextBox2

''

Me.TextBox2.Location = New System.Drawing.Point(80,56)

Me.TextBox2.Name =" TextBox2"

Me.TextBox2.Size = New System.Drawing.Size(112,20)

Me.TextBox2.TabIndex = 3

Me.TextBox2.Text =" TextBox2"

''

''Button2

' '

Me.Button2.Location = New System.Drawing.Point(136,88)

Me.Button2.Name =" Button2"

Me.Button2.TabIndex = 4

Me.Button2.Text =" Add Child"

''

''Button3 < br $>
''

Me.Button3.Location = New System.Drawing.Point(240,88)

Me.Button3.Name =" Button3"

Me.Button3.Size = New System.Drawing.Size(96,23)

Me.Button3.TabIndex = 5

Me.Button3.Text =删除父母

''

''Button4

''

Me.Button4.Location = New Sy stem.Drawing.Point(376,88)

Me.Button4.Name =" Button4"

Me.Button4.Size = New System.Drawing.Size(96 ,23)

Me.Button4.TabIndex = 6

Me.Button4.Text =" Show Changes"

''

''Button5

''

Me.Button5.Location =新System.Drawing.Point(24,16)

Me.Button5.Name =" Button5"

Me.Button5.TabIndex = 7

Me.Button5.Text ="加载数据>

''

''CheckBox1

''

Me.CheckBox1.Checked = True

Me .CheckBox1.CheckState = System.Windows.Forms.CheckState.Checked

Me.CheckBox1.Location = New System.Drawing.Point(104,16)

Me.CheckBox1 .Name =" CheckBox1"

Me.CheckBox1.Size = New System.Drawing.Size(64,24)

Me.CheckBox1.TabIndex = 8
Me.CheckBox1.Text =" Async"

''

''Form1

''

Me.AutoScaleBaseSize = New System.Drawing.Size(5,13)

Me.ClientSize = New System.Drawing.Size(496,334)

Me.Controls.Add(Me.CheckBox1)

Me.Controls.Add(Me.Button5)

Me.Controls.Add(Me.Button4)

Me.Controls.Add(Me.Button3)

Me.Controls.Add(Me.Button2)

Me.Controls.Add(我。 TextBox2)

Me.Controls.Add(Me.Button1)

Me.Controls.Add(Me.TextBox1)

Me.Controls。添加(Me.DataGrid1)

Me.Name =" Form1"
Me.Text =" Form1"

CType(Me。 DataGrid1,System.ComponentModel.ISupportInitialize)。EndInit()

Me.ResumeLayout(False)


End Sub


#End Region

私有类DataAccess

私有Const SQL_CONNECTION_STRING As String = _

" Data Source = localhost; " &安培; _

" Initial Catalog = Northwind;" &安培; _

集成安全性= SSPI


公共事件DataLoaded(ByVal发送者为对象,ByVal e As EventArgs)

受保护的Overridable Sub OnDataLoaded(ByVal e As EventArgs)

RaiseEvent DataLoaded(Me,e)

End Sub


Public Sub GetData (ByRef ds As DataSet)

ds =新数据集

Dim da,da2 As SqlDataAdapter

Dim cnn As SqlConnection

尝试

cnn =新的SqlConnection(SQL_CONNECTION_STRING)

da =新的SqlDataAdapter(" SELECT * FROM Region",cnn)

da.Fill(ds," Region")

da = New SqlDataAdapter(" SELECT * FROM Territories",cnn)

da.Fill(ds ,地区)


ds.Relations.Add(" Region_Territories",_

ds.Tables(" Region")。列( " RegionID"),_

ds.Tables(" Territories")。列(" RegionID"))


ds.Dat aSetName =" RegionTerritories"


OnDataLoaded(EventArgs.Empty)


Catch Exp As Exception

MessageBox。显示(Exp.Message)

结束尝试

结束子


结束班


Private Delegate Sub GetDataArgsDelegate(ByVal e As EventArgs)


Private WithEvents作为新DataAccess访问

私有myDataSet作为DataSet

私有cmParent,cmChild为CurrencyManager


私有m_async为布尔值=真

公共属性LoadAsync()为布尔值

获取

返回m_async

结束获取

设置(ByVal值为布尔值)

m_async =值

结束集

结束属性


私有m_isDataLoaded为布尔值= False

公共属性IsDataLoaded()As Boolean

获取

返回m_isDataLoaded

结束获取

设置(ByVal值为布尔值)

m_isDataLoaded =值
结束集

结束财产


私有子按钮5_Click(ByVal发送者为System.Object,ByVal e As

System.EventArgs)处理Button5.Click

Me.Button5.Enabled = False

Me.BeginGetData()

结束Sub


Private Sub BeginGetData()

m_isDataLoaded = False

Me.DataGrid1.DataSource = Nothing

Me.TextBox1.DataBindings.Clear()

Me.TextBox2.DataBindings.Clear()

Me.TextBox1.Text =""

Me.TextBox2.Text =正在加载数据...


如果Me.LoadAsync那么

Dim t As New Threading.Thread(地址:Me.GetData)

t.Name = Me.Name +" DataThread"

t.IsBackground = True

t.Start( )

Else

Me.GetData()

结束如果

结束子

Private Sub EndGetData(ByVal e As EventArgs)

m_isDataLoaded = True


Me.DataGrid1.DataSourc e = myDataSet

Me.DataGrid1.DataMember =" Region.Region_Territories"


Me.TextBox1.DataBindings.Add(" Text",myDataSet, " Region.RegionID")

Me.TextBox2.DataBindings.Add(" Text",myDataSet,

" Region.RegionDescription")


cmParent = Me.BindingContext(myDataSet," Region")

cmChild = Me.BindingContext(myDataSet," Region.Region_Territories")

Me.Button5.Enabled = True

End Sub


Public Sub GetData()

''模拟更长的时间。 ....

System.Threading.Thread.Sleep(5000)

Access.GetData(myDataSet)

End Sub


Private Sub Access_DataLoaded(ByVal sender As Object,ByVal e As

System.EventArgs)处理Access.DataLoaded

如果Me.InvokeRequired那么

'' - Marshall到UI线程...

Dim dlg As New GetDataArgsDelegate(Address Of EndGetData)

Dim args()As Object = {e}

Me.BeginInvoke(dlg,args)

Else

Me.EndGetData(EventArgs.Empty)

结束如果

结束子


Private Sub Button1_Click(ByVal发送者)作为System.Object,ByVal e As

System.EventArgs)处理Button1.Click

如果Me.IsDataLoaded则

cmParent.Position + = 1

结束如果

结束子


Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button2.Click

如果Me.IsDataLoaded则

cmChild.AddNew()

结束如果< br $>
End Sub


Private Sub Button3_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button3。点击

如果Me.IsDataLoaded那么

cmParent.RemoveAt(cmParent.Position)

结束如果

End Sub


Public Overridable Sub ShowDiffData()

'' - Vi在网络浏览器中的差异

尝试

如果不是(myDataSet什么都没有)那么


Dim cFileName As String =

Environment.GetFolderPath(Environment.SpecialFolde r.LocalApplicationData)+

" \Diff"

Dim dsDiffgram As DataSet


如果myDataSet.HasChanges那么

dsDiffgram = myDataSet.GetChanges()

dsDiffgram.WriteXml(cFileName + myDataSet.DataSetName +" .xml" ,

XmlWriteMode.DiffGram)

System.Diagnostics.Process.Start(" file://" + cFileName +

myDataSet.DataSetName +" .xml")

Else

MessageBox.Show(" Please make changes first。) ;,显示更改,

MessageBoxButtons.OK,MessageBoxIcon.Information)

结束如果

结束如果

Catch exp As Exception

结束尝试

End Sub


Private Sub Button4_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button4.Click

如果Me.IsDataLoaded则

Me.ShowDiffData()

结束如果

结束子


Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,ByVal e

As System。 EventArgs)Handles CheckBox1.CheckedChanged

Me.LoadAsync = Me.CheckBox1.Checked

End Sub

End Class

" Doug Bell" < du*@bigpond.com>在消息中写道

新闻:e9 ************** @ TK2MSFTNGP12.phx.gbl ...
Hi Doug,

You can execute the loading of your data on a separate thread so that the
form is still responsive to the user, however, you need to be careful that
none of the UI elements work with that data before the data is retrieved.
Once the data is loaded, your data access class should raise an event that
you can handle so you can call the invoke method to marshal the call to the
UI thread. Here''s the basic idea (note- this example uses the SQL northwind
database):

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

''This call is required by the Windows Form Designer.
InitializeComponent()

''Add any initialization after the InitializeComponent() call

End Sub

''Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

''Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

''NOTE: The following procedure is required by the Windows Form Designer
''It can be modified using the Windows Form Designer.
''Do not modify it using the code editor.
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.CheckBox1 = New System.Windows.Forms.CheckBox
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginIni t()
Me.SuspendLayout()
''
''DataGrid1
''
Me.DataGrid1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(16, 120)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(472, 208)
Me.DataGrid1.TabIndex = 0
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point(24, 56)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(48, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "TextBox1"
''
''Button1
''
Me.Button1.Location = New System.Drawing.Point(24, 88)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 2
Me.Button1.Text = "Next"
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(80, 56)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(112, 20)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = "TextBox2"
''
''Button2
''
Me.Button2.Location = New System.Drawing.Point(136, 88)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 4
Me.Button2.Text = "Add Child"
''
''Button3
''
Me.Button3.Location = New System.Drawing.Point(240, 88)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(96, 23)
Me.Button3.TabIndex = 5
Me.Button3.Text = "Delete Parent"
''
''Button4
''
Me.Button4.Location = New System.Drawing.Point(376, 88)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(96, 23)
Me.Button4.TabIndex = 6
Me.Button4.Text = "Show Changes"
''
''Button5
''
Me.Button5.Location = New System.Drawing.Point(24, 16)
Me.Button5.Name = "Button5"
Me.Button5.TabIndex = 7
Me.Button5.Text = "Load Data"
''
''CheckBox1
''
Me.CheckBox1.Checked = True
Me.CheckBox1.CheckState = System.Windows.Forms.CheckState.Checked
Me.CheckBox1.Location = New System.Drawing.Point(104, 16)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(64, 24)
Me.CheckBox1.TabIndex = 8
Me.CheckBox1.Text = "Async"
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(496, 334)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit( )
Me.ResumeLayout(False)

End Sub

#End Region

Private Class DataAccess
Private Const SQL_CONNECTION_STRING As String = _
"Data Source=localhost;" & _
"Initial Catalog=Northwind;" & _
"Integrated Security=SSPI"

Public Event DataLoaded(ByVal sender As Object, ByVal e As EventArgs)
Protected Overridable Sub OnDataLoaded(ByVal e As EventArgs)
RaiseEvent DataLoaded(Me, e)
End Sub

Public Sub GetData(ByRef ds As DataSet)
ds = New DataSet
Dim da, da2 As SqlDataAdapter
Dim cnn As SqlConnection
Try
cnn = New SqlConnection(SQL_CONNECTION_STRING)

da = New SqlDataAdapter("SELECT * FROM Region", cnn)
da.Fill(ds, "Region")
da = New SqlDataAdapter("SELECT * FROM Territories", cnn)
da.Fill(ds, "Territories")

ds.Relations.Add("Region_Territories", _
ds.Tables("Region").Columns("RegionID"), _
ds.Tables("Territories").Columns("RegionID"))

ds.DataSetName = "RegionTerritories"

OnDataLoaded(EventArgs.Empty)

Catch Exp As Exception
MessageBox.Show(Exp.Message)
End Try
End Sub

End Class

Private Delegate Sub GetDataArgsDelegate(ByVal e As EventArgs)

Private WithEvents Access As New DataAccess
Private myDataSet As DataSet
Private cmParent, cmChild As CurrencyManager

Private m_async As Boolean = True
Public Property LoadAsync() As Boolean
Get
Return m_async
End Get
Set(ByVal Value As Boolean)
m_async = Value
End Set
End Property

Private m_isDataLoaded As Boolean = False
Public Property IsDataLoaded() As Boolean
Get
Return m_isDataLoaded
End Get
Set(ByVal Value As Boolean)
m_isDataLoaded = Value
End Set
End Property

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Me.Button5.Enabled = False
Me.BeginGetData()
End Sub

Private Sub BeginGetData()
m_isDataLoaded = False
Me.DataGrid1.DataSource = Nothing
Me.TextBox1.DataBindings.Clear()
Me.TextBox2.DataBindings.Clear()
Me.TextBox1.Text = ""
Me.TextBox2.Text = "Loading Data..."

If Me.LoadAsync Then
Dim t As New Threading.Thread(AddressOf Me.GetData)
t.Name = Me.Name + "DataThread"
t.IsBackground = True
t.Start()
Else
Me.GetData()
End If
End Sub

Private Sub EndGetData(ByVal e As EventArgs)
m_isDataLoaded = True

Me.DataGrid1.DataSource = myDataSet
Me.DataGrid1.DataMember = "Region.Region_Territories"

Me.TextBox1.DataBindings.Add("Text", myDataSet, "Region.RegionID")
Me.TextBox2.DataBindings.Add("Text", myDataSet,
"Region.RegionDescription")

cmParent = Me.BindingContext(myDataSet, "Region")
cmChild = Me.BindingContext(myDataSet, "Region.Region_Territories")
Me.Button5.Enabled = True
End Sub

Public Sub GetData()
''Simulates a longer time.....
System.Threading.Thread.Sleep(5000)
Access.GetData(myDataSet)
End Sub

Private Sub Access_DataLoaded(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Access.DataLoaded
If Me.InvokeRequired Then
''-- Marshall to the UI thread...
Dim dlg As New GetDataArgsDelegate(AddressOf EndGetData)
Dim args() As Object = {e}
Me.BeginInvoke(dlg, args)
Else
Me.EndGetData(EventArgs.Empty)
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Me.IsDataLoaded Then
cmParent.Position += 1
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Me.IsDataLoaded Then
cmChild.AddNew()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If Me.IsDataLoaded Then
cmParent.RemoveAt(cmParent.Position)
End If
End Sub

Public Overridable Sub ShowDiffData()
''-- View the diffgram in the web browser
Try
If Not (myDataSet Is Nothing) Then

Dim cFileName As String =
Environment.GetFolderPath(Environment.SpecialFolde r.LocalApplicationData) +
"\Diff"
Dim dsDiffgram As DataSet

If myDataSet.HasChanges Then
dsDiffgram = myDataSet.GetChanges()
dsDiffgram.WriteXml(cFileName + myDataSet.DataSetName + ".xml",
XmlWriteMode.DiffGram)
System.Diagnostics.Process.Start("file://" + cFileName +
myDataSet.DataSetName + ".xml")
Else
MessageBox.Show("Please make changes first.", "Show Changes",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Catch exp As Exception
End Try
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
If Me.IsDataLoaded Then
Me.ShowDiffData()
End If
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged
Me.LoadAsync = Me.CheckBox1.Checked
End Sub
End Class

"Doug Bell" <du*@bigpond.com> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
我有一个具有数据访问类的应用程序。和用户界面
类。

用于从一个系统接收采购订单数据并将已处理的交易推送到另一个系统。

系统通常运行良好。
目前用户界面要求每15分钟刷新一次数据
(可选),数据访问类连接到数据库并检索
数据结构适合应用程序。在检索期间,它显示消息,通知用户各种下载。每个应用程序都有自己的数据访问类。根据用户所在的位置刷新数据需要30秒到5分钟

我被要求使刷新透明,以便用户不会
必须等待数据访问层获取其数据,因为某些站点与网络的连接速度很慢。

我不知道如何实现这一新要求。
我认为我可以将数据访问类作为一个单独的应用程序
加载用户界面,然后定期检索
数据并将其保存到本地数据库文件中(mdb?)而不是进入当前的数据集,然后让用户界面异步连接到本地数据库并更新其记录。

我会感谢任何意见。

问候

道格
Hi,
I have an application that has a "Data Access Class" and "User Interface
Class".

It is for receiving Purchase Order data from one system and pushing
processed transactions to another system.

The system generally works quite well.
Currently the User interface calls for a refresh of data every 15 minutes
(selectable) and the Data Access Class connects to the DB and retrieves
the
data structured to suit the application. During the retrieval it displays
messages informing the User of the various downloads. Each application has
its own Data Access Class. It takes between 30 seconds and 5 minutes to
refresh the data dependant on where the User is located

I have been asked to make the refresh transparent so that the User does
not
have to wait for the Data Access Layer to get its data as some site have a
very slow connections to the network.

I am not sure how to achieve this new requirement.
I thought that I could make the Data Access Class a separate application
that loads with the User interface and then periodically retrieves the
data
and saves it into a local database file (mdb ?) rather than into the
current
Data Set and then have the User Interface asynchronously connect to the
local database and update its records.

I would appreciate any oppinions.

Regards

Doug



道格,

我绝对没有从你的消息中看到你在做什么。我认为

新闻组消息无法显示。你可以尝试它而不是它b / b
变得可能很长以至于没有人读它,所以在我看来它没有任何意义解释




然而你问了一个意见。我肯定不会在访问数据库中复制你的数据。

。我见过很多人在这些新闻组中尝试这种方式。难以管理和降低成本

可能需要很长时间。


为了给你我的第一个想法,就是在服务器上创建XML文件数据集

而不是通过实例使用

webservice在15分钟的基础上分发那些。 (你需要决定是否在时间基础上或根据需要在你的

服务器上创建xmlfiles)。


然而,最后只是一个想法,我已经阅读了你的消息,从来没有

做了。


我希望这会有所帮助


Cor
Doug,

I absolute don''t see from your message what you are doing. I think that an
newsgroup message is not able to show that. You can try it however than it
becomes probably so long that nobody reads it, so it has no sense to explain
it more in my opinion.

However you asked an opinion. I surely would not go the direction in
duplicating your data in an access database. I have seen a lot of people
trying that in these newsgroups. It is difficult managable and cost as well
probably a lot of time.

To give you my first idea, that was creating XML files dataset on the server
and than distribute those on that 15 minute base by instance with a
webservice. (Where you than would have to decide if you create on your
server the xmlfiles on a time base or on demand).

However that last is just an idea that I got reading your message and never
did.

I hope this helps somehow

Cor


谢谢贝丝,我会看一下。之前我没有做任何事情。

我想知道我是否可以通过缓冲来锁定对数据的访问权限

进入一个secon数据集,更新ds1,然后将ds1克隆到ds2,以便它只是暂时不可用?


Thanjs


" Beth Massi [建筑师MVP]" < BM **** @ comcast.net>在消息中写道

新闻:eV ************** @ tk2msftngp13.phx.gbl ...
Thanks Beth, I will have a look at that. I haven''t done anything in
different threads before.
I wonder if I could get around locking access to the data by buffering it
into a secon data set, updating ds1 and then cloning ds1 to ds2 so that it
is only unavailable momentarily?

Thanjs

"Beth Massi [Architect MVP]" <bm****@comcast.net> wrote in message
news:eV**************@tk2msftngp13.phx.gbl...
嗨道格,表单仍然响应用户,但是,您需要小心
没有UI元素在检索数据之前处理这些数据。
加载数据后,您的数据访问类应该引发一个可以处理的事件,这样您就可以调用invoke方法来调用$ b的调用。 $ b UI线程。这是基本的想法(注意 - 这个例子使用SQL
northwind数据库):

公共类Form1
继承System.Windows.Forms.Form

#Region" Windows窗体设计器生成的代码

Public Sub New()
MyBase.New()

''Windows窗体设计器需要此调用。
InitializeComponent()
''在InitializeComponent()调用后添加任何初始化

End Sub

''表格覆盖处理清理组件列表。
受保护的重载覆盖子处理(ByVal处理为布尔值)
如果处理则
如果不是(组件是什么)那么
components.Dispose()结束如果
MyBase.Dispose(处理)
结束子

''Windows窗体设计器要求
私有组件作为系统.ComponentModel.IContainer

''注意:Windows窗体设计器需要以下步骤
''可以使用Windows窗体设计器修改它。
''不要使用代码编辑器修改它。
Friend WithEvents DataGrid1 As Syst em.Windows.Forms.DataGrid
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms .TextBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
< System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System。 Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.CheckBox1 = New System.Windows。 Forms.CheckBox
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).BeginIni t()Me.SuspendLayout()
''
''DataGrid1
''
Me.DataGrid1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top或
System.Windows.Forms.AnchorStyles.Bottom)_
或System.Windows .Forms.AnchorStyles.Left)_
或System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
Me.DataGrid1.Dat aMember =""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(16,120)
我。 DataGrid1.Name =" DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(472,208)
Me.DataGrid1.TabIndex = 0
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point(24,56)
Me.TextBox1.Name =" TextBox1"
我。 TextBox1.Size = New System.Drawing.Size(48,20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text =" TextBox1"
''
''Button1
''
Me.Button1.Location = New System.Drawing.Point(24,88)
Me.Button1.Name =" Button1"
我。 Button1.TabIndex = 2
Me.Button1.Text =" Next"
''
''TextBox2
''
Me.TextBox2.Location =新系统.Drawing.Point(80,56)
Me.TextBox2.Name =& TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(112,20)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text =" TextBox2"
''
''Button2
''
Me.Button2.Location = New System.Drawing.Point(136,88)
Me.Button2.Name = Button2
Me.Button2.TabIndex = 4
Me.Button2.Text =" Add Child"
''
''Button3
''< br.> Me.Button3.Location = New System.Drawing.Point(240,88)
Me.Button3.Name =" Button3"
Me.Button3.Size = New System.Drawing.Size (96,23)
Me.Button3.TabIndex = 5
Me.Button3.Text =删除父母
''
''Button4
''
Me.Button4.Location = New System.Drawing.Point(376,88)
Me.Button4.Name =" Button4"
Me.Button4.Size = New System.Drawing。大小(96,23)
Me.Button4.TabIndex = 6
Me.Button4.Text =" Show Chan ges"
''
''Button5
''
Me.Button5.Location = New System.Drawing.Point(24,16)
Me.Button5。 Name =" Button5"
Me.Button5.TabIndex = 7
Me.Button5.Text =加载数据
''
''CheckBox1
' '
Me.CheckBox1.Checked = True
Me.CheckBox1.CheckState = System.Windows.Forms.CheckState.Checked
Me.CheckBox1.Location = New System.Drawing.Point(104, 16)
Me.CheckBox1.Name =" CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(64,24)
Me.CheckBox1.TabIndex = 8
Me.CheckBox1.Text =" Async"
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5,13)
Me.ClientSize = New System.Drawing.Size(496,334)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Co ntrols.Add(Me.Button2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.DataGrid1)
Me.Name =" Form1"
Me.Text =" Form1"
CType(Me.DataGrid1,System。 ComponentModel.ISupportInitialize)。EndInit()
Me.ResumeLayout(False)

End Sub

#End Region
私有类DataAccess
私有Const SQL_CONNECTION_STRING As String = _
" Data Source = localhost;" &安培; _
初始目录= Northwind; &安培; _
集成安全性= SSPI

公共事件DataLoaded(ByVal发送者作为对象,ByVal e As EventArgs)
受保护的可覆盖子OnDataLoaded(ByVal e As EventArgs)
RaiseEvent DataLoaded(Me,e)
End Sub
公共子GetData(ByRef ds As DataSet)
ds =新数据集
Dim da,da2 As SqlDataAdapter
Dim cnn As SqlConnection
尝试
cnn =新的SqlConnection(SQL_CONNECTION_STRING)
da =新的SqlDataAdapter(" SELECT * FROM Region",cnn)
da.Fill(ds," Region")
da = New SqlDataAdapter(" SELECT * FROM Territories",cnn)
da.Fill(ds," Territories")

ds.Relations.Add(" Region_Territories",_
ds.Tables(" Region")。Columns(" RegionID"),_
ds.Tables(" Territories" ;)。列(RegionID))

ds.DataSetName =" RegionTerritories&q uot;

OnDataLoaded(EventArgs.Empty)

将Exp作为异常捕获
MessageBox.Show(Exp.Message)
结束尝试
End Sub

结束类

私人代表Sub GetDataArgsDelegate(ByVal e As EventArgs)

Private WithEvents作为新DataAccess访问
私有myDataSet作为DataSet
私有cmParent,cmChild为CurrencyManager
私有m_async为Boolean = True
公共属性LoadAsync()为布尔值
获取
返回m_async
结束获取
设置(ByVal值为布尔值)
m_async =值
结束集
结束属性

私有m_isDataLoaded为布尔值=假获取
返回m_isDataLoaded
结束获取
设置(ByVal值为布尔值)
m_isDataLoaded =值
结束集
结束属性

私有子按钮5_Click(ByVal发送者为System.Object,ByVal e As
System.EventArgs)处理Button5.Click
Me.Button5.Enabled = False
Me.BeginGetData()
End Sub

私有子BeginGetData()
m_isDataLoaded = False
Me.DataGrid1.DataSource = Nothing
Me.TextBox1.DataBindings.Clear()
Me.TextBox2.DataBindings.Clear()
Me.TextBox1.Text =""
Me.TextBox2.Text ="正在加载数据......

如果Me.LoadAsync然后
Dim t As New Threading.Thread(AddressOf Me.GetData)
t.Name = Me.Name +" DataThread"
t.IsBackground = True
t.Start()
其他
Me.GetData ()
结束如果
结束Sub

私有子EndGetData(ByVal e As EventArgs)
m_isDataLoaded = True

Me.DataGrid1。 DataSource = myDataSet
Me.DataGrid1.DataMember =" Region.Region_Territories"

Me.TextBox1.DataBindings.Add(" Text",myDataSet," Region.RegionID")< br.> Me.TextBox2。 DataBindings.Add(" Text",myDataSet,
" Region.RegionDescription")

cmParent = Me.BindingContext(myDataSet," Region")
cmChild = Me .BindingContext(myDataSet," Region.Region_Territories")
Me.Button5.Enabled = True
End Sub

Public Sub GetData()
''模拟a更长的时间.....
System.Threading.Thread.Sleep(5000)
Access.GetData(myDataSet)
End Sub

Private Sub Access_DataLoaded(ByVal sender As Object,ByVal e As
System.EventArgs)处理Access.DataLoaded
如果Me.InvokeRequired那么
'' - Marshall到UI线程...
Dim dlg作为New GetDataArgsDelegate(AddressOf EndGetData)
Dim args()As Object = {e}
Me.BeginInvoke(dlg,args)
另外
Me.EndGetData(EventArgs.Empty)
结束如果


私有子按钮1_Click(ByVal发送者为System.Object,ByVal e As
System.EventArg s)处理Button1.Click
如果Me.IsDataLoaded那么
cmParent.Position + = 1
结束如果
结束子

私人子按钮2_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button2.Click
如果Me.IsDataLoaded则
cmChild.AddNew()
结束如果
结束Sub

Private Sub Button3_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button3.Click
如果Me.IsDataLoaded则
cmParent。 RemoveAt(cmParent.Position)
结束如果
结束子

公共可覆盖子ShowDiffData()
'' - 在网络浏览器中查看diffgram
尝试
如果不是(myDataSet什么都没有)那么

Dim cFileName As String =
Environment.GetFolderPath(Environment.SpecialFolde r.LocalApplicationData)
+" \\ \\ Diff"
Dim dsDiffgram As DataSet

如果myDataSet.HasChanges那么
dsDiffgram = myDataSet.G etChanges()
dsDiffgram.WriteXml(cFileName + myDataSet.DataSetName +" .xml",
XmlWriteMode.DiffGram)
System.Diagnostics.Process.Start(" file://" ; + cFileName +
myDataSet.DataSetName +" .xml")
Else
MessageBox.Show(" Please make changes first。"," Show Changes",
MessageBoxButtons.OK,MessageBoxIcon.Information)
结束如果结束如果
Catch exp为例外
结束尝试
结束子

私人子Button4_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button4.Click
如果Me.IsDataLoaded那么
Me.ShowDiffData()
结束如果
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,ByVal $ b $ as As System.EventArgs)Handles CheckBox1.CheckedChanged
Me.LoadAsync = Me.CheckBox1.Checked
End Sub
End Class

Doug Bell < du*@bigpond.com>在消息中写道
新闻:e9 ************** @ TK2MSFTNGP12.phx.gbl ...
Hi Doug,

You can execute the loading of your data on a separate thread so that the
form is still responsive to the user, however, you need to be careful that
none of the UI elements work with that data before the data is retrieved.
Once the data is loaded, your data access class should raise an event that
you can handle so you can call the invoke method to marshal the call to the UI thread. Here''s the basic idea (note- this example uses the SQL northwind database):

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

''This call is required by the Windows Form Designer.
InitializeComponent()

''Add any initialization after the InitializeComponent() call

End Sub

''Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

''Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

''NOTE: The following procedure is required by the Windows Form Designer
''It can be modified using the Windows Form Designer.
''Do not modify it using the code editor.
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.CheckBox1 = New System.Windows.Forms.CheckBox
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginIni t() Me.SuspendLayout()
''
''DataGrid1
''
Me.DataGrid1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(16, 120)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(472, 208)
Me.DataGrid1.TabIndex = 0
''
''TextBox1
''
Me.TextBox1.Location = New System.Drawing.Point(24, 56)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(48, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = "TextBox1"
''
''Button1
''
Me.Button1.Location = New System.Drawing.Point(24, 88)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 2
Me.Button1.Text = "Next"
''
''TextBox2
''
Me.TextBox2.Location = New System.Drawing.Point(80, 56)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(112, 20)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = "TextBox2"
''
''Button2
''
Me.Button2.Location = New System.Drawing.Point(136, 88)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 4
Me.Button2.Text = "Add Child"
''
''Button3
''
Me.Button3.Location = New System.Drawing.Point(240, 88)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(96, 23)
Me.Button3.TabIndex = 5
Me.Button3.Text = "Delete Parent"
''
''Button4
''
Me.Button4.Location = New System.Drawing.Point(376, 88)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(96, 23)
Me.Button4.TabIndex = 6
Me.Button4.Text = "Show Changes"
''
''Button5
''
Me.Button5.Location = New System.Drawing.Point(24, 16)
Me.Button5.Name = "Button5"
Me.Button5.TabIndex = 7
Me.Button5.Text = "Load Data"
''
''CheckBox1
''
Me.CheckBox1.Checked = True
Me.CheckBox1.CheckState = System.Windows.Forms.CheckState.Checked
Me.CheckBox1.Location = New System.Drawing.Point(104, 16)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(64, 24)
Me.CheckBox1.TabIndex = 8
Me.CheckBox1.Text = "Async"
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(496, 334)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit( )
Me.ResumeLayout(False)

End Sub

#End Region

Private Class DataAccess
Private Const SQL_CONNECTION_STRING As String = _
"Data Source=localhost;" & _
"Initial Catalog=Northwind;" & _
"Integrated Security=SSPI"

Public Event DataLoaded(ByVal sender As Object, ByVal e As EventArgs)
Protected Overridable Sub OnDataLoaded(ByVal e As EventArgs)
RaiseEvent DataLoaded(Me, e)
End Sub

Public Sub GetData(ByRef ds As DataSet)
ds = New DataSet
Dim da, da2 As SqlDataAdapter
Dim cnn As SqlConnection
Try
cnn = New SqlConnection(SQL_CONNECTION_STRING)

da = New SqlDataAdapter("SELECT * FROM Region", cnn)
da.Fill(ds, "Region")
da = New SqlDataAdapter("SELECT * FROM Territories", cnn)
da.Fill(ds, "Territories")

ds.Relations.Add("Region_Territories", _
ds.Tables("Region").Columns("RegionID"), _
ds.Tables("Territories").Columns("RegionID"))

ds.DataSetName = "RegionTerritories"

OnDataLoaded(EventArgs.Empty)

Catch Exp As Exception
MessageBox.Show(Exp.Message)
End Try
End Sub

End Class

Private Delegate Sub GetDataArgsDelegate(ByVal e As EventArgs)

Private WithEvents Access As New DataAccess
Private myDataSet As DataSet
Private cmParent, cmChild As CurrencyManager

Private m_async As Boolean = True
Public Property LoadAsync() As Boolean
Get
Return m_async
End Get
Set(ByVal Value As Boolean)
m_async = Value
End Set
End Property

Private m_isDataLoaded As Boolean = False
Public Property IsDataLoaded() As Boolean
Get
Return m_isDataLoaded
End Get
Set(ByVal Value As Boolean)
m_isDataLoaded = Value
End Set
End Property

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Me.Button5.Enabled = False
Me.BeginGetData()
End Sub

Private Sub BeginGetData()
m_isDataLoaded = False
Me.DataGrid1.DataSource = Nothing
Me.TextBox1.DataBindings.Clear()
Me.TextBox2.DataBindings.Clear()
Me.TextBox1.Text = ""
Me.TextBox2.Text = "Loading Data..."

If Me.LoadAsync Then
Dim t As New Threading.Thread(AddressOf Me.GetData)
t.Name = Me.Name + "DataThread"
t.IsBackground = True
t.Start()
Else
Me.GetData()
End If
End Sub

Private Sub EndGetData(ByVal e As EventArgs)
m_isDataLoaded = True

Me.DataGrid1.DataSource = myDataSet
Me.DataGrid1.DataMember = "Region.Region_Territories"

Me.TextBox1.DataBindings.Add("Text", myDataSet, "Region.RegionID")
Me.TextBox2.DataBindings.Add("Text", myDataSet,
"Region.RegionDescription")

cmParent = Me.BindingContext(myDataSet, "Region")
cmChild = Me.BindingContext(myDataSet, "Region.Region_Territories")
Me.Button5.Enabled = True
End Sub

Public Sub GetData()
''Simulates a longer time.....
System.Threading.Thread.Sleep(5000)
Access.GetData(myDataSet)
End Sub

Private Sub Access_DataLoaded(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Access.DataLoaded
If Me.InvokeRequired Then
''-- Marshall to the UI thread...
Dim dlg As New GetDataArgsDelegate(AddressOf EndGetData)
Dim args() As Object = {e}
Me.BeginInvoke(dlg, args)
Else
Me.EndGetData(EventArgs.Empty)
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If Me.IsDataLoaded Then
cmParent.Position += 1
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If Me.IsDataLoaded Then
cmChild.AddNew()
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If Me.IsDataLoaded Then
cmParent.RemoveAt(cmParent.Position)
End If
End Sub

Public Overridable Sub ShowDiffData()
''-- View the diffgram in the web browser
Try
If Not (myDataSet Is Nothing) Then

Dim cFileName As String =
Environment.GetFolderPath(Environment.SpecialFolde r.LocalApplicationData) + "\Diff"
Dim dsDiffgram As DataSet

If myDataSet.HasChanges Then
dsDiffgram = myDataSet.GetChanges()
dsDiffgram.WriteXml(cFileName + myDataSet.DataSetName + ".xml",
XmlWriteMode.DiffGram)
System.Diagnostics.Process.Start("file://" + cFileName +
myDataSet.DataSetName + ".xml")
Else
MessageBox.Show("Please make changes first.", "Show Changes",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
Catch exp As Exception
End Try
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
If Me.IsDataLoaded Then
Me.ShowDiffData()
End If
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Me.LoadAsync = Me.CheckBox1.Checked
End Sub
End Class

"Doug Bell" <du*@bigpond.com> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...

我有一个具有数据访问类的应用程序和用户界面
类。

用于从一个系统接收采购订单数据并将已处理的交易推送到另一个系统。

The system generally works quite well.
Currently the User interface calls for a refresh of data every 15
minutes (selectable) and the Data Access Class connects to the DB and retrieves
the
data structured to suit the application. During the retrieval it
displays messages informing the User of the various downloads. Each application
has its own Data Access Class. It takes between 30 seconds and 5 minutes to
refresh the data dependant on where the User is located

I have been asked to make the refresh transparent so that the User does
not
have to wait for the Data Access Layer to get its data as some site have
a very slow connections to the network.

I am not sure how to achieve this new requirement.
I thought that I could make the Data Access Class a separate application
that loads with the User interface and then periodically retrieves the
data
and saves it into a local database file (mdb ?) rather than into the
current
Data Set and then have the User Interface asynchronously connect to the
local database and update its records.

I would appreciate any oppinions.

Regards

Doug
Hi,
I have an application that has a "Data Access Class" and "User Interface
Class".

It is for receiving Purchase Order data from one system and pushing
processed transactions to another system.

The system generally works quite well.
Currently the User interface calls for a refresh of data every 15 minutes (selectable) and the Data Access Class connects to the DB and retrieves
the
data structured to suit the application. During the retrieval it displays messages informing the User of the various downloads. Each application has its own Data Access Class. It takes between 30 seconds and 5 minutes to
refresh the data dependant on where the User is located

I have been asked to make the refresh transparent so that the User does
not
have to wait for the Data Access Layer to get its data as some site have a very slow connections to the network.

I am not sure how to achieve this new requirement.
I thought that I could make the Data Access Class a separate application
that loads with the User interface and then periodically retrieves the
data
and saves it into a local database file (mdb ?) rather than into the
current
Data Set and then have the User Interface asynchronously connect to the
local database and update its records.

I would appreciate any oppinions.

Regards

Doug




这篇关于背景数据检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆