VB.NET example

The VB.NET example is based on a solution named Custom Label Generator.sln, which is used to create a simple web application able to handle Pierbridge Label Requests and generate custom labels accordingly. This solution can be modified to match the requirements of each project. The solution consists of the following files:

  • CustomLabelGenerator.aspx
  • CustomLabelParameters.vb
  • LogFile.vb
  • Web.config

The CustomLabelGenerator.aspx consists of the main logic of the custom label generator. Without any modifications the label generator will receive a request from the system, which includes the data from Pierbridge Label Request, append these to the appropriate thermal code and send back the custom label content. The label type is chosen based on the Format parameter, which is received with the label request.

Access request properties

Top

The Pierbridge Label Request data will be stored in a number of CustomLabelParameters, which provide an easy access to each individual field through a property. If necessary, access to these parameters can be obtained by:

Dim parameters As New CustomLabelParameters(Request.Form)
parameters.PurchaseOrderNumber

An exception to accessing label properties is the Field1 though to Field20 parameters. These can be obtained by using a GetField(‘fieldName’) method:

Dim field As String = parameters.GetField("Field1")

Adding custom parameters

Top

If additional data is required it can be looked up from any data source. In the examples, these are the Shipping Order Header and Shipping Order Line Items tables. The connection details are stored in the Web.config file and should be modified accordingly.

<connectionStrings>
	<add name="LabelGeneratorConnectionString" connectionString="Data Source=DEVSPL;Initial Catalog=My Database;User ID=usr;Password=pwd"/>
</connectionStrings>

TThe example below shows how a value passed in through the Pierbridge Label Request in Field1 is used as a condition to look up a Record Key One value from Shipping Line Items table. ShipmentID and PackageID parameters are also available for CustomLabel types through Pierbridge Ship Request.

Dim filter As String = parameters.GetField("Field1")
Dim columnName As String = "Record Key One"
Dim columnValue As String = String.Empty

Required conditions or multiple return values should be added similarly to the sample below:

Dim Query As New StringBuilder
Query.Append("SELECT [Shipping Order Line Items].[" + columnName + "]")
Query.Append("FROM [Shipping Order Line Items] ")
Query.Append("JOIN [Shipping Order Header] ")
Query.Append("ON [Shipping Order Line Items].[Shipping Order Header ID] = [Shipping Order Header].[ID] ")
Query.Append("WHERE [Shipping Order Header].ID = ")
Query.Append(filter)

Creating thermal labels

Top

Based on the requested label format the required thermal label type is selected:

If parameters.Format = CustomLabelParameters.OutputFormat.Eltron Then label.Append("N")
	...
ElseIf parameters.Format = CustomLabelParameters.OutputFormat.Zebra Then label.Append("f165")
	...
ElseIf parameters.Format = CustomLabelParameters.OutputFormat.Datamax Then label.Append("~SD20")
	...
Else
	logFile.WriteLogToFile("Label format is not supported by label generator")
End If

Both Request and custom parameters are added to all labels using parameter properties:

label.Append("A85,240,0,4,1,1,N," + parameters.ReceiverName)
label.Append("A85,270,0,4,1,1,N," + parameters.ReceiverCompany)
label.Append("A85,300,0,4,1,1,N," + parameters.ReceiverAddress1)
label.Append("A10,430,0,4,1,1,N," + "ADDITIONAL INFO")
label.Append("A85,430,0,4,1,1,N," + columnValue)

Multiple labels

Top

If a single custom label generator is used to produce multiple labels these can be identified by using the available CustomLabelName parameter and configured in the Administration App Data > Reference Data > Custom Labels.

Multiple labels with a same CustomLabelName can also be added to a single thermal label by creating anumber of labels one after another:

‘label 1
label.Append("N")
label.Append("OD10")
label.Append("q812")
label.Append("Q1218,24")
label.Append("D15")
label.Append("ZB")
label.Append("A10,30,0,1,1,1,N," + "FROM")
label.Append("A85,30,0,1,1,1,N," + parameters.SenderName);
label.Append("P1")
label.Append("N")

‘label 2
label.Append("N")
label.Append("OD10")
label.Append("q812")
label.Append("Q1218,24")
label.Append("D15")
label.Append("ZB")
label.Append("A10,30,0,1,1,1,N," + "FROM")
label.Append("A85,30,0,1,1,1,N," + parameters.SenderName)
label.Append("P1")
label.Append("N")

Error logging

Top

The label generator uses a log file for error logging in case any error occurs. The error messages are written in a log file. The error log path is configured in the Web.config file and should be modified to match the installation. Error messages are customizable and can be changed:

LogFile.WriteLogToFile("No Data returned with: filter: " + filter + ", column name: " + columnName + " ." + ex.Message)
Article last edited 30 April 2021