By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,362 Members | 3,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,362 IT Pros & Developers. It's quick & easy.

Need some help badly! Please!!

P: n/a
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or
comments on how to make this work I would be grateful! I have been working
on this for the past 4 days and nothing I do seems to get me any closer to
the solution. Below is a program that I am working on for a class project.
The original code was provided for us which is what I have below. What we
have to do is make the app run so that it allows the user to add additional
pizzas to the order form. I have tried making this go through a loop, add an
entry button for each pizza order but every time it calculates the order it
clears out what I have or won't display anything. Please can anyone give me
some help here????

Thank you!

Mike
'OBJECT DESCRIPTION SETTING

'ddlPizzaSize (default properties)

'chkPeperoni Text "Pepperoni"

'chkSausage Text "Sausage"

'chkGreenPeppers Text "Green Peppers"

'chkBlackOlives Text "Black Olives"

'chkHam Text "Ham"

'chkOnions Text "Onions"

'txtNewReleases Text (Empty)

'txtStandard Text (Empty)

'btnCalculate Text "Calculate Total
and Generate Coupon"

'lblInstructions Visable False

' Boarderstyle Double

' Text "Print
and cut out your coupon to save!"

' (The pnlCoupon below is a grid layout panel from the Toolbox's HTML
Section)

'lblOrderDesc Font X-small

'lblPizzaTotal Text "<p align="right">$0.00"

'lblMovieTotal Text "<p align="right">$0.00"

'lblSubTotal Text "<p align="right">$0.00"

'lblTax Text "<p align="right">$0.00"

'lblDelivery Text "<p align="right">$0.00"

'lblTotal Text "<p align="right">$0.00"

'

'lblDiscount Text "<p align="right">$0.00"

' ForeColor Red

'

'lblYourPrice Text "<p align="right">$0.00"

' ForeColor Red

' Font Larger

'

'lblExpDate Text "<p align="right"> Offer valid
through 04/01/9999

' Font Smaller

'

Public Class WebForm1

Inherits System.Web.UI.Page

'Business logic constants

Const MEDIUM_BASE_PRICE As Double = 8.99

Const LARGE_BASE_PRICE As Double = 10.99

Const GIGANTIC_BASE_PRICE As Double = 12.99

Const TOPPING_PRICE As Double = 0.99

Const STANDARD_VIDEO_PRICE As Double = 1.95

Const NEW_RELEASE_VIDEO_PRICE As Double = 2.95

Const DELIVERY_FEE As Double = 2.0

Const TAX_RATE As Double = 0.065

Const COUPON_DISCOUNT As Double = 0.1 '(10 Percent)

Const FREE_DELIVERY_AMOUNT As Double = 20

'HTML constants

Const HTML_LEFT_ALIGN As String = "<p align=""left""> "

Const HTML_RIGHT_ALIGN As String = "<p align=""right""> "

Const HTML_INDENT As String = "&nbsp &nbsp &nbsp &nbsp "

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim liNone, liMedium, liLarge, liGigantic As ListItem

'On first showing, fill ListBox, setExpDate and set Discount description

If Not IsPostBack Then

ddlPizzaSize.Items.Clear()

liNone = New ListItem

liNone.Text = "None"

liNone.Value = "None"

liMedium = New ListItem

liMedium.Text = "Medium (8"") -- " & FormatCurrency(MEDIUM_BASE_PRICE)

liMedium.Value = "Medium"

liLarge = New ListItem

liLarge.Text = "Large (10"")-- " & FormatCurrency(LARGE_BASE_PRICE)

liLarge.Value = "Large"

liGigantic = New ListItem

liGigantic.Text = "Gigantic (12"") -- " &
FormatCurrency(GIGANTIC_BASE_PRICE)

liGigantic.Value = "Gigantic"

ddlPizzaSize.Items.Add(liNone)

ddlPizzaSize.Items.Add(liMedium)

ddlPizzaSize.Items.Add(liLarge)

ddlPizzaSize.Items.Add(liGigantic)

ddlPizzaSize.SelectedIndex = 0

lblExpDate.Text = HTML_RIGHT_ALIGN & "Offer valid through " & _

FormatDateTime(Today().AddDays(7))

lblDiscountDesc.Text = FormatPercent(COUPON_DISCOUNT, 0) & " discount:"

End If

End Sub



Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalculate.Click

Dim Desc As String

Dim ToppingDesc As String

Dim HasToppingFlag As Boolean

Dim NewReleaseCount As Integer

Dim StandardCount As Integer

Dim Pizzas As Double

Dim Movies As Double

Dim SubTotal As Double

Dim DeliveryFee As Double

Dim Total As Double

Dim Discount As Double

Dim YourPrice As Double

'Build a string with HTML formatted text describing the order

Desc = ""

If ddlPizzaSize.SelectedItem.Value <> "None" Then

ToppingDesc = ""

HasToppingFlag = False

If chkPepperoni.Checked Then

ToppingDesc &= HTML_INDENT & "pepperoni <br>"

HasToppingFlag = True

End If

If chkSausage.Checked Then

ToppingDesc &= HTML_INDENT & "sausage <br>"

HasToppingFlag = True

End If

If chkHam.Checked Then

ToppingDesc &= HTML_INDENT & "ham <br>"

HasToppingFlag = True

End If

If chkBlackOlives.Checked Then

ToppingDesc &= HTML_INDENT & "black olives <br>"

HasToppingFlag = True

End If

If chkGreenPeppers.Checked Then

ToppingDesc &= HTML_INDENT & "green peppers <br>"

HasToppingFlag = True

End If

If chkOnions.Checked Then

ToppingDesc &= HTML_INDENT & "onions <br>"

HasToppingFlag = True

End If

If HasToppingFlag = False Then

Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.SelectedItem.Value & _

" cheese pizza. <br>"

Else

Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.SelectedItem.Value & _

" pizza with the following toppings: <br>" & ToppingDesc & "<br>"

End If

End If

NewReleaseCount = Val(txtNewReleases.Text)

If NewReleaseCount <> 0 Then

Desc &= NewReleaseCount.ToString & " new release video"

If NewReleaseCount > 1 Then Desc &= "s"

Desc &= "<br>"

End If

StandardCount = Val(txtStandard.Text)

If StandardCount <> 0 Then

Desc &= StandardCount.ToString & " standard video"

If StandardCount > 1 Then Desc &= "s"

Desc &= "<br>"

End If

'Assign the built string to the label

lblOrderDesc.Text = Desc

'Determine the Pizza SubTotal using business logic values

Select Case ddlPizzaSize.SelectedItem.Value

Case "None" : Pizzas = 0.0

Case "Medium" : Pizzas = MEDIUM_BASE_PRICE

Case "Large" : Pizzas = LARGE_BASE_PRICE

Case "Gigantic" : Pizzas = GIGANTIC_BASE_PRICE

End Select

If chkPepperoni.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkSausage.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkHam.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkBlackOlives.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkGreenPeppers.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkOnions.Checked Then Pizzas = Pizzas + TOPPING_PRICE

lblPizzaTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Pizzas)

'Determine the movie subtotal using business logic values

Movies = NewReleaseCount * NEW_RELEASE_VIDEO_PRICE

Movies = Movies + StandardCount * STANDARD_VIDEO_PRICE

lblMovieTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Movies)

'Determine the order subtotal, tax, delivery, and total

SubTotal = Pizzas + Movies

lblSubTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(SubTotal)

lblTax.Text = HTML_RIGHT_ALIGN & FormatCurrency(SubTotal * TAX_RATE)

If SubTotal > FREE_DELIVERY_AMOUNT Then

DeliveryFee = 0

Else

DeliveryFee = DELIVERY_FEE

End If

lblDelivery.Text = HTML_RIGHT_ALIGN & FormatCurrency(DeliveryFee)

Total = SubTotal + (SubTotal * TAX_RATE) + DeliveryFee

lblTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Total)

'Determine the discount and the coupon price

Discount = Total * COUPON_DISCOUNT

lblDiscount.Text = HTML_RIGHT_ALIGN & FormatCurrency(Discount)

YourPrice = Total - Discount

lblYourPrice.Text = HTML_RIGHT_ALIGN & FormatCurrency(YourPrice)

'Make the coupon and instructions visible

pnlCoupon.Visible = True

lblInstructions.Visible = True

End Sub

End Class

Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Think about what the code is doing. You have code to handle the original
page load, but afterward, nothing is happening.

You have a few ways to go about doing this but I'd suggest that you hvae
some sort of collection that holds the original items. Store this
collection in Viewstate or session state. Then, Add your items via the
Click event of your button, to the session variable. Load the controls in
the Else part of your If Not Page.IsPostBack. There are a few different
ways you can go about doing this, but I think the part that's tripping you
us is the post back. SInce it's a class project I'm a bit reluctant to hand
you the whole code, but I'll gladly walk you in the right direction.
Another thing - Val() is created by Satan himself - you can use Int32.Parse
for instance to turn strings into Int32s or other numeric values. You
should try catch these because you can Int32.Parse("MyName") because it
won't turn into a real number. I believe VB has an IsNumeric Function - but
if I were you, I'd add some regex validators for each control that can only
take in Numeric input - you should validate the data at the UI level as well
as checking for it before you actually attempt to do anything with it.

