Imports System.Data.SqlClient
Public Class RegistrosDAO







    Public Function CargarInv(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a left join REP0 on REP0.CodInv=a.CodInv where row > " + Ini.ToString + " and row <= " + final.ToString + ""


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function

    Public Function CargarInvLETE(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a inner join LET0 on LET0.CodInv=a.CodInv where row > " + Ini.ToString + " and row <= " + final.ToString + ""

        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function



    Public Function CargarInvVCN(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a inner join VCN on VCN.CodInv=a.CodInv where row > " + Ini.ToString + " and row <= " + final.ToString + ""


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function


    Public Function CargarInvPBUR(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a inner join PBUR on PBUR.CodInv=a.CodInv where row > " + Ini.ToString + " and row <= " + final.ToString + ""


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function

    Public Function CargarInvPPER(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a inner join PPER0 on PPER0.CodInv=a.CodInv right join PPER1 on PPER1.CodInv=a.CodInv right join PPER2 on PPER2.CodInv=a.CodInv  where row > " + Ini.ToString + " and row <= " + final.ToString + ""


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function



    Public Function CargarInvFUTU(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a inner join FUT0 on FUT0.CodInv=a.CodInv   where row > " + Ini.ToString + " and row <= " + final.ToString + ""


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function

    Public Function CargarInvOPC(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a inner join OPC0 on OPC0.CodInv=a.CodInv   where row > " + Ini.ToString + " and row <= " + final.ToString + ""


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function


    Public Function CargarInvACCC(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If

        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodIF Like '%" + codigo + "%') a inner join ACC0 on ACC0.CodInv=a.CodInv    where row > " + Ini.ToString + " and row <= " + final.ToString + ""
        ' Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodIF Like '%" + codigo + "%') a inner join ACC0 on ACC0.CodInv=a.CodInv inner join ACC1 on ACC1.CodInv=a.CodInv   where row > " + Ini.ToString + " and row <= " + final.ToString + ""

        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function


    Public Function CargarInvPEMP(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a inner join PEMP0 on PEMP0.CodInv=a.CodInv inner join PEMP1 on PEMP1.CodInv=a.CodInv where row > " + Ini.ToString + " and row <= " + final.ToString + ""


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function




    Public Function CargarInvFINV(ByVal codigo As String, ByVal Ini As Integer, ByVal final As Integer)
        Dim objCon As New Conexion
        If (Ini = 1) Then
            Ini = Ini - 1
        End If
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim sql = "Select * FROM( SELECT *, ROW_NUMBER() OVER (ORDER BY CodInv)  As row FROM INV0 where CodInv Like '%" + codigo + "%') a inner join FINV on FINV.CodInv=a.CodInv inner join FINV1 on FINV1.CodInv=a.CodInv where row > " + Ini.ToString + " and row <= " + final.ToString + ""


        Dim cmd As New SqlCommand(sql, cn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader

        Return dr
    End Function

    Public Function Contador(ByVal codigo As String)
        Dim objCon As New Conexion
        Dim Cantidad As Integer
        Dim sql As String
        Dim Valor, tamaño
        Dim cmd As SqlCommand = New SqlCommand
        Dim cn As SqlConnection = objCon.Conectar
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        sql = "select count(*) from INV0 where CodInv Like '%" + codigo + "%'"
        cmd.CommandText = sql
        cmd.Connection = cn


        Cantidad = cmd.ExecuteScalar
        cn.Close()
        Valor = Math.Round(Cantidad / 100, 0)
        If (Cantidad > Valor) Then
            tamaño = Valor + 1
        Else
            tamaño = Valor
        End If
        Return tamaño
    End Function




End Class
