🔒 Closed Pahelp Gawa ng Resibo sa c#

Status
Not open for further replies.
PAHELP PO PANO KO GAGAWING RECEIPT YUNG MGA NASA DATA GRID VIEW?
1621147884451.webp

1621147928137.webp
 
[XX='PHC-Minchi, c: 1205801, m: 857057'][/XX]

First to do is learn how to get all values from datagrid.
[CODE title="Layout & Print Receipt"]using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Drawing;

namespace TicketingSystem
{
public class Ticket
{
PrintDocument pdoc = null;
int ticketNo;
DateTime TicketDate;
String Source, Destination,DrawnBy;
float Amount;

public int TicketNo
{
//set the person name
set { this.ticketNo = value; }
//get the person name
get { return this.ticketNo; }
}
public DateTime ticketDate
{
//set the person name
set { this.TicketDate = value; }
//get the person name
get { return this.TicketDate; }
}

public String source
{
//set the person name
set { this.Source = value; }
//get the person name
get { return this.Source; }
}
public String destination
{
//set the person name
set { this.Destination = value; }
//get the person name
get { return this.Destination; }
}
public float amount
{
//set the person name
set { this.Amount = value; }
//get the person name
get { return this.Amount; }
}
public String drawnBy
{
//set the person name
set { this.DrawnBy = value; }
//get the person name
get { return this.DrawnBy; }
}

public Ticket()
{

}
public Ticket(int ticketNo, DateTime TicketDate, String Source,
String Destination, float Amount, String DrawnBy)
{
this.ticketNo = ticketNo;
this.TicketDate = TicketDate;
this.Source = Source;
this.Destination = Destination;
this.Amount = Amount;
this.DrawnBy = DrawnBy;
}
public void print()
{
PrintDialog pd = new PrintDialog();
pdoc = new PrintDocument();
PrinterSettings ps = new PrinterSettings();
Font font = new Font("Courier New", 15);


PaperSize psize = new PaperSize("Custom", 100, 200);
//ps.DefaultPageSettings.PaperSize = psize;

pd.Document = pdoc;
pd.Document.DefaultPageSettings.PaperSize = psize;
//pdoc.DefaultPageSettings.PaperSize.Height =320;
pdoc.DefaultPageSettings.PaperSize.Height = 820;

pdoc.DefaultPageSettings.PaperSize.Width = 520;

pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);

DialogResult result = pd.ShowDialog();
if (result == DialogResult.OK)
{
PrintPreviewDialog pp = new PrintPreviewDialog();
pp.Document = pdoc;
result = pp.ShowDialog();
if (result == DialogResult.OK)
{
pdoc.Print();
}
}

}
void pdoc_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics graphics = e.Graphics;
Font font = new Font("Courier New", 10);
float fontHeight = font.GetHeight();
int startX = 50;
int startY = 55;
int Offset = 40;
graphics.DrawString("Welcome to MSST", new Font("Courier New", 14),
new SolidBrush(Color.Black), startX, startY + Offset);
Offset = Offset + 20;
graphics.DrawString("Ticket No:" + this.TicketNo,
new Font("Courier New", 14),
new SolidBrush(Color.Black), startX, startY + Offset);
Offset = Offset + 20;
graphics.DrawString("Ticket Date :" + this.ticketDate,
new Font("Courier New", 12),
new SolidBrush(Color.Black), startX, startY + Offset);
Offset = Offset + 20;
String underLine = "------------------------------------------";
graphics.DrawString(underLine, new Font("Courier New", 10),
new SolidBrush(Color.Black), startX, startY + Offset);

Offset = Offset + 20;
String Source= this.source;
graphics.DrawString("From "+Source+" To "+Destination, new Font("Courier New", 10),
new SolidBrush(Color.Black), startX, startY + Offset);

Offset = Offset + 20;
String Grosstotal = "Total Amount to Pay = " + this.amount;

Offset = Offset + 20;
underLine = "------------------------------------------";
graphics.DrawString(underLine, new Font("Courier New", 10),
new SolidBrush(Color.Black), startX, startY + Offset);
Offset = Offset + 20;

graphics.DrawString(Grosstotal , new Font("Courier New", 10),
new SolidBrush(Color.Black), startX, startY + Offset);
Offset = Offset + 20;
String DrawnBy = this.drawnBy;
graphics.DrawString("Conductor - "+DrawnBy, new Font("Courier New", 10),
new SolidBrush(Color.Black), startX, startY + Offset);
}
}
}
[/CODE]

the top part is the model. learn to send datagrid data to model. and get all data from model and put in this code.
Model.
Public Class Ticket.
Public Void Print (printing settings)
The actual layout code to be printed.

Source.
Codeproject . com

Keyword.
Simple-Receipt-Like-Printing-Using-the-Csharp-Prin
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 1K
    Views
  • 2
    Participants
Last reply from:
PHC-Minchi

Online now

Members online
989
Guests online
787
Total visitors
1,776

Forum statistics

Threads
2,275,621
Posts
28,964,488
Members
1,231,885
Latest member
xbim101
Back
Top