7
Answers

Printing a sales bill using dotmatrix printer

ullas K

ullas K

13y
19.6k
1
Hi,
    I am developing a windows application project for a super market.Now i want to create a sales bill .I need  ITEM NAME,QTY,RATE,AMOUNT as Columns. I should enter the item name ,qty, rate and amount .For this which control should i use in c#.net and how can i print the contents of that control through a dotmatrix printer to make printing faster.The bill format which i expect to be printed out is should be like what i have shown below

                                           ABC SUPERMARKET
                                           No/10,Ammankovil street
                                            Chennai
-------------------------------------------------------------------------------------------------------------------------------------------

Bill NO : 1                                                        Date: 12/12/2012
-------------------------------------------------------------------------------------------------------------------------------------------
Sl.No        Item Name          Qty              Rate              Amount
-------------------------------------------------------------------------------------------------------------------------------------------
  1           xyz              2               120.00            240.00
  2           abc              1               500.00            500.00
  3                   asd                          3                           100.00                    300.00
-------------------------------------------------------------------------------------------------------------------------------------------
  Total :                                                                                                      1040.00

Please provide me the code to do this.I have asked this question many times but nobody has given me a right solution.I do not want a printdialog to appear first and then go for printing as this will be tedious process in a crowdy supermarket where continous bill printing is to be made

Thanks in advance

Ullas
Answers (7)
0
ullas K

ullas K

NA 55 0 13y
Thank u Kedar very much .Sure.i will reply u if i get a solution.Hope u will let me know if u too get a solution
0
kedar pawgi

kedar pawgi

NA 105 38.3k 13y
Hi Shaju..
what i feel is solution to your problem is you will have to send the sql query output to a text file...or when u do the data entery in datagrid view u will have write a code on save button to send the details to a text file. First do the process of saving the record and take that Id from master table and take all the sales items from details table do the query and send that whole date to a text file.. i am searching solution to print to a text file.. i have to do the same thing..i know how to do the query and all...i m searching for code to print to a text file..if ur using data set then ur job is quiet easy.. i am using ADODB so i not getting how to do that...i have some idea.. if ur using dataset then u can do it directly using "writeline" and streamwrite object. U try that else if i got solution i will send u the code..or another thing is u can do with crystalreportviewer. Its also easy way to do...but still u will have to use two button on that and then send that report to text file...
Hope u got idea... surely i will get solution soon. i will reply u...You can direct send to print and u can view it also..with "process.start("abc.txt")"  and if u need more info about this u can check following site...http://www.dotnetperls.com/process-start
this is good one..reply if u got any solution..of sending query to txt file.
so that it will help me too..
0
Frogleg

Frogleg

NA 7.9k 33k 13y
0
ullas K

ullas K

NA 55 0 13y
I do not know whether you have understood what i have asked for.What i have shown above is just a sample of the sales bill which i should get printed through a dotmatrix printer.My question is how can i get a printout just in the same format as i have shown above when i click the print button.In my application i am entering all these data's on a datagridview with columns Sl.no,Item Name,Qty,Rate and Amount.And at last i am also calculating the Total .In short i should get the contents of this datagridview printed in the above format through  a dotmatrix printer for making printing fast.
0
Frogleg

Frogleg

NA 7.9k 33k 13y
What I did was create a form with 2 buttons, printDocument1 and a printPreviewDialog1.
One button was called print, the other print preview (the latter just to make sure everything looked OK before printing.
I copied the supermarket text from above into "test.txt" file which resides in bin/debug folder

here is code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace SuperMarketPrint
{
    public partial class Form1 : Form
    {
        string str;
        Font myFont = new Font("Arial", 10);
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            readTxt();
        }

        public void readTxt()
        {

            using (StreamReader sr = new StreamReader("test.txt"))
            {
                str = sr.ReadToEnd();
       
            }

        }
        private void bttnPrint_Click(object sender, EventArgs e)
        {
            printDocument1.Print();
        }

        private void bttnPreview_Click(object sender, EventArgs e)
        {

            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();
              
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawString(str, myFont, Brushes.Black, 100, 10);
        }
             

     
    }
}
0
ullas K

ullas K

NA 55 0 13y
Thanks for your support.But the problem is that i cannot open the project file you provided because i think it is done in a higher version of Visual studio.I am using VS2005 and VS2008.So when i am trying to open it is saying the file is created in a higher version
0
Frogleg

Frogleg

NA 7.9k 33k 13y
See if this helps