dcsimg
Results 1 to 4 of 4

Thread: How to retrieve a ticket for re-printing in VB.NET?

  1. #1

    Thread Starter
    Addicted Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    134

    How to retrieve a ticket for re-printing in VB.NET?

    Hello!

    I have an application that can preview & print a sales ticket, I'd like to know how do I retrieve the last ticket for re-printing? and how do I save these tickets for future retrieval?

    Thank you.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,168

    Re: How to retrieve a ticket for re-printing in VB.NET?

    That depends what constitutes a ticket and that is completely up to you. I would suggest that there are two main options.

    The first would be that you have one or more tables in your database for the data in a ticket and then you can retrieve that data and go through the same printing logic each. The second would be that you use the same GDI+ code you're currently using to print to draw onto a Bitmap object instead and then you can use a single call to DrawImage to do the printing. You can save that Bitmap as a file or in a database and reprint it as required.

    If you are going to use a database then I'd go the first option. An added advantage of that is that, should you change your output format in the future, any reprints will follow the new format. If you prefer a file per ticket then go with the second option.

  3. #3

    Thread Starter
    Addicted Member Spybot's Avatar
    Join Date
    Jan 2019
    Posts
    134

    Re: How to retrieve a ticket for re-printing in VB.NET?

    Hi jmc!

    Thanks for the reply.

    In my case I definitely op for the second one, since the data that goes in the ticket is created on the fly, is not in a table. So I've created an extra table in my database to save all this ticket stuff for later retrieval.

    I've read a couple of documents & several samples about "saving a Graphics object into a jpg or bmp" etc... but, at the end I just got my self even more confused.

    Some say it is not possible to directly convert a graphics object into a bitmap, they explain that it is a process to create a Bitmap object with the correct size to draw on, then create a Graphics for that bitmap and then save it.

    How exactly this is done? can you please provide a little sample on how to do that? I honestly don't know where to begin with.

    Also how exactly the data gets saved in the table?, So, I save it as type ____? since I'm using SQlite database, I didn't see an image type when creating my table columns.
    Last edited by Spybot; Jun 14th, 2019 at 05:56 PM.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,168

    Re: How to retrieve a ticket for re-printing in VB.NET?

    Quote Originally Posted by Spybot View Post
    I've read a couple of documents & several samples about "saving a Graphics object into a jpg or bmp" etc... but, at the end I just got my self even more confused.

    Some say it is not possible to directly convert a graphics object into a bitmap, they explain that it is a process to create a Bitmap object with the correct size to draw on, then create a Graphics for that bitmap and then save it.

    How exactly this is done? can you please provide a little sample on how to do that? I honestly don't know where to begin with.
    It's not a case of converting anything to anything else. GDI+ is implemented in Windows Forms via the Graphics class. Any Graphics object draws onto a GDI+ canvas. It's up to you to create a Graphics object from the appropriate canvas.

    At the moment, you are using e.Graphics in the PrintPage event handler of a PrintDocument object. That is a Graphics object created for you to draw on a printed page. The first step is to extract the code that uses the Graphics object into its own method and then call that method from the PrintPage event handler, passing in e.Graphics as an argument. The code won't change other than to separate it into two methods.

    Once you have a method that takes a Graphics object as an argument, you can call that method anywhere and pass it any Graphics object you want. That means that you can create a Bitmap object, call Graphics.FromImage to get a Graphics object to draw on it, then pass that Grpahics to your method. Now, instead of printing your data onto a printed page, you will draw it onto that Bitmap. You can then do whatever you like with that Bitmap, including save it to a file. In your PrintPage event handler, you would now make a single call to DrawImage to draw that Bitmap on the printed page.
    Quote Originally Posted by Spybot View Post
    Also how exactly the data gets saved in the table?, So, I save it as type ____? since I'm using SQlite database, I didn't see an image type when creating my table columns.
    You wouldn't store an image in the database. The image idea was if you weren't going to use a database. I was suggesting storing the text you are printing. It would be stored like any other text. If I remember correctly, on of the things you printing is a company name. In that case, your new table would need a CompanyName column. Etc. If you have an unknown number of list items to print then you'll need a related child table to store the list items. There's nothing different about this data than anything else you would store in a database.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width