, , , . , . , , , , .
, , .
, ! , , , . ( - , ! , , , .)
: currentY, . itemperpage, totalnumber amount, ! , !
:
int itemsPerPage = 40;
int itemHeight = 25;
int totalNumber = -1;
int itemsToPrint = 75;
int itemsPrinted = 0;
int pagesPrinted = 0;
- , , , , . GraphicsUnit Display, 1/100 . , . , ! . ... , !
, : String.Format() string.PadLeft(). , , tostring()!
:
, , , ββ , , .
, DB: , , PrintPage. : : : while (...reader.Read() ), , implict: PrintPage - .
range(). , . . DataReader , PrintPage: , , .
, MySql, , MySql -prefix. . , , .
MySqlConnection DBC = new MySqlConnection("");
MySqlCommand CMD = null;
MySqlDataReader DR = null;
int range ()
{
CMD = new MySqlCommand("select count(0) from test.artists ", DBC);
var count = CMD.ExecuteScalar();
int counter = Convert.ToInt32(count);
CMD = new MySqlCommand("select artist_ID, artist, genres from test.artists ", DBC);
DR = CMD.ExecuteReader();
return (int)counter;
}
print, :
private void cb_print_Click(object sender, EventArgs e)
{
totalNumber = range();
try
{
if (DBC.State == ConnectionState.Open)
{
pagesPrinted = 0;
printPreviewDlg.Document = printDocument1;
printPreviewDlg.ShowDialog();
}
} catch (Exception q) { MessageBox.Show("" + q); }
DR.Dispose();
}
, Reader range!
, PrintPage:
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
int itemsOnPage = 0;
pagesPrinted++;
float currentY = 12;
e.Graphics.DrawString(String.Format(
"HEADER - printing {0} items of {1} - Page {2}",
itemsToPrint, totalNumber, pagesPrinted),
Font, Brushes.Black, 1, currentY);
currentY += 30;
try
{
while (itemsOnPage < itemsPerPage && itemsPrinted < itemsToPrint - 1
&& DR.Read())
{
string row = String.Format("{0,5:000} Artist: {1,20} ({2}) ",
DR[0], DR[1], DR[2]);
e.Graphics.DrawString(row, DefaultFont, Brushes.Black, 50, currentY);
currentY += itemHeight;
itemsPrinted++;
itemsOnPage++;
if ( itemsPrinted < itemsToPrint && itemsOnPage >= itemsPerPage)
{
itemsOnPage = 0;
e.HasMorePages = true;
return;
}
else
{
e.HasMorePages = false;
}
}
} catch (Exception ef)
{
MessageBox.Show("" + ef);
}
}