Member 10296413
public partial class frmBook : Form
{
public const Int32 FILE_ATTRIBUTE_NORMAL = 128;//Intializing Port Attributes
public const Int32 INVALID_HANDLE_VALUE = -1;
public const Int32 GENERIC_READ = -2147483648;
public const Int32 GENERIC_WRITE = 1073741824;
public const Int32 CREATE_NEW = 1;
public const Int32 CREATE_ALWAYS = 2;
public const Int32 OPEN_EXISTING = 3;
protected void Print_Ticket(string ticketNo, string seatNo, string Showtime, string Price)
{
IntPtr ptr = CreateFile("LPT1", GENERIC_WRITE, 0,
IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero);
/* Is bad handle? INVALID_HANDLE_VALUE */
if (ptr.ToInt32() == -1)
{
/* ask the framework to marshall the win32 error code to an exception */
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
}
else
{
/////// Print Reciept Print//////
FileStream lpt = new FileStream(ptr, FileAccess.ReadWrite);
byte[] LineFeedChar = new byte[] { 13, 10 };
byte[] BackNormalChar = new byte[] { 27, 33, 0 };
byte[] CuttingChar = new byte[] { 29, 86, 66 };
Byte[] buf_TheaterName = new Byte[8048];
Byte[] buf_Address = new Byte[8048];
Byte[] buf_Line1 = new Byte[8048];
Byte[] buf_TicketNo = new Byte[8048];
Byte[] buf_Date = new Byte[8048];
Byte[] buf_SeatNo = new Byte[8048];
Byte[] buf_Showtime = new Byte[8048];
Byte[] buf_Price = new Byte[8048];
Byte[] buf_FooterMsg = new Byte[8048];
StringBuilder strFooter = new StringBuilder();
lpt.Write(CuttingChar, 0, 3); //
buf_TheaterName = System.Text.Encoding.ASCII.GetBytes(" " + cmbTheatre.Text.ToString() + " ");
lpt.Write(buf_TheaterName, 0, buf_TheaterName.Length);
lpt.Write(LineFeedChar, 0, 2);
buf_TicketNo = System.Text.Encoding.ASCII.GetBytes("Ticket No :".PadLeft(9) + ticketNo.PadLeft(3));//
lpt.Write(buf_TicketNo, 0, buf_TicketNo.Length);//
lpt.Write(LineFeedChar, 0, 2);
buf_Date = System.Text.Encoding.ASCII.GetBytes("Date :".PadLeft(9) + dteBookDate.Text.PadLeft(3));
lpt.Write(buf_Date, 0, buf_Date.Length);
lpt.Write(LineFeedChar, 0, 2);
buf_SeatNo = System.Text.Encoding.ASCII.GetBytes("Seat No :".PadLeft(9) + seatNo.PadLeft(3));
lpt.Write(buf_SeatNo, 0, buf_SeatNo.Length);
lpt.Write(LineFeedChar, 0, 2);
buf_Showtime = System.Text.Encoding.ASCII.GetBytes("Show Time :".PadLeft(9) + Showtime.PadLeft(3));
lpt.Write(buf_Showtime, 0, buf_Showtime.Length);
lpt.Write(LineFeedChar, 0, 2);
buf_Price = System.Text.Encoding.ASCII.GetBytes("Price :".PadLeft(9) + Price.PadLeft(3));
lpt.Write(buf_Price, 0, buf_Price.Length);
lpt.Write(LineFeedChar, 0, 2);
buf_FooterMsg = System.Text.Encoding.ASCII.GetBytes(" Thank You Visit Agin ");
lpt.Write(buf_FooterMsg, 0, buf_FooterMsg.Length);
lpt.Write(LineFeedChar, 0, 2);
lpt.Write(CuttingChar, 0, 3);
lpt.Write(BackNormalChar, 0, 3);
lpt.Close();
}
}