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 = "        "
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 3 934
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 = "        " 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
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 ideasor 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
.
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 = "        "
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 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...
|
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 this metho
------------------
Sub cute(sender As Object, e As EventArgs
Response.Write(ddlColors.SelectedItem.text
End Su
------------------
|
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 returned. Somehow, when the
submit button is pressed the value in the Hidden field disappears into cyber
nothing. Please help. This application is...
|
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 my log in but the ASP log in. No
problem. I get an error.
So first in experiment I try and use the sa account. I
|
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. If a customer rents several DVDs, every third one of each type is free. You need to tell the user what their total cost of rental whould be based on...
| |
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 project and it is running, just not the way it is supposed to. In the "posting guidelines" section it says not to post the whole source code, but that is...
|
by: lchristy0213 |
last post by:
I just started programming and I'm trying to get python to read a txt file and then turn the letters in the file into notes with certain frequencies, and then create a wav file. I'm doing ok but could really use some help. Thank you in advance. This is what I have:
noteFileName=raw_input("What file are the notes in?")...
|
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 error_reference_uid="1234567">
<Error item_number="13579" error_code="odd" />
<Error item_number="2468" error_code="even" />
|
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 the application passes the information that should be equal. i.e 479 ST-Vieurtur
as the "Destination" with the call below:
if...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |