Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Datagrid rows number, name, tax and price

 

Need to add values on receipt from datagrid to PrintReceiptPage

Some help?


What I have tried:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace POS_TEST
{
    public partial class Form1 : Form
    {
        public static string barKod = "";
        public static string osobaIme = "";
        public static string datumUlaska = "";
        public static string osobaFirma = "";


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            BarCodePrint.PrintReceiptForTransaction(barKod, osobaComboBox.Text, vrijemePrijavePicker.Value.ToString("dd.MM.yyyy. HH:mm:00"), firmaComboBox.Text);

        }


        private static void PrintReceiptPage(object sender, PrintPageEventArgs e)
        {

        }

        class BarCodePrint
        {
            public static string barKod = "";
            public static string osobaIme = "";
            public static string datumUlaska = "";
            public static string osobaFirma = "";
            public static void PrintReceiptForTransaction(string bK, string osoba, string datum, string firma)
            {
                barKod = bK;
                osobaIme = osoba;
                datumUlaska = datum;
                osobaFirma = firma;
                PrintDocument recordDoc = new PrintDocument();

                recordDoc.DocumentName = "BarKod gosta";
                recordDoc.PrintPage += new PrintPageEventHandler(BarCodePrint.PrintReceiptPage); // function below
                recordDoc.PrintController = new StandardPrintController(); // hides status dialog popup
                                                                           // Comment if debugging 
                PrinterSettings ps = new PrinterSettings();
                ps.PrinterName = "POS-58";
                recordDoc.PrinterSettings = ps;
                recordDoc.Print();
                // --------------------------------------
                // Uncomment if debugging - shows dialog instead
                //PrintPreviewDialog printPrvDlg = new PrintPreviewDialog();
                //printPrvDlg.Document = recordDoc;
                //printPrvDlg.Width = 1200;
                //printPrvDlg.Height = 800;
                //printPrvDlg.ShowDialog();
                // --------------------------------------
                recordDoc.Dispose();

            }





            private static void PrintReceiptPage(object sender, PrintPageEventArgs e)
            {
                float x = 10;
                float y = 5;
                float width = 170.0F; // max width I found through trial and error
                float height = 0F;

                Font drawFontArial12Bold = new Font("Arial", 10, FontStyle.Bold);
                Font drawFontArial11Regular = new Font("Arial", 8, FontStyle.Regular);
                Font drawFontArial7Regular = new Font("Arial", 8, FontStyle.Regular);
                Font drawFontArial7Italic = new Font("Arial", 8, FontStyle.Italic);
                SolidBrush drawBrush = new SolidBrush(Color.Black);

                // Set format of string.
                StringFormat drawFormatCenter = new StringFormat();
                drawFormatCenter.Alignment = StringAlignment.Center;
                StringFormat drawFormatLeft = new StringFormat();
                drawFormatLeft.Alignment = StringAlignment.Near;
                StringFormat drawFormatRight = new StringFormat();
                drawFormatRight.Alignment = StringAlignment.Far;

                // Draw string to screen.

                string text = "T.R. LAD S.P.";
                e.Graphics.DrawString(text, drawFontArial12Bold, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial12Bold).Height;

                text = "22. BRIGADE VRS, Kotor Varoš";
                e.Graphics.DrawString(text, drawFontArial7Italic, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial7Italic).Height;

                text = "- MALOPRODAJNI RAČUN -\n";
                e.Graphics.DrawString(text, drawFontArial11Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial11Regular).Height;



                text = " ";
                e.Graphics.DrawString(text, drawFontArial11Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial11Regular).Height;
                text = " ";
                e.Graphics.DrawString(text, drawFontArial11Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial11Regular).Height;


                text = " ";
                e.Graphics.DrawString(text, drawFontArial11Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial11Regular).Height;



                // ... and so on

                //BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
                //Image barCodeImeage = bdraw.Draw(barKod, 60);
                //Console.WriteLine(x + " " + y + " " + width + " " + height);
                //e.Graphics.DrawImage(barCodeImeage, new RectangleF(x, y, width, 60));
                //y += 65;
                //Console.WriteLine(barCodeImeage.Size);

                text = osobaIme;
                e.Graphics.DrawString(text, drawFontArial11Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial11Regular).Height;

                //text = osobaFirma;
                //e.Graphics.DrawString(text, drawFontArial7Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                //y += e.Graphics.MeasureString(text, drawFontArial7Regular).Height;


                text = "----------------------------------------";
                e.Graphics.DrawString(text, drawFontArial7Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial7Regular).Height;

                text = "Datum: " + DateTime.Now.ToString();
                e.Graphics.DrawString(text, drawFontArial7Italic, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial7Italic).Height;



                text = "----------------------------------------";
                e.Graphics.DrawString(text, drawFontArial7Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial7Regular).Height;


                text = "HVALA VAM NA POSJETI";
                e.Graphics.DrawString(text, drawFontArial7Regular, drawBrush, new RectangleF(x, y, width, height), drawFormatCenter);
                y += e.Graphics.MeasureString(text, drawFontArial7Regular).Height;
            }
        }

        private void roba_uslugeBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.roba_uslugeBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.lAD_2019DataSet);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'lAD_2019DataSet.roba_usluge' table. You can move, or remove it, as needed.
            this.roba_uslugeTableAdapter.Fill(this.lAD_2019DataSet.roba_usluge);

        }
    }
}
Posted
Comments
Richard MacCutchan 21-Jan-19 12:13pm    
Some help? With what? You need to explain where in your code the problem occurs, and exact details of what is not working.
Goran Bibic 21-Jan-19 12:57pm    
private static void PrintReceiptPage

Here need to put values number, name, tax and price from datagrid

Some help?
[no name] 21-Jan-19 16:28pm    
"Grid" and "data" are not the same thing.

My dog watches (the) TV; I watch a "program" (i.e. data). You don't tell someone just to "watch TV".

What / where's your "data"?
j snooze 21-Jan-19 17:17pm    
Once your data is in the datagrid you can usually loop through the rows in the datagrid and grab the cell values by column.
Just search the internet for looping through datagrid rows and columns you'll get something like
foreach(DataGridRow row in MyDataGridName.Rows)
{
row[columnIndex or Fieldname].Value
}

That should get you through the grid to grab the values. Obviously that is not exact syntax, just some pseudo code to help get you started. I'm also assuming the data is already in the datagrid, you just want to know how to get at it to put it on the receipt.
Goran Bibic 22-Jan-19 2:42am    
Yes. Thats right. Data is in datagrid, just need to add on invoice

Data column on Datagrid rows are number, name, tax and price

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900