private void btmImprimir_Click(object sender, EventArgs e)
{
int lv;
Dominio.ImprimirRuta imRuta = new Dominio.ImprimirRuta();
for (lv = 0; lv < this.lvResultados.Items.Count; lv++)
{
imRuta = new Dominio.ImprimirRuta();
imRuta.NombreCalle = this.lvResultados.Items[lv].SubItems[0].Text.Trim();
imRuta.Altura = this.lvResultados.Items[lv].SubItems[1].Text.Trim();
imRuta.Comuna = this.lvResultados.Items[lv].SubItems[3].Text.Trim();
imRuta.Observacion = this.lvResultados.Items[lv].SubItems[2].Text.Trim();
imRuta.Fecha = this.lvResultados.Items[lv].SubItems[4].Text.Trim();
arregloRutas.Add(imRuta);
}
PaperSize carta = new PaperSize();
carta.RawKind = 1;
ImprimirRutas.DefaultPageSettings.PaperSize = carta;
ImprimirRutas.DocumentName = "Impresión del reporte";
ImprimirRutas.PrinterSettings.PrinterName = @"\\PROLIANT\Brother HL-6050D/DN series";
ImprimirRutas.Print();
}
private void ImprimirRutas_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
// MEMBRETE DE LA PAGINA
Pen myPen2 = new Pen(Color.Black);
myPen2.DashStyle = DashStyle.DashDotDot;
e.Graphics.DrawRectangle(myPen2, 3, 3, 800, 40);
e.Graphics.DrawString("CEMENTERIO METROPOLITANO LTDA. ", new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 10, 10, new StringFormat());
e.Graphics.DrawString("INFORME RUTAS DIARIAS: ", new Font("Courier", 8, FontStyle.Bold), Brushes.Black, 300, 10, new StringFormat());
e.Graphics.DrawString("FECHA: " + DateTime.Now.ToShortDateString(), new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 600, 10, new StringFormat());
// Encabezado de las columnas
e.Graphics.DrawString(clNombreCalle.Text, new Font("Courier", 10), Brushes.Black, 10, 50, new StringFormat());
e.Graphics.DrawString(this.clAltura.Text, new Font("Courier", 10), Brushes.Black, 200, 50, new StringFormat());
e.Graphics.DrawString(this.clComuna.Text, new Font("Courier", 10), Brushes.Black, 300, 50, new StringFormat());
e.Graphics.DrawString(this.clObservación.Text, new Font("Courier", 10), Brushes.Black, 500, 50, new StringFormat());
e.Graphics.DrawString(this.clObservación.Text, new Font("Courier", 10), Brushes.Black, 700, 50, new StringFormat());
// IMPRIMIMOS EL CONTENIDO
int saltoDeLinea = 100;
int linea = 120;
for (int i = 0; i < 45; i++)
{
try
{
Dominio.ImprimirRuta iRutas = (Dominio.ImprimirRuta)arregloRutas[contador];
if (iRutas != null)
{
MessageBox.Show(iRutas.NombreCalle);
e.Graphics.DrawString(contador.ToString(), new Font("Courier", 10, FontStyle.Regular), Brushes.Black, 2, saltoDeLinea, new StringFormat());
e.Graphics.DrawString(iRutas.NombreCalle, new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 10, saltoDeLinea, new StringFormat());
e.Graphics.DrawString(iRutas.Altura, new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 200, saltoDeLinea, new StringFormat());
e.Graphics.DrawString(iRutas.Comuna, new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 300, saltoDeLinea, new StringFormat());
e.Graphics.DrawString(iRutas.Observacion, new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 500, saltoDeLinea, new StringFormat());
e.Graphics.DrawString(iRutas.Fecha, new Font("Courier", 8, FontStyle.Regular), Brushes.Black, 700, saltoDeLinea, new StringFormat());
Pen myPen1 = new Pen(Color.Black);
myPen1.DashStyle = DashStyle.Solid;
e.Graphics.DrawLine(myPen1, 850, linea, 10, linea);
saltoDeLinea += 20;
linea += 20;
}
contador++;
}
catch (Exception exs)
{
e.HasMorePages = false; return;
}
}
//agregamos las nuevas paginas
try
{
if (arregloRutas[contador + 1] != null)
{
e.HasMorePages = true;
e.Graphics.DrawString("PASA A LA SIGUIENTE PAGINA ...", new Font("Courier", 6, FontStyle.Regular), Brushes.Black, 600, 1023, new StringFormat());
}
else
{
e.HasMorePages = false;
}
}
catch (Exception ex)
{
e.HasMorePages = false;
}
}