
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
Imports System.Runtime.InteropServices
Imports System.IO
Public Class FrmRptInvoiceList
#Region "Mov. Pantalla"
    <DllImport("user32.Dll", EntryPoint:="ReleaseCapture")>
    Private Shared Sub ReleaseCapture()

    End Sub

    <DllImport("user32.Dll", EntryPoint:="SendMessage")>
    Private Shared Sub SendMessage(hWnd As IntPtr, wMsg As Integer, wParam As Integer, lParam As Integer)

    End Sub

#End Region
    Private Sub btnCerrar_Click(sender As Object, e As EventArgs) Handles btnCerrar.Click
        Me.Close()
    End Sub

    Private Sub PanelBarraTitulo_MouseMove(sender As Object, e As MouseEventArgs) Handles PanelBarraTitulo.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub

    Private Sub lblEncabezado_MouseMove(sender As Object, e As MouseEventArgs) Handles lblEncabezado.MouseMove
        ReleaseCapture()
        SendMessage(Me.Handle, &H112&, &HF012&, 0)
    End Sub
    Private Sub FrmRptInvoiceList_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim cn As SqlConnection
            Dim ds As New DataSet
            Dim da As New SqlDataAdapter
            Dim Sql As String = Nothing

            Dim ParaCoti(0) As ReportParameter


            If GlobalVariables.VarOrigen = False Then
                If GlobalVariables.varReporteConsulta = 1 Then
                    Sql = "SELECT * FROM Invoices where " & GlobalVariables.varCriterioConsulta
                ElseIf GlobalVariables.varReporteConsulta = 0 Then
                    Sql = "SELECT TOP 250 * FROM Invoices order by Id desc"
                ElseIf GlobalVariables.varReporteConsulta = 3 Then
                    Sql = "SELECT * FROM Invoices order by Id desc"
                End If
                ParaCoti(0) = New ReportParameter("Titulo", "HISTORIAL/REPORTEO DE INVOICES & REMISIONES")

            ElseIf GlobalVariables.VarOrigen = True Then
                If GlobalVariables.varReporteConsulta = 1 Then
                    Sql = "SELECT * FROM Invoices where " & GlobalVariables.varCriterioConsulta
                ElseIf GlobalVariables.varReporteConsulta = 0 Then
                    Sql = "SELECT * FROM Invoices where pagado=0 order by Id desc"
                End If
                ParaCoti(0) = New ReportParameter("Titulo", "FACTURAS PENDIENTES DE PAGO")
            End If

            cn = New SqlConnection(GlobalVariables.cstring)
            Dim cm As New SqlCommand(Sql, cn)
            cn.Open()
            da = New SqlDataAdapter(cm)
            ds = New DataSet()
            da.Fill(ds)

            '>>A PARTIR DE AQUI SE CONFIGURA EL REPORTE
            Dim rptDataSource As ReportDataSource
            Dim strReport As String = "RptDocsList.rdlc"

            With Me.RPVDatos.LocalReport
                .ReportPath = strReport
                .DataSources.Clear()
                .SetParameters(ParaCoti)
            End With
            rptDataSource = New ReportDataSource("DsDocs", ds.Tables(0))
            Me.RPVDatos.LocalReport.DataSources.Add(rptDataSource)
            Me.RPVDatos.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
        Catch ex As Exception
            MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

        Me.RPVDatos.RefreshReport()
    End Sub
    Sub CreaPDF()
        Dim byteViewer As Byte() = RPVDatos.LocalReport.Render("PDF")
        Dim saveFileDialog1 As New SaveFileDialog()
        saveFileDialog1.Filter = "PDF files (.pdf)|*.pdf"
        saveFileDialog1.FilterIndex = 2
        saveFileDialog1.RestoreDirectory = True

        Dim NombreProv As String = FrmInvoices.Cliente.Text
        Dim ParteNombre() As String = NombreProv.Split(" ")

        Dim newFile As New FileStream("C:\IRGodam\PDFS\" & FrmInvoices.Folio.Text & ParteNombre(0) & ".pdf", FileMode.Create)
        newFile.Write(byteViewer, 0, byteViewer.Length)
        newFile.Close()
    End Sub

    Dim lx, ly As Integer
    Dim sw, sh As Integer
    Dim VarVentanaEstatus As Boolean
    Private Sub PanelBarraTitulo_DoubleClick(sender As Object, e As EventArgs) Handles PanelBarraTitulo.DoubleClick
        If VarVentanaEstatus = False Then
            lx = Me.Location.X
            ly = Me.Location.Y
            sw = Me.Size.Width
            sh = Me.Size.Height

            'btnMaximizar.Visible = False
            ' btnRestaurar.Visible = True
            Me.Size = Screen.PrimaryScreen.WorkingArea.Size
            Me.Location = Screen.PrimaryScreen.WorkingArea.Location
            VarVentanaEstatus = True

        ElseIf VarVentanaEstatus = True Then
            Me.Size = New Size(sw, sh)
            Me.Location = New Point(lx, ly)
            ' btnMaximizar.Visible = True
            'btnRestaurar.Visible = False
            VarVentanaEstatus = False
        End If

    End Sub
End Class