Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Problema con Printpage e my Function StampaRighe
sabato 13 dicembre 2008 - 13.27
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
ans66
Profilo
| Junior Member
62
messaggi | Data Invio:
sab 13 dic 2008 - 13:27
875_FRM_Menu.zip
Con una variabile boolean, visibile in tutto il Form, faccio partire il loop che serve a scegliere la Query (Quer = stringa) e la variabile (Tipostampa = "USCITE") solo la prima volta (If Secondavolta=False). Nella funzione StampaRiga faccio diventare SecondaVolta=True nella parte della Routine dove si trova il contatore PagineStampate (If ControllaPagine). Quer & TipoStampa devono essere pero` Static per mantenere valore precedente
Ad uno primo controllo sembrerebbe funzionare.
Antonio
da Printpage faccio partire una funzione StampaRighe che deve stampare 12 righe di un recordset poi fare un salto pagina e stampare le rimanenti righe del recordset. Ho impostato altre funzioni per somma giorno e mese. Dopo il salto pagina mi stampa righe del recordset gia` stampate e mi crea errore su somma mese perche` mi viene modificato uno dei parametri passati nella funzione. Allego file VB
Grazie per l'aiuto
N.B.: Ho capito che il problema sta nel fatto che le variabili Qstr & Tipostampa passate dalla routine StampaRighe(Qstr, DoveCol, Top, e, HFont, TipoStampa) non mantengono lo stesso valore passato della prima volta quando viene riavviata la ruotine Printpage. Non ho risolto neanche indicando le variabili come static
ilario
Profilo
| Senior Member
309
messaggi | Data Invio:
dom 14 dic 2008 - 16:02
ciao
hai provato a inserire il codice della funzione StampaRighe direttamente in printpage e vedere se li funziona?
ans66
Profilo
| Junior Member
62
messaggi | Data Invio:
mar 16 dic 2008 - 22:10
funziona anche in una funziona a parte..per ora ho risolto
ilario
Profilo
| Senior Member
309
messaggi | Data Invio:
mer 17 dic 2008 - 16:30
scrivi come hai fatto potrà essere utili ad altri
ciao
ilario
ans66
Profilo
| Junior Member
62
messaggi | Data Invio:
ven 19 dic 2008 - 21:16
Dim SecondaVolta As Boolean = False
----------------------------------------------------------------------------------
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim dt As New System.Data.DataTable
Static TipoStampa As String = vbNullString
Static Qstr As String
Static nr As Integer = 0
'Dim RigheTotali As Integer = dt.Rows.Count - 1
Dim ControllaPagine As Boolean = True
If SecondaVolta = False Then
If QualeStampa = -1 Then
Qstr = "SELECT tbl_EntrateUscite.Data_Operazione, " & _
"tbl_EntrateUscite.Descrizione, " & _
"tbl_EntrateUscite.Amm_ent_usc, " & _
"tbl_Categorie.Categoria, tbl_Soggetti.Nome, " & _
"tbl_Soggetti.Cognome FROM tbl_Soggetti INNER JOIN (tbl_Categorie " & _
"INNER JOIN tbl_EntrateUscite ON tbl_Categorie.id_Categorie = " & _
"tbl_EntrateUscite.tbl_Cat) ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE(((tbl_EntrateUscite.Amm_ent_usc) < 0)) ORDER BY tbl_EntrateUscite.Data_Operazione;"
QualeStampa = 0
TipoStampa = "STAMPA USCITE"
ElseIf QualeStampa = 1 Then
Qstr = "SELECT tbl_EntrateUscite.Data_Operazione, " & _
"tbl_EntrateUscite.Descrizione, " & _
"tbl_EntrateUscite.Amm_ent_usc, " & _
"tbl_Categorie.Categoria, tbl_Soggetti.Nome, " & _
"tbl_Soggetti.Cognome FROM tbl_Soggetti INNER JOIN (tbl_Categorie " & _
"INNER JOIN tbl_EntrateUscite ON tbl_Categorie.id_Categorie = " & _
"tbl_EntrateUscite.tbl_Cat) ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE(((tbl_EntrateUscite.Amm_ent_usc) > 0)) ORDER BY tbl_EntrateUscite.Data_Operazione;"
QualeStampa = 0
TipoStampa = "STAMPA ENTRATE"
ElseIf QualeStampa = 2 Then
Qstr = "SELECT tbl_EntrateUscite.Data_Operazione, " & _
"tbl_EntrateUscite.Descrizione, " & _
"tbl_EntrateUscite.Amm_ent_usc, " & _
"tbl_Categorie.Categoria, tbl_Soggetti.Nome, " & _
"tbl_Soggetti.Cognome FROM tbl_Soggetti INNER JOIN (tbl_Categorie " & _
"INNER JOIN tbl_EntrateUscite ON tbl_Categorie.id_Categorie = " & _
"tbl_EntrateUscite.tbl_Cat) ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"ORDER BY tbl_EntrateUscite.Data_Operazione;"
QualeStampa = 0
TipoStampa = "STAMPA USCITE / ENTRATE"
ElseIf QualeStampa = -3 Then
Qstr = "SELECT tbl_EntrateUscite.Data_Operazione, " & _
"tbl_EntrateUscite.Descrizione, tbl_EntrateUscite.Amm_ent_usc, " & _
"tbl_Categorie.Categoria, tbl_Soggetti.Nome, tbl_Soggetti.Cognome " & _
"FROM tbl_Soggetti INNER JOIN (tbl_Categorie INNER JOIN " & _
"tbl_EntrateUscite ON tbl_Categorie.id_Categorie = " & _
"tbl_EntrateUscite.tbl_Cat) ON tbl_Soggetti.ID_Soggetto = " & _
"tbl_EntrateUscite.tbl_Sog WHERE(((tbl_EntrateUscite.Amm_ent_usc) < 0) " & _
"And ((tbl_Soggetti.Nome) = '" & NomeSog & "') And ((tbl_Soggetti.Cognome) ='" & _
CognomeSog & "')) ORDER BY tbl_EntrateUscite.Data_Operazione;"
QualeStampa = 0
TipoStampa = "STAMPA USCITE PER " & CognomeSog & Space(1) & NomeSog
ElseIf QualeStampa = 3 Then
Qstr = "SELECT tbl_EntrateUscite.Data_Operazione, " & _
"tbl_EntrateUscite.Descrizione, tbl_EntrateUscite.Amm_ent_usc, " & _
"tbl_Categorie.Categoria, tbl_Soggetti.Nome, tbl_Soggetti.Cognome " & _
"FROM tbl_Soggetti INNER JOIN (tbl_Categorie INNER JOIN " & _
"tbl_EntrateUscite ON tbl_Categorie.id_Categorie = " & _
"tbl_EntrateUscite.tbl_Cat) ON tbl_Soggetti.ID_Soggetto = " & _
"tbl_EntrateUscite.tbl_Sog WHERE(((tbl_EntrateUscite.Amm_ent_usc) > 0) " & _
"And ((tbl_Soggetti.Nome) = '" & NomeSog & "') And ((tbl_Soggetti.Cognome) ='" & _
CognomeSog & "')) ORDER BY tbl_EntrateUscite.Data_Operazione;"
QualeStampa = 0
TipoStampa = "STAMPA ENTRATE PER " & CognomeSog & Space(1) & NomeSog
ElseIf QualeStampa = 4 Then
Qstr = "SELECT tbl_EntrateUscite.Data_Operazione, " & _
"tbl_EntrateUscite.Descrizione, tbl_EntrateUscite.Amm_ent_usc, " & _
"tbl_Categorie.Categoria, tbl_Soggetti.Nome, tbl_Soggetti.Cognome " & _
"FROM tbl_Soggetti INNER JOIN (tbl_Categorie INNER JOIN tbl_EntrateUscite " & _
"ON tbl_Categorie.id_Categorie = tbl_EntrateUscite.tbl_Cat) ON " & _
"tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE(((tbl_Soggetti.Nome) ='" & NomeSog & "') And ((tbl_Soggetti.Cognome) = '" & _
CognomeSog & "')) ORDER BY tbl_EntrateUscite.Data_Operazione;"
QualeStampa = 0
TipoStampa = "STAMPA USCITE / ENTRATE " & CognomeSog & Space(1) & NomeSog
End If
End If
'Crea l'intestazione
Dim Rect As New Rectangle
Dim ColCorrente As Integer = 0 'Indica la colonna corrente
Dim Top As Integer = e.MarginBounds.Top 'Top = Margine superiore
Dim Left As Integer = e.MarginBounds.Left 'Left = Margine sinistro
Dim Height As Integer = New Font("Arial", 12, FontStyle.Regular).Height
Dim BrHeader As SolidBrush = New SolidBrush(Me.BackColor)
Dim HFont As Font = New Font("Arial", 12, FontStyle.Regular)
Dim drawFormat As New StringFormat()
drawFormat.Alignment = StringAlignment.Center
Dim DoveCol(5) As Single
dt = LanciaQ(Qnorm, 1, Qstr)
Dim Fn As New Font("Arial", 24, FontStyle.Bold)
e.Graphics.DrawString(Date.Today.ToShortDateString, New Font("Arial", 12, FontStyle.Bold), Brushes.Blue, 20, 20)
Dim drawRect As New RectangleF(40, 45, 700, Fn.Height)
e.Graphics.DrawString(TipoStampa, New Font("Arial", 24, FontStyle.Bold), Brushes.Red, drawRect, drawFormat)
StampaChart(e, TipoStampa)
Dim Img As String = Microsoft.VisualBasic.FileIO.SpecialDirectories. _
AllUsersApplicationData & "\chart.jpg"
e.Graphics.DrawImage(Image.FromFile(Img), 150, 100, 490, 350)
Left = 40
Top = 470
DoveCol(0) = 40
For i As Integer = 0 To 5
'Testo dell'Header
Dim ColText As String = dt.Columns(i).ColumnName
If i = 0 Then ColText = "Data Operazione"
If i = 2 Then ColText = "Ammontare"
'Rettangolo dell'Header corrente
Rect = New Rectangle(Left, Top, e.Graphics.MeasureString(ColText, HFont).Width, Height)
'Colora l'Header
e.Graphics.FillRectangle(BrHeader, Rect)
'Linee dell'Intestazione
e.Graphics.DrawRectangle(New Pen(Color.Gray, 1), Rect)
'Disegna il testo dell'Header
e.Graphics.DrawString(ColText, HFont, Brushes.Black, Left, _
Top + (e.Graphics.MeasureString(ColText, HFont).Height / 6)) '/2
'Calcola la prossima coordinata Left
Left += e.Graphics.MeasureString(ColText, HFont).Width
If i = 4 Then Left += e.Graphics.MeasureString("A", HFont).Width
If i <> 1 Then
Left += e.Graphics.MeasureString("AA", HFont).Width
ElseIf i = 1 Then
Left += e.Graphics.MeasureString("AAAAA", HFont).Width
End If
If i < 5 Then DoveCol(i + 1) = Left
Next
Top += HFont.Height * 2
StampaRighe(Qstr, DoveCol, Top, e, HFont, TipoStampa)
End Sub
Private Sub StampaRighe(ByVal Quer As String, ByVal DoveR() As Single, ByVal Alto As Single, _
ByVal evt As System.Drawing.Printing.PrintPageEventArgs, _
ByVal Fn As System.Drawing.Font, ByVal Chestampa As String)
'Stampa la righe
Static PagineStampate As Integer = 0
Static RigaCorrente As Integer = 0
Dim dt As New System.Data.DataTable
Dim inPiuRighe As Integer = 0
Dim Left As Single = 0
Dim CelText As String = vbNullString
Dim ControllaPagine As Boolean = True
Dim DataUltimoRecord As Date
Static cnt As Integer = 0
'Righe Totali nel Recordset
dt = LanciaQ(Qnorm, 1, Quer)
Dim MaxRighe As Integer = 12
'In totale quante pagine
Dim MaxPagine As Integer = dt.Rows.Count - 1 / MaxRighe
Dim testResult As Double = (dt.Rows.Count - 1) Mod MaxRighe
If testResult <> 0 Then MaxPagine += 1
For cnt = RigaCorrente To 11 + RigaCorrente
If cnt <= dt.Rows.Count - 1 Then
Dim SommaGiorno As Decimal = PerSommaGG(dt, cnt, Chestampa)
If SommaGiorno <> 0 Then
evt.Graphics.DrawString("Somma " & dt.Rows(cnt - 1).Item(0), New Font("Arial", 12, FontStyle.Bold), _
Brushes.Red, DoveR(0), Alto)
evt.Graphics.DrawString(FormatCurrency(SommaGiorno), _
New Font("Arial", 12, FontStyle.Bold), Brushes.Red, DoveR(2), _
Alto)
Alto += Fn.Height * 2
End If
'Somma Mese
Dim SommaMs As Decimal = PerSommaMs(dt, cnt, Chestampa)
If SommaMs <> 0 Then
evt.Graphics.DrawString("Somma " & MonthName(Month(dt.Rows(cnt - 1).Item(0))), New Font("Arial", 12, FontStyle.Bold), _
Brushes.Green, DoveR(0), Alto)
evt.Graphics.DrawString(FormatCurrency(SommaMs), _
New Font("Arial", 12, FontStyle.Bold), Brushes.Green, DoveR(2), _
Alto)
Alto += Fn.Height * 2
End If
For i As Integer = 0 To 5
If Not DBNull.Value.Equals(dt.Rows(cnt).Item(i)) Then
Left = DoveR(i)
CelText = dt.Rows(cnt).Item(i)
If i = 1 Then
If CelText.Length > 13 Then CelText = CelText.Substring(0, 13)
ElseIf i = 3 Then
If CelText.Length > 7 Then CelText = CelText.Substring(0, 7)
ElseIf i = 2 Then
SomTot += CelText
CelText = FormatCurrency(CelText)
End If
evt.Graphics.DrawString(CelText, Fn, Brushes.Black, DoveR(i), _
Alto)
Else
CelText = vbNullString
End If
Next
'Ci sono altre righe?
ElseIf cnt > dt.Rows.Count - 1 Then
RigaCorrente = 0
ControllaPagine = False
evt.HasMorePages = False
SecondaVolta = False
Exit For
End If
'Incrementa il contatore delle righe stampate
Alto += Fn.Height
RigaCorrente += 1
Next cnt
'Devo controllare le pagine se non ho ancora terminato il numero di righe da
'Stampare
If ControllaPagine Then
'Incrementea il contatore delle pagine stampate
PagineStampate += 1
SecondaVolta = True
'Controlla se ci sono altre pagine da stampare...
If PagineStampate < MaxPagine Then
'Ci sono altre pagine
evt.HasMorePages = True
Else
'Fine delle pagine
evt.HasMorePages = False
'Azzera le variabili Static per un successivo utilizzo
RigaCorrente = 0
PagineStampate = 0
End If
End If
If cnt > dt.Rows.Count - 1 Then
DataUltimoRecord = dt.Rows(dt.Rows.Count - 1).Item(0) ' Data dell'ultimo record
Dim Qry As String = vbNullString
If Chestampa = "STAMPA USCITE" Then
Qry = "Select Sum([Amm_ent_usc]) FROM tbl_EntrateUscite " & _
"WHERE (((([Amm_ent_usc]))<0) AND ((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & ") AND ((Day([Data_Operazione]))=" & _
DataUltimoRecord.Day & "));"
ElseIf Chestampa = "STAMPA ENTRATE" Then
Qry = "Select Sum([Amm_ent_usc]) FROM tbl_EntrateUscite " & _
"WHERE (((([Amm_ent_usc]))>0) AND ((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & ") AND ((Day([Data_Operazione]))=" & _
DataUltimoRecord.Day & "));"
ElseIf Chestampa = "STAMPA USCITE / ENTRATE" Then
Qry = "SELECT Sum([Amm_ent_usc]) FROM tbl_EntrateUscite " & _
"WHERE (((Month([Data_Operazione]))=" & DataUltimoRecord.Month & _
") AND ((Day([Data_Operazione]))=" & DataUltimoRecord.Day & _
"));"
ElseIf Chestampa = "STAMPA USCITE PER " & CognomeSog & Space(1) & NomeSog Then
Qry = "Select Sum([Amm_ent_usc]) FROM tbl_Soggetti INNER JOIN " & _
"tbl_EntrateUscite ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE (((tbl_EntrateUscite.[Amm_ent_usc])<0) AND ((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & ") AND ((Day([Data_Operazione]))=" & _
DataUltimoRecord.Day & ") AND ((tbl_Soggetti.Nome)='" & _
NomeSog & "') AND ((tbl_Soggetti.Cognome)='" & CognomeSog & "'));"
ElseIf Chestampa = "STAMPA ENTRATE PER " & CognomeSog & Space(1) & NomeSog Then
Qry = "Select Sum([Amm_ent_usc]) FROM tbl_Soggetti INNER JOIN " & _
"tbl_EntrateUscite ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE (((tbl_EntrateUscite.[Amm_ent_usc])>0) AND ((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & ") AND ((Day([Data_Operazione]))=" & _
DataUltimoRecord.Day & ") AND ((tbl_Soggetti.Nome)='" & _
NomeSog & "') AND ((tbl_Soggetti.Cognome)='" & CognomeSog & "'));"
ElseIf Chestampa = "STAMPA USCITE / ENTRATE " & CognomeSog & Space(1) & NomeSog Then
Qry = "SELECT Sum([Amm_ent_usc]) FROM tbl_Soggetti INNER JOIN " & _
"tbl_EntrateUscite ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE (((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & ") AND ((Day([Data_Operazione]))='" & _
DataUltimoRecord.Day & "') AND ((tbl_Soggetti.Nome)='" & _
NomeSog & "') AND ((tbl_Soggetti.Cognome)='" & CognomeSog & "'));"
Else
Qry = "SELECT Sum([Amm_ent_usc]) FROM tbl_EntrateUscite " & _
"WHERE (((Month([Data_Operazione]))=" & DataUltimoRecord.Month & _
") AND ((Day([Data_Operazione]))=" & DataUltimoRecord.Day & _
"));"
End If
dt = LanciaQ("", 1, Qry) 'Query per somma giorno ultimo record
evt.Graphics.DrawString("Somma " & DataUltimoRecord, New Font("Arial", 12, FontStyle.Bold), _
Brushes.Red, DoveR(0), Alto)
evt.Graphics.DrawString(FormatCurrency(dt.Rows(0).Item(0)), _
New Font("Arial", 12, FontStyle.Bold), Brushes.Red, DoveR(2), _
Alto)
Alto += Fn.Height * 2
If Chestampa = "STAMPA USCITE" Then
Qry = "SELECT Sum([Amm_ent_usc]) FROM(tbl_EntrateUscite) " & _
"WHERE (((([Amm_ent_usc]))<0) AND ((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & "));"
ElseIf Chestampa = "STAMPA ENTRATE" Then
Qry = "SELECT Sum([Amm_ent_usc]) FROM(tbl_EntrateUscite) " & _
"WHERE (((([Amm_ent_usc]))>0) AND ((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & "));"
ElseIf Chestampa = "STAMPA USCITE / ENTRATE" Then
Qry = "SELECT Sum([Amm_ent_usc]) FROM tbl_EntrateUscite " & _
"WHERE (((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & "));"
ElseIf Chestampa = "STAMPA USCITE PER " & CognomeSog & Space(1) & NomeSog Then
Qry = "SELECT Sum([Amm_ent_usc]) FROM tbl_Soggetti INNER JOIN " & _
"tbl_EntrateUscite ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE (((([Amm_ent_usc]))<0) AND ((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & ") AND ((tbl_Soggetti.Nome)='" & _
NomeSog & "') AND ((tbl_Soggetti.Cognome)='" & _
CognomeSog & "'));"
ElseIf Chestampa = "STAMPA ENTRATE PER " & CognomeSog & Space(1) & NomeSog Then
Qry = "SELECT Sum([Amm_ent_usc]) FROM tbl_Soggetti INNER JOIN " & _
"tbl_EntrateUscite ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE (((([Amm_ent_usc]))>0) AND ((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & ") AND ((tbl_Soggetti.Nome)='" & _
NomeSog & "') AND ((tbl_Soggetti.Cognome)='" & _
CognomeSog & "'));"
ElseIf Chestampa = "STAMPA USCITE / ENTRATE " & CognomeSog & Space(1) & NomeSog Then
Qry = "SELECT Sum([Amm_ent_usc]) FROM tbl_Soggetti INNER JOIN " & _
"tbl_EntrateUscite ON tbl_Soggetti.ID_Soggetto = tbl_EntrateUscite.tbl_Sog " & _
"WHERE (((Month([Data_Operazione]))=" & DataUltimoRecord.Month & _
") AND ((tbl_Soggetti.Nome)='" & NomeSog & "') AND ((tbl_Soggetti.Cognome)='" & _
CognomeSog & "'));"
Else
Qry = "SELECT Sum([Amm_ent_usc]) FROM tbl_EntrateUscite " & _
"WHERE (((Month([Data_Operazione]))=" & _
DataUltimoRecord.Month & "));"
End If
dt = LanciaQ("", 1, Qry) 'Query per somma mese ultimo record
evt.Graphics.DrawString("Somma " & MonthName(Month(DataUltimoRecord)), New Font("Arial", 12, FontStyle.Bold), _
Brushes.Green, DoveR(0), Alto)
evt.Graphics.DrawString(FormatCurrency(dt.Rows(0).Item(0)), _
New Font("Arial", 12, FontStyle.Bold), Brushes.Green, DoveR(2), _
Alto)
Alto += Fn.Height * 2
evt.Graphics.DrawString("Somma Totale", New Font("Arial", 12, FontStyle.Bold), _
Brushes.Blue, DoveR(0), Alto)
evt.Graphics.DrawString(FormatCurrency(SomTot), _
New Font("Arial", 12, FontStyle.Bold), Brushes.Blue, DoveR(2), _
Alto)
cnt = 0
End If
End Sub
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !