Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
1
Answer
Print receipt from pos printer and add datagrid values c#
Goran Bibic
6y
6.6k
1
Reply
Datagrid rows number, name, tax and price
Need to add values on receipt from datagrid
Some help?
<pre>
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 RACUN -\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;
//////////////////////////////////////////////////////////////////////////////////
HERE NEED TO ADD VALUES FROM DATAGRID....SOME HELP?
///////////////////////////////////////////////////////////////////////////////////
// ... 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);
}
}
} </pre>
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
can you share Database schema for bus booking system ASP.NET
String Function