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"
'chkGreenPepper s 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"
'lblInstruction s 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.P age
'Business logic constants
Const MEDIUM_BASE_PRI CE As Double = 8.99
Const LARGE_BASE_PRIC E As Double = 10.99
Const GIGANTIC_BASE_P RICE As Double = 12.99
Const TOPPING_PRICE As Double = 0.99
Const STANDARD_VIDEO_ PRICE As Double = 1.95
Const NEW_RELEASE_VID EO_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_A MOUNT As Double = 20
'HTML constants
Const HTML_LEFT_ALIGN As String = "<p align=""left""> "
Const HTML_RIGHT_ALIG N As String = "<p align=""right"" > "
Const HTML_INDENT As String = "        "
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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.It ems.Clear()
liNone = New ListItem
liNone.Text = "None"
liNone.Value = "None"
liMedium = New ListItem
liMedium.Text = "Medium (8"") -- " & FormatCurrency( MEDIUM_BASE_PRI CE)
liMedium.Value = "Medium"
liLarge = New ListItem
liLarge.Text = "Large (10"")-- " & FormatCurrency( LARGE_BASE_PRIC E)
liLarge.Value = "Large"
liGigantic = New ListItem
liGigantic.Text = "Gigantic (12"") -- " &
FormatCurrency( GIGANTIC_BASE_P RICE)
liGigantic.Valu e = "Gigantic"
ddlPizzaSize.It ems.Add(liNone)
ddlPizzaSize.It ems.Add(liMediu m)
ddlPizzaSize.It ems.Add(liLarge )
ddlPizzaSize.It ems.Add(liGigan tic)
ddlPizzaSize.Se lectedIndex = 0
lblExpDate.Text = HTML_RIGHT_ALIG N & "Offer valid through " & _
FormatDateTime( Today().AddDays (7))
lblDiscountDesc .Text = FormatPercent(C OUPON_DISCOUNT, 0) & " discount:"
End If
End Sub
Private Sub btnCalculate_Cl ick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCalculate.Cl ick
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.Se lectedItem.Valu e <> "None" Then
ToppingDesc = ""
HasToppingFlag = False
If chkPepperoni.Ch ecked Then
ToppingDesc &= HTML_INDENT & "pepperoni <br>"
HasToppingFlag = True
End If
If chkSausage.Chec ked 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.Check ed Then
ToppingDesc &= HTML_INDENT & "onions <br>"
HasToppingFlag = True
End If
If HasToppingFlag = False Then
Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.Se lectedItem.Valu e & _
" cheese pizza. <br>"
Else
Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.Se lectedItem.Valu e & _
" pizza with the following toppings: <br>" & ToppingDesc & "<br>"
End If
End If
NewReleaseCount = Val(txtNewRelea ses.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.T oString & " standard video"
If StandardCount > 1 Then Desc &= "s"
Desc &= "<br>"
End If
'Assign the built string to the label
lblOrderDesc.Te xt = Desc
'Determine the Pizza SubTotal using business logic values
Select Case ddlPizzaSize.Se lectedItem.Valu e
Case "None" : Pizzas = 0.0
Case "Medium" : Pizzas = MEDIUM_BASE_PRI CE
Case "Large" : Pizzas = LARGE_BASE_PRIC E
Case "Gigantic" : Pizzas = GIGANTIC_BASE_P RICE
End Select
If chkPepperoni.Ch ecked Then Pizzas = Pizzas + TOPPING_PRICE
If chkSausage.Chec ked 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.Check ed Then Pizzas = Pizzas + TOPPING_PRICE
lblPizzaTotal.T ext = HTML_RIGHT_ALIG N & FormatCurrency( Pizzas)
'Determine the movie subtotal using business logic values
Movies = NewReleaseCount * NEW_RELEASE_VID EO_PRICE
Movies = Movies + StandardCount * STANDARD_VIDEO_ PRICE
lblMovieTotal.T ext = HTML_RIGHT_ALIG N & FormatCurrency( Movies)
'Determine the order subtotal, tax, delivery, and total
SubTotal = Pizzas + Movies
lblSubTotal.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( SubTotal)
lblTax.Text = HTML_RIGHT_ALIG N & FormatCurrency( SubTotal * TAX_RATE)
If SubTotal > FREE_DELIVERY_A MOUNT Then
DeliveryFee = 0
Else
DeliveryFee = DELIVERY_FEE
End If
lblDelivery.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( DeliveryFee)
Total = SubTotal + (SubTotal * TAX_RATE) + DeliveryFee
lblTotal.Text = HTML_RIGHT_ALIG N & FormatCurrency( Total)
'Determine the discount and the coupon price
Discount = Total * COUPON_DISCOUNT
lblDiscount.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( Discount)
YourPrice = Total - Discount
lblYourPrice.Te xt = HTML_RIGHT_ALIG N & FormatCurrency( YourPrice)
'Make the coupon and instructions visible
pnlCoupon.Visib le = True
lblInstructions .Visible = True
End Sub
End Class 3 947
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("My Name") 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.co m> wrote in message
news:eQ******** *****@TK2MSFTNG P10.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"
'chkGreenPepper s 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"
'lblInstruction s 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.P age
'Business logic constants
Const MEDIUM_BASE_PRI CE As Double = 8.99
Const LARGE_BASE_PRIC E As Double = 10.99
Const GIGANTIC_BASE_P RICE As Double = 12.99
Const TOPPING_PRICE As Double = 0.99
Const STANDARD_VIDEO_ PRICE As Double = 1.95
Const NEW_RELEASE_VID EO_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_A MOUNT As Double = 20 'HTML constants
Const HTML_LEFT_ALIGN As String = "<p align=""left""> "
Const HTML_RIGHT_ALIG N As String = "<p align=""right"" > "
Const HTML_INDENT As String = "        " Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) 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.It ems.Clear()
liNone = New ListItem
liNone.Text = "None"
liNone.Value = "None"
liMedium = New ListItem
liMedium.Text = "Medium (8"") -- " & FormatCurrency( MEDIUM_BASE_PRI CE)
liMedium.Value = "Medium"
liLarge = New ListItem
liLarge.Text = "Large (10"")-- " & FormatCurrency( LARGE_BASE_PRIC E)
liLarge.Value = "Large"
liGigantic = New ListItem
liGigantic.Text = "Gigantic (12"") -- " & FormatCurrency( GIGANTIC_BASE_P RICE)
liGigantic.Valu e = "Gigantic"
ddlPizzaSize.It ems.Add(liNone)
ddlPizzaSize.It ems.Add(liMediu m)
ddlPizzaSize.It ems.Add(liLarge )
ddlPizzaSize.It ems.Add(liGigan tic)
ddlPizzaSize.Se lectedIndex = 0
lblExpDate.Text = HTML_RIGHT_ALIG N & "Offer valid through " & _
FormatDateTime( Today().AddDays (7))
lblDiscountDesc .Text = FormatPercent(C OUPON_DISCOUNT, 0) & " discount:"
End If
End Sub
Private Sub btnCalculate_Cl ick(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnCalculate.Cl ick
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.Se lectedItem.Valu e <> "None" Then
ToppingDesc = ""
HasToppingFlag = False
If chkPepperoni.Ch ecked Then
ToppingDesc &= HTML_INDENT & "pepperoni <br>"
HasToppingFlag = True
End If
If chkSausage.Chec ked 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.Check ed Then
ToppingDesc &= HTML_INDENT & "onions <br>"
HasToppingFlag = True
End If
If HasToppingFlag = False Then
Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.Se lectedItem.Valu e & _
" cheese pizza. <br>"
Else
Desc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.Se lectedItem.Valu e & _
" pizza with the following toppings: <br>" & ToppingDesc & "<br>"
End If
End If
NewReleaseCount = Val(txtNewRelea ses.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.T oString & " standard video"
If StandardCount > 1 Then Desc &= "s"
Desc &= "<br>"
End If
'Assign the built string to the label
lblOrderDesc.Te xt = Desc
'Determine the Pizza SubTotal using business logic values
Select Case ddlPizzaSize.Se lectedItem.Valu e
Case "None" : Pizzas = 0.0
Case "Medium" : Pizzas = MEDIUM_BASE_PRI CE
Case "Large" : Pizzas = LARGE_BASE_PRIC E
Case "Gigantic" : Pizzas = GIGANTIC_BASE_P RICE
End Select
If chkPepperoni.Ch ecked Then Pizzas = Pizzas + TOPPING_PRICE
If chkSausage.Chec ked 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.Check ed Then Pizzas = Pizzas + TOPPING_PRICE
lblPizzaTotal.T ext = HTML_RIGHT_ALIG N & FormatCurrency( Pizzas)
'Determine the movie subtotal using business logic values
Movies = NewReleaseCount * NEW_RELEASE_VID EO_PRICE
Movies = Movies + StandardCount * STANDARD_VIDEO_ PRICE
lblMovieTotal.T ext = HTML_RIGHT_ALIG N & FormatCurrency( Movies)
'Determine the order subtotal, tax, delivery, and total
SubTotal = Pizzas + Movies
lblSubTotal.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( SubTotal)
lblTax.Text = HTML_RIGHT_ALIG N & FormatCurrency( SubTotal * TAX_RATE)
If SubTotal > FREE_DELIVERY_A MOUNT Then
DeliveryFee = 0
Else
DeliveryFee = DELIVERY_FEE
End If
lblDelivery.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( DeliveryFee)
Total = SubTotal + (SubTotal * TAX_RATE) + DeliveryFee
lblTotal.Text = HTML_RIGHT_ALIG N & FormatCurrency( Total)
'Determine the discount and the coupon price
Discount = Total * COUPON_DISCOUNT
lblDiscount.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( Discount)
YourPrice = Total - Discount
lblYourPrice.Te xt = HTML_RIGHT_ALIG N & FormatCurrency( YourPrice)
'Make the coupon and instructions visible
pnlCoupon.Visib le = 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,DataTextFiel d 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.co m> wrote in message news:eQ******* ******@TK2MSFTN GP10.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" 'chkGreenPepper s
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"
'lblInstruction s
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.P age
'Business logic constants
Const MEDIUM_BASE_PRI CE As Double = 8.99
Const LARGE_BASE_PRIC E As Double = 10.99
Const GIGANTIC_BASE_P RICE As Double = 12.99
Const TOPPING_PRICE As Double = 0.99
Const STANDARD_VIDEO_ PRICE As Double = 1.95
Const NEW_RELEASE_VID EO_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_A MOUNT As Double = 20 'HTML constants
Const HTML_LEFT_ALIGN As String = "<p align=""left""> "
Const HTML_RIGHT_ALIG N As String = "<p
align=""right"" > " Const HTML_INDENT As String = " " Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArg s) 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.It ems.Clear()
liNone = New ListItem
liNone.Text = "None"
liNone.Value = "None"
liMedium = New ListItem
liMedium.Text = "Medium (8"") -- " & FormatCurrency
(MEDIUM_BASE_PR ICE) liMedium.Value = "Medium"
liLarge = New ListItem
liLarge.Text = "Large (10"")-- " & FormatCurrency
(LARGE_BASE_PRI CE) liLarge.Value = "Large"
liGigantic = New ListItem
liGigantic.Text = "Gigantic (12"") -- " & FormatCurrency( GIGANTIC_BASE_P RICE)
liGigantic.Valu e = "Gigantic"
ddlPizzaSize.It ems.Add(liNone)
ddlPizzaSize.It ems.Add(liMediu m)
ddlPizzaSize.It ems.Add(liLarge )
ddlPizzaSize.It ems.Add(liGigan tic)
ddlPizzaSize.Se lectedIndex = 0
lblExpDate.Text = HTML_RIGHT_ALIG N & "Offer valid
through " & _ FormatDateTime( Today().AddDays (7))
lblDiscountDesc .Text = FormatPercent(C OUPON_DISCOUNT,
0) & " discount:" End If
End Sub
Private Sub btnCalculate_Cl ick(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles btnCalculate.Cl ick
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.Se lectedItem.Valu e <> "None" Then
ToppingDesc = ""
HasToppingFlag = False
If chkPepperoni.Ch ecked Then
ToppingDesc &= HTML_INDENT & "pepperoni <br>"
HasToppingFlag = True
End If
If chkSausage.Chec ked 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.Check ed Then
ToppingDesc &= HTML_INDENT & "onions <br>"
HasToppingFlag = True
End If
If HasToppingFlag = False Then
Desc = HTML_LEFT_ALIGN & "A " &
ddlPizzaSize.Se lectedItem.Valu e & _ " cheese pizza. <br>"
Else
Desc = HTML_LEFT_ALIGN & "A " &
ddlPizzaSize.Se lectedItem.Valu e & _ " pizza with the following toppings: <br>" &
ToppingDesc & "<br>" End If
End If
NewReleaseCount = Val(txtNewRelea ses.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.T oString & " standard video"
If StandardCount > 1 Then Desc &= "s"
Desc &= "<br>"
End If
'Assign the built string to the label
lblOrderDesc.Te xt = Desc
'Determine the Pizza SubTotal using business logic
values Select Case ddlPizzaSize.Se lectedItem.Valu e
Case "None" : Pizzas = 0.0
Case "Medium" : Pizzas = MEDIUM_BASE_PRI CE
Case "Large" : Pizzas = LARGE_BASE_PRIC E
Case "Gigantic" : Pizzas = GIGANTIC_BASE_P RICE
End Select
If chkPepperoni.Ch ecked Then Pizzas = Pizzas +
TOPPING_PRICE If chkSausage.Chec ked 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.Check ed Then Pizzas = Pizzas +
TOPPING_PRICE lblPizzaTotal.T ext = HTML_RIGHT_ALIG N & FormatCurrency
(Pizzas) 'Determine the movie subtotal using business logic
values Movies = NewReleaseCount * NEW_RELEASE_VID EO_PRICE
Movies = Movies + StandardCount * STANDARD_VIDEO_ PRICE
lblMovieTotal.T ext = HTML_RIGHT_ALIG N & FormatCurrency
(Movies) 'Determine the order subtotal, tax, delivery, and total
SubTotal = Pizzas + Movies
lblSubTotal.Tex t = HTML_RIGHT_ALIG N & FormatCurrency
(SubTotal) lblTax.Text = HTML_RIGHT_ALIG N & FormatCurrency
(SubTotal * TAX_RATE) If SubTotal > FREE_DELIVERY_A MOUNT Then
DeliveryFee = 0
Else
DeliveryFee = DELIVERY_FEE
End If
lblDelivery.Tex t = HTML_RIGHT_ALIG N & FormatCurrency
(DeliveryFee) Total = SubTotal + (SubTotal * TAX_RATE) + DeliveryFee
lblTotal.Text = HTML_RIGHT_ALIG N & FormatCurrency( Total)
'Determine the discount and the coupon price
Discount = Total * COUPON_DISCOUNT
lblDiscount.Tex t = HTML_RIGHT_ALIG N & FormatCurrency
(Discount) YourPrice = Total - Discount
lblYourPrice.Te xt = HTML_RIGHT_ALIG N & FormatCurrency
(YourPrice) 'Make the coupon and instructions visible
pnlCoupon.Visib le = 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_PRI CE As Double = 8.99
Const LARGE_BASE_PRIC E As Double = 10.99
Const GIGANTIC_BASE_P RICE As Double = 12.99
Const TOPPING_PRICE As Double = 0.99
Const STANDARD_VIDEO_ PRICE As Double = 1.95
Const NEW_RELEASE_VID EO_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_A MOUNT As Double = 20
'HTML constants
Const HTML_LEFT_ALIGN As String = "<p align=""left""> "
Const HTML_RIGHT_ALIG N 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.EventArg s) 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.It ems.Clear()
liNone = New ListItem
liNone.Text = "None"
liNone.Value = "None"
liMedium = New ListItem
liMedium.Text = "Medium (8"") -- " & FormatCurrency( MEDIUM_BASE_PRI CE)
liMedium.Value = "Medium"
liLarge = New ListItem
liLarge.Text = "Large (10"")-- " & FormatCurrency( LARGE_BASE_PRIC E)
liLarge.Value = "Large"
liGigantic = New ListItem
liGigantic.Text = "Gigantic (12"") -- " &
FormatCurrency( GIGANTIC_BASE_P RICE)
liGigantic.Valu e = "Gigantic"
ddlPizzaSize.It ems.Add(liNone)
ddlPizzaSize.It ems.Add(liMediu m)
ddlPizzaSize.It ems.Add(liLarge )
ddlPizzaSize.It ems.Add(liGigan tic)
ddlPizzaSize.Se lectedIndex = 0
lblExpDate.Text = HTML_RIGHT_ALIG N & "Offer valid through " & _
FormatDateTime( Today().AddDays (7))
lblDiscountDesc .Text = FormatPercent(C OUPON_DISCOUNT, 0) & " discount:"
Else
Session("mPizza s") = 0
Session("lPizza s") = 0
Session("gPizza s") = 0
Session("sToppi ngs") = 0
Session("numPiz zas") = 0
Session("sDesc" ) = mDesc
End If
End Sub
Private Sub btnCalculate_Cl ick(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnCalculate.Cl ick
'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(txtNewRelea ses.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.T oString & " standard video"
If StandardCount > 1 Then mDesc &= "s"
mDesc &= "<br>"
End If
'Assign the built string to the label
lblOrderDesc.Te xt = Session("sDesc" )
'Determine the movie subtotal using business logic values
Movies = NewReleaseCount * NEW_RELEASE_VID EO_PRICE
Movies = Movies + StandardCount * STANDARD_VIDEO_ PRICE
lblMovieTotal.T ext = HTML_RIGHT_ALIG N & FormatCurrency( Movies)
'Determine the order subtotal, tax, delivery, and total
SubTotal = (Session("mPizz as") * MEDIUM_BASE_PRI CE) + (Session("lPizz as") *
LARGE_BASE_PRIC E) + (Session("gPizz as") * GIGANTIC_BASE_P RICE) +
(Session("sTopp ings") * TOPPING_PRICE) + Movies
lblSubTotal.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( SubTotal)
lblTax.Text = HTML_RIGHT_ALIG N & FormatCurrency( SubTotal * TAX_RATE)
If SubTotal > FREE_DELIVERY_A MOUNT Then
DeliveryFee = 0
Else
DeliveryFee = DELIVERY_FEE
End If
lblDelivery.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( DeliveryFee)
Total = SubTotal + (SubTotal * TAX_RATE) + DeliveryFee
lblTotal.Text = HTML_RIGHT_ALIG N & FormatCurrency( Total)
'Determine the discount and the coupon price
Discount = Total * COUPON_DISCOUNT
lblDiscount.Tex t = HTML_RIGHT_ALIG N & FormatCurrency( Discount)
YourPrice = Total - Discount
lblYourPrice.Te xt = HTML_RIGHT_ALIG N & FormatCurrency( YourPrice)
'Make the coupon and instructions visible
pnlCoupon.Visib le = True
lblInstructions .Visible = True
End Sub
Private Sub btnOrder_Click( ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnOrder.Click
Dim ToppingDesc As String
Dim HasToppingFlag As Boolean
'Build a string with HTML formatted text describing the order
mDesc = ""
If ddlPizzaSize.Se lectedItem.Valu e <> "None" Then
ToppingDesc = ""
HasToppingFlag = False
If chkPepperoni.Ch ecked Then
ToppingDesc &= HTML_INDENT & "pepperoni <br>"
HasToppingFlag = True
End If
If chkSausage.Chec ked 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.Check ed Then
ToppingDesc &= HTML_INDENT & "onions <br>"
HasToppingFlag = True
End If
If HasToppingFlag = False Then
mDesc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.Se lectedItem.Valu e & _
" cheese pizza. <br>"
Else
mDesc = HTML_LEFT_ALIGN & "A " & ddlPizzaSize.Se lectedItem.Valu e & _
" pizza with the following toppings: <br>" & ToppingDesc & "<br>"
End If
End If
'Determine the Pizza SubTotal using business logic values
If Session("numPiz zas") < 2 Then
Select Case ddlPizzaSize.Se lectedItem.Valu e
Case "None" : Session("mPizza s") = Session("mPizza s") + 0.0
Case "Medium" : Session("mPizza s") = Session("mPizza s") + 1
Case "Large" : Session("lPizza s") = Session("lPizza s") + 1
Case "Gigantic" : Session("gPizza s") = Session("gPizza s") + 1
End Select
If chkPepperoni.Ch ecked Then Session("sToppi ngs") = Session("sToppi ngs") + 1
If chkSausage.Chec ked Then Session("sToppi ngs") = Session("sToppi ngs") + 1
If chkHam.Checked Then Session("sToppi ngs") = Session("sToppi ngs") + 1
If chkBlackOlives. Checked Then Session("sToppi ngs") = Session("sToppi ngs") +
1
If chkGreenPeppers .Checked Then Session("sToppi ngs") = Session("sToppi ngs")
+ 1
If chkOnions.Check ed Then Session("sToppi ngs") = Session("sToppi ngs") + 1
lblPizzaTotal.T ext = HTML_RIGHT_ALIG N & FormatCurrency( (Session("mPizz as") *
MEDIUM_BASE_PRI CE) + (Session("lPizz as") * LARGE_BASE_PRIC E) +
(Session("gPizz as") * GIGANTIC_BASE_P RICE) + (Session("sTopp ings") *
TOPPING_PRICE))
Else
lblLimitThree.V isible = 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 is what I have below. What we
have to do is make the app run so that it allows the user to add...
|
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 supremely important to me.
Anyhow is greatly appreciated thank you
the code is as follows:
public...
|
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 the amount of Dvds the user enters(decides to rent).
Based on the following input:
3 current 3...
| |
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 all I know to do because I have no idea where the problem is. I asked a friend, who is a literally...
|
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?")
noteFile=open(noteFileName,'r')
song=
for line in noteFile:
print line
tone=
|
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 (!ColumnEqual(LastSourceRow, SourceRow))
When the comparison function is called, a and b look exactly alike but...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |