Imports C1.Data

Public Class ViewOrderForm
    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
    Friend WithEvents c1DataView1 As C1.Data.C1DataView
    Friend WithEvents c1DataSet1 As C1.Data.C1DataSet
    Friend WithEvents gridItems As C1.Win.C1TrueDBGrid.C1TrueDBGrid
    Friend WithEvents label1 As System.Windows.Forms.Label
    Friend WithEvents buttonCancel As System.Windows.Forms.Button
    Friend WithEvents buttonOK As System.Windows.Forms.Button

    '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.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ViewOrderForm))
        Me.c1DataView1 = New C1.Data.C1DataView()
        Me.c1DataSet1 = New C1.Data.C1DataSet()
        Me.gridItems = New C1.Win.C1TrueDBGrid.C1TrueDBGrid()
        Me.label1 = New System.Windows.Forms.Label()
        Me.buttonCancel = New System.Windows.Forms.Button()
        Me.buttonOK = New System.Windows.Forms.Button()
        CType(Me.c1DataView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.c1DataSet1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.gridItems, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'c1DataView1
        '
        Me.c1DataView1.BindingContextCtrl = Nothing
        Me.c1DataView1.DataSet = Me.c1DataSet1
        Me.c1DataView1.TableName = ""
        Me.c1DataView1.TableViewName = "Order Details"
        '
        'c1DataSet1
        '
        Me.c1DataSet1.BindingContextCtrl = Nothing
        Me.c1DataSet1.DataLibrary = "DataLibrary1"
        Me.c1DataSet1.DataLibraryUrl = ""
        Me.c1DataSet1.DataSetDef = "DataSet"
        Me.c1DataSet1.Locale = New System.Globalization.CultureInfo("en-US")
        Me.c1DataSet1.SchemaClassName = "DataLibrary1.DataClass"
        Me.c1DataSet1.SchemaDef = Nothing
        Me.c1DataSet1.SuppressNotifications = False
        '
        'gridItems
        '
        Me.gridItems.AllowFilter = True
        Me.gridItems.AllowRowSizing = C1.Win.C1TrueDBGrid.RowSizingEnum.AllRows
        Me.gridItems.AllowSort = True
        Me.gridItems.CaptionHeight = 17
        Me.gridItems.CollapseColor = System.Drawing.Color.Black
        Me.gridItems.DataChanged = False
        Me.gridItems.DataSource = Me.c1DataView1
        Me.gridItems.BackColor = System.Drawing.Color.Empty
        Me.gridItems.ExpandColor = System.Drawing.Color.Black
        Me.gridItems.Images.Add(CType(resources.GetObject("resource.Images"), System.Drawing.Bitmap))
        Me.gridItems.Location = New System.Drawing.Point(8, 24)
        Me.gridItems.MarqueeStyle = C1.Win.C1TrueDBGrid.MarqueeEnum.DottedCellBorder
        Me.gridItems.Name = "gridItems"
        Me.gridItems.PreviewInfo.Location = New System.Drawing.Point(0, 0)
        Me.gridItems.PreviewInfo.Size = New System.Drawing.Size(0, 0)
        Me.gridItems.PreviewInfo.ZoomFactor = 75
        Me.gridItems.RecordSelectorWidth = 16
        Me.gridItems.RowHeight = 15
        Me.gridItems.RowSubDividerColor = System.Drawing.Color.DarkGray
        Me.gridItems.ScrollTips = False
        Me.gridItems.Size = New System.Drawing.Size(496, 216)
        Me.gridItems.TabIndex = 7
        Me.gridItems.Text = "c1TrueDBGrid1"
        Me.gridItems.PropBag = CType(resources.GetObject("gridItems.PropBag"), String)
        '
        'label1
        '
        Me.label1.Location = New System.Drawing.Point(8, 8)
        Me.label1.Name = "label1"
        Me.label1.TabIndex = 8
        Me.label1.Text = "Order items:"
        '
        'buttonCancel
        '
        Me.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.buttonCancel.Location = New System.Drawing.Point(432, 256)
        Me.buttonCancel.Name = "buttonCancel"
        Me.buttonCancel.TabIndex = 6
        Me.buttonCancel.Text = "Close"
        '
        'buttonOK
        '
        Me.buttonOK.Location = New System.Drawing.Point(272, 256)
        Me.buttonOK.Name = "buttonOK"
        Me.buttonOK.Size = New System.Drawing.Size(152, 23)
        Me.buttonOK.TabIndex = 5
        Me.buttonOK.Text = "Update database now"
        '
        'ViewOrderForm
        '
        Me.AcceptButton = Me.buttonOK
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(512, 293)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.gridItems, Me.label1, Me.buttonCancel, Me.buttonOK})
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "ViewOrderForm"
        Me.Text = "ViewOrderForm"
        CType(Me.c1DataView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.c1DataSet1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.gridItems, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub buttonOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonOK.Click
        c1DataSet1.Update()
    End Sub

    Private Sub buttonCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonCancel.Click
        Close()
    End Sub

    Dim _orderId As Integer = -1
    Public Property OrderID() As Integer
        Get
            Return _orderId
        End Get
        Set(ByVal Value As Integer)
            _orderId = Value
            c1DataView1.RowFilter = "OrderID = " + _orderId.ToString()
        End Set
    End Property

    Private Sub c1DataSet1_UpdateError(ByVal sender As Object, ByVal e As C1.Data.DataSetEventArgs) Handles c1DataSet1.UpdateError

        ' Handling Update errors on the client
        If (e.Error Is Nothing) Then ' e.Error == null means concurrency conflict

            Dim form As UnitPriceForm = New UnitPriceForm()

            Dim rows As C1DataRow() = c1DataSet1.Tables("Order Details").GetErrors()
            If (rows.Length = 0) Then Exit Sub

            ' To simplify the sample, we assume that conflict occured in a single row

            Dim orderID As Integer = rows(0)("OrderID")
            Dim productID As Integer = rows(0)("ProductID")
            Dim values As Object() = rows(0).ItemArray

            form.numericNew.Value = rows(0)("UnitPrice")
            c1DataSet1.Fill()
            Dim key(1) As Object
            key(0) = orderID
            key(1) = productID
            Dim row As C1DataRow = c1DataSet1.Tables("Order Details").Rows.Find(key)
            If (row Is Nothing) Then Exit Sub

            form.numericStored.Value = row("UnitPrice")
            Dim res As DialogResult
            res = form.ShowDialog()
            If (res = System.Windows.Forms.DialogResult.Retry) Then ' the user specified a new UnitPrice value, try again
                row.ItemArray = values
                row("UnitPrice") = form.numericNew.Value
                e.Status = DataSetEventStatusEnum.[Continue]
            ElseIf (res = System.Windows.Forms.DialogResult.Ignore) Then ' accept all changes except the UnitPrice value
                row.ItemArray = values
                row("UnitPrice") = form.numericStored.Value
                e.Status = DataSetEventStatusEnum.[Continue]
            Else
                e.Status = DataSetEventStatusEnum.Skip ' cancel the update
            End If
        End If
    End Sub
End Class