Again I don't want to cross the line w/ anything your instructor may not
approve of so I'm being limited in what I'm going to say. However let me
ask you this.... have you considered using a DataTable object for instance,
and then just binding your controls to it, setting the DataSource,
DataTextField and DataValueFields, and then calling DataBind()? By Storing
the DataTable in Session state, you could just add the avlues to the session
variable and then bind to the session variable either way. I think this is
probably the way to go as opposed to just adding those values to a control.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Mike" <mi**@work.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or comments on how to make this work I would be grateful! I have been working
on this for the past 4 days and nothing I do seems to get me any closer to
the solution. Below is a program that I am working on for a class project.
The original code was provided for us which is what I have below. What we
have to do is make the app run so that it allows the user to add additional pizzas to the order form. I have tried making this go through a loop, add an entry button for each pizza order but every time it calculates the order it clears out what I have or won't display anything. Please can anyone give me some help here????

Thank you!

Mike
'OBJECT DESCRIPTION SETTING

'ddlPizzaSize (default properties)

'chkPeperoni Text "Pepperoni"

'chkSausage Text "Sausage"

'chkGreenPeppers Text "Green Peppers"

'chkBlackOlives Text "Black Olives"

'chkHam Text "Ham"

'chkOnions Text "Onions"

'txtNewReleases Text (Empty)

'txtStandard Text (Empty)

'btnCalculate Text "Calculate Total
and Generate Coupon"

'lblInstructions Visable False

' Boarderstyle Double

' Text "Print
and cut out your coupon to save!"

' (The pnlCoupon below is a grid layout panel from the Toolbox's HTML
Section)

'lblOrderDesc Font X-small

'lblPizzaTotal Text "<p align="right">$0.00"

'lblMovieTotal Text "<p align="right">$0.00"

'lblSubTotal Text "<p align="right">$0.00"

'lblTax Text "<p align="right">$0.00"

'lblDelivery Text "<p align="right">$0.00"

'lblTotal Text "<p align="right">$0.00"

'

'lblDiscount Text "<p align="right">$0.00"

' ForeColor Red

'

'lblYourPrice Text "<p align="right">$0.00"

' ForeColor Red

' Font Larger

'

'lblExpDate Text "<p align="right"> Offer valid through 04/01/9999

' Font Smaller

'

Public Class WebForm1

Inherits System.Web.UI.Page

'Business logic constants

Const MEDIUM_BASE_PRICE As Double = 8.99

Const LARGE_BASE_PRICE As Double = 10.99

Const GIGANTIC_BASE_PRICE As Double = 12.99

Const TOPPING_PRICE As Double = 0.99

Const STANDARD_VIDEO_PRICE As Double = 1.95

Const NEW_RELEASE_VIDEO_PRICE As Double = 2.95

Const DELIVERY_FEE As Double = 2.0

Const TAX_RATE As Double = 0.065

Const COUPON_DISCOUNT As Double = 0.1 '(10 Percent)

Const FREE_DELIVERY_AMOUNT As Double = 20

'HTML constants

Const HTML_LEFT_ALIGN As String = "<p align=""left""> "

Const HTML_RIGHT_ALIGN As String = "<p align=""right""> "

Const HTML_INDENT As String = "&nbsp &nbsp &nbsp &nbsp "

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim liNone, liMedium, liLarge, liGigantic As ListItem

'On first showing, fill ListBox, setExpDate and set Discount description

If Not IsPostBack Then

ddlPizzaSize.Items.Clear()

liNone = New ListItem

liNone.Text = "None"

liNone.Value = "None"

liMedium = New ListItem

liMedium.Text = "Medium (8"") -- " & FormatCurrency(MEDIUM_BASE_PRICE)

liMedium.Value = "Medium"

liLarge = New ListItem

liLarge.Text = "Large (10"")-- " & FormatCurrency(LARGE_BASE_PRICE)

liLarge.Value = "Large"

liGigantic = New ListItem

liGigantic.Text = "Gigantic (12"") -- " &
FormatCurrency(GIGANTIC_BASE_PRICE)

liGigantic.Value = "Gigantic"

ddlPizzaSize.Items.Add(liNone)

ddlPizzaSize.Items.Add(liMedium)

ddlPizzaSize.Items.Add(liLarge)

ddlPizzaSize.Items.Add(liGigantic)

ddlPizzaSize.SelectedIndex = 0

lblExpDate.Text = HTML_RIGHT_ALIGN & "Offer valid through " & _

FormatDateTime(Today().AddDays(7))

lblDiscountDesc.Text = FormatPercent(COUPON_DISCOUNT, 0) & " discount:"

End If

End Sub



Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalculate.Click

Dim Desc As String

Dim ToppingDesc As String

Dim HasToppingFlag As Boolean

Dim NewReleaseCount As Integer

Dim StandardCount As Integer

Dim Pizzas As Double

Dim Movies As Double

Dim SubTotal As Double

Dim DeliveryFee As Double

Dim Total As Double

Dim Discount As Double

Dim YourPrice As Double

'Build a string with HTML formatted text describing the order

Desc = ""

If ddlPizzaSize.SelectedItem.Value <> "None" Then

ToppingDesc = ""

HasToppingFlag = False

If chkPepperoni.Checked Then

ToppingDesc &= HTML_INDENT & "pepperoni <br>"

HasToppingFlag = True

End If

If chkSausage.Checked Then

ToppingDesc &= HTML_INDENT & "sausage <br>"

HasToppingFlag = True

End If

If chkHam.Checked Then

ToppingDesc &= HTML_INDENT & "ham <br>"

HasToppingFlag = True

End If

If chkBlackOlives.Checked Then

ToppingDesc &= HTML_INDENT & "black olives <br>"

HasToppingFlag = True

End If

If chkGreenPeppers.Checked Then

ToppingDesc &= HTML_INDENT & "green peppers <br>"

HasToppingFlag = True

End If

If chkOnions.Checked Then

ToppingDesc &= HTML_INDENT & "onions <br>"

HasToppingFlag = True

End If

If HasToppingFlag = False Then

Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.SelectedItem.Value & _

" cheese pizza. <br>"

Else

Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.SelectedItem.Value & _

" pizza with the following toppings: <br>" & ToppingDesc & "<br>"

End If

End If

NewReleaseCount = Val(txtNewReleases.Text)

If NewReleaseCount <> 0 Then

Desc &= NewReleaseCount.ToString & " new release video"

If NewReleaseCount > 1 Then Desc &= "s"

Desc &= "<br>"

End If

StandardCount = Val(txtStandard.Text)

If StandardCount <> 0 Then

Desc &= StandardCount.ToString & " standard video"

If StandardCount > 1 Then Desc &= "s"

Desc &= "<br>"

End If

'Assign the built string to the label

lblOrderDesc.Text = Desc

'Determine the Pizza SubTotal using business logic values

Select Case ddlPizzaSize.SelectedItem.Value

Case "None" : Pizzas = 0.0

Case "Medium" : Pizzas = MEDIUM_BASE_PRICE

Case "Large" : Pizzas = LARGE_BASE_PRICE

Case "Gigantic" : Pizzas = GIGANTIC_BASE_PRICE

End Select

If chkPepperoni.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkSausage.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkHam.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkBlackOlives.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkGreenPeppers.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkOnions.Checked Then Pizzas = Pizzas + TOPPING_PRICE

lblPizzaTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Pizzas)

'Determine the movie subtotal using business logic values

Movies = NewReleaseCount * NEW_RELEASE_VIDEO_PRICE

Movies = Movies + StandardCount * STANDARD_VIDEO_PRICE

lblMovieTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Movies)

'Determine the order subtotal, tax, delivery, and total

SubTotal = Pizzas + Movies

lblSubTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(SubTotal)

lblTax.Text = HTML_RIGHT_ALIGN & FormatCurrency(SubTotal * TAX_RATE)

If SubTotal > FREE_DELIVERY_AMOUNT Then

DeliveryFee = 0

Else

DeliveryFee = DELIVERY_FEE

End If

lblDelivery.Text = HTML_RIGHT_ALIGN & FormatCurrency(DeliveryFee)

Total = SubTotal + (SubTotal * TAX_RATE) + DeliveryFee

lblTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Total)

'Determine the discount and the coupon price

Discount = Total * COUPON_DISCOUNT

lblDiscount.Text = HTML_RIGHT_ALIGN & FormatCurrency(Discount)

YourPrice = Total - Discount

lblYourPrice.Text = HTML_RIGHT_ALIGN & FormatCurrency(YourPrice)

'Make the coupon and instructions visible

pnlCoupon.Visible = True

lblInstructions.Visible = True

End Sub

End Class

Jul 21 '05 #2

P: n/a
W.G.

Thanks for the reply.

Unfortunatly you have gone over my head with some of what
you are talking about. I'm in a begginers class so some of
the code is just given to us. But if I follow some of your
logic, and what I have been trying do so far, is that the
code refreshes the page every time I click to calculate
the order wiping out everything.

But I think your right the IsPostBack is throwing me off.
I tried changing it from If Not to just If.... But I think
you made a good point that I was trying to work in. I
tried adding in a "enter order" button that would "add"
the cost of the pizza to subtotal. But the wall I keep
running into was how to keep adding to the description of
the order, and then I was running into getting the pizza
subtotal to calculate out to the total with tax and
discount and so on... and then reset the drop down list
and the checkboxes for toppings so that the user can add
to the order.

