Imports System.Data.SqlClient

Public Class clsFuncoesGerais

    Public Enum Operacao
        Inclusao
        Alteracao
    End Enum

    Public Shared Function EncontraCodigo(ByVal strName As String) As String

        Dim IntCodigo As Integer = InStr("strname", "-")
        strName = Mid(strName, 0, IntCodigo)
        Return strName

    End Function

    Public Shared Function FindEmpresaByCode(ByVal intCodigo As Integer) As String

        Dim clsBanco As New clsBanco
        Dim strsql As String = "SELECT NOME_EMP FROM TBL_EMPRESA WHERE CODIGO_EMP = " & intCodigo

        Dim dr As SQLDatareader = clsBanco.RetornaDataReader(strsql.ToString)
        strsql = ""
        If dr.Read Then
            strsql = dr("NOME_EMP").ToString
        End If

        Return strsql

    End Function

    Public Shared Function FindValueByCode(ByVal intCodigo As Integer) As String

        Dim clsBanco As New clsBanco
        Dim strsql As String = "SELECT VALORUNITARIO_PROD FROM TBL_PRODUTO WHERE CODIGO_PROD = " & intCodigo

        Dim dr As SqlDataReader = clsBanco.RetornaDataReader(strsql.ToString)
        strsql = ""
        If dr.Read Then
            strsql = dr("VALORUNITARIO_PROD").ToString
        End If

        Return strsql

    End Function
    Public Shared Function GetCodigo() As Long



        'Instancia a variavel para arrumar a data e hora retirando "/", ":" e " "
        Dim strCodigo As String = Date.Now.ToString("yyyyMMddssfff")
        strCodigo = strCodigo.Replace(":", "")
        strCodigo = strCodigo.Replace(" ", "")
        Return CLng(strCodigo)

    End Function

    Public Shared Function RetornaDivisao(ByVal strCodigo As String) As String

        'P-1-200909234

        Dim IntCaracter1 As Integer = InStr(strCodigo, "-") + 1
        Dim intCaracter2 As Integer = InStr(IntCaracter1, strCodigo, "-")
        Dim strDivisao As String = Mid(strCodigo, 1, 1)
        Dim strstring As String = ""



        Select Case strDivisao
            Case "P"
                strstring = Mid(strCodigo, IntCaracter1, intCaracter2 - IntCaracter1)
            Case "N"
                strstring = Mid(strCodigo, 3)
        End Select

        Return strstring


    End Function


    Public Shared Function RetornaNomeDivisao(ByVal strCodigo As String) As String

        'P-1-200909234

        Dim clsBanco As New clsBanco
        Dim strsql As String = "SELECT NOME_DIV FROM TBL_DIVISAO WHERE CODIGO_DIV = " & RetornaDivisao(strCodigo)

        Dim dr As SqlDataReader = clsBanco.RetornaDataReader(strsql.ToString)

        If dr.Read() Then
            Return CStr(dr("NOME_DIV"))
        Else
            Return ""
        End If

    End Function





    Public Shared Function RetornaCodigoProjeto(ByVal strCodigo As String) As String

        'P-1-200909234

        Dim IntCaracter1 As Integer = InStr(strCodigo, "-") + 1
        Dim intCaracter2 As Integer = InStr(IntCaracter1, strCodigo, "-")
        Return Mid(strCodigo, intCaracter2 + 1)

    End Function


   

End Class
