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;
}
}