Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: yasser.17 en 30 Enero 2013, 22:05 pm



Título: Ayuda imprimir VB .Net
Publicado por: yasser.17 en 30 Enero 2013, 22:05 pm
Hola necesito ayuda con un listado en un programa que estoy haciendo. Tengo una actividad para cada actividad tengo una colección de movimientos, los movimientos tienen personas que lo hacen. Necesito imprimir por cada persona los movimientos que tiene, la consulta esta pronta, pero el problema es cuando llego al final de la pagina en ves de agregarme una pagina nueva lo que hace es seguir imprimiendo en la misma pagina en la parte de arriba. Si alguien puede darme una ayuda, lo agradezco.
Aquí les dejo el segmento de código:

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim ObjAct As Actividades = Nothing

        ObjAct = ComboBox1.SelectedItem



        If Not ObjAct Is Nothing Then
            ' Definir fuente para imprimir
            Dim fuenteimpresion As System.Drawing.Font = New Font("Arial", 12)
            Dim fuenteT As System.Drawing.Font = New Font("Arial", 12, FontStyle.Bold)

            Dim DE As DictionaryEntry
            Dim DE2 As DictionaryEntry
            Dim topMargin As Double = e.MarginBounds.Top
            Dim yPos As Double = 0
            Dim lineasXpagina As Double = 0
            Dim count As Integer = 0
            Dim texto As String = ""
            Dim linea As LineasMov
            Dim ObjMov As Movimientos
            Dim ColP As New Hashtable
            lineasXpagina = e.MarginBounds.Height / fuenteimpresion.GetHeight(e.Graphics)


            texto = vbTab & vbTab & ObjAct.Descripcion & " de la fecha " & ObjAct.Fecha

            yPos = topMargin + (count * fuenteimpresion.GetHeight(e.Graphics))

            e.Graphics.DrawString(texto, fuenteT, System.Drawing.Brushes.Black, 12, yPos)

            count += 2
            yPos = topMargin + (count * fuenteimpresion.GetHeight(e.Graphics))

            Dim Col As Hashtable = Administrador.DevolverInstancia.ObtenerMovimientos(ObjAct)

            For Each DE In Col

                ObjMov = DE.Value
                Dim total As Integer = 0
                total = (ObjMov.Cantidad * ObjMov.PrecioV) / ObjMov.Articulo.Unidad

                If ColP.ContainsKey(ObjMov.Persona.Id) = True Then
                    linea = Nothing
                    linea = ColP(ObjMov.Persona.Id)
                    If Not linea Is Nothing Then
                        linea.Total += total
                    End If
                Else
                    linea = New LineasMov(ObjMov.Id, ObjMov.Persona, total)
                    ColP.Add(linea.Persona.Id, linea)
                End If
            Next

            Col.Clear()


            For Each DE In ColP
                    linea = DE.Value
                    Col = Administrador.DevolverInstancia.ObtenerMovPersonas(linea.Persona, ObjAct)

                    Dim fuente2 As System.Drawing.Font = New Font("Arial", 12, FontStyle.Bold)
                    texto = vbTab & linea.Persona.Apellido & ", " & linea.Persona.Nombre
                    e.Graphics.DrawString(texto, fuente2, System.Drawing.Brushes.Black, 12, yPos)

                    count += 1
                    yPos = topMargin + (count * fuenteimpresion.GetHeight(e.Graphics))

                    texto = vbTab & "Cantidad"
                    e.Graphics.DrawString(texto, fuenteimpresion, System.Drawing.Brushes.Black, 12, yPos)

                    texto = vbTab & vbTab & vbTab & "Descripción"
                    e.Graphics.DrawString(texto, fuenteimpresion, System.Drawing.Brushes.Black, 12, yPos)

                    texto = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "Monto"
                    e.Graphics.DrawString(texto, fuenteimpresion, System.Drawing.Brushes.Black, 12, yPos)

                    count += 1
                    yPos = topMargin + (count * fuenteimpresion.GetHeight(e.Graphics))


                For Each DE2 In Col

                    ObjMov = DE2.Value

                    texto = vbTab & ObjMov.Cantidad
                    e.Graphics.DrawString(texto, fuenteimpresion, System.Drawing.Brushes.Black, 12, yPos)

                    texto = vbTab & vbTab & vbTab & ObjMov.Articulo.Descripcion
                    e.Graphics.DrawString(texto, fuenteimpresion, System.Drawing.Brushes.Black, 12, yPos)

                    texto = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & (ObjMov.PrecioV * ObjMov.Cantidad) / ObjMov.Articulo.Unidad
                    e.Graphics.DrawString(texto, fuenteimpresion, System.Drawing.Brushes.Black, 12, yPos)

                    count += 1
                    yPos = topMargin + (count * fuenteimpresion.GetHeight(e.Graphics))
                    xi += 1

                    If count > lineasXpagina Then
                        e.HasMorePages = True
                        count = 0
                    Else
                        e.HasMorePages = False
                    End If
                Next


                    texto = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & "Total"
                    e.Graphics.DrawString(texto, fuenteimpresion, System.Drawing.Brushes.Black, 12, yPos)

                    count += 1
                    yPos = topMargin + (count * fuenteimpresion.GetHeight(e.Graphics))

                    texto = vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & linea.Total
                    e.Graphics.DrawString(texto, fuenteimpresion, System.Drawing.Brushes.Black, 12, yPos)

                    count += 2
                    yPos = topMargin + (count * fuenteimpresion.GetHeight(e.Graphics))

                If count > lineasXpagina Then
                    e.HasMorePages = True
                    count = 0
                Else
                    e.HasMorePages = False
                End If
            Next
        End If
    End Sub