Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I am trying to print on multiple pages but I can not seem to be able to get it right.

I have a while loop that is pulling info from a database (the results of an SQL search).

I know where the bottom of the page is so I added this:

(line > maxPage)
{
e.hasMorePages(true);
line = 0;
}
else
{
e.hasMorePages(false);
}

 

However, I do not get a new page. It prints over the original.

 

If anyone has any ideas I would be very grateful.

 

Thanks,

Harold Clements

 

(Please note that I am using J# but I can translate answers in C# or VB.NET.)

Posted (edited)

The whole method

 

What event do you have that code in? Will need to see more code...

 

Sorry, yes the whole method looks like this:

 

Thanks for you help, Harold.

 

private void printBOM(System.Drawing.Printing.PrintPageEventArgs e)
{
            Brush b = new SolidBrush(Color.get_Black());
Brush br = new SolidBrush(Color.get_LightGray());
Font f = new Font("Courier New", 9, FontStyle.Regular);
	
String sql = "SELECT ComponentPart, ComponentID, ComponentDescription, ManufactureShortForm, " + //0-3
	"ComponentShortForm, ManufacturePartNumber, ComponentQuantity, ComponentIdent, " + //4-7
	"tblKitParts.EngineeringChangeNoteID " + //8
             "FROM tblKitParts, tblComponent, tblManufacture, tblComponentType " +
	"WHERE MotherLevel = " + partNo + " " +
	"AND ComponentID = ComponentPart " + 
	"AND ManufactureID = ManufactureCode " +
	"AND tblComponentType.ComponentTypeID = tblComponent.ComponentType ";

try
{	
	int k = 0; //not used 
             x = minX; //reset X position
	OleDbCommand oc = new OleDbCommand(sql, myConnection);

	myConnection.Open();	
	OleDbDataReader dr = oc.ExecuteReader();

	while (dr.Read())
	{
		k ++; 
		//Different colour for each line printed
		if (k % 2 == 0) {br = new SolidBrush(Color.get_LightGray());}
		else {br = new SolidBrush (Color.get_WhiteSmoke());}
		x = minX; 
		e.get_Graphics().FillRectangle(br, x, y, maxX, cr); //Print solid blocks
		e.get_Graphics().DrawString(System.Convert.ToString(dr.GetInt32(0)), f, b, x, y);
		x += 45;
		e.get_Graphics().DrawString(dr.GetString(4), f, b, x, y);
		x += 45;
		e.get_Graphics().DrawString(dr.GetString(2), f, b, x, y);
		x += 320;
		e.get_Graphics().DrawString(System.Convert.ToString(dr.GetInt32(6)), f, b, x, y);
		x += 45;
		e.get_Graphics().DrawString(dr.GetString(3), f, b, x, y);
		x += 45;
		if (dr.IsDBNull(5)) {e.get_Graphics().DrawString("", f, b, x, y);}
		else {e.get_Graphics().DrawString(dr.GetString(5), f, b, x, y);}
		x += 320;
		if (dr.IsDBNull(8)) {e.get_Graphics().DrawString("", f, b, x, y);}
		else e.get_Graphics().DrawString(getECNData(dr.GetInt32(8)), f, b, x, y);
			
		getAlternative(e, dr.GetInt32(0), partNo, br);
			
		x = minX; //Reset X Position
		e.get_Graphics().FillRectangle(br, x, y, maxX, cr); //Print blocks
		e.get_Graphics().DrawString("Locations:", f, b, x, y);
		x += 90;
		if (dr.IsDBNull(7)) {e.get_Graphics().DrawString("", f, b, x, y);}
		else {e.get_Graphics().DrawString(dr.GetString(7), new Font("Courier New", 9, FontStyle.Bold), b, x, y);}
		y += cr; //Next line
			
		if ((y+(cr*2)) >= maxY) 
		{
			e.set_HasMorePages(true);
			y = minY;
		}
		else {e.set_HasMorePages(false);}
	}
	myConnection.Close();
}
catch (Exception error)
{
	MessageBox.Show (error.toString() + extraErrorInfo, "Exception Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (System.InvalidOperationException error)
{
	MessageBox.Show (error.toString() + extraErrorInfo, "InvalidOperationException Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (System.Data.OleDb.OleDbException error)
{
	MessageBox.Show (error.toString() + extraErrorInfo, "OleDbException Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (System.NullReferenceException error)
{
	MessageBox.Show (error.toString() + extraErrorInfo, "NullReferenceException Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
	x = minX; //Reset X.
	y += 8;   //Move page down.
	e.get_Graphics().DrawLine(new System.Drawing.Pen(Color.get_Blue(), 1), //Blue line
	             new System.Drawing.Point(x, y),
		new System.Drawing.Point(maxX, y));
	e.get_Graphics().DrawString("*** End of Listing ***", 
		new Font("Courier New", 9, FontStyle.Bold),
		new SolidBrush(Color.get_Black()), x, y+3);
	y = minY;
	x = minX;
}
}

Edited by haroldjclements

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...