Public Class usrcntlAuswertungWocheAuslastung
    Dim cDIENST As New cDienstplan
    Dim cPF As New cProgramFunctions
    ' Dim montag As Date
    Dim niederlassung = ""


    Dim DP_SETTINGS As cDienstSettings

   
    Public Sub init(montag, niederlassung)
        Me.niederlassung = niederlassung
        DP_SETTINGS = New cDienstSettings(niederlassung)

        lbl_Std_Mo.Text = getStd(montag).ToString("F1")
        lbl_Std_Di.Text = getStd(montag.AddDays(1)).ToString("F1")
        lbl_Std_Mi.Text = getStd(montag.AddDays(2)).ToString("F1")
        lbl_Std_Do.Text = getStd(montag.AddDays(3)).ToString("F1")
        lbl_Std_Fr.Text = getStd(montag.AddDays(4)).ToString("F1")
        lbl_Std_Sa.Text = getStd(montag.AddDays(5)).ToString("F1")
        lbl_Std_So.Text = getStd(montag.AddDays(6)).ToString("F1")
        'lbl_Abf_mo

        lbl_Abf_Mo.Text = getAbf(montag).ToString("F1")
        lbl_Abf_Di.Text = getAbf(montag.AddDays(1)).ToString("F1")
        lbl_Abf_Mi.Text = getAbf(montag.AddDays(2)).ToString("F1")
        lbl_Abf_Do.Text = getAbf(montag.AddDays(3)).ToString("F1")
        lbl_Abf_Fr.Text = getAbf(montag.AddDays(4)).ToString("F1")
        lbl_Abf_Sa.Text = getAbf(montag.AddDays(5)).ToString("F1")
        lbl_Abf_So.Text = getAbf(montag.AddDays(6)).ToString("F1")

        lblMA8Std_Mo.Text = CDbl(CDbl(lbl_Std_Mo.Text) / 8).ToString("F1")
        lblMA8Std_Di.Text = CDbl(CDbl(lbl_Std_Di.Text) / 8).ToString("F1")
        lblMA8Std_Mi.Text = CDbl(CDbl(lbl_Std_Mi.Text) / 8).ToString("F1")
        lblMA8Std_Do.Text = CDbl(CDbl(lbl_Std_Do.Text) / 8).ToString("F1")
        lblMA8Std_Fr.Text = CDbl(CDbl(lbl_Std_Fr.Text) / 8).ToString("F1")
        lblMA8Std_Sa.Text = CDbl(CDbl(lbl_Std_Sa.Text) / 8).ToString("F1")
        lblMA8Std_So.Text = CDbl(CDbl(lbl_Std_So.Text) / 8).ToString("F1")

        lblAbfMA_Mo.Text = CDbl(CDbl(lbl_Abf_Mo.Text) / CDbl(lblMA8Std_Mo.Text)).ToString("F1")
        lblAbfMA_Di.Text = CDbl(CDbl(lbl_Abf_Di.Text) / CDbl(lblMA8Std_Di.Text)).ToString("F1")
        lblAbfMA_Mi.Text = CDbl(CDbl(lbl_Abf_Mi.Text) / CDbl(lblMA8Std_Mi.Text)).ToString("F1")
        lblAbfMA_Do.Text = CDbl(CDbl(lbl_Abf_Do.Text) / CDbl(lblMA8Std_Do.Text)).ToString("F1")
        lblAbfMA_Fr.Text = CDbl(CDbl(lbl_Abf_Fr.Text) / CDbl(lblMA8Std_Fr.Text)).ToString("F1")
        lblAbfMA_Sa.Text = CDbl(CDbl(lbl_Abf_Sa.Text) / CDbl(lblMA8Std_Sa.Text)).ToString("F1")
        lblAbfMA_So.Text = CDbl(CDbl(lbl_Abf_So.Text) / CDbl(lblMA8Std_So.Text)).ToString("F1")


        Exit Sub
    End Sub


    Function getStd(datum As Date) As Double
        ' Dim schicht = ""
        'Select Case niederlassung
        '    Case "SUB" : schicht = "'ZOLL_VM','ZOLL_NM','ZOLL_TAG'"
        '    Case "QS" : schicht = "'QS'"
        '    Case "WAI" : schicht = "'ZOLL_VM','ZOLL_NM','ZOLL_TAG'"
        '    Case "SBG" : schicht = "'ZOLL_VM','ZOLL_NM','ZOLL_TAG'"
        '    Case "NKD" : schicht = "'ZOLL_VM','ZOLL_NM','ZOLL_TAG'"
        '     Case "ATILLA" : schicht = "'ZOLL_VM','ZOLL_NM','ZOLL_TAG','ZOLL_NACHT'"
        ' End Select

        Dim list As List(Of cDienstEintrag) = cDIENST.getDienstEintragListBenSchicht(datum, niederlassung)
        If list IsNot Nothing Then
            For Each l In list
                getStd += cPF.getDiff(l.dstetr_von, l.dstetr_bis, "", False)
                getStd -= CDbl(l.dstetr_pause)
            Next
        End If


        'For Each r As DataRow In cDIENST.loadDGV("SELECT [dstetr_von],[dstetr_bis],[dstetr_pause]  FROM [ADMIN].[dbo].[tblDienstplanEintraege] " &
        '" WHERE dstetr_datum = '" & datum.ToShortDateString & "' AND [dstetr_niederlassung]='" & IIf(niederlassung = "QS", "SUB", niederlassung) & "' AND [dstetr_art] IN (" & schicht & ") ").Rows
        'getStd += cPF.getDiff(r("dstetr_bis"), r("dstetr_von"), "", False)
        'getStd -= CDbl(r("dstetr_pause"))
        Return getStd
    End Function
    Function getAbf(datum As Date) As Double
        Try

            Dim art = ""
        Dim nl = ""

        If DP_SETTINGS Is Nothing Then Return 0
        If DP_SETTINGS.dpset_AbfArt = String.Empty Then Return 0
        If DP_SETTINGS.dpset_AbfArt.Contains(",") Then
            For Each a In DP_SETTINGS.dpset_AbfArt.Split(",")
                art &= a & ","
            Next : art = art.TrimEnd(",")
        Else
            art = DP_SETTINGS.dpset_AbfArt
        End If

        If DP_SETTINGS.dpset_AbfNL.Contains(",") Then
            For Each a In DP_SETTINGS.dpset_AbfNL.Split(",")
                nl &= a & ","
            Next : nl = nl.TrimEnd(",")
        Else
            nl = DP_SETTINGS.dpset_AbfNL
        End If



        Dim filiale = ""
        If DP_SETTINGS.dpset_Filiale.Contains(",") Then
            For Each a In DP_SETTINGS.dpset_Filiale.Split(",")
                filiale &= "'" & a & "',"
            Next : filiale = filiale.TrimEnd(",")
        Else
            filiale = "'" & DP_SETTINGS.dpset_Filiale & "'"
        End If

        Dim sql = "SELECT isnull(SUM(Abfertigungsanzahl) ,0) FROM [VERAG].[dbo].[Speditionsbuch]  INNER JOIN [VERAG].[dbo].[Personal] ON ID=Personalnummer " &
        " WHERE Abfertigungsdatum = '" & datum.ToShortDateString & "' AND FilialenNr IN (" & filiale & ")  AND Abfertigungsart IN(" & art & ") and Niederlassung IN (" & nl & ")"

        '      Return cDIENST.getValueTxtBySql("SELECT count(*) as anz  FROM [Speditionsbuch]  where Abfertigungsdatum = '" & datum.ToShortDateString & "' AND FilialenNr IN (" & filiale & ")  AND Abfertigungsart IN(" & art & ")", "FMZOLL")
        Return cDIENST.getValueTxtBySql(sql, "FMZOLL")

        Catch ex As Exception
            MsgBox(ex.Message & ex.StackTrace)
        End Try
    End Function
End Class
