dumpsterdivingdave
asked on
Filtering Database results to print a report
I am having trouble filtering my database to print a report using only the wanted selections. My current code is as follows:
e.Graphics.DrawString("End of Night Report for " + System.DateTime.Today.Date , fntHeader, Brushes.Black, sngPrintX, sngPrintY)
sngPrintY += fntHeader.GetHeight + 25
e.Graphics.DrawString("Sta rTag" + ControlChars.Tab + ControlChars.Tab + "Last Name" + ControlChars.Tab + _
"Start Date" + ControlChars.Tab + ControlChars.Tab + "Status" + ControlChars.Tab + ControlChars.Tab + _
"Last Agent", fntUnderline, Brushes.Black, sngPrintX, sngPrintY)
sngPrintY += fntRegular.GetHeight + 2
frmMain.cboStarTag.Selecte dIndex = 0
While frmMain.cboStarTag.Selecte dIndex < frmMain.cboStarTag.Items.C ount
e.Graphics.DrawString(frmM ain.txtSta rTag.Text + ControlChars.Tab + frmMain.txtLastName.Text + ControlChars.Tab + _
ControlChars.Tab + frmMain.dtpStartDate.Value .Date.ToSt ring + ControlChars.Tab + frmMain.cboStatus.Text + _
ControlChars.Tab + frmMain.txtAgent.Text, fntRegular, Brushes.Black, sngPrintX, sngPrintY)
sngPrintY += fntRegular.GetHeight + 2
If frmMain.cboStarTag.Selecte dIndex = (frmMain.cboStarTag.Items. Count - 1) Then
Exit Sub
End If
frmMain.cboStarTag.Selecte dIndex += 1
End While
frmMain.dbaBlackhole.Fill( frmMain.ds Blackhole. Progress)
frmMain.dbaQuery.Fill(frmM ain.dsQuer y.Progress )
frmMain.dbaBlackhole.FillB y(frmMain. dsBlackhol e.Progress , "Complete")
frmMain.dbaQuery.FillBy(fr mMain.dsQu ery.Progre ss, "Complete")
frmMain.cboStarTag.Selecte dIndex = 0
While frmMain.cboStarTag.Selecte dIndex < frmMain.cboStarTag.Items.C ount
If frmMain.dtpFinishDate.Valu e.Day = System.DateTime.Today.Day Then
e.Graphics.DrawString(frmM ain.txtSta rTag.Text + ControlChars.Tab + frmMain.txtLastName.Text + ControlChars.Tab + _
ControlChars.Tab + frmMain.dtpStartDate.Value .Date.ToSt ring + ControlChars.Tab + frmMain.cboStatus.Text + _
ControlChars.Tab + frmMain.txtAgent.Text, fntRegular, Brushes.Black, sngPrintX, sngPrintY)
sngPrintY += fntRegular.GetHeight + 2
End If
If frmMain.cboStarTag.Selecte dIndex = (frmMain.cboStarTag.Items. Count - 1) Then
Exit Sub
End If
frmMain.cboStarTag.Selecte dIndex += 1
End While
Currently, it will display the print preview, but on the document will only be those entries in the database that meet the critera where their status is "In-Repair". What I want it to do is display all records that have a status of "In-Repair" or "Complete" if the finish date is the same as the current date. I have tried omitting the If frmMain.dtpFinishDate.Valu e.Day = System.DateTime.Today.Day Then to try and get it to just display all In-Repair and Complete units, but it still only prints/shows the In-Repair units.
Any help?
e.Graphics.DrawString("End
sngPrintY += fntHeader.GetHeight + 25
e.Graphics.DrawString("Sta
"Start Date" + ControlChars.Tab + ControlChars.Tab + "Status" + ControlChars.Tab + ControlChars.Tab + _
"Last Agent", fntUnderline, Brushes.Black, sngPrintX, sngPrintY)
sngPrintY += fntRegular.GetHeight + 2
frmMain.cboStarTag.Selecte
While frmMain.cboStarTag.Selecte
e.Graphics.DrawString(frmM
ControlChars.Tab + frmMain.dtpStartDate.Value
ControlChars.Tab + frmMain.txtAgent.Text, fntRegular, Brushes.Black, sngPrintX, sngPrintY)
sngPrintY += fntRegular.GetHeight + 2
If frmMain.cboStarTag.Selecte
Exit Sub
End If
frmMain.cboStarTag.Selecte
End While
frmMain.dbaBlackhole.Fill(
frmMain.dbaQuery.Fill(frmM
frmMain.dbaBlackhole.FillB
frmMain.dbaQuery.FillBy(fr
frmMain.cboStarTag.Selecte
While frmMain.cboStarTag.Selecte
If frmMain.dtpFinishDate.Valu
e.Graphics.DrawString(frmM
ControlChars.Tab + frmMain.dtpStartDate.Value
ControlChars.Tab + frmMain.txtAgent.Text, fntRegular, Brushes.Black, sngPrintX, sngPrintY)
sngPrintY += fntRegular.GetHeight + 2
End If
If frmMain.cboStarTag.Selecte
Exit Sub
End If
frmMain.cboStarTag.Selecte
End While
Currently, it will display the print preview, but on the document will only be those entries in the database that meet the critera where their status is "In-Repair". What I want it to do is display all records that have a status of "In-Repair" or "Complete" if the finish date is the same as the current date. I have tried omitting the If frmMain.dtpFinishDate.Valu
Any help?
ASKER
it is running from the printpage event. I can get it to filter the data the first time, but it wont do it the second time. I have tried both doing a complete Fill and FillBy.
How many pages are you printing?
Bob
Bob
ASKER
As many as it takes to print out all of the records. I know how to print multiple pages with the e.HasMorePages = true command, but I can't get the program to filter the data a second time. Like in the above example, it would filter it a first time with the lines:
frmMain.dbaBlackhole.FillB y(frmMain. dsBlackhol e.Progress , "In-Repair")
frmMain.dbaQuery.FillBy(fr mMain.dsQu ery.Progre ss, "In-Repair")
Which I accidently cut off the top, but once it went through and added all of those records to the printpage, It wont re-filter the records to only show those that have a status of Complete
frmMain.dbaBlackhole.FillB
frmMain.dbaQuery.FillBy(fr
Which I accidently cut off the top, but once it went through and added all of those records to the printpage, It wont re-filter the records to only show those that have a status of Complete
ASKER
Ok, I figured out another way to do it beside filtering the database.
If I use a if statement and examine the contents of what is to be added then I can just filter through the entire database and select what I want... Like this:
frmMain.cboStarTag.Selecte dIndex = 0
While frmMain.cboStarTag.Selecte dIndex < frmMain.cboStarTag.Items.C ount
If frmMain.cboStatus.Text = "In-Repair" Then
e.Graphics.DrawString(frmM ain.cboSta rTag.Text, fntRegular, Brushes.Black, sngPrintX, sngPrintY)
e.Graphics.DrawString(frmM ain.txtLas tName.Text , fntRegular, Brushes.Black, sngPrintX + 100, sngPrintY)
e.Graphics.DrawString(frmM ain.dtpSta rtDate.Val ue.Date, fntRegular, Brushes.Black, sngPrintX + 200, sngPrintY)
e.Graphics.DrawString("N/A ", fntRegular, Brushes.Black, sngPrintX + 300, sngPrintY)
e.Graphics.DrawString(frmM ain.cboSta tus.Text, fntRegular, Brushes.Black, sngPrintX + 400, sngPrintY)
e.Graphics.DrawString(frmM ain.txtAge nt.Text, fntRegular, Brushes.Black, sngPrintX + 500, sngPrintY)
sngPrintY += fntRegular.GetHeight + 2
RecordNo += 1
End If
If frmMain.cboStatus.Text = "Complete" And (DateDiff(DateInterval.Day , System.DateTime.Today.Date , frmMain.dtpFinishDate.Valu e.Date) = 0) Then
e.Graphics.DrawString(frmM ain.cboSta rTag.Text, fntRegular, Brushes.LimeGreen, sngPrintX, sngPrintY)
e.Graphics.DrawString(frmM ain.txtLas tName.Text , fntRegular, Brushes.LimeGreen, sngPrintX + 100, sngPrintY)
e.Graphics.DrawString(frmM ain.dtpSta rtDate.Val ue.Date, fntRegular, Brushes.LimeGreen, sngPrintX + 200, sngPrintY)
e.Graphics.DrawString(frmM ain.dtpFin ishDate.Va lue.Date, fntRegular, Brushes.LimeGreen, sngPrintX + 300, sngPrintY)
e.Graphics.DrawString(frmM ain.cboSta tus.Text, fntRegular, Brushes.LimeGreen, sngPrintX + 400, sngPrintY)
e.Graphics.DrawString(frmM ain.txtAge nt.Text, fntRegular, Brushes.LimeGreen, sngPrintX + 500, sngPrintY)
sngPrintY += fntRegular.GetHeight + 2
RecordNo += 1
End If
frmMain.cboStarTag.Selecte dIndex += 1
If frmMain.cboStarTag.Selecte dIndex = (frmMain.cboStarTag.Items. Count - 1) Then
Exit Sub
End If
End While
If I use a if statement and examine the contents of what is to be added then I can just filter through the entire database and select what I want... Like this:
frmMain.cboStarTag.Selecte
While frmMain.cboStarTag.Selecte
If frmMain.cboStatus.Text = "In-Repair" Then
e.Graphics.DrawString(frmM
e.Graphics.DrawString(frmM
e.Graphics.DrawString(frmM
e.Graphics.DrawString("N/A
e.Graphics.DrawString(frmM
e.Graphics.DrawString(frmM
sngPrintY += fntRegular.GetHeight + 2
RecordNo += 1
End If
If frmMain.cboStatus.Text = "Complete" And (DateDiff(DateInterval.Day
e.Graphics.DrawString(frmM
e.Graphics.DrawString(frmM
e.Graphics.DrawString(frmM
e.Graphics.DrawString(frmM
e.Graphics.DrawString(frmM
e.Graphics.DrawString(frmM
sngPrintY += fntRegular.GetHeight + 2
RecordNo += 1
End If
frmMain.cboStarTag.Selecte
If frmMain.cboStarTag.Selecte
Exit Sub
End If
End While
What is the filtering criteria? Is it by page? Should it only be done once, and not in every page?
Bob
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bob