EDN Admin
Well-known member
I am currently building an application in Visual Studio that uses a populated Listbox. Based on the selection made, it should narrow records in the table to only show records containing the matching field.
Once that selection has been made, a button will be pressed to print these records individually (I am using a thermal printer with 1.2x1.2" labels). Each label should contain the information from a single row, and then print the following row on the
next label, until all have been printed.
Right now, I have the Print button setup so that it will print the format I want on the label successfully. Now it is a matter of populating the textboxes with the data, printing it, and moving to the next.
The table "JDA" contains the following fields:
Store<br/>
SKU<br/>
Vendor Name<br/>
Vendor VSN<br/>
Description<br/>
MSRP<br/>
Price<br/>
Change<br/>
Section<br/>
Row<br/>
Quantity<br/>
<br/>
The listbox filters all records based on the Store field. The textboxes that should be printed reflect the: SKU, Vendor VSN, Vendor Name, Description, Price, MSRP. Also, the quantity field needs to somehow be implemented so that it knows how many
of a particular record need to be printed.
This is the part I am having trouble with.
Here is my code so far:
<pre class="prettyprint lang-vb Option Strict On
Option Explicit On
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
StoreManagement.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.StoresTableAdapter3.Fill(Me.JDADS.Stores)
Me.JDATableAdapter1.Fill(Me.JDADS.JDA)
Dim storeNums = From dr As JDADS.StoresRow In JDADS.Stores _
Select dr.StoreNum Distinct Order By StoreNum
For Each storeNum As Double In storeNums
ListBox1.Items.Add(storeNum.ToString)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
Dim userSelectedStoreNum As Double = -1
If Not Double.TryParse(ListBox1.Items(ListBox1.SelectedIndex).ToString, userSelectedStoreNum) Then
Throw New Exception("Something Went Wrong!")
Else
Dim qry = From dr As JDADS.JDARow In JDADS.JDA _
Where dr.store = userSelectedStoreNum
Stop
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
PrintDocument1.PrinterSettings.Copies = 1
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString(SKUTextBox.Text, SKUTextBox.Font, Brushes.Black, 25, 12)
e.Graphics.DrawString(SKULabel.Text, SKULabel.Font, Brushes.Black, 6, 12)
e.Graphics.DrawString(VTextBox.Text, VTextBox.Font, Brushes.Black, 85, 12)
e.Graphics.DrawString(VLabel.Text, VLabel.Font, Brushes.Black, 70, 12)
e.Graphics.DrawString(MfgTextBox.Text, MfgTextBox.Font, Brushes.Black, 20, 24)
e.Graphics.DrawString(MfgLabel.Text, MfgLabel.Font, Brushes.Black, 6, 24)
e.Graphics.DrawString(DescTextBox.Text, DescTextBox.Font, Brushes.Black, 6, 34)
e.Graphics.DrawString(MSRPTextBox.Text, MSRPTextBox.Font, Brushes.Black, 6, 60)
e.Graphics.DrawString(MSRPLabel.Text, MSRPLabel.Font, Brushes.Black, 6, 52)
e.Graphics.DrawString(PriceTextBox.Text, PriceTextBox.Font, Brushes.Black, 65, 60)
e.Graphics.DrawString(PriceLabel.Text, PriceLabel.Font, Brushes.Black, 65, 52)
e.Graphics.DrawString(SmBarcode.Text, SmBarcode.Font, Brushes.Black, 0, 85)
End Sub
End Class[/code]
<br/>
View the full article
Once that selection has been made, a button will be pressed to print these records individually (I am using a thermal printer with 1.2x1.2" labels). Each label should contain the information from a single row, and then print the following row on the
next label, until all have been printed.
Right now, I have the Print button setup so that it will print the format I want on the label successfully. Now it is a matter of populating the textboxes with the data, printing it, and moving to the next.
The table "JDA" contains the following fields:
Store<br/>
SKU<br/>
Vendor Name<br/>
Vendor VSN<br/>
Description<br/>
MSRP<br/>
Price<br/>
Change<br/>
Section<br/>
Row<br/>
Quantity<br/>
<br/>
The listbox filters all records based on the Store field. The textboxes that should be printed reflect the: SKU, Vendor VSN, Vendor Name, Description, Price, MSRP. Also, the quantity field needs to somehow be implemented so that it knows how many
of a particular record need to be printed.
This is the part I am having trouble with.
Here is my code so far:
<pre class="prettyprint lang-vb Option Strict On
Option Explicit On
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
StoreManagement.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.StoresTableAdapter3.Fill(Me.JDADS.Stores)
Me.JDATableAdapter1.Fill(Me.JDADS.JDA)
Dim storeNums = From dr As JDADS.StoresRow In JDADS.Stores _
Select dr.StoreNum Distinct Order By StoreNum
For Each storeNum As Double In storeNums
ListBox1.Items.Add(storeNum.ToString)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
Dim userSelectedStoreNum As Double = -1
If Not Double.TryParse(ListBox1.Items(ListBox1.SelectedIndex).ToString, userSelectedStoreNum) Then
Throw New Exception("Something Went Wrong!")
Else
Dim qry = From dr As JDADS.JDARow In JDADS.JDA _
Where dr.store = userSelectedStoreNum
Stop
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
PrintDocument1.PrinterSettings.Copies = 1
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString(SKUTextBox.Text, SKUTextBox.Font, Brushes.Black, 25, 12)
e.Graphics.DrawString(SKULabel.Text, SKULabel.Font, Brushes.Black, 6, 12)
e.Graphics.DrawString(VTextBox.Text, VTextBox.Font, Brushes.Black, 85, 12)
e.Graphics.DrawString(VLabel.Text, VLabel.Font, Brushes.Black, 70, 12)
e.Graphics.DrawString(MfgTextBox.Text, MfgTextBox.Font, Brushes.Black, 20, 24)
e.Graphics.DrawString(MfgLabel.Text, MfgLabel.Font, Brushes.Black, 6, 24)
e.Graphics.DrawString(DescTextBox.Text, DescTextBox.Font, Brushes.Black, 6, 34)
e.Graphics.DrawString(MSRPTextBox.Text, MSRPTextBox.Font, Brushes.Black, 6, 60)
e.Graphics.DrawString(MSRPLabel.Text, MSRPLabel.Font, Brushes.Black, 6, 52)
e.Graphics.DrawString(PriceTextBox.Text, PriceTextBox.Font, Brushes.Black, 65, 60)
e.Graphics.DrawString(PriceLabel.Text, PriceLabel.Font, Brushes.Black, 65, 52)
e.Graphics.DrawString(SmBarcode.Text, SmBarcode.Font, Brushes.Black, 0, 85)
End Sub
End Class[/code]
<br/>
View the full article