0
My question is, can I generate a report (I don’t know if I can call it that):
Report: Date of payment
Client: xxxxxx xxx xxx xxxx
Payment date: xx/xx/xxxx
Signing
It would be a very simple layout basically what I did above without using database anyway, would fill the values and print what is filled and end.
The layout of the program is this:
How can I do that? And if it is possible, because I researched some and did not understand very well, since my Visualstudio does not have the CrystalReports
UPDATE
Class Print.Cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Impressao
{
public static class Funcoes
{
/// <summary>
/// Gera a impressão de um texto
/// </summary>
/// <param name="_textoImpressao">string para impressão</param>
/// <param name="_font">Fonte da impressão</param>
/// <param name="_impressora">Nome da impressora, informar null ou "" para padrão do windows</param>
public static void ImprimirString(string _textoImpressao, Font _font, string _impressora)
{
string[] linhas = _textoImpressao.Split('\n');
Queue<string> filaLinhas = new Queue<string>();
foreach (string l in linhas)
{
filaLinhas.Enqueue(l);
}
PrintDocument p = new PrintDocument();
p.PrintPage += delegate (object sender1, PrintPageEventArgs ev)
{
Font printFont = _font;
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
//Calcular o número de linhas por página
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
// Imprime cada linha do texto
while (count < linesPerPage && filaLinhas.Count > 0)
{
line = filaLinhas.Dequeue();
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black, 0, yPos, new StringFormat());
count++;
}
// Se existir mais linhas, gera outra página.
if (line != null && filaLinhas.Count > 0)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
};
PrintDialog diag = new PrintDialog();
diag.Document = p;
diag.PrinterSettings.PrinterName = _impressora;
if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
p.Print();
}
}
}
}
Print Generate button: (I try to call the class but don’t think)
private void button1_Click(object sender, EventArgs e)
{
Impressao b = new Impressao();
DateTime dataPagamento = DateTime.Now;
string clienteNome = "Fulano da Silva Sauro";
string texto = "Relatório de Pagamento" + "\n";
texto += "Cliente: " + clienteNome + "\n";
texto += "Data Pagamento: " + dataPagamento.ToString("dd/MM/yyyy HH:mm");
FuncoesImprimir.ImprimirString(texto, new Font("Consolas", 12f, FontStyle.Regular), null);
}
How will you print ? "normal" printer, matricial, dual (Thermal) ?
– Rovann Linhalis
In a normal printer, sheet A4, what I need is to open the report with the data filled already put to print and end
– WSS
your command should look something like
Impressao.Funcoes.ImprimirString(..);
– Rovann Linhalis
See how it looks, it doesn’t seem to find
– WSS
Ata understood, now stopped.. I was trying to instantiate the class, but doing as I said gave,
– WSS