Imports System.Collections.Generic
Imports System.Text
Imports System.Data.SqlClient
Imports System.Data

Public Class clsHistorico

    Private _CODIGO_HIST As Integer
    Public Property CODIGO_HIST() As Integer
        Get
            Return _CODIGO_HIST
        End Get
        Set(ByVal value As Integer)
            _CODIGO_HIST = value
        End Set
    End Property

    Private _CODIGO_PROJ As Long
    Public Property CODIGO_PROJ() As Long
        Get
            Return _CODIGO_PROJ
        End Get
        Set(ByVal value As Long)
            _CODIGO_PROJ = value
        End Set
    End Property

    Private _CODIGO_CHECK As Integer
    Public Property CODIGO_CHECK() As Integer
        Get
            Return _CODIGO_CHECK
        End Get
        Set(ByVal value As Integer)
            _CODIGO_CHECK = value
        End Set
    End Property

    Private _DATA_HIST As DateTime
    Public Property DATA_HIST() As DateTime
        Get
            Return _DATA_HIST
        End Get
        Set(ByVal value As DateTime)
            _DATA_HIST = value
        End Set
    End Property

    Private _CODIGO_CONT As Long
    Public Property CODIGO_CONT() As Long
        Get
            Return _CODIGO_CONT
        End Get
        Set(ByVal value As Long)
            _CODIGO_CONT = value
        End Set
    End Property

    Private _HISTORICO_HIST As String
    Public Property HISTORICO_HIST() As String
        Get
            Return _HISTORICO_HIST
        End Get
        Set(ByVal value As String)
            _HISTORICO_HIST = value
        End Set
    End Property

    Private _CODIGO_CLASS As Integer
    Public Property CODIGO_CLASS() As Integer
        Get
            Return _CODIGO_CLASS
        End Get
        Set(ByVal value As Integer)
            _CODIGO_CLASS = value
        End Set
    End Property

    Private _PROXCONTATO_HIST As DateTime
    Public Property PROXCONTATO_HIST() As DateTime
        Get
            Return _PROXCONTATO_HIST
        End Get
        Set(ByVal value As DateTime)
            _PROXCONTATO_HIST = value
        End Set
    End Property

    Private _ATIVO As Boolean
    Public Property ATIVO() As Boolean
        Get
            Return _ATIVO
        End Get
        Set(ByVal value As Boolean)
            _ATIVO = value
        End Set
    End Property

    Private _ATUALIZADO As Boolean
    Public Property ATUALIZADO() As Boolean
        Get
            Return _ATUALIZADO
        End Get
        Set(ByVal value As Boolean)
            _ATUALIZADO = value
        End Set
    End Property

    Private _DATAATUALIZACAO As DateTime
    Public Property DATAATUALIZACAO() As DateTime
        Get
            Return _DATAATUALIZACAO
        End Get
        Set(ByVal value As DateTime)
            _DATAATUALIZACAO = value
        End Set
    End Property

    Public Function SelectHISTORICO() As DataSet

        Dim clsBanco As New clsBanco
        Dim strsql As String
        strsql = "SELECT * FROM TBL_HISTORICO"
        Return clsBanco.RetornaDataSet(strsql.ToString)

    End Function

    Public Function SelectHistoricoForGrid(ByVal lngCodigoProj As Long) As DataSet

        Dim clsBanco As New clsBanco
        Dim strsql As String
        strsql = "SELECT "
        strsql = strsql & " H.CODIGO_HIST "
        strsql = strsql & ",H.DATA_HIST "
        strsql = strsql & ",H.HISTORICO_HIST"
        strsql = strsql & ",(SELECT C.NOME_CONT FROM TBL_CONTATO AS C WHERE C.CODIGO_CONT = H.CODIGO_CONT) AS CONTATO"
        strsql = strsql & ",H.PROXCONTATO_HIST"

        strsql = strsql & ",(SELECT CLASS.NOME_CLASS FROM TBL_CLASSIFICACAO AS CLASS WHERE  CLASS.CODIGO_CLASS = H.CODIGO_CLASS) AS Classificacao"
        strsql = strsql & ",(SELECT CHK.NOME_CHECK FROM TBL_CHECKMATE AS CHK WHERE CHK.CODIGO_CHECK = H.CODIGO_CHECK) AS CheckMate"
        

        strsql = strsql & " FROM TBL_HISTORICO AS H"
        strsql = strsql & " WHERE H.CODIGO_PROJ = " & lngCodigoProj
     
        Return clsBanco.RetornaDataSet(strsql.ToString)

    End Function

    Public Sub DeleteHISTORICO(ByVal IntCodigo As Integer)
        Dim clsBanco As New clsBanco
        Dim strsql As String
        strsql = "DELETE FROM TBL_HISTORICO"
        strsql = strsql & " WHERE CODIGO_HIST  =  " & IntCodigo
        clsBanco.ExecutaComando(strsql.ToString)
    End Sub

    Public Sub UpdateHISTORICO(ByVal IntCodigo As Integer)
        Dim clsBanco As New clsBanco

        Dim strsql As String

        strsql = "UPDATE TBL_HISTORICO  SET "
        strsql = strsql & "CODIGO_PROJ = " & _CODIGO_PROJ
        strsql = strsql & ",DATA_HIST= '" & Format(_DATA_HIST, "MM/dd/yyyy hh:mm:ss") & "'"
        strsql = strsql & ",CODIGO_CONT = " & _CODIGO_CONT
        strsql = strsql & ",CODIGO_CHECK = " & _CODIGO_CHECK
        strsql = strsql & ",HISTORICO_HIST= '" & _HISTORICO_HIST & "'"
        strsql = strsql & ",CODIGO_CLASS = " & _CODIGO_CLASS
        strsql = strsql & ",PROXCONTATO_HIST= '" & Format(_PROXCONTATO_HIST, "MM/dd/yyyy hh:mm:ss") & "'"
        If _ATIVO = True Then
            strsql = strsql & ",ATIVO= " & 1
        Else
            strsql = strsql & ",ATIVO= " & 0
        End If
        strsql = strsql & ",ATUALIZADO= " & 1
        strsql = strsql & ",DATAATUALIZACAO= '" & _DATAATUALIZACAO & "'"
        strsql = strsql & " WHERE CODIGO_HIST = " & IntCodigo

        clsBanco.ExecutaComando(strsql.ToString)
    End Sub

    Public Sub InsertHISTORICO()
        Dim clsBanco As New clsBanco

        Dim strsql As String

        strsql = "INSERT INTO TBL_HISTORICO("
        strsql = strsql & "CODIGO_PROJ"
        strsql = strsql & ",DATA_HIST"
        strsql = strsql & ",CODIGO_CONT"
        strsql = strsql & ",HISTORICO_HIST"
        strsql = strsql & ",CODIGO_CLASS"
        strsql = strsql & ",CODIGO_CHECK"
        strsql = strsql & ",PROXCONTATO_HIST"
        strsql = strsql & ",ATIVO"
        strsql = strsql & ",ATUALIZADO"
        strsql = strsql & ",DATAATUALIZACAO"
        strsql = strsql & ")VALUES("
        strsql = strsql & CODIGO_PROJ
        strsql = strsql & ",'" & Format(_DATA_HIST, "MM/dd/yyyy hh:mm:ss") & "'"
        strsql = strsql & "," & _CODIGO_CONT
        strsql = strsql & ",'" & _HISTORICO_HIST & "'"
        strsql = strsql & "," & _CODIGO_CLASS
        strsql = strsql & "," & _CODIGO_CHECK
        strsql = strsql & ",'" & Format(_PROXCONTATO_HIST, "MM/dd/yyyy hh:mm:ss") & "'"
        If _ATIVO = True Then
            strsql = strsql & "," & 1
        Else
            strsql = strsql & "," & 0
        End If
        
        strsql = strsql & "," & 1
        strsql = strsql & ",'" & Format(Date.Now, "MM/dd/yyyy hh:mm:ss") & "'"
        strsql = strsql & ")"

        clsBanco.ExecutaComando(strsql.ToString)
    End Sub

End Class

