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

Public Class clsDetalheProjeto

    Private _CODIGO_DETPROJ As Integer
    Public Property CODIGO_DETPROJ() As Integer
        Get
            Return _CODIGO_DETPROJ
        End Get
        Set(ByVal value As Integer)
            _CODIGO_DETPROJ = 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_PROD As Integer
    Public Property CODIGO_PROD() As Integer
        Get
            Return _CODIGO_PROD
        End Get
        Set(ByVal value As Integer)
            _CODIGO_PROD = value
        End Set
    End Property
    Private _QTDE_PROD As Integer
    Public Property QTDE_PROD() As Integer
        Get
            Return _QTDE_PROD
        End Get
        Set(ByVal value As Integer)
            _QTDE_PROD = value
        End Set
    End Property
    Private _VLUNITARIO_PROD As Integer
    Public Property VLUNITARIO_PROD() As Integer
        Get
            Return _VLUNITARIO_PROD
        End Get
        Set(ByVal value As Integer)
            _VLUNITARIO_PROD = value
        End Set
    End Property
    Private _CODIGO_UNID As Integer
    Public Property CODIGO_UNID() As Integer
        Get
            Return _CODIGO_UNID
        End Get
        Set(ByVal value As Integer)
            _CODIGO_UNID = 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 SelectDetalheProjeto() As DataSet
        Dim clsBanco As New clsBanco
        Dim strsql As String
        strsql = "SELECT * FROM TBL_DETALHEPROJETO"
        Return clsBanco.RetornaDataSet(strsql.ToString)

    End Function

    Public Function SelectDetalheProjetoforGrid(ByVal lngCodigo As Long) As DataSet
        Dim clsBanco As New clsBanco
        Dim strsql As String
        strsql = "SELECT "
        strsql = strsql & "D.CODIGO_DETPROJ"
        strsql = strsql & ",P.NOME_PROD"
        strsql = strsql & ",P.DESCR_PROD"
        strsql = strsql & ",D.QTDE_PROD"
        strsql = strsql & ",D.VLUNITARIO_PROD"
        strsql = strsql & ",U.NOME_UNID"
        strsql = strsql & ",P.CODIGO_PROD"
        strsql = strsql & " FROM TBL_DETALHEPROJETO AS D "
        strsql = strsql & " INNER JOIN TBL_PRODUTO AS P"
        strsql = strsql & " ON D.CODIGO_PROD = P.CODIGO_PROD"
        strsql = strsql & " INNER JOIN TBL_UNIDADEMEDIDA AS U"
        strsql = strsql & " ON P.CODIGO_UNID = U.CODIGO_UNID"
        strsql = strsql & " WHERE D.CODIGO_PROJ = " & lngCodigo

        Return clsBanco.RetornaDataSet(strsql.ToString)

    End Function

    Public Sub DeleteDETALHEPROJETO(ByVal IntCodigo As Integer)
        Dim clsBanco As New clsBanco
        Dim strsql As String
        strsql = "DELETE FROM TBL_DETALHEPROJETO"
        strsql = strsql & " WHERE CODIGO_DETPROJ  =  " & IntCodigo
        clsBanco.ExecutaComando(strsql.ToString)
    End Sub

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

        Dim strsql As String

        strsql = "UPDATE TBL_DETALHEPROJETO  SET "
        strsql = strsql & "CODIGO_PROJ = " & _CODIGO_PROJ
        strsql = strsql & ",CODIGO_PROD = " & _CODIGO_PROD
        strsql = strsql & ",QTDE_PROD = " & _QTDE_PROD
        strsql = strsql & ",VLUNITARIO_PROD = " & _VLUNITARIO_PROD
        strsql = strsql & ",CODIGO_UNID = " & _CODIGO_UNID
        strsql = strsql & ",ATUALIZADO= " & 1
        strsql = strsql & ",DATAATUALIZACAO= '" & _DATAATUALIZACAO & "'"
        strsql = strsql & " WHERE CODIGO_DETPROJ = " & IntCodigo

        clsBanco.ExecutaComando(strsql.ToString)
    End Sub

    Public Sub InsertDETALHEPROJETO()
        Dim clsBanco As New clsBanco

        Dim strsql As String

        strsql = "INSERT INTO TBL_DETALHEPROJETO("
        strsql = strsql & "CODIGO_PROJ"
        strsql = strsql & ",CODIGO_PROD"
        strsql = strsql & ",QTDE_PROD"
        strsql = strsql & ",VLUNITARIO_PROD"
        strsql = strsql & ",ATUALIZADO"
        strsql = strsql & ",DATAATUALIZACAO"
        strsql = strsql & ")VALUES("
        strsql = strsql & _CODIGO_PROJ
        strsql = strsql & "," & _CODIGO_PROD
        strsql = strsql & "," & _QTDE_PROD
        strsql = strsql & "," & Replace(CStr(_VLUNITARIO_PROD), ",", ".")
        strsql = strsql & "," & 1
        strsql = strsql & ",'" & _DATAATUALIZACAO & "'"
        strsql = strsql & ")"

        clsBanco.ExecutaComando(strsql.ToString)
    End Sub
End Class

