473,287 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Need some help badly! Please!!

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
3 1559
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bilal | last post by:
hi all I am facing a little problem. I have a form with a dropdownlist control. I have a button and when i click the form posts back The problem is that in the on button click event i'm calling...
2
by: Sam Samnah | last post by:
I am building a custome control and I need to access the information in the hidden field (HtmlInputHidden HIH) so that when a button is pressed the information in the hidden fields value is...
4
by: IcedCrow | last post by:
I have stumbled upon a serious problem and I hope someone can help me out. I have programmed a web service in VB.NET. When I use integrated security for the piece, of course it does not use...
3
by: Mike | last post by:
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...
0
by: tgregg6 | last post by:
I need help with my problem I am stuck and I don't know what to do!!! The problem is: This program calculates the charges for DVD rentals where current releases cost $3.5 and all others cast $2.50....
2
by: Dalton | last post by:
This is all kind of in another language to, I mean I understand most of the words in relation to programming, but my field of work/study is IT. Anyways, on to the problem. I am working on my 5th...
2
by: tengtium | last post by:
can somebody help me. i have this simple record. error_reference_uid item_number error_code 1234567 13579 odd 1234567 2468 even and i want to create this xml. <Errors...
3
by: DragonLord | last post by:
Here is the situation I am inserting rows into a datagridview and then using a function to group similar rows together based on a column. When I call to compare the lastrow with the current row...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.