On the page that I made, when you hit a button it should print some bar codes from the data you inputted into textboxes, and write them to the database. The problem is, it will only print when running from the local host (our server), but when we upload it to our customer's server, it wont print when we try it. Here is the code for the page.
3 1892
Imports System.Data
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices
Imports System.Web.Configuration
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Dim cnOper As String = "DSN=GDC"
Dim CustNo As String
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
CustNo = Request.QueryString("custno")
End Sub
Public Function OdbcGetDataReader(ByVal cnnString As String, _
ByVal selectTxt As String, _
ByRef retDatRdr As OdbcDataReader, _
ByRef errString As String) As Boolean
Dim return_status As Boolean = True
Dim connection As New OdbcConnection(cnnString)
Dim command As New OdbcCommand(selectTxt, connection)
Try
connection.Open()
retDatRdr = command.ExecuteReader(CommandBehavior.CloseConnect ion)
Catch exSQL As OdbcException
errString = exSQL.Message
return_status = False
Catch ex As Exception
errString = ex.Message
return_status = False
Finally
End Try
Return (return_status)
End Function
Public Sub PrintLPLabels(ByVal item As String, ByVal lot As String, ByVal qty As String, ByVal lp As String)
Dim pd As New PrintDocument
Dim str As New StringBuilder
str.Append("C" & Microsoft.VisualBasic.Chr(13))
str.Append("I9" & Microsoft.VisualBasic.Chr(13))
str.Append("P" & Microsoft.VisualBasic.Chr(13))
str.Append("E3;F3;" & Microsoft.VisualBasic.Chr(13))
str.Append("H1;f3;o1375,30;c25;b0;h23;w11;d3,Item " & Microsoft.VisualBasic.Chr(13))
str.Append("H2;f3;o1405,260;c25;b0;h40;w20;d3," & item & "" & Microsoft.VisualBasic.Chr(13))
str.Append("B3;f3;o1315,60;c6;w5;h110;d3," & item & "" & Microsoft.VisualBasic.Chr(13))
str.Append("H4;f3;o1100,30;c25;b0;h23;w11;d3,Lot Number" & Microsoft.VisualBasic.Chr(13))
str.Append("H5;f3;o1130,260;c25;b0;h40;w20;d3," & lot & "" & Microsoft.VisualBasic.Chr(13))
str.Append("B6;f3;o1040,60;c6;w5;h110;d3," & lot & "" & Microsoft.VisualBasic.Chr(13))
str.Append("H10;f3;o550,30;c25;b0;h23;w11;d3,Qty " & Microsoft.VisualBasic.Chr(13))
str.Append("H12;f3;o580,260;c25;b0;h40;w20;d3," & qty & " lbs." & Microsoft.VisualBasic.Chr(13))
str.Append("B11;f3;o490,60;c6;w5;h110;d3," & qty & "" & Microsoft.VisualBasic.Chr(13))
str.Append("H16;f3;o150,30;c25;b0;h23;w11;d3,LP" & Microsoft.VisualBasic.Chr(13))
str.Append("H17;f3;o160,260;c25;b0;h31;w15;d3," & lp & "" & Microsoft.VisualBasic.Chr(13))
str.Append("B18;f3;o90,60;c6;w3;h75;d3," & lp & "" & Microsoft.VisualBasic.Chr(13))
str.Append("R" & Microsoft.VisualBasic.Chr(13))
str.Append("E3,1" & Microsoft.VisualBasic.Chr(13))
str.Append("1" & Microsoft.VisualBasic.Chr(13))
str.Append("1" & Microsoft.VisualBasic.Chr(13))
str.Append("" & Microsoft.VisualBasic.Chr(13))
str.Append("P" & Microsoft.VisualBasic.Chr(13))
str.Append("E3;" & Microsoft.VisualBasic.Chr(13))
str.Append("R" & Microsoft.VisualBasic.Chr(13))
Dim t As String
pd.PrinterSettings = New PrinterSettings
pd.PrinterSettings.PrinterName = pd.PrinterSettings.PrinterName
t = str.ToString
clsPrintLabels.SendStringToPrinter(pd.PrinterSetti ngs.PrinterName, t)
End Sub
Public Class clsPrintLabels
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Structure DOCINFOW
<MarshalAs(UnmanagedType.LPWStr)> Public pDocName As String
<MarshalAs(UnmanagedType.LPWStr)> Public pOutputFile As String
<MarshalAs(UnmanagedType.LPWStr)> Public pDataType As String
End Structure
<DllImport("winspool.Drv", EntryPoint:="OpenPrinterW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As Integer, ByVal pd As Integer) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="ClosePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(ByVal hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="StartDocPrinterW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StartDocPrinter(ByVal hPrinter As IntPtr, ByVal level As Int32, ByRef pDI As DOCINFOW) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="EndDocPrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EndDocPrinter(ByVal hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="StartPagePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StartPagePrinter(ByVal hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="EndPagePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function EndPagePrinter(ByVal hPrinter As IntPtr) As Boolean
End Function
<DllImport("winspool.Drv", EntryPoint:="WritePrinter", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function WritePrinter(ByVal hPrinter As IntPtr, ByVal pBytes As IntPtr, ByVal dwCount As Int32, ByRef dwWritten As Int32) As Boolean
End Function
<DllImport("kernel32.dll", EntryPoint:="GetLastError", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=False, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function GetLastError() As Int32
End Function
Public Shared Function SendBytesToPrinter(ByVal szPrinterName As String, ByVal pBytes As IntPtr, ByVal dwCount As Int32) As Boolean
Dim hPrinter As IntPtr
Dim dwError As Int32 .
Dim di As DOCINFOW).
Dim dwWritten As Int32
Dim bSuccess As Boolean
With di
.pDocName = "My Visual Basic .NET RAW Document"
.pDataType = "RAW"
End With
bSuccess = False
Try
If OpenPrinter(szPrinterName, hPrinter, 0) = True Then
If StartDocPrinter(hPrinter, 1, di) Then
If StartPagePrinter(hPrinter) Then
bSuccess = WritePrinter(hPrinter, pBytes, dwCount, dwWritten)
EndPagePrinter(hPrinter)
End If
EndDocPrinter(hPrinter)
End If
ClosePrinter(hPrinter)
End If
Catch ex As Exception
End Try
If bSuccess = False Then
dwError = GetLastError()
End If
Return bSuccess
End Function
Public Shared Function SendFileToPrinter(ByVal szPrinterName As String, ByVal szFileName As String) As Boolean
Dim fs As New FileStream(szFileName, FileMode.Open)
Dim br As New BinaryReader(fs)
Dim bytes(fs.Length) As Byte
Dim bSuccess As Boolean
Dim pUnmanagedBytes As IntPtr
bytes = br.ReadBytes(fs.Length)
pUnmanagedBytes = Marshal.AllocCoTaskMem(fs.Length)
Marshal.Copy(bytes, 0, pUnmanagedBytes, fs.Length)
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, fs.Length)
Marshal.FreeCoTaskMem(pUnmanagedBytes)
Return bSuccess
End Function ' SendFileToPrinter()
Public Shared Function SendStringToPrinter(ByVal szPrinterName As String, ByVal szString As String)
Dim pBytes As IntPtr
Dim dwCount As Int32
dwCount = szString.Length()
pBytes = Marshal.StringToCoTaskMemAnsi(szString)
SendBytesToPrinter(szPrinterName, pBytes, dwCount)
Marshal.FreeCoTaskMem(pBytes)
End Function
End Class
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim x As Integer
For x = 1 To txttoprint.Text
Dim updat As New OdbcCommand
Dim ins As New OdbcCommand
Dim cn As New OdbcConnection(cnOper)
updat.CommandText = "Update config set lp_num = lp_num+1 where Company='GDC Warehousing'"
updat.Connection = cn
cn.Open()
updat.ExecuteNonQuery()
cn.Close()
Dim idr As IDataReader
Dim strsql, strerr As String
strsql = "Select lp_num from config where Company='GDC Warehousing'"
If OdbcGetDataReader(cnOper, strsql, idr, strerr) = False Then
Exit Sub
End If
Dim lp As Integer
While idr.Read
lp = idr.Item("lp_num")
End While
Dim newlp As String
newlp = "L" & lp
Dim newdate As String
Dim yy As String = Today.Year
Dim dd As String = Today.Day
Dim mm As String = Today.Month
newdate = yy & "," & mm & "," & dd
ins.CommandText = "Insert Into wimstr " & "(wi_whse,wi_loc,wi_item,wi_lot,wi_qty,wi_date,wi_ zone,wi_lp,wi_pick,wi_cycchk,wi_sublot,wi_usdef1,w i_ordno,wi_status,wi_memo,wi_history,wi_custno,wi_ pallqty,wi_defrate) values ('INTR', 'INTR', '" & txtitem.Text & "','" & txtlot.Text & "'," & txtquantity.Text & ", Date(" & newdate & "), 'INTR','" & newlp & "','','','','','','','','','" & CustNo & "',0,0)"
ins.Connection = cn
cn.Open()
ins.ExecuteNonQuery()
cn.Close()
lblText.Text = "Record Added"
PrintLPLabels(txtitem.Text, txtlot.Text, txtquantity.Text, newlp)
Next
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jody Gelowitz |
last post by:
I am trying to find the definition of "Safe Printing" and cannot find out
exactly what this entitles. The reason is that I am trying to print
contents from a single textbox to no avail using the...
|
by: Suzanka |
last post by:
Hello,
I have an application written in C# on visual studio .NET. It is a web
aplication.
The application consists of many different forms, that users
occassionaly want to print out for filing....
|
by: Arif |
last post by:
I C# code prints very slow as compared to a third party barcode printing
software. That software prints approximately 10 labels in 2 seconds while my
C# code prints 10 labels in 5 to 6 seconds. And...
|
by: Jody Gelowitz |
last post by:
I am trying to find the definition of "Safe Printing" and cannot find out
exactly what this entitles. The reason is that I am trying to print
contents from a single textbox to no avail using the...
|
by: Jody Gelowitz |
last post by:
I am trying to find the definition of "Safe Printing" and cannot find out
exactly what this entitles. The reason is that I am trying to print
contents from a single textbox to no avail using the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |