private void SetInvoiceData(Graphics g, System.Drawing.Printing.PrintPageEventArgs e)
{
string FieldValue = "";
int CurrentRecord = 0;
int RecordsPerPage = 20;
decimal Amount = 0;
bool StopReading = false;
int xItems = leftMargin;
CurrentY = CurrentY + InvoiceFontHeight;
g.DrawString("Items", InvoiceFont, BlueBrush, xItems, CurrentY);
int xQty = xItems + (int)g.MeasureString("Items", InvoiceFont).Width + 4;
g.DrawString("Qty", InvoiceFont, BlueBrush, xQty, CurrentY);
int xPrice = xQty + (int)g.MeasureString("Qty", InvoiceFont).Width + 72;
g.DrawString("Price", InvoiceFont, BlueBrush, xPrice, CurrentY);
int xSubTotal = xPrice + (int)g.MeasureString("Price", InvoiceFont).Width + 4;
g.DrawString("SubTotal", InvoiceFont, BlueBrush, xSubTotal, CurrentY);
AmountPosition = xSubTotal + (int)g.MeasureString("SubTotal", InvoiceFont).Width + 4;
CurrentY = CurrentY + InvoiceFontHeight + 8;
while (CurrentRecord < RecordsPerPage)
{
foreach (DataGridViewRow row in itemgridview.Rows)
{
FieldValue = row.Cells[0].Value.ToString();
g.DrawString(FieldValue, InvoiceFont, BlackBrush, xItems, CurrentY);
FieldValue = row.Cells[1].Value.ToString();
if (FieldValue.Length > 20)
FieldValue = FieldValue.Remove(20, FieldValue.Length - 20);
g.DrawString(FieldValue, InvoiceFont, BlackBrush, xQty, CurrentY);
FieldValue = row.Cells[2].Value.ToString();
g.DrawString(FieldValue, InvoiceFont, BlackBrush, xPrice, CurrentY);
FieldValue = row.Cells[3].Value.ToString();
g.DrawString(FieldValue, InvoiceFont, BlackBrush, xSubTotal, CurrentY);
CurrentY = CurrentY + InvoiceFontHeight;
if (itemgridview.Rows.Count.ToString() == null)
{
StopReading = true;
break;
}
else
{
CurrentRecord++;
}
}
}