Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2009
    Messaggi
    25

    rendere una query a visbilità globale

    allora vi posto il mio codice:

    codice:
    Imports System.Windows.Forms
    Imports ADODB
    Imports Connection
    Imports System.Drawing.Printing
    Imports Microsoft.Office.Interop
    
    
    
    Public Class Dialog2
        
        Shared rs As New ADODB.Recordset
        Shared objc As New Connection
    
        Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            PageSetupDialog1.Document = PrintDocument1
            If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
                'PrintDocument1.Print()
                If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                    'PrintDocument1.Print()
    
                    If PrintPreviewDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                        PrintDocument1.Print()
                    End If
                End If
            End If
            Dim sql As String = "SELECT Cognome,nome,Indirizzo,Cap,Citta,Prov From arc_completo where tipo_iscritto='A' and Iscrizione_Avvocati is not NULL"
            objc.open_connection()
            rs = objc.esegui_query(sql, 1)
            
            'Percorso relativo Documents Application.StartupPath &
    
        End Sub
        
    
        Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Close()
        End Sub
    
        Public Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            Dim Font As New Font("Arial", 8)
            Static i As Integer = 0
            
            Dim X As Integer = 8
    
            
    
    
            Dim str As String
            Static Pagina As Integer
            Dim Parziale As Double
            Static Incrementale As Double
            Static Totale As Double
            Dim offset As Integer = 150
            Dim j As Integer = 0
            For i = i To i + 8
                If (rs.EOF = False) Then
                    e.Graphics.DrawString("sign.", Font, Brushes.Black, X, 15 + (j * offset))
                    e.Graphics.DrawString(rs("Cognome").Value, Font, Brushes.Black, X, 30 + (j * offset))
                    e.Graphics.DrawString(rs("nome").Value, Font, Brushes.Black, X + 85, 30 + (j * offset))
                    e.Graphics.DrawString(rs("Indirizzo").Value, Font, Brushes.Black, X, 45 + (j * offset))
                    e.Graphics.DrawString(rs("Cap").Value, Font, Brushes.Black, X, 60 + (j * offset))
                    e.Graphics.DrawString(rs("Citta").Value, Font, Brushes.Black, X + 40, 60 + (j * offset))
                    e.Graphics.DrawString(rs("Prov").Value, Font, Brushes.Black, X + 200, 60 + (j * offset))
                    rs.MoveNext()
    
                    e.Graphics.DrawString("sign.", Font, Brushes.Black, X + 300, 15 + (j * offset))
                    e.Graphics.DrawString(rs("Cognome").Value, Font, Brushes.Black, X + 300, 30 + (j * offset))
                    e.Graphics.DrawString(rs("nome").Value, Font, Brushes.Black, X + 385, 30 + (j * offset))
                    e.Graphics.DrawString(rs("Indirizzo").Value, Font, Brushes.Black, X + 300, 45 + (j * offset))
                    e.Graphics.DrawString(rs("Cap").Value, Font, Brushes.Black, X + 300, 60 + (j * offset))
                    e.Graphics.DrawString(rs("Citta").Value, Font, Brushes.Black, X + 340, 60 + (j * offset))
                    e.Graphics.DrawString(rs("Prov").Value, Font, Brushes.Black, X + 510, 60 + (j * offset))
                    rs.MoveNext()
    
                    e.Graphics.DrawString("sign.", Font, Brushes.Black, X + 600, 15 + (j * offset))
                    e.Graphics.DrawString(rs("Cognome").Value, Font, Brushes.Black, X + 600, 30 + (j * offset))
                    e.Graphics.DrawString(rs("nome").Value, Font, Brushes.Black, X + 685, 30 + (j * offset))
                    e.Graphics.DrawString(rs("Indirizzo").Value, Font, Brushes.Black, X + 600, 45 + (j * offset))
                    e.Graphics.DrawString(rs("Cap").Value, Font, Brushes.Black, X + 600, 60 + (j * offset))
                    e.Graphics.DrawString(rs("Citta").Value, Font, Brushes.Black, X + 640, 60 + (j * offset))
                    e.Graphics.DrawString(rs("Prov").Value, Font, Brushes.Black, X + 800, 60 + (j * offset))
                    rs.MoveNext()
    
                    j = j + 1
                    e.HasMorePages = True
    
                Else
                    j = j + 1
                    e.HasMorePages = False
                End If
            Next i
    
    
        End Sub
    
        Private Sub PrintPreviewDialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewDialog1.Load
    
        End Sub
    End Class
    questo form gestisce la stampa di numerosi record circa 3000 impaginandoli secondo lo schema in una tabella 8*3, il problema che ho è il seguente: ogni volta che chiamo la routine di stampa (da quello che ho capito) l'evento e.HasMorePages = True fa una specie di chiamata ricorsiva alla funzione stessa creando una nuova pagina(gestione di più pagine). Ora, se faccio eseguire la query nella routine di stampa ad ogni nuova chiamata(con l'evento e.HasMorePages = True) rieseguo la query e stampo sempre gli stessi dati(generando un numero di pagine infinito)...se metto la query nel chiamante logicamente la printdocument1(nome della funzione) non me la vede mi da errore di "oggetto chiuso". esiste un modo per eseguire la query e rendere il resulset visibile in tutto il progetto.

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,480

    Moderazione

    In futuro, specifica il linguaggio anche nel titolo - come da Regolamento - e formatta il codice sorgente usando il tag [CODE].

    Qui correggo io.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2009
    Messaggi
    25
    grazie....!!!

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,481
    Ma scusa, l'esecuzione della query nel chiamante la metti dopo la Print ?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  5. #5
    Utente di HTML.it
    Registrato dal
    Nov 2009
    Messaggi
    25
    evidentemente hai ragione!!!
    troppe ore di programmazione fanno male....
    ora funziona solo che mi da un errore di db_null dopo 10 pagine

  6. #6
    Utente di HTML.it
    Registrato dal
    Nov 2009
    Messaggi
    25
    risolto anche questo grazie a tutti...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.