B
Brent White
I am probably too dense to figure it out for myself, so I am asking
here. I am writing an ASP.NET page in VB.NET 2005 that will allow a
user to scan (using a Windows CE based scanner with IE trying to
impersonate a Windows XP session) items to an order, then print to a
network printer. I had some great help from vbCity in how to print
the document. From a PC running Windows XP, it works great. From the
scanner, which does not have a LAN login, it works until the page
tries to output the text string to the printer.
This is the page's VB code:
Imports System.Data.SqlClient
Imports System.Data
Imports System.String
Imports System.Drawing.Printing
Imports System.Drawing
Partial Public Class WebForm1
Inherits System.Web.UI.Page
Dim quantity As Long
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.TextBox1.Focus()
End Sub
Private WithEvents myprinter As New PrintDocument()
Private Sub myPrinter_PrintPage(ByVal sender As Object, ByVal e As
PrintPageEventArgs) Handles myprinter.PrintPage
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim printFont = New Font("Courier New", 10)
Dim sb As StringBuilder = New StringBuilder()
Dim SQLCN As New SqlConnection
("server=JOMAR;uid=reports;pwd=reports;database=ee8idbbd")
Dim SQLCOMM As New SqlCommand
Dim sqlrs As SqlDataReader
SQLCN.Open()
SQLCOMM.Connection = SQLCN
SQLCOMM.CommandType = CommandType.StoredProcedure
SQLCOMM.CommandText = "bdg_procSalesOrder"
SQLCOMM.Parameters.AddWithValue("@ORDERNUMBER", Session
("OrderNumber"))
sqlrs = SQLCOMM.ExecuteReader
sb.Append("ORDER #:" + Session("OrderNumber") + " " +
"DateTime: " + DateTime.Now.ToString() + Environment.NewLine +
Environment.NewLine)
sb.Append(" " + "STYLE " + "QUANTITY " +
"PRICE " + "TOTAL " + Environment.NewLine +
Environment.NewLine)
While sqlrs.Read
sb.Append("LINE " + sqlrs(1).ToString.PadRight(5 - Len
(sqlrs(1).ToString)) + sqlrs(2).ToString.PadRight(14 - Len(sqlrs
(2).ToString)) + sqlrs(3).ToString.PadRight(14 - Len(sqlrs
(3).ToString)) + Format(sqlrs(4).ToString, "Currency").PadRight(14 -
Len(Format(sqlrs(4).ToString, "Currency"))) + Format(sqlrs
(5).ToString, "Currency").PadRight(14 - Len(Format(sqlrs(5).ToString,
"Currency"))) + Environment.NewLine + Environment.NewLine)
End While
e.Graphics.DrawString(sb.ToString(), printFont, Brushes.Black,
leftMargin, topMargin)
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim sqlcn As New SqlConnection
("server=JOMAR;uid=reports;pwd=reports;database=ee8idbbd")
Dim sqlcomm As New SqlCommand
Dim sqlprice As New SqlCommand
Dim ERROUT As Long
sqlcn.Open()
If Left(Me.TextBox1.Text, 1) = "S" Then
'Response.Write("NEW STYLE")
'Dim stringresult As String
Try
sqlcomm.Connection = sqlcn
sqlcomm.CommandText = "bdg_fillgsorder"
sqlcomm.CommandType = CommandType.StoredProcedure
sqlcomm.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
sqlcomm.Parameters.AddWithValue("@ORDER_NUMBER",
Session("OrderNumber"))
sqlcomm.Parameters.AddWithValue("@ORDER_LINE", Session
("LineNumber"))
sqlcomm.Parameters.AddWithValue("@QUANTITY", Session
("quantity"))
sqlcomm.Parameters.AddWithValue("@UnitPrice", Session
("PRICE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
sqlcomm.ExecuteNonQuery()
Session("STYLE") = Right(Me.TextBox1.Text, Len
(Me.TextBox1.Text) - 1)
sqlprice.Connection = sqlcn
sqlprice.CommandText = "bdg_GSPricing"
sqlprice.CommandType = CommandType.StoredProcedure
sqlprice.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
Dim oNum As Double
oNum = (sqlprice.ExecuteScalar())
' stringresult = oNum.ToString
Session("PRICE") = oNum
'Session("LineNumber") = Session("LineNumber") + 1
Session("quantity") = 0
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Catch EX As Exception
Response.Write("Invalid Style")
errout = 1
'Beep()
Finally ' Session("STYLE") = null
If ERROUT = 0 Then
Session("LineNumber") = Session("LineNumber") + 1
Session("quantity") = 0
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Else
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
End If
'Server.Transfer("Style.aspx")
End Try
ElseIf Me.TextBox1.Text = "END" Then
Response.Write("Finished")
sqlcomm.Connection = sqlcn
sqlcomm.CommandText = "bdg_fillgsorder"
sqlcomm.CommandType = CommandType.StoredProcedure
sqlcomm.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
sqlcomm.Parameters.AddWithValue("@ORDER_NUMBER", Session
("OrderNumber"))
sqlcomm.Parameters.AddWithValue("@ORDER_LINE", Session
("LineNumber"))
sqlcomm.Parameters.AddWithValue("@QUANTITY", Session
("quantity"))
sqlcomm.Parameters.AddWithValue("@UnitPrice", Session
("PRICE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
sqlcomm.ExecuteNonQuery()
sqlcn.Close()
myprinter.PrinterSettings.PrinterName = "\
\195.1.2.222\hp3"
myprinter.Print()
Server.Transfer("Default.aspx", True)
ElseIf Not IsNumeric(Me.TextBox1.Text) Then
Response.Write("Invalid Number")
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Else
Session("quantity") = Session("quantity") + CLng
(Me.TextBox1.Text)
Response.Write(Session("Quantity").ToString + " UNITS OF
STYLE " + Session("STYLE").ToString)
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
End If
End Sub
End Class
When I run this code on the PC, I get a print out (not the prettiest
printout but that's something different) on the printer \
\195.1.2.222\hp3
Do the same thing on the scanner, you scan the barcode "END" and it
gets the error:
InvalidPrinterException
The error message on the screen says that the settings to access
printer '\\195.1.2.222\hp3' are not valid (I turned off the custom
error page...it's an intranet webpage, anyway).
I see some instructions on how to do this, but they are very vague.
The IIS runs on a Windows 2000 Advanced Server box. If I could put a
new instance of IIS and register it on a 2003 box this quickly, I
would, but I fear it will interfere with other applications running on
the box.
Can someone please enlighten me with specifics on how to do this? I
would greatly appreciate it.
here. I am writing an ASP.NET page in VB.NET 2005 that will allow a
user to scan (using a Windows CE based scanner with IE trying to
impersonate a Windows XP session) items to an order, then print to a
network printer. I had some great help from vbCity in how to print
the document. From a PC running Windows XP, it works great. From the
scanner, which does not have a LAN login, it works until the page
tries to output the text string to the printer.
This is the page's VB code:
Imports System.Data.SqlClient
Imports System.Data
Imports System.String
Imports System.Drawing.Printing
Imports System.Drawing
Partial Public Class WebForm1
Inherits System.Web.UI.Page
Dim quantity As Long
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.TextBox1.Focus()
End Sub
Private WithEvents myprinter As New PrintDocument()
Private Sub myPrinter_PrintPage(ByVal sender As Object, ByVal e As
PrintPageEventArgs) Handles myprinter.PrintPage
Dim leftMargin As Single = e.MarginBounds.Left
Dim topMargin As Single = e.MarginBounds.Top
Dim printFont = New Font("Courier New", 10)
Dim sb As StringBuilder = New StringBuilder()
Dim SQLCN As New SqlConnection
("server=JOMAR;uid=reports;pwd=reports;database=ee8idbbd")
Dim SQLCOMM As New SqlCommand
Dim sqlrs As SqlDataReader
SQLCN.Open()
SQLCOMM.Connection = SQLCN
SQLCOMM.CommandType = CommandType.StoredProcedure
SQLCOMM.CommandText = "bdg_procSalesOrder"
SQLCOMM.Parameters.AddWithValue("@ORDERNUMBER", Session
("OrderNumber"))
sqlrs = SQLCOMM.ExecuteReader
sb.Append("ORDER #:" + Session("OrderNumber") + " " +
"DateTime: " + DateTime.Now.ToString() + Environment.NewLine +
Environment.NewLine)
sb.Append(" " + "STYLE " + "QUANTITY " +
"PRICE " + "TOTAL " + Environment.NewLine +
Environment.NewLine)
While sqlrs.Read
sb.Append("LINE " + sqlrs(1).ToString.PadRight(5 - Len
(sqlrs(1).ToString)) + sqlrs(2).ToString.PadRight(14 - Len(sqlrs
(2).ToString)) + sqlrs(3).ToString.PadRight(14 - Len(sqlrs
(3).ToString)) + Format(sqlrs(4).ToString, "Currency").PadRight(14 -
Len(Format(sqlrs(4).ToString, "Currency"))) + Format(sqlrs
(5).ToString, "Currency").PadRight(14 - Len(Format(sqlrs(5).ToString,
"Currency"))) + Environment.NewLine + Environment.NewLine)
End While
e.Graphics.DrawString(sb.ToString(), printFont, Brushes.Black,
leftMargin, topMargin)
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim sqlcn As New SqlConnection
("server=JOMAR;uid=reports;pwd=reports;database=ee8idbbd")
Dim sqlcomm As New SqlCommand
Dim sqlprice As New SqlCommand
Dim ERROUT As Long
sqlcn.Open()
If Left(Me.TextBox1.Text, 1) = "S" Then
'Response.Write("NEW STYLE")
'Dim stringresult As String
Try
sqlcomm.Connection = sqlcn
sqlcomm.CommandText = "bdg_fillgsorder"
sqlcomm.CommandType = CommandType.StoredProcedure
sqlcomm.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
sqlcomm.Parameters.AddWithValue("@ORDER_NUMBER",
Session("OrderNumber"))
sqlcomm.Parameters.AddWithValue("@ORDER_LINE", Session
("LineNumber"))
sqlcomm.Parameters.AddWithValue("@QUANTITY", Session
("quantity"))
sqlcomm.Parameters.AddWithValue("@UnitPrice", Session
("PRICE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
sqlcomm.ExecuteNonQuery()
Session("STYLE") = Right(Me.TextBox1.Text, Len
(Me.TextBox1.Text) - 1)
sqlprice.Connection = sqlcn
sqlprice.CommandText = "bdg_GSPricing"
sqlprice.CommandType = CommandType.StoredProcedure
sqlprice.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
Dim oNum As Double
oNum = (sqlprice.ExecuteScalar())
' stringresult = oNum.ToString
Session("PRICE") = oNum
'Session("LineNumber") = Session("LineNumber") + 1
Session("quantity") = 0
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Catch EX As Exception
Response.Write("Invalid Style")
errout = 1
'Beep()
Finally ' Session("STYLE") = null
If ERROUT = 0 Then
Session("LineNumber") = Session("LineNumber") + 1
Session("quantity") = 0
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Else
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
End If
'Server.Transfer("Style.aspx")
End Try
ElseIf Me.TextBox1.Text = "END" Then
Response.Write("Finished")
sqlcomm.Connection = sqlcn
sqlcomm.CommandText = "bdg_fillgsorder"
sqlcomm.CommandType = CommandType.StoredProcedure
sqlcomm.Parameters.AddWithValue("@STYLE", Session
("STYLE"))
sqlcomm.Parameters.AddWithValue("@ORDER_NUMBER", Session
("OrderNumber"))
sqlcomm.Parameters.AddWithValue("@ORDER_LINE", Session
("LineNumber"))
sqlcomm.Parameters.AddWithValue("@QUANTITY", Session
("quantity"))
sqlcomm.Parameters.AddWithValue("@UnitPrice", Session
("PRICE"))
'sqlcomm.Parameters(0).SqlDbType = SqlDbType.VarChar
'sqlcomm.Parameters(0).Size = 15
'sqlcomm.Parameters(0).Direction =
ParameterDirection.Output
sqlcomm.ExecuteNonQuery()
sqlcn.Close()
myprinter.PrinterSettings.PrinterName = "\
\195.1.2.222\hp3"
myprinter.Print()
Server.Transfer("Default.aspx", True)
ElseIf Not IsNumeric(Me.TextBox1.Text) Then
Response.Write("Invalid Number")
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Else
Session("quantity") = Session("quantity") + CLng
(Me.TextBox1.Text)
Response.Write(Session("Quantity").ToString + " UNITS OF
STYLE " + Session("STYLE").ToString)
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
End If
End Sub
End Class
When I run this code on the PC, I get a print out (not the prettiest
printout but that's something different) on the printer \
\195.1.2.222\hp3
Do the same thing on the scanner, you scan the barcode "END" and it
gets the error:
InvalidPrinterException
The error message on the screen says that the settings to access
printer '\\195.1.2.222\hp3' are not valid (I turned off the custom
error page...it's an intranet webpage, anyway).
I see some instructions on how to do this, but they are very vague.
The IIS runs on a Windows 2000 Advanced Server box. If I could put a
new instance of IIS and register it on a 2003 box this quickly, I
would, but I fear it will interfere with other applications running on
the box.
Can someone please enlighten me with specifics on how to do this? I
would greatly appreciate it.