'ONLY contains shared methods/functions

Imports RGBC_Forecast.SystemFunctions

Public Class ProjectFunctions

  Public Shared Function sql_get_Users(ByVal strDomainLogin As String, ByVal strDomain As String) As String
    Return "SELECT * " & _
      "FROM mstUserGroup" & strDomain & " INNER JOIN mstUser ON mstUserGroup" & strDomain & ".UserGroupID = mstUser.refUserGroup" & strDomain & "ID " & _
      "WHERE mstUser.strDomainLogin = '" & strDomainLogin & "'"

  End Function

  Public Overloads Shared Function FormatPercent(ByVal MyValue As Object, Optional ByVal intDecimals As Integer = 0, Optional ByVal IncludeLeadingDigit As TriState = TriState.UseDefault, Optional ByVal UseParensForNeg As TriState = TriState.UseDefault, Optional ByVal GroupDigits As TriState = TriState.UseDefault) As String
    'overloads the standard formatPerc function to add in "+" sign for positives
    Try
      If CDbl(MyValue) > 0 Then
        Return "+" & Microsoft.VisualBasic.FormatPercent(MyValue, intDecimals, IncludeLeadingDigit, UseParensForNeg, GroupDigits)
      Else
        Return Microsoft.VisualBasic.FormatPercent(MyValue, intDecimals, IncludeLeadingDigit, UseParensForNeg, GroupDigits)
      End If

    Catch ex As Exception
      Return "0.0"
    End Try

  End Function


  Public Overloads Shared Function FormatNumber(ByVal MyValue As Object, Optional ByVal intDecimals As Integer = 0, Optional ByVal IncludeLeadingDigit As TriState = TriState.UseDefault, Optional ByVal UseParensForNeg As TriState = TriState.UseDefault, Optional ByVal GroupDigits As TriState = TriState.UseDefault) As String
    'rgbc's server is set up with number format = "999 999.99", which is lame. it should be "999,999.99"
    Try

      Return Microsoft.VisualBasic.FormatNumber(MyValue, intDecimals, IncludeLeadingDigit, UseParensForNeg, GroupDigits).ToString.Replace(Chr(160), ",")
      'OMG! I HAVE NEVER SEEN SOMETHING THIS STUPID! LIVE SERVER SETTINGS NUMBER FORMATS NOT A SPACE CHARACTER, BUT A chr(160). WTF IS 160?! FUCKING PIECE OF SHIT! DIE!
    Catch ex As Exception
      Return "0.0"
    End Try
  End Function

  Public Shared Function sql_insert_BrandQF_Job(ByVal BrandID As Integer, ByVal Finyear As Integer, ByVal BrandName As String, Optional ByVal CopyBrandID As Integer = 0) As String
    'Dim para As New Collection

    'para.Add(BrandID, "BrandID")
    'para.Add(Finyear, "FinYear")
    'para.Add(CopyBrandID, "CopyBrandID")

    Dim para As String = "BrandID=" & BrandID & "|Finyear=" & Finyear & "|CopyBrandID=" & CopyBrandID & "|BrandName=" & BrandName

      Return "INSERT INTO sysCronJob(dtCronJob, Type, param, Status)" & _
             "VALUES('" & Date.Now.ToString("yyyyMMddHHmm") & "', 'BrandQF', '" & para.ToString & "', 'New')"
  End Function

  Public Shared Function sql_remove_duplicate_BrandQF_Job(ByVal BrandID As Integer, ByVal Finyear As Integer, ByVal BrandName As String, Optional ByVal CopyBrandID As Integer = 0) As String

    Dim para As String = "BrandID=" & BrandID & "|Finyear=" & Finyear & "|CopyBrandID=" & CopyBrandID & "|BrandName=" & BrandName

    Return "UPDATE sysCronJob SET Status = 'Removed', Result = 'Duplicate Job in Queue [" & Date.Now.ToString("yyyyMMdd HH:mm:ss") & "]' WHERE Type = 'BrandQF' AND param like '" & para.ToString & "' AND Status = 'New' "
  End Function

End Class