The other I didn't quite understand the Int32 and how it
works, but your right there is a IsNumeric function.

Does some of that help what I am trying to do? Sorry but
I'm still lost. I appreciate the help, but I need a little
more.

Thanks!

Mike
-----Original Message-----
Think about what the code is doing. You have code to handle the originalpage load, but afterward, nothing is happening.

You have a few ways to go about doing this but I'd suggest that you hvaesome sort of collection that holds the original items. Store thiscollection in Viewstate or session state. Then, Add your items via theClick event of your button, to the session variable. Load the controls inthe Else part of your If Not Page.IsPostBack. There are a few differentways you can go about doing this, but I think the part that's tripping youus is the post back. SInce it's a class project I'm a bit reluctant to handyou the whole code, but I'll gladly walk you in the right direction.Another thing - Val() is created by Satan himself - you can use Int32.Parsefor instance to turn strings into Int32s or other numeric values. Youshould try catch these because you can Int32.Parse ("MyName") because itwon't turn into a real number. I believe VB has an IsNumeric Function - butif I were you, I'd add some regex validators for each control that can onlytake in Numeric input - you should validate the data at the UI level as wellas checking for it before you actually attempt to do anything with it.
Again I don't want to cross the line w/ anything your instructor may notapprove of so I'm being limited in what I'm going to say. However let meask you this.... have you considered using a DataTable object for instance,and then just binding your controls to it, setting the DataSource,DataTextField and DataValueFields, and then calling DataBind()? By Storingthe DataTable in Session state, you could just add the avlues to the sessionvariable and then bind to the session variable either way. I think this isprobably the way to go as opposed to just adding those values to a control.
--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com"Mike" <mi**@work.com> wrote in message
news:eQ*************@TK2MSFTNGP10.phx.gbl...
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas
or
comments on how to make this work I would be grateful!
I have been working on this for the past 4 days and nothing I do seems to get me any closer to the solution. Below is a program that I am working on for a class project. The original code was provided for us which is what I have below. What we have to do is make the app run so that it allows the user to addadditional
pizzas to the order form. I have tried making this go
through a loop, addan
entry button for each pizza order but every time it
calculates the orderit
clears out what I have or won't display anything.
Please can anyone giveme
some help here????

Thank you!

Mike
'OBJECT DESCRIPTION SETTING

'ddlPizzaSize (default properties)

'chkPeperoni
Text "Pepperoni"
'chkSausage Text "Sausage"
'chkGreenPeppers Text "Green Peppers"
'chkBlackOlives Text "Black Olives"
'chkHam Text "Ham"
'chkOnions Text "Onions"
'txtNewReleases Text (Empty)
'txtStandard Text (Empty)
'btnCalculate Text "Calculate Total and Generate Coupon"

'lblInstructions Visable False
' Boarderstyle Double
' Text "Print and cut out your coupon to save!"

' (The pnlCoupon below is a grid layout panel from the Toolbox's HTML Section)

'lblOrderDesc Font X-small

'lblPizzaTotal Text "<p align="right">$0.00"
'lblMovieTotal Text "<p align="right">$0.00"
'lblSubTotal Text "<p align="right">$0.00"
'lblTax Text "<p align="right">$0.00"
'lblDelivery Text "<p align="right">$0.00"
'lblTotal Text "<p align="right">$0.00"
'

'lblDiscount Text "<p align="right">$0.00"
' ForeColor Red

'

'lblYourPrice Text "<p align="right">$0.00"
' ForeColor Red

' Font Larger
'

'lblExpDate Text "<p align="right"> Offervalid
through 04/01/9999

' Font

Smaller
'

Public Class WebForm1

Inherits System.Web.UI.Page

'Business logic constants

Const MEDIUM_BASE_PRICE As Double = 8.99

Const LARGE_BASE_PRICE As Double = 10.99

Const GIGANTIC_BASE_PRICE As Double = 12.99

Const TOPPING_PRICE As Double = 0.99

Const STANDARD_VIDEO_PRICE As Double = 1.95

Const NEW_RELEASE_VIDEO_PRICE As Double = 2.95

Const DELIVERY_FEE As Double = 2.0

Const TAX_RATE As Double = 0.065

Const COUPON_DISCOUNT As Double = 0.1 '(10 Percent)

Const FREE_DELIVERY_AMOUNT As Double = 20

'HTML constants

Const HTML_LEFT_ALIGN As String = "<p align=""left""> "

Const HTML_RIGHT_ALIGN As String = "<p align=""right""> "
Const HTML_INDENT As String = " "

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim liNone, liMedium, liLarge, liGigantic As ListItem

'On first showing, fill ListBox, setExpDate and set Discount description
If Not IsPostBack Then

