Public Class usrCntlAuswertungAuslastungMA
    Dim cDIENST As New cDienstplan
    Dim cPF As New cProgramFunctions

    Public SETTINGS As cDienstSettings

    Dim von As Integer = 6
    Dim bis As Integer = 21
    Dim bottomSpacing As Integer = 12
    Dim montag As Date = Now
    Dim niederlassung As String = ""
    Dim maAnz As Integer = 0
    Dim loaded = False

    Public Sub init(montag As Date, niederlassung As String)
        ' Me.niederlassung = niederlassung
        ' lbl_Std_Mo.Text = getStd(montag).ToString("F1")
        '  lbl_Std_Di.Text = getStd(montag.AddDays(1)).ToString("F1")
        ' initPnl(pnlMo)
        Me.montag = montag
        Me.niederlassung = niederlassung
        SETTINGS = New cDienstSettings(niederlassung)
        von = SETTINGS.dpset_WoAuslVon
        bis = SETTINGS.dpset_WoAuslBis
        Me.maAnz = cDIENST.getValueTxtBySql("SELECT COUNT(*)  FROM [tblDienstMitarb]  where dstma_niederlassung='" & niederlassung & "'", "ADMIN")

        loaded = True
        Me.Refresh()
    End Sub


    Sub initPnl(pnl As Panel, datum As Date)
        If Not loaded Then Exit Sub

        Dim intervallAnz = bis - von + 1
        Dim intervallBreite = pnl.Width / intervallAnz
        Dim img As Image = New Bitmap(pnl.Width, pnl.Height)

        Dim g As Graphics = pnl.CreateGraphics

        Dim left = 0

        'For t = 0 To 6
        Dim list As List(Of cDienstEintrag) = cDIENST.getDienstEintragListBenSchicht(datum, niederlassung)

        If list IsNot Nothing Then
            For i = von To bis
                Dim anz As Integer = 0
                For Each l In list
                    Dim timeVon As TimeSpan = TimeSpan.Parse(i & ":00")
                    Dim timeVonDB As TimeSpan = TimeSpan.Parse(l.dstetr_von)
                    Dim timeBis As TimeSpan = TimeSpan.Parse(IIf((i + 1) = 24, "00", (i + 1)) & ":00")
                    Dim timeBisDB As TimeSpan = TimeSpan.Parse(l.dstetr_bis)
                    '   MsgBox(timeVon.TotalMinutes & " _  " & timeVonDB.TotalMinutes)
                    If timeVonDB <= timeVon And timeBisDB >= timeBis Then
                        anz += 1
                    End If
                Next
                Dim height = anz * ((pnl.Height - bottomSpacing) / maAnz)
                g.FillRectangle(Brushes.Brown, New Rectangle(left, pnl.Height - height - bottomSpacing, intervallBreite - 1, height))
                '  g.DrawRectangle(Pens.Gray, New Rectangle(left, pnl.Height - height - bottomSpacing, intervallBreite, height))
                If i Mod 2 = 0 Then g.DrawString(i.ToString("00."), New Font(Me.Font.FontFamily, 7), Brushes.Brown, New Point(left, pnl.Height - bottomSpacing + 1))
                left += intervallBreite
            Next
        End If
        'Next


    End Sub

    Private Sub btn_Click(sender As Object, e As EventArgs)
        init(CDate("23.01.2017"), "WAI")
    End Sub

   
    Private Sub pnlMo_Paint(sender As Object, e As PaintEventArgs) Handles pnlMo.Paint
        initPnl(sender, montag.AddDays(0))
    End Sub

    Private Sub pnlDi_Paint(sender As Object, e As PaintEventArgs) Handles pnlDi.Paint
        initPnl(sender, montag.AddDays(1))
    End Sub

    Private Sub pnlMi_Paint(sender As Object, e As PaintEventArgs) Handles pnlMi.Paint
        initPnl(sender, montag.AddDays(2))
    End Sub

    Private Sub pnlDo_Paint(sender As Object, e As PaintEventArgs) Handles pnlDo.Paint
        initPnl(sender, montag.AddDays(3))
    End Sub

    Private Sub pnlFr_Paint(sender As Object, e As PaintEventArgs) Handles pnlFr.Paint
        initPnl(sender, montag.AddDays(4))
    End Sub

    Private Sub pnlSa_Paint(sender As Object, e As PaintEventArgs) Handles pnlSa.Paint
        initPnl(sender, montag.AddDays(5))
    End Sub

    Private Sub pnlSo_Paint(sender As Object, e As PaintEventArgs) Handles pnlSo.Paint
        initPnl(sender, montag.AddDays(6))
    End Sub
End Class
