Link to home
Start Free TrialLog in
Avatar of dumpsterdivingdave
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("StarTag" + 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.SelectedIndex = 0
        While frmMain.cboStarTag.SelectedIndex < frmMain.cboStarTag.Items.Count
            e.Graphics.DrawString(frmMain.txtStarTag.Text + ControlChars.Tab + frmMain.txtLastName.Text + ControlChars.Tab + _
                ControlChars.Tab + frmMain.dtpStartDate.Value.Date.ToString + ControlChars.Tab + frmMain.cboStatus.Text + _
                ControlChars.Tab + frmMain.txtAgent.Text, fntRegular, Brushes.Black, sngPrintX, sngPrintY)
            sngPrintY += fntRegular.GetHeight + 2
            If frmMain.cboStarTag.SelectedIndex = (frmMain.cboStarTag.Items.Count - 1) Then
                Exit Sub
            End If
            frmMain.cboStarTag.SelectedIndex += 1
        End While
        frmMain.dbaBlackhole.Fill(frmMain.dsBlackhole.Progress)
        frmMain.dbaQuery.Fill(frmMain.dsQuery.Progress)
        frmMain.dbaBlackhole.FillBy(frmMain.dsBlackhole.Progress, "Complete")
        frmMain.dbaQuery.FillBy(frmMain.dsQuery.Progress, "Complete")
        frmMain.cboStarTag.SelectedIndex = 0
        While frmMain.cboStarTag.SelectedIndex < frmMain.cboStarTag.Items.Count
            If frmMain.dtpFinishDate.Value.Day = System.DateTime.Today.Day Then
            e.Graphics.DrawString(frmMain.txtStarTag.Text + ControlChars.Tab + frmMain.txtLastName.Text + ControlChars.Tab + _
                ControlChars.Tab + frmMain.dtpStartDate.Value.Date.ToString + ControlChars.Tab + frmMain.cboStatus.Text + _
                ControlChars.Tab + frmMain.txtAgent.Text, fntRegular, Brushes.Black, sngPrintX, sngPrintY)
            sngPrintY += fntRegular.GetHeight + 2
            End If
            If frmMain.cboStarTag.SelectedIndex = (frmMain.cboStarTag.Items.Count - 1) Then
                Exit Sub
            End If
            frmMain.cboStarTag.SelectedIndex += 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.Value.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?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Where is this code running from?  A Paint event handler?

Bob
Avatar of dumpsterdivingdave
dumpsterdivingdave

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
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.FillBy(frmMain.dsBlackhole.Progress, "In-Repair")
frmMain.dbaQuery.FillBy(frmMain.dsQuery.Progress, "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
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.SelectedIndex = 0
        While frmMain.cboStarTag.SelectedIndex < frmMain.cboStarTag.Items.Count
            If frmMain.cboStatus.Text = "In-Repair" Then
                e.Graphics.DrawString(frmMain.cboStarTag.Text, fntRegular, Brushes.Black, sngPrintX, sngPrintY)
                e.Graphics.DrawString(frmMain.txtLastName.Text, fntRegular, Brushes.Black, sngPrintX + 100, sngPrintY)
                e.Graphics.DrawString(frmMain.dtpStartDate.Value.Date, fntRegular, Brushes.Black, sngPrintX + 200, sngPrintY)
                e.Graphics.DrawString("N/A", fntRegular, Brushes.Black, sngPrintX + 300, sngPrintY)
                e.Graphics.DrawString(frmMain.cboStatus.Text, fntRegular, Brushes.Black, sngPrintX + 400, sngPrintY)
                e.Graphics.DrawString(frmMain.txtAgent.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.Value.Date) = 0) Then
                e.Graphics.DrawString(frmMain.cboStarTag.Text, fntRegular, Brushes.LimeGreen, sngPrintX, sngPrintY)
                e.Graphics.DrawString(frmMain.txtLastName.Text, fntRegular, Brushes.LimeGreen, sngPrintX + 100, sngPrintY)
                e.Graphics.DrawString(frmMain.dtpStartDate.Value.Date, fntRegular, Brushes.LimeGreen, sngPrintX + 200, sngPrintY)
                e.Graphics.DrawString(frmMain.dtpFinishDate.Value.Date, fntRegular, Brushes.LimeGreen, sngPrintX + 300, sngPrintY)
                e.Graphics.DrawString(frmMain.cboStatus.Text, fntRegular, Brushes.LimeGreen, sngPrintX + 400, sngPrintY)
                e.Graphics.DrawString(frmMain.txtAgent.Text, fntRegular, Brushes.LimeGreen, sngPrintX + 500, sngPrintY)
                sngPrintY += fntRegular.GetHeight + 2
                RecordNo += 1
            End If
            frmMain.cboStarTag.SelectedIndex += 1
            If frmMain.cboStarTag.SelectedIndex = (frmMain.cboStarTag.Items.Count - 1) Then
                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
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial