Hy!
Class for direct print commands:
Public Class DATECS
Const strANS As String = "______,_,__;"
Private LDN As Short 'Logical Device Number
Private strLine As String
Private BillCtr As Integer
Dim noNbDec As New System.Globalization.NumberFormatInfo
Dim niDec As New System.Globalization.NumberFormatInfo
Dim threeDec As New System.Globalization.NumberFormatInfo
Public Sub New(ByVal strPath As String, ByVal LogicalDeviceNb As Short)
On Error GoTo errHandler
FileOpen(1, strPath, OpenMode.Output)
LDN = LogicalDeviceNb
BlockKeypad()
noNbDec.NumberDecimalDigits = 0
niDec.NumberDecimalDigits = 2
threeDec.NumberDecimalDigits = 3
Exit Sub
errHandler:
Err.Raise(Err.Number, "New DATECS", Err.Description)
End Sub
Public Sub BlockKeypad()
strLine = "H," & CStr(LDN) & ",______,_,__;"
PrintLine(1, strLine)
End Sub
Public Sub UnBlockKeypad()
strLine = "F," & CStr(LDN) & ",______,_,__;"
PrintLine(1, strLine)
End Sub
Public Sub AddProduct(ByVal productName As String, ByVal Qtyvar As Decimal, ByVal SalesValue As Decimal, ByVal SAIDvar As Integer, ByVal CatIDvar As Integer, ByVal VATGroup As Short)
strLine = "S," & CStr(LDN) & "," & strANS & Trim(Mid(productName, 1, 22)) & ";" & SalesValue.ToString("f", niDec) & ";" & Qtyvar.ToString("f", noNbDec) & ";" & CStr(SAIDvar) & ";" & CStr(CatIDvar) & ";" & CStr(VATGroup) & ";" & "0;0;"
PrintLine(1, strLine)
End Sub
Public Sub CashInOut(ByVal dSum As Decimal, Optional ByVal bWithdraw As Boolean = False)
Dim iCode As Integer = 1
'0 - cash IN
'1- cash OUT
On Error GoTo errHandler
If bWithdraw Then
iCode = 1 'cash out
Else
iCode = 0 'cash in
End If
strLine = "I," & CStr(LDN) & "," & strANS & iCode & ";" & dSum.ToString("f", niDec) & ";;;;"
PrintLine(1, strLine)
Exit Sub
errHandler:
MsgBox("Error nb: " & Err.Number & ", " & "Error desc.: " & Err.Description & ", Error src.: " & " WithdrawInput")
End Sub
Public Sub DiscountIncrease(ByVal dProcent As Decimal, Optional ByVal iCode As Integer = 1)
'0 -Increase
'1- Discount
strLine = "C," & CStr(LDN) & "," & strANS & iCode & ";" & dProcent.ToString("f", niDec) & ";;;;"
MsgBox(strLine)
PrintLine(1, strLine)
End Sub
Public Sub AddTextLine(ByVal T1 As String, Optional ByRef T2 As String = "", Optional ByRef T3 As String = "", Optional ByRef T4 As String = "", Optional ByRef T5 As String = "")
strLine = "P," & CStr(LDN) & "," & strANS & T1 & ";"
If Not IsDBNull(T2) Then strLine = strLine & T2 & ";"
If Not IsDBNull(T3) Then strLine = strLine & T3 & ";"
If Not IsDBNull(T4) Then strLine = strLine & T4 & ";"
If Not IsDBNull(T5) Then strLine = strLine & T5 & ";"
PrintLine(1, strLine)
End Sub
Public Sub Subtotal()
PrintLine(1, "T," & CStr(LDN) & "," & strANS & "4;;;;;")
'0 - cash
'1-ceck
'2-card
'3-ticket
'4 -subtotal
End Sub
Public Sub AddPayment(ByVal pmtType As Short)
PrintLine(1, "T," & CStr(LDN) & "," & strANS & CStr(pmtType) & ";;;;;")
End Sub
End Class
This is how you use this class:
Public Function DATECSFiscal() As String
Dim sHeader As String
Dim myBill As New DATECS
Dim c() As String
Dim SA As String = ""
Dim sSeparator As New StringBuilder()
Dim dQty As Decimal
Dim dPrice As Decimal
Dim dNetAmount As Decimal
Dim dInitialAmount As Decimal
Dim dSubTotal As Decimal
Dim iDepID As Integer = 1
Dim iGroupArt As Integer = 1
Dim dDiscount As Decimal
On Error GoTo errHandler
LDN = 1
BillCtr = CInt(dtData.Rows(0).Item(12))
myBill = New DATECS(BillINPPath, LDN, BillCtr)
SA = dtData.Rows(0).Item(10).ToString
myBill.AddTextLine(SA & " " & dtData.Rows(0).Item(11).ToString)
myBill.AddTextLine("Product Qty SubTotal")
sSeparator = New StringBuilder
sSeparator.Append("-", pLineSize)
myBill.AddTextLine(sSeparator.ToString)
dNetAmount = CDec(dtData.Rows(0).Item(15))
dInitialAmount = CDec(dtData.Rows(0).Item(13))
dDiscount = CDec(dtData.Rows(0).Item(14))
Dim drt As System.Data.DataRow
For Each drt In dtData.Rows
dQty = CDec(drt.Item(1).ToString())
dPrice = CDec(drt.Item(3).ToString)
dSubTotal = CDec(drt.Item(4).ToString)
iDepID = (CDec(drt.Item(17)) Mod maxDepNb) + 1
iGroupArt = (CDec(drt.Item(18)) Mod maxArtNb) + 1
myBill.AddProduct(Mid(Trim(drt.Item(2).ToString), 1, productLength), dQty, dPrice, iDepID, iGroupArt, 1)
Next
myBill.Subtotal()
If dDiscount > 0 Then
DiscountRate = (dDiscount / dInitialAmount) * 100
myBill.DiscountIncrease(DiscountRate)
End If
Select Case PmtModality
Case Is = 2 'Cash
myBill.AddPayment(0)
Case Is = 3 'Credit Card
myBill.AddPayment(2)
End Select
myBill.CloseFiscalBill()
myBill = Nothing
Dim pResult As String
pResult = RunPrinterProcess(AppDriverPath, Port & " 9600 """ & BillINPPath & "\Bill" & CStr(BillCtr) & ".INP""")
On Error Resume Next
FileClose(1)
End Function
Private Function RunPrinterProcess(ByVal sFileName As String, ByVal sArguments As String) As String
Try
RunPrinterProcess = "OK"
Dim oPro As New Process
With oPro
.StartInfo.UseShellExecute = True
.StartInfo.Arguments = sArguments '"COM1 9600 " & InpFilePath
.StartInfo.FileName = sFileName '' "C:\Program Files\Datecs Applications\FPrintWIN\FPrint.exe"
.Start()
End With
Catch ex As Exception
RunPrinterProcess = "Error nb: " & Err.Number & ", " & "Error desc.: " & Err.Description & ", Error src.: " & " RunPrinterProcess " & " FileName: " & sFileName & " , Arguments: " & sArguments
FileClose(1)
End Try
End Function
First you must have FPrint.exe installed on the pc where the software is, and the printer must be connected to this pc.
In the code above I create a file "C:\Bill1.inp" and then I create and start the process :
"C:\Program Files\Datecs Applications\FPrint WIN\FPrint.exe" COM1 9600"C:\Bill1.inp"
Your file looks like this:
H,1,______,_,__;1,0;
P,1,______,_,__;Salon Sa1;;;;;
P,1,______,_,__;Product Qty SubTotal;;;;;
P,1,______,_,__;----------------------;;;;;
S,1,______,_,__;Miere 10gr;1.00;1;2;1;1;0;0;
T,1,______,_,__,4;;;;;
My printer is Datecs MP55B ...but if you have another type ...the only thing that will change will be the commands (but you will find this in documentation of your printer)
There is another example of inp file (another printer model):
48,1,______,_,__;1;000000;0;
49,1,______,_,__;Gherkins;0.05;1.000;5;0;0;0;
49,1,______,_,__;Gherkins;-0.05;1.000;5;0;0;0;
49,1,______,_,__;Potatoes;0.02;1.000;2;0;0;0;
49,1,______,_,__;Potatoes;-0.02;1.000;2;0;0;0;
T,1,______,_,__;
For testing, you have to enter in programming mode in cash register.
For Datecs MB55B I had to enter to cash register this:
ON
429 TOTAL
(or something like this...but you will find this in your cash register documentation also)
After testing you have to go back to sale mode.
The CashInOut and DiscountIncrease are not working...yet..I don't know why , because this is the sintax, I'm still testing..
If you must have this code in C:
http://www.developerfusion.com/tools/convert/vb-to-csharp/[
^]
Have a nice day!
Alina