Imports IntraSell_DLL

Public Class ucOrderSysteme

    Public Event SystemAusgewaehlt(system As Object)

    Shared Function SQL_OPEN_ORDERS_SYSTEM() As String
        Return <a>
        SELECT System, count(Nummer) as Cnt 
        FROM   buchvorgang
        WHERE  Typ='AU' and Datum >= date_add(CURRENT_TIMESTAMP, INTERVAL - 1  DAY )
        GROUP BY System
        </a>.Value
    End Function

    Public Sub LadeDaten()
        Try
            TableLayoutPanel1.Controls.Clear()

            Dim data = OpenRecordsetInMemory(SQL_OPEN_ORDERS_SYSTEM)
            For Each r In data.Rows
                Dim button As New Button
                Dim system = r("System")
                button.Margin = New Padding(0)
                button.BackgroundImage = GetBackgroundForSystem(system)
                button.BackgroundImageLayout = ImageLayout.Zoom
                button.Text = r("System") & " " & r("Cnt") & " Orders"
                button.TextAlign = ContentAlignment.TopLeft
                button.Tag = r("System")
                button.Dock = DockStyle.Fill

                AddHandler button.Click, AddressOf SystemButton_Click

                TableLayoutPanel1.Controls.Add(button)
            Next
        Catch ex As Exception
            HandleAppError(ex, Silent:=True)
        End Try
    End Sub

    Private Function GetBackgroundForSystem(system As Object) As Image
        Try
            If IsDBNull(system) Then
                Return IntraSell_Net.My.Resources.Resources.Waiter32x
            End If

            Select Case system
                Case "tconnect" : Return IntraSell_Net.My.Resources.Resources.Lieferservice_at
                Case "mjam" : Return IntraSell_Net.My.Resources.Resources.mjam_logo
                Case "online" : Return IntraSell_Net.My.Resources.Resources.truck_delivery
                Case "hungrylama" : Return IntraSell_Net.My.Resources.Resources.hungry_lama_1
            End Select

            Return IntraSell_Net.My.Resources.Resources.Zusteller

        Catch ex As Exception
            Return IntraSell_Net.My.Resources.Resources.Zusteller
        End Try
    End Function

    Private Sub SystemButton_Click(sender As Object, e As EventArgs)
        Try
            Dim button = CType(sender, Button)
            RaiseEvent SystemAusgewaehlt(button.Tag)
        Catch ex As Exception
            HandleAppError(ex, Silent:=True)
        End Try
    End Sub

End Class
