Posted by: Sourav | September 26, 2016

A practical example of queue class,Vb Teacher Sourav,Kolkata 09748184075


<form id=”form1″ runat=”server”>

Counter 1 Counter 2 Counter 3

</form>

 

Public Class WebForm1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If (Session(“TokenQueue”)) Is Nothing Then
Dim queuetokens As Queue(Of Integer) = New Queue(Of Integer)

Session(“TokenQueue”) = queuetokens

End If
End Sub

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
Dim tokenQueue As Queue(Of Integer) = (DirectCast(Session(“TokenQueue”), Queue(Of Integer)))

Label1.Text = “There are ” + tokenQueue.Count.ToString() + ” customers before you in the queue”
‘Label1.Text = “hello”
If Session(“lastTokenNumberIssued”) Is Nothing Then
Session(“lastTokenNumberIssued”) = 0
End If

Dim nextTokenNumberToIssue As Integer = CInt(Session(“lastTokenNumberIssued”)) + 1
Session(“lastTokenNumberIssued”) = nextTokenNumberToIssue
tokenQueue.Enqueue(nextTokenNumberToIssue)

addtokenslistbox(tokenQueue)

End Sub
Private Sub addtokenslistbox(ByVal tokenqueue As Queue(Of Integer))

ListBox1.Items.Clear()
For Each i As Integer In tokenqueue
ListBox1.Items.Add(i.ToString)

Next
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
servenextcustomer(TextBox1, 1)
End Sub
Private Sub servenextcustomer(ByVal textbox As TextBox, ByVal counternumber As Integer)
Dim tokenQueue As Queue(Of Integer) = (DirectCast(Session(“TokenQueue”), Queue(Of Integer)))
If tokenQueue.Count <= 0 Then
TextBox4.Text = “No customers in the queue”
textbox.Text = “”
Else
Dim tokennumbertobeserved As Integer = tokenQueue.Dequeue
textbox.Text = tokennumbertobeserved
TextBox4.Text = “Token number : ” + tokennumbertobeserved.ToString + ” ,Please go to Counter ” + counternumber.ToString
addtokenslistbox(tokenQueue)
End If
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
servenextcustomer(TextBox2, 2)
End Sub

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
servenextcustomer(TextBox3, 3)
End Sub
End Class

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: