Option Strict On
Option Explicit On
Imports IntraSell_DLL

Public Module Functions

    Public Function ConnStringIntraSellData() As String
        Dim conn As String
        Try
            conn = My.Settings.intrasell_daten_2_ConnectionString
        Catch ex As Exception
            Dim settings As New ClassSettings
            conn = settings.Read("intrasell_daten_2_ConnectionString")
        End Try
        Return VarValue_Default("DB_CONN_STRING", conn)
    End Function

    ''' <summary>
    ''' Problem: Access round is making round to even (not to the bigger)
    ''' This function makes to proper rounding
    ''' Example Format(1312.545,"#.00")
    ''' is different than RoundUp(1312.545,2)
    ''' </summary>
    ''' <param name="what"></param>
    ''' <param name="Position"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function RoundUp(what As Double, Optional Position As Integer = 0) As String
        Dim formatExpression As String = "#." & Left("0000000000", Position)
        Return Format(what, formatExpression)
    End Function

    Public Function ToSQLDate(dat As Date) As String
        Return "'" & Year(dat) & "-" & Month(dat) & "-" & Microsoft.VisualBasic.Day(dat) & "'"
    End Function

    ''' <summary>
    ''' returns the current app folder
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AppFolder() As String
        Return GetAppPath()
    End Function

    ''' <summary>
    ''' used in ms access. Kept for compatibility reasons.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DbFolder() As String
        Return GetAppPath()
    End Function

    ''' <summary>
    ''' Betriebszeiten anpassen
    ''' </summary>
    ''' <param name="d1"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AdaptZeiten(d1 As Date) As Date
        If ExistsVarValue(BETRIEB_STARTZEIT) Then
            Dim start_Std = VarValue(BETRIEB_STARTZEIT)
            If start_Std.Contains(":") Then
                Dim std As String = start_Std.Split(CChar(":"))(0)
                Dim min As String = start_Std.Split(CChar(":"))(1)
                Return d1.AddHours(CInt(std)).AddMinutes(CInt(min))
            End If
        End If
        Return d1
    End Function

    ''' <summary>
    ''' Nimmt den Vortag z.Bsp. falls die Abfrage genau nach mitternach stattfindet
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AdaptToday() As Date
        Return Today
        If Now < AdaptZeiten(Today) Then
            Return Today.AddDays(-1)
        End If
    End Function

End Module