ddlPizzaSize.Items.Clear()

liNone = New ListItem

liNone.Text = "None"

liNone.Value = "None"

liMedium = New ListItem

liMedium.Text = "Medium (8"") -- " & FormatCurrency (MEDIUM_BASE_PRICE)
liMedium.Value = "Medium"

liLarge = New ListItem

liLarge.Text = "Large (10"")-- " & FormatCurrency (LARGE_BASE_PRICE)
liLarge.Value = "Large"

liGigantic = New ListItem

liGigantic.Text = "Gigantic (12"") -- " &
FormatCurrency(GIGANTIC_BASE_PRICE)

liGigantic.Value = "Gigantic"

ddlPizzaSize.Items.Add(liNone)

ddlPizzaSize.Items.Add(liMedium)

ddlPizzaSize.Items.Add(liLarge)

ddlPizzaSize.Items.Add(liGigantic)

ddlPizzaSize.SelectedIndex = 0

lblExpDate.Text = HTML_RIGHT_ALIGN & "Offer valid through " & _
FormatDateTime(Today().AddDays(7))

lblDiscountDesc.Text = FormatPercent(COUPON_DISCOUNT, 0) & " discount:"
End If

End Sub



Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

Dim Desc As String

Dim ToppingDesc As String

Dim HasToppingFlag As Boolean

Dim NewReleaseCount As Integer

Dim StandardCount As Integer

Dim Pizzas As Double

Dim Movies As Double

Dim SubTotal As Double

Dim DeliveryFee As Double

Dim Total As Double

Dim Discount As Double

Dim YourPrice As Double

'Build a string with HTML formatted text describing the order
Desc = ""

If ddlPizzaSize.SelectedItem.Value <> "None" Then

ToppingDesc = ""

HasToppingFlag = False

If chkPepperoni.Checked Then

ToppingDesc &= HTML_INDENT & "pepperoni <br>"

HasToppingFlag = True

End If

If chkSausage.Checked Then

ToppingDesc &= HTML_INDENT & "sausage <br>"

HasToppingFlag = True

End If

If chkHam.Checked Then

ToppingDesc &= HTML_INDENT & "ham <br>"

HasToppingFlag = True

End If

If chkBlackOlives.Checked Then

ToppingDesc &= HTML_INDENT & "black olives <br>"

HasToppingFlag = True

End If

If chkGreenPeppers.Checked Then

ToppingDesc &= HTML_INDENT & "green peppers <br>"

HasToppingFlag = True

End If

If chkOnions.Checked Then

ToppingDesc &= HTML_INDENT & "onions <br>"

HasToppingFlag = True

End If

If HasToppingFlag = False Then

Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.SelectedItem.Value & _
" cheese pizza. <br>"

Else

Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.SelectedItem.Value & _
" pizza with the following toppings: <br>" & ToppingDesc & "<br>"
End If

End If

NewReleaseCount = Val(txtNewReleases.Text)

If NewReleaseCount <> 0 Then

Desc &= NewReleaseCount.ToString & " new release video"

If NewReleaseCount > 1 Then Desc &= "s"

Desc &= "<br>"

End If

StandardCount = Val(txtStandard.Text)

If StandardCount <> 0 Then

Desc &= StandardCount.ToString & " standard video"

If StandardCount > 1 Then Desc &= "s"

Desc &= "<br>"

End If

'Assign the built string to the label

lblOrderDesc.Text = Desc

'Determine the Pizza SubTotal using business logic values
Select Case ddlPizzaSize.SelectedItem.Value

Case "None" : Pizzas = 0.0

Case "Medium" : Pizzas = MEDIUM_BASE_PRICE

Case "Large" : Pizzas = LARGE_BASE_PRICE

Case "Gigantic" : Pizzas = GIGANTIC_BASE_PRICE

End Select

If chkPepperoni.Checked Then Pizzas = Pizzas + TOPPING_PRICE
If chkSausage.Checked Then Pizzas = Pizzas + TOPPING_PRICE
If chkHam.Checked Then Pizzas = Pizzas + TOPPING_PRICE

If chkBlackOlives.Checked Then Pizzas = Pizzas + TOPPING_PRICE
If chkGreenPeppers.Checked Then Pizzas = Pizzas + TOPPING_PRICE
If chkOnions.Checked Then Pizzas = Pizzas + TOPPING_PRICE
lblPizzaTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency (Pizzas)
'Determine the movie subtotal using business logic values
Movies = NewReleaseCount * NEW_RELEASE_VIDEO_PRICE

Movies = Movies + StandardCount * STANDARD_VIDEO_PRICE

lblMovieTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency (Movies)
'Determine the order subtotal, tax, delivery, and total

SubTotal = Pizzas + Movies

lblSubTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency (SubTotal)
lblTax.Text = HTML_RIGHT_ALIGN & FormatCurrency (SubTotal * TAX_RATE)
If SubTotal > FREE_DELIVERY_AMOUNT Then

DeliveryFee = 0

Else

DeliveryFee = DELIVERY_FEE

End If

lblDelivery.Text = HTML_RIGHT_ALIGN & FormatCurrency (DeliveryFee)
Total = SubTotal + (SubTotal * TAX_RATE) + DeliveryFee

lblTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Total)

'Determine the discount and the coupon price

Discount = Total * COUPON_DISCOUNT

lblDiscount.Text = HTML_RIGHT_ALIGN & FormatCurrency (Discount)
YourPrice = Total - Discount

lblYourPrice.Text = HTML_RIGHT_ALIGN & FormatCurrency (YourPrice)
'Make the coupon and instructions visible

pnlCoupon.Visible = True

lblInstructions.Visible = True

End Sub

End Class

.

Jul 21 '05 #3

P: n/a
Hey W.G.

Looking around session state is in our next chapter, but I don't see why I
couldn't use it now.

I started modifying the code a little. Right now I was just trying to get
the subtotal to keep adding, but I must be missing something. Your right
though the IsPostBack is really messing me up. I added a new button so that
all the user would need to do is select the pizza, toppings and then click
"add to order". Once they are done ordering their pizzas then they click on
the calculate total button to display their pizza descriptions and dollar
amounts. Could you take a look at what I have and see what I am messing up?
Thanks!!

Mike

'Business logic constants

Const MEDIUM_BASE_PRICE As Double = 8.99

Const LARGE_BASE_PRICE As Double = 10.99

Const GIGANTIC_BASE_PRICE As Double = 12.99

Const TOPPING_PRICE As Double = 0.99

Const STANDARD_VIDEO_PRICE As Double = 1.95

Const NEW_RELEASE_VIDEO_PRICE As Double = 2.95

Const DELIVERY_FEE As Double = 2.0

Const TAX_RATE As Double = 0.065

Const COUPON_DISCOUNT As Double = 0.1 '(10 Percent)

Const FREE_DELIVERY_AMOUNT As Double = 20

'HTML constants

Const HTML_LEFT_ALIGN As String = "<p align=""left""> "

Const HTML_RIGHT_ALIGN As String = "<p align=""right""> "

Const HTML_INDENT As String = "&nbsp &nbsp &nbsp &nbsp "

Dim mDesc As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

Dim liNone, liMedium, liLarge, liGigantic As ListItem

Dim mDesc As String

'On first showing, fill ListBox, setExpDate and set Discount description

If Not IsPostBack Then

ddlPizzaSize.Items.Clear()

liNone = New ListItem

liNone.Text = "None"

liNone.Value = "None"

liMedium = New ListItem

liMedium.Text = "Medium (8"") -- " & FormatCurrency(MEDIUM_BASE_PRICE)

liMedium.Value = "Medium"

liLarge = New ListItem

liLarge.Text = "Large (10"")-- " & FormatCurrency(LARGE_BASE_PRICE)

liLarge.Value = "Large"

liGigantic = New ListItem

liGigantic.Text = "Gigantic (12"") -- " &
FormatCurrency(GIGANTIC_BASE_PRICE)

liGigantic.Value = "Gigantic"

ddlPizzaSize.Items.Add(liNone)

ddlPizzaSize.Items.Add(liMedium)

ddlPizzaSize.Items.Add(liLarge)

ddlPizzaSize.Items.Add(liGigantic)

ddlPizzaSize.SelectedIndex = 0

lblExpDate.Text = HTML_RIGHT_ALIGN & "Offer valid through " & _

FormatDateTime(Today().AddDays(7))

lblDiscountDesc.Text = FormatPercent(COUPON_DISCOUNT, 0) & " discount:"

Else

Session("mPizzas") = 0

Session("lPizzas") = 0

Session("gPizzas") = 0

Session("sToppings") = 0

Session("numPizzas") = 0

Session("sDesc") = mDesc

End If

End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCalculate.Click

'Dim Desc As String

Dim ToppingDesc As String

Dim HasToppingFlag As Boolean

Dim NewReleaseCount As Integer

Dim StandardCount As Integer

Dim Pizzas As Double

Dim Movies As Double

Dim SubTotal As Double

Dim DeliveryFee As Double

Dim Total As Double

Dim Discount As Double

Dim YourPrice As Double


NewReleaseCount = Val(txtNewReleases.Text)

If NewReleaseCount <> 0 Then

mDesc &= NewReleaseCount.ToString & " new release video"

If NewReleaseCount > 1 Then mDesc &= "s"

mDesc &= "<br>"

End If

StandardCount = Val(txtStandard.Text)

If StandardCount <> 0 Then

mDesc &= StandardCount.ToString & " standard video"

If StandardCount > 1 Then mDesc &= "s"

mDesc &= "<br>"

End If

'Assign the built string to the label

lblOrderDesc.Text = Session("sDesc")

'Determine the movie subtotal using business logic values

Movies = NewReleaseCount * NEW_RELEASE_VIDEO_PRICE

Movies = Movies + StandardCount * STANDARD_VIDEO_PRICE

lblMovieTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Movies)

'Determine the order subtotal, tax, delivery, and total

SubTotal = (Session("mPizzas") * MEDIUM_BASE_PRICE) + (Session("lPizzas") *
LARGE_BASE_PRICE) + (Session("gPizzas") * GIGANTIC_BASE_PRICE) +
(Session("sToppings") * TOPPING_PRICE) + Movies

lblSubTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(SubTotal)

lblTax.Text = HTML_RIGHT_ALIGN & FormatCurrency(SubTotal * TAX_RATE)

If SubTotal > FREE_DELIVERY_AMOUNT Then

DeliveryFee = 0

Else

DeliveryFee = DELIVERY_FEE

End If

lblDelivery.Text = HTML_RIGHT_ALIGN & FormatCurrency(DeliveryFee)

Total = SubTotal + (SubTotal * TAX_RATE) + DeliveryFee

lblTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency(Total)

'Determine the discount and the coupon price

Discount = Total * COUPON_DISCOUNT

lblDiscount.Text = HTML_RIGHT_ALIGN & FormatCurrency(Discount)

YourPrice = Total - Discount

lblYourPrice.Text = HTML_RIGHT_ALIGN & FormatCurrency(YourPrice)

'Make the coupon and instructions visible

pnlCoupon.Visible = True

lblInstructions.Visible = True

End Sub

Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOrder.Click

Dim ToppingDesc As String

Dim HasToppingFlag As Boolean

'Build a string with HTML formatted text describing the order

mDesc = ""

If ddlPizzaSize.SelectedItem.Value <> "None" Then

ToppingDesc = ""

HasToppingFlag = False

If chkPepperoni.Checked Then

ToppingDesc &= HTML_INDENT & "pepperoni <br>"

HasToppingFlag = True

End If

If chkSausage.Checked Then

ToppingDesc &= HTML_INDENT & "sausage <br>"

HasToppingFlag = True

End If

If chkHam.Checked Then

ToppingDesc &= HTML_INDENT & "ham <br>"

HasToppingFlag = True

End If

If chkBlackOlives.Checked Then

ToppingDesc &= HTML_INDENT & "black olives <br>"

HasToppingFlag = True

End If

If chkGreenPeppers.Checked Then

ToppingDesc &= HTML_INDENT & "green peppers <br>"

HasToppingFlag = True

End If

If chkOnions.Checked Then

ToppingDesc &= HTML_INDENT & "onions <br>"

HasToppingFlag = True

End If

If HasToppingFlag = False Then

mDesc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.SelectedItem.Value & _

" cheese pizza. <br>"

Else

mDesc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.SelectedItem.Value & _

" pizza with the following toppings: <br>" & ToppingDesc & "<br>"

End If

End If

'Determine the Pizza SubTotal using business logic values

If Session("numPizzas") < 2 Then

Select Case ddlPizzaSize.SelectedItem.Value

Case "None" : Session("mPizzas") = Session("mPizzas") + 0.0

Case "Medium" : Session("mPizzas") = Session("mPizzas") + 1

Case "Large" : Session("lPizzas") = Session("lPizzas") + 1

Case "Gigantic" : Session("gPizzas") = Session("gPizzas") + 1

End Select

If chkPepperoni.Checked Then Session("sToppings") = Session("sToppings") + 1

If chkSausage.Checked Then Session("sToppings") = Session("sToppings") + 1

If chkHam.Checked Then Session("sToppings") = Session("sToppings") + 1

If chkBlackOlives.Checked Then Session("sToppings") = Session("sToppings") +
1

If chkGreenPeppers.Checked Then Session("sToppings") = Session("sToppings")
+ 1

If chkOnions.Checked Then Session("sToppings") = Session("sToppings") + 1

lblPizzaTotal.Text = HTML_RIGHT_ALIGN & FormatCurrency((Session("mPizzas") *
MEDIUM_BASE_PRICE) + (Session("lPizzas") * LARGE_BASE_PRICE) +
(Session("gPizzas") * GIGANTIC_BASE_PRICE) + (Session("sToppings") *
TOPPING_PRICE))

Else

lblLimitThree.Visible = True

End If

End Sub

End Class
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.