⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderproductdialog.vb

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 VB
字号:
Imports Microsoft.Practices.Mobile.DisconnectedAgent

Public Class OrderProductDialog

    Private ordersresults As OrdersResultSet

    Private Sub OrderProductDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If AppDatabaseDataSetUtil.DesignerUtil.IsRunTime Then
            'TODO: Delete this line of code to remove the default AutoFill for 'AppDatabaseDataSet.Orders'.
            Me.OrdersTableAdapter.Fill(Me.AppDatabaseDataSet.Orders)

            ' Go to the newly added record
            Me.OrdersBindingSource.MoveLast()
        End If

    End Sub

    Private Sub ConfirmMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfirmMenuItem.Click
        ordersresults.ReadLast()
        ordersresults.Quantity = Int32.Parse(Me.QuantityTextBox.Text)
        ordersresults.Update()

        QueueWebServiceRequest()

        Me.DialogResult = DialogResult.OK
    End Sub

    Private Sub CancelMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelMenuItem.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Public Sub New(ByVal ordersRsltSet As OrdersResultSet)

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

        ' Add any initialization after the InitializeComponent() call.
        Me.ordersresults = ordersRsltSet
    End Sub

    Private Sub QueueWebServiceRequest()
        ' Queue the order to the Disconnected Service Agent

        ' IMPORTANT for VB developers:
        ' The generate disconnected service agent tool in the Mobile Client Software factory generates C# code only. Hence, if you want
        ' to use the tools you could add a C# project to your solution, add the Web feference to that project and generate the DSA in there.
        ' Then you could call the DSA using code such as the following:
        '
        'Dim agent As OrdersServiceDisconnectedAgent = New OrdersServiceDisconnectedAgent(RequestManager.Instance.RequestQueue)
        'agent.PostOrder(Me.customerNameTextBox.Text, Int32.Parse(Me.ProductIdTextBox.Text), Int32.Parse(Me.QuantityTextBox.Text))
        '
        ' However, you would also have to handle the 'success' and 'error' callbacks yourself in C# in the tool generated Callback class.
        ' If you do not want to do that, then you can queue a request to the RequestManager 'manually' as follows:

        Dim behaviour As New OfflineBehavior
        behaviour.MessageId = System.Guid.NewGuid() ' This is how you set the unique messageID
        behaviour.Stamps = 10 ' Can overide defaults for properties on the request
        behaviour.MaxRetries = 3
        behaviour.ReturnCallback = New CommandCallback(GetType(OrderProductDialog), "OnPostOrderReturn")
        behaviour.ExceptionCallback = New CommandCallback(GetType(OrderProductDialog), "OnPostOrderException")

        Dim request As New Request
        request.Behavior = behaviour
        request.CallParameters = New Object() {Me.customerNameTextBox.Text, Int32.Parse(Me.ProductIdTextBox.Text), Int32.Parse(Me.QuantityTextBox.Text)}
        request.MethodName = "PostOrder"
        request.OnlineProxyType = GetType(OrdersWebService.OrdersService) ' This is the Web Service proxy
        request.Endpoint = "Orders"

        RequestManager.Instance.RequestQueue.Enqueue(request)

    End Sub

    Public Sub OnPostOrderReturn(ByVal arequest As Request, ByVal parameters As Object(), ByVal returnValue As Int32)
        MessageBox.Show("Callback from Disconnected Service Agent")
        Dim orders As OrdersResultSet = New OrdersResultSet()

        While (orders.Read())
            If (orders.ServerOrderId = 0) Then
                orders.ServerOrderId = returnValue
                orders.Update()
                Exit While
            End If
        End While
        orders.Dispose()
    End Sub

    Public Function OnPostOrderException(ByVal arequest As Request, ByVal ex As Exception) As OnExceptionAction
        Throw New NotImplementedException("Not implemented", ex)
    End Function

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -