 |
BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5  | This is the forum to discuss the Wrox book Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter Kit by David Sussman, Alex Homer; ISBN: 9780764588075 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

November 26th, 2006, 11:31 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I think I really need your help !
using System;
using System.Collections.Generic;
public class CartItem
{
private int _menuItemID;
private string _itemName;
private string _itemSize;
private int _quantity;
private decimal _itemPrice;
public CartItem(int MenuItemID, string ItemName, string ItemSize, int Quantity, decimal ItemPrice)
{
_menuItemID = MenuItemID;
_itemName = ItemName;
_itemSize = ItemSize;
_quantity = Quantity;
_itemPrice = ItemPrice;
}
public int MenuItemID
{
get
{
return _menuItemID;
}
set
{
_menuItemID = value;
}
}
public string ItemName
{
get
{
return _itemName;
}
set
{
_itemName = value;
}
}
public string ItemSize
{
get
{
return _itemSize;
}
set
{
_itemSize = value;
}
}
public int Quantity
{
get
{
return _quantity;
}
set
{
_quantity = value;
}
}
public decimal ItemPrice
{
get
{
return _itemPrice;
}
set
{
_itemPrice = value;
}
}
public decimal LineValue
{
get
{
return _quantity * _itemPrice;
}
}
}
public class ShoppingCart
{
private decimal _salesTaxPercent;
private List<CartItem> _items = new List<CartItem>();
public ShoppingCart()
{
if (_items is Nullable)
{
_items = new List<CartItem>();
}
_salesTaxPercent = Convert.ToDecimal("5.20");
}
public List<CartItem> Items
{
get
{
return _items;
}
}
public decimal SubTotal
{
get
{
decimal tot = 0;
foreach (CartItem item in _items)
{
tot += item.LineValue;
}
return tot;
}
}
private decimal _deliveryCharge = 3.5m;
public decimal DeliveryCharge
{
get
{
return _deliveryCharge;
}
set
{
_deliveryCharge = value;
}
}
public decimal SalesTaxPercent
{
get
{
return _salesTaxPercent;
}
}
public decimal SalesTax
{
get
{
return (SubTotal + DeliveryCharge) * SalesTaxPercent;
}
}
public decimal Total
{
get
{
return SubTotal + DeliveryCharge + SalesTax;
}
}
public void Insert(int MenuItemID, string ItemName, string ItemSize, int Quantity, decimal ItemPrice)
{
int idx = ItemIndex(MenuItemID, ItemSize);
if (idx == -1)
{
CartItem NewItem = new CartItem();
NewItem.MenuItemID = MenuItemID;
NewItem.ItemSize = ItemSize;
NewItem.ItemName = itemName;
NewItem.Quantity = Quantity;
NewItem.ItemPrice = ItemPrice;
_items.Add(NewItem);
}
else
{
_items(idx).Quantity += 1;
}
}
public void Update(int MenuItemID, string ItemName, string ItemSize, int Quantity, decimal ItemPrice)
{
int idx = ItemIndex(MenuItemID, ItemSze);
if (idx != -1)
{
_items(idx).Quantity = Quantity;
}
}
public void Delete(int MenuItemID, string ItemName, string ItemSize, int Quantity, decimal ItemPrice)
{
int idx = ItemIndex(MenuItemID, ItemSize);
if (idx != -1)
{
_items.RemoveAt(idx);
}
}
private int ItemIndex(int MenuItemID, string ItemSize)
{
foreach (CartItem item in _items)
{
if (item.MenuItemID = MenuItemID & item.ItemSize = ItemSize)
{
return index;
}
index += 1;
}
return -1;
}
}
|
|

November 26th, 2006, 11:33 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Public Class CartItem
Private _menuItemID As Integer
Private _itemName As String
Private _itemSize As String
Private _quantity As Integer
Private _itemPrice As Decimal
Public Sub New()
End Sub
Public Sub New(ByVal MenuItemID As Integer, ByVal ItemName As String, ByVal ItemSize As String, ByVal Quantity As Integer, ByVal ItemPrice As Decimal)
_menuItemID = MenuItemID
_itemName = ItemName
_itemSize = ItemSize
_quantity = Quantity
_itemPrice = ItemPrice
End Sub
''' <summary>
''' The ID of the menu item
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property MenuItemID() As Integer
Get
Return _menuItemID
End Get
Set(ByVal value As Integer)
_menuItemID = value
End Set
End Property
''' <summary>
''' The name of the menu item
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ItemName() As String
Get
Return _itemName
End Get
Set(ByVal value As String)
_itemName = value
End Set
End Property
''' <summary>
''' The size of the menu item
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ItemSize() As String
Get
Return _itemSize
End Get
Set(ByVal value As String)
_itemSize = value
End Set
End Property
''' <summary>
''' The quantity required
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Quantity() As Integer
Get
Return _quantity
End Get
Set(ByVal value As Integer)
_quantity = value
End Set
End Property
''' <summary>
''' The price of the menu item
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ItemPrice() As Decimal
Get
Return _itemPrice
End Get
Set(ByVal value As Decimal)
_itemPrice = value
End Set
End Property
''' <summary>
''' The value of the items
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property LineValue() As Decimal
Get
Return _quantity * _itemPrice
End Get
End Property
End Class
Public Class ShoppingCart
Private _salesTaxPercent As Decimal
Private _items As List(Of CartItem)
Public Sub New()
If _items Is Nothing Then
_items = New List(Of CartItem)
End If
_salesTaxPercent = Convert.ToDecimal(ConfigurationManager.AppSettings ("SalesTax"))
End Sub
Public ReadOnly Property Items() As List(Of CartItem)
Get
Return _items
End Get
End Property
Public ReadOnly Property SubTotal() As Decimal
Get
Dim tot As Decimal
For Each item As CartItem In _items
tot += item.LineValue
Next
Return tot
End Get
End Property
Private _deliveryCharge = 3.5
Public Property DeliveryCharge() As Decimal
Get
Return _deliveryCharge
End Get
Set(ByVal value As Decimal)
_deliveryCharge = value
End Set
End Property
''' <summary>
''' The percentage of sales tax
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks>Fetched from the web.config application configuration section. Read only.</remarks>
Public ReadOnly Property SalesTaxPercent() As Decimal
Get
Return _salesTaxPercent
End Get
End Property
''' <summary>
''' The value of the sales tax to be added to the order
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks>Read only</remarks>
Public ReadOnly Property SalesTax() As Decimal
Get
Return (SubTotal + DeliveryCharge) * SalesTaxPercent
End Get
End Property
''' <summary>
''' The total value of the order
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks>Read only</remarks>
Public ReadOnly Property Total() As Decimal
Get
Return SubTotal + DeliveryCharge + SalesTax
End Get
End Property
''' <summary>
''' Insert a new item into the cart
''' </summary>
''' <param name="MenuItemID"></param>
''' <param name="ItemSize"></param>
''' <param name="itemName"></param>
''' <param name="ItemPrice"></param>
''' <param name="Quantity"></param>
''' <remarks></remarks>
Public Sub Insert(ByVal MenuItemID As Integer, ByVal ItemSize As String, ByVal itemName As String, ByVal ItemPrice As Decimal, ByVal Quantity As Integer)
' check to see if the item already exists in the cart
Dim idx As Integer = ItemIndex(MenuItemID, ItemSize)
' -1 means the item wasn't in the cart already, so add it
If idx = -1 Then
' create a new cart item
Dim NewItem As New CartItem()
' set the properties of the new cart item to those passed into the Insert method
NewItem.MenuItemID = MenuItemID
NewItem.ItemSize = ItemSize
NewItem.ItemName = itemName
NewItem.Quantity = Quantity
NewItem.ItemPrice = ItemPrice
' add the new item to the collection
_items.Add(NewItem)
Else
' the item already exists, so just increment the quantity
_items(idx).Quantity += 1
End If
End Sub
''' <summary>
''' Update the quantity for an existing item in the cart
''' </summary>
''' <param name="MenuItemID"></param>
''' <param name="ItemSize"></param>
''' <param name="Quantity"></param>
''' <remarks></remarks>
Public Sub Update(ByVal MenuItemID As Integer, ByVal ItemSize As String, ByVal Quantity As Integer)
' TODO: reader exercise
' If the quantity is 0 the item could be removed from the cart
' you could put an 'If' statement in to check for the quantity
' - if it is less than or equal to 0 then cal the Delete method
' - if it is greater than 0 then use the code below
' find the index number of the item
Dim idx As Integer = ItemIndex(MenuItemID, ItemSize)
' if the item exists (that is, if the index value isn't -1), then update it
If idx <> -1 Then
_items(idx).Quantity = Quantity
End If
End Sub
''' <summary>
''' Delete an item from the collection
''' </summary>
''' <param name="MenuItemID"></param>
''' <param name="ItemSize"></param>
''' <remarks></remarks>
Public Sub Delete(ByVal MenuItemID As Integer, ByVal ItemSize As String)
' find the index number of the item
Dim idx As Integer = ItemIndex(MenuItemID, ItemSize)
' if the item exists (that is, if the index value isn't -1), then remove it
If idx <> -1 Then
_items.RemoveAt(idx)
End If
End Sub
''' <summary>
''' Fetch the index number of an item in the cart
''' </summary>
''' <param name="MenuItemID"></param>
''' <param name="ItemSize"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function ItemIndex(ByVal MenuItemID As Integer, ByVal ItemSize As String) As Integer
Dim index As Integer
' loop through the items search for a match
For Each item As CartItem In _items
' if the ID and the Size match, then the item has been found
If item.MenuItemID = MenuItemID AndAlso item.ItemSize = ItemSize Then
Return index
End If
index += 1
Next
' -1 indicates no match, so the item didn't exist in the collection
Return -1
End Function
End Class
|
|

November 26th, 2006, 11:34 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm try to write the ShoppingCart. vb by C#
But is runs not so well!
Help me !
Thanks!
|
|

November 26th, 2006, 11:36 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
public class ShoppingCart
{
private decimal _salesTaxPercent;
private List<CartItem> _items = new List<CartItem>();
public ShoppingCart()
{
if (_items is Nullable)
{
_items = new List<CartItem>();
}
_salesTaxPercent = Convert.ToDecimal("5.20");
}
public List<CartItem> Items
{
get
{
return _items;
}
}
public decimal SubTotal
{
get
{
decimal tot = 0;
foreach (CartItem item in _items)
{
tot += item.LineValue;
}
return tot;
}
}
private decimal _deliveryCharge = 3.5m;
public decimal DeliveryCharge
{
get
{
return _deliveryCharge;
}
set
{
_deliveryCharge = value;
}
}
public decimal SalesTaxPercent
{
get
{
return _salesTaxPercent;
}
}
public decimal SalesTax
{
get
{
return (SubTotal + DeliveryCharge) * SalesTaxPercent;
}
}
public decimal Total
{
get
{
return SubTotal + DeliveryCharge + SalesTax;
}
}
public void Insert(int MenuItemID, string ItemName, string ItemSize, int Quantity, decimal ItemPrice)
{
int idx = ItemIndex(MenuItemID, ItemSize);
if (idx == -1)
{
CartItem NewItem = new CartItem();
NewItem.MenuItemID = MenuItemID;
NewItem.ItemSize = ItemSize;
NewItem.ItemName = itemName;
NewItem.Quantity = Quantity;
NewItem.ItemPrice = ItemPrice;
_items.Add(NewItem);
}
else
{
_items(idx).Quantity += 1;
}
}
public void Update(int MenuItemID, string ItemName, string ItemSize, int Quantity, decimal ItemPrice)
{
int idx = ItemIndex(MenuItemID, ItemSze);
if (idx != -1)
{
_items(idx).Quantity = Quantity;
}
}
public void Delete(int MenuItemID, string ItemName, string ItemSize, int Quantity, decimal ItemPrice)
{
int idx = ItemIndex(MenuItemID, ItemSize);
if (idx != -1)
{
_items.RemoveAt(idx);
}
}
private int ItemIndex(int MenuItemID, string ItemSize)
{
foreach (CartItem item in _items)
{
if (item.MenuItemID = MenuItemID & item.ItemSize = ItemSize)
{
return index;
}
index += 1;
}
return -1;
}
}
This parts is so terrible,I was failed!
|
|

November 26th, 2006, 11:36 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
help me!
I really need your help!
|
|

November 26th, 2006, 11:55 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks!
|
|

November 27th, 2006, 11:06 AM
|
 |
Wrox Staff
Points: 18,059, Level: 58 |
|
|
Join Date: May 2003
Posts: 1,906
Thanks: 62
Thanked 139 Times in 101 Posts
|
|
Kuuy: 2 notes for you about these forums:
1. Please don't cross post. You posted all of these same posts in another book's forum as well.
2. Since it doesn't appear that these posts are about either book, please be sure in the future to ask your general ASP.NET questions that aren't about a book in one of the general ASP.NET forums here such as the ASP.NET 2.0 Beginner Forum:
http://p2p.wrox.com/forum.asp?FORUM_ID=133
I've deleted the repeated posts from the Server Controls book forum this time. Thanks.
Jim Minatel
Senior Acquisitions Editor
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
Jim's Book of the week: No book this week - Donate to the Red Cross!
|
|

November 27th, 2006, 12:53 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm so sorry!
Thanks for your advices!
|
|
 |