locked
problem with my shopping cart RRS feed

  • Question

  • User1915774515 posted

     Hello

     I'm developing a shopping cart in asp.net. But I'm stuck with a problem.

     I can add items to my shopping basket but i want to check that an item is already in the basket.

     I work with a list.

    Here is my code to add an item to my shopping cart:

    1    Dim orderline As New Orderline("DeleteVinyl.aspx?id=" & vinyl.vinylId, vinyl.vinylId, Session("lidId"), vinyl.title, artist.name, DropDownListAmount.SelectedValue, LabelPrice.Text * DropDownListAmount.SelectedValue, Now)
    2    
    3    Dim items As New List(Of Orderline)
    4    
    5    items = DirectCast(Session("karretje"), List(Of Orderline))
    6    
    7    if not items.contains(orderline) then
    8        items.add(orderline)
    9    end if
    After i did that I check if the item is allready in the shopping cart. If so I add 1 to my amount in orderline:
    1    For Each item As Orderlijn In items
    2        If item.VinylId = orderline.VinylId Then
    3           orderline.Amount += 1
    4        End If
    5    Next
    

    He adds 1 to my amount but the problem is that he keeps adding a new line in my shopping cart. For example:

    item   amount
    test   1
    test   2

    Can anyone help me with this problem?

    Kind regards
    Jurgen

    Thursday, January 8, 2009 2:54 PM

Answers

  • User-1760427068 posted

    I'm going to put an example here.  Please feel free to send me a private message if you want to make changes or additions to this project (it will be a work in progress).

     For a simple model I'm going to assume that you sell three products with names 1)red vinyl (price 20), 2)yellow vinyl (price 30), 3)blue vinyl (price 25).  A person has the opportunity to buy 1, 2, 3, 4 or 5 vinyls.

    [while I am making this I want to ask you a question: would you be interested in having dynamic controls so that you don't have to hard code the products into the page--imagine that you change the products you sell and if you have dynamic controls then the changes you make to a database (listing your products) automatically are carried over to your page with no additional work on your part.  The dynamic controls could include a textbox for each product too.]

    Can you post the code for your aspx page? I don't think I can duplicate the problem if I don't have your aspx page code (I might need the code behind too, not sure yet)

    Possibly is your goal that you have a table that for each record (row) it lists the customer name (or customer id) then also the quantities for the different types of vinyls (in my examples, three kinds)?

    -----------------------------

    Design of table "Vinyl1" (in database)

    • id, int (PRIMARY KEY- 1,1)
    • CustomerID nvarchar(20) NOT NULL
    • CustomerName nvarchar(50) NOT NULL
    • CustomerPhone nvarchar(20) NOT NULL
    • finalized bit  (default value is false)
    • RedVinylQty int (default value is 0)
    • YellowVinylQty int (default value is 0)
    • BlueVinylQty (default value is 0)

    Rational- when changes are made, they go to the table.  The 'finalized' bit changes from 0 to 1 if they press the finalize button.  Also if a potential customer makes choices but never clicks finalize you can call phone them and ask if they have questions or need help (and possibly make another sale). 

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="CreateTable.aspx.vb" Inherits="CreateTable" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Create Table</title>
    </head>
    <body>
        <form id="form1" runat="server">
    
        <asp:Button ID="CreateTableButton" runat="server" Text="Create Table" />
    
        </form>
    </body>
    </html>

     

    
    ********aspx code above*******************aspx.vb code behind below************* 
    

     

    Imports System.Data.SqlClient
    Imports System.Data
    
    Partial Class CreateTable
        Inherits System.Web.UI.Page
    
        Protected Sub CreateTableButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateTableButton.Click
    
            Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
            Dim createstatement As String = "CREATE TABLE Vinyl1 (id int IDENTITY(1,1) PRIMARY Key, CustomerID nvarchar(20) NOT NULL, CustomerName nvarchar(50) NOT NULL, CustomerPhone nvarchar(50) NOT NULL, finalized bit DEFAULT 'False', RedVinylQty int DEFAULT '0', YellowVinylQty int DEFAULT '0', BlueVinylQty int DEFAULT '0')"
            Dim cmd As SqlCommand = New SqlCommand(createstatement, conn)
            cmd.CommandType = CommandType.Text
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
    
        End Sub
    
    End Class
     working on at the moment -- 
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 8, 2009 5:51 PM
  • User1589032278 posted

    I had a suggestion to you which I used in one of my projects

    I used a stored procedure to add the products to a Shopping Cart which will check first if item already in the bascket, if yes it won't add it otherwise it will add it, Try it

     

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    
    CREATE PROCEDURE [dbo].[usp_AddToShoppingCart]
    	@UserlID varchar(50),
    	@ProductID int
    	
    AS
    BEGIN
    	-- SET NOCOUNT ON added to prevent extra result sets from
    	-- interfering with SELECT statements.
    	SET NOCOUNT ON;
    
        -- Insert statements for procedure here
    	UPDATE    ShoppingCart
    	SET DateAdded = getdate()
    	WHERE MemRefferalID = @UserID AND ProductID = @ProductID
    
    	IF @@rowcount = 0
    	
    	INSERT INTO ShoppingCart
                   (UserID, ProductID, DateAdded)
    	VALUES     (@MemRefferalID,@ProductID,getdate())
    
    END
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 2:13 PM

All replies

  • User-1760427068 posted

    Hi Jurgen:

    I'd like to help you with this.  Can you help me with a few questions to better understand what is happening?

    Here's how I think through it:

    1. You have a page where you select items (checkboxes, Textboxes, etc.)
    2. You push a button, the algorithm adds items to a list, you go to a second page
    3. The second page shows what you have on the list (i.e., what is in the shopping cart) (3 goes to 4 or 5)
    4. You can click a button to go back and make changes or
    5. You can click a button to finalize

    I don't understand what you mean when you say you want to check if an item is already in the basket.  Possibly you mean that if someone is at step 3 above and they  decide to go back, step 4, that they won't accidently buy a single item twice? (and then an angry customer who received two of something demands that you pay shipping return charges, etc.)

    Are people checking checkboxes to order an item?  Alternately do they have textboxes into which they can type in integers for quantities if you sell more than one of something?

    I think I can modify an example of a shopping cart that I have to fit your responses to the above questions.  Let me know if you are interested.

    (I'm looking at your question again and thinking, possibly, if you're not using textboxes for quantities, but you were given that option, possibly, that might eliminate the problem?) 

    (I'm also thinking if I post an example and you say that it is what you want, we can compare code and see the difference.)

     

    Thursday, January 8, 2009 4:39 PM
  • User1915774515 posted

     I have a gridview with a select button. If you click on the select button it goes to a page where you can see your order with a picture.

    There is a possibility to change the amount of vinyls with a dropdownlist. 

    If I want to order a vinyl i click on a button. When I've done that the order is in the shopping cart with the amount of vinyls that are ordered.
    This thing works completely.

    Now the user can order other vinyls...

    But if the user clicks on a vinyl that is allready ordered and in the basket, the item just comes under the other ordered items. This may not happen. In this case the amount of the allready ordered item must increase.

     You get it?

    If you want you may place a piece of code here and then we can compare.

    Thanks for helping

     

    Thursday, January 8, 2009 5:17 PM
  • User-1760427068 posted

    I'm going to put an example here.  Please feel free to send me a private message if you want to make changes or additions to this project (it will be a work in progress).

     For a simple model I'm going to assume that you sell three products with names 1)red vinyl (price 20), 2)yellow vinyl (price 30), 3)blue vinyl (price 25).  A person has the opportunity to buy 1, 2, 3, 4 or 5 vinyls.

    [while I am making this I want to ask you a question: would you be interested in having dynamic controls so that you don't have to hard code the products into the page--imagine that you change the products you sell and if you have dynamic controls then the changes you make to a database (listing your products) automatically are carried over to your page with no additional work on your part.  The dynamic controls could include a textbox for each product too.]

    Can you post the code for your aspx page? I don't think I can duplicate the problem if I don't have your aspx page code (I might need the code behind too, not sure yet)

    Possibly is your goal that you have a table that for each record (row) it lists the customer name (or customer id) then also the quantities for the different types of vinyls (in my examples, three kinds)?

    -----------------------------

    Design of table "Vinyl1" (in database)

    • id, int (PRIMARY KEY- 1,1)
    • CustomerID nvarchar(20) NOT NULL
    • CustomerName nvarchar(50) NOT NULL
    • CustomerPhone nvarchar(20) NOT NULL
    • finalized bit  (default value is false)
    • RedVinylQty int (default value is 0)
    • YellowVinylQty int (default value is 0)
    • BlueVinylQty (default value is 0)

    Rational- when changes are made, they go to the table.  The 'finalized' bit changes from 0 to 1 if they press the finalize button.  Also if a potential customer makes choices but never clicks finalize you can call phone them and ask if they have questions or need help (and possibly make another sale). 

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="CreateTable.aspx.vb" Inherits="CreateTable" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Create Table</title>
    </head>
    <body>
        <form id="form1" runat="server">
    
        <asp:Button ID="CreateTableButton" runat="server" Text="Create Table" />
    
        </form>
    </body>
    </html>

     

    
    ********aspx code above*******************aspx.vb code behind below************* 
    

     

    Imports System.Data.SqlClient
    Imports System.Data
    
    Partial Class CreateTable
        Inherits System.Web.UI.Page
    
        Protected Sub CreateTableButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateTableButton.Click
    
            Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
            Dim createstatement As String = "CREATE TABLE Vinyl1 (id int IDENTITY(1,1) PRIMARY Key, CustomerID nvarchar(20) NOT NULL, CustomerName nvarchar(50) NOT NULL, CustomerPhone nvarchar(50) NOT NULL, finalized bit DEFAULT 'False', RedVinylQty int DEFAULT '0', YellowVinylQty int DEFAULT '0', BlueVinylQty int DEFAULT '0')"
            Dim cmd As SqlCommand = New SqlCommand(createstatement, conn)
            cmd.CommandType = CommandType.Text
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
    
        End Sub
    
    End Class
     working on at the moment -- 
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 8, 2009 5:51 PM
  • User-1760427068 posted

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="ChooseVinyl.aspx.vb" Inherits="ChooseVinyl" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
    
        CustomerID: <asp:TextBox ID="CustomerIDTextBox" runat="server"></asp:TextBox><br /><br />
        
        CustomerName: <asp:TextBox ID="CustomerNameTextBox" runat="server"></asp:TextBox><br /><br />
        
        <table>
        <tr>
        <td>Red Vinyl</td><td>Yellow Vinyl</td><td>Blue Vinyl</td>
        </tr>
        <tr>
        <td><asp:DropDownList ID="RedVinylQtyDropDownList" runat="server">
            <asp:ListItem>0</asp:ListItem>
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList></td>
        <td><asp:DropDownList ID="YellowVinylQtyDropDownList" runat="server">
            <asp:ListItem>0</asp:ListItem>
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList></td> 
        <td><asp:DropDownList ID="BlueVinylQtyDropDownList" runat="server">
            <asp:ListItem>0</asp:ListItem>
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem>5</asp:ListItem>
            </asp:DropDownList></td>
        </tr>
        </table><br /><br />
        
        <asp:Button ID="UpdateButton" runat="server" Text="Update" /><br /><br />
        
        <div id="debug" runat="server" />
        
    
        </form>
    </body>
    </html>

     

    ******************aspx code above*************aspx.vb code behind below*************************

     

    Imports System.Data.SqlClient
    
    Partial Class ChooseVinyl
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
    
            'Check if the CustomerID already has a record
            debug.InnerHtml += "just started<br />"
            Dim conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
            Dim selectstatement As String = "Select id FROM Vinyl1 WHERE CustomerID=@customerid"
            Dim cmd As SqlCommand = New SqlCommand(selectstatement, conn)
            cmd.Parameters.AddWithValue("@customerid", CustomerIDTextBox.Text)
            conn.Open()
            Dim theid As String = Convert.ToString(cmd.ExecuteScalar())
            conn.Close()
            cmd.Dispose()
    
            If theid = "" Then
                Dim insertstatement As String = "INSERT INTO Vinyl1 (CustomerID, CustomerName, CustomerPhone) VALUES (@customerid, 'unknown', 'unknown')"
                cmd = New SqlCommand(insertstatement, conn)
                cmd.Parameters.AddWithValue("@customerid", CustomerIDTextBox.Text)
                conn.Open()
                cmd.ExecuteNonQuery()
                conn.Close()
                cmd.Dispose()
            End If
    
            Dim updatestatement As String = "UPDATE Vinyl1 SET CustomerName=@customername WHERE CustomerID=@customerid "
            updatestatement += "UPDATE Vinyl1 SET RedVinylQty=@red WHERE CustomerID=@customerid "
            updatestatement += "UPDATE Vinyl1 SET BlueVinylQty=@blue WHERE CustomerID=@customerid "
            updatestatement += "UPDATE Vinyl1 SET YellowVinylQty=@yellow WHERE CustomerID=@customerid "
            cmd = New SqlCommand(updatestatement, conn)
            cmd.Parameters.AddWithValue("@customername", CustomerNameTextBox.Text)
            cmd.Parameters.AddWithValue("@customerid", CustomerIDTextBox.Text)
            cmd.Parameters.AddWithValue("@red", RedVinylQtyDropDownList.Text)
            cmd.Parameters.AddWithValue("@blue", BlueVinylQtyDropDownList.Text)
            cmd.Parameters.AddWithValue("@yellow", YellowVinylQtyDropDownList.Text)
            conn.Open()
            cmd.ExecuteNonQuery()
            conn.Close()
            cmd.Dispose()
        End Sub
    End Class

     

    ********************************

    ********************************

    work is not finished yet -- we should discuss -- I think you will want it so the button click on the above page takes to a checkout page (even though with only three items we could argue that the page is simple enough to serve both as ordering and reviewing.  I assume you will want it to that the checkout page offers a link to take the program back to the shopping cart page.

    Also I'll want to know if A) you want me to look at both your aspx and code behind page for what you have (you can private message them to me if you prefer that); B) if we should take the above example further; C) if some of the things mentioned in an earlier post might appeal to you more than the above example.

     

    Thursday, January 8, 2009 10:29 PM
  • User1915774515 posted

    Here is my code for the aspx page:

     

    <%@ Page Language="VB" MasterPageFile="~/MJMusicShop.master" AutoEventWireup="false" CodeFile="BestelPlaat.aspx.vb" Inherits="plaat" Theme="MJMusicShop" title="Plaat bestellen" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <h1>Bestellen</h1>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <table>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                    <tr>
                        <td><asp:Image ID="ImageAfbeeldingVinyl" runat="server" Height="100" Width="100" /></td>
                        <td>
                            <asp:Label ID="LabelVinyl" runat="server" Text="Label" Font-Bold="True"></asp:Label>
                            <asp:Label ID="LabelUitgever" runat="server" Text="Label" Font-Italic="true"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>Prijs:</td>
                        <td><asp:Label ID="LabelPrijs" runat="server" Text="Label"></asp:Label></td>
                    </tr>
                    <tr>
                        <td><asp:Label ID="LabelAantal" runat="server" Text="Label"></asp:Label></td>
                        <td>
                            <asp:DropDownList ID="DropDownListAantal" runat="server">
                            </asp:DropDownList><asp:Button ID="ButtonUpdate" runat="server" Text="Update" />
                        </td>
                    </tr>
                    <tr>
                        <td><asp:Label ID="LabelVoorraad" runat="server" Text=""></asp:Label></td>
                        <td>
                            <asp:Image ID="ImageVoorraad" runat="server" /><i><asp:Label ID="LabelStock" runat="server" Text="Label"></asp:Label></i>
                        </td>
                    </tr>
            </ContentTemplate>
        </asp:UpdatePanel>
            <tr>
                <td><asp:Button ID="ButtonBestel" runat="server" Text="Bestel" /></td>
                <td><asp:Label ID="LabelFout" runat="server" Text="Label"></asp:Label></td>
            </tr>
        </table>
    </asp:Content>
    
    
    And here is my code behind the aspx page:

    Partial Class plaat
    Inherits System.Web.UI.Page

    Private _totaal, _prijs, _id, _artiestId, _berekening As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim blVinyl As BLVinyl = New BLVinyl
    Dim blArtiest As BLArtiest = New BLArtiest
    Dim blUitgever As BLUitgever = New BLUitgever
    Dim id As Integer = Request.QueryString("id")
    Dim artiestId As Integer = Request.QueryString("artiestId")

    Dim vinyl As Vinyl = blVinyl.GetVinylId(id)
    Dim artiest As Artiest = blArtiest.GetArtiestId(vinyl.artiestId)
    Dim uitgever As Uitgever = blUitgever.GetUitgeverById(vinyl.uitgeverId)

    _id = vinyl.vinylId

    _prijs = vinyl.prijs
    _artiestId = vinyl.artiestId

    If vinyl.afbeelding = "" Then
    ImageAfbeeldingVinyl.ImageUrl = "images/noPic.gif"
    Else
    ImageAfbeeldingVinyl.ImageUrl = vinyl.afbeelding
    End If

    LabelVinyl.Text = artiest.naam & " - " & vinyl.titel & "<br />"
    LabelUitgever.Text = uitgever.naam
    LabelPrijs.Text = "€ " & _prijs
    LabelAantal.Text = "Aantal:"
    LabelVoorraad.Text = "Voorraad:"
    LabelStock.Visible = False
    LabelFout.Visible = False

    If Not (Me.IsPostBack) Then
    Voorraad()
    End If

    For i As Integer = 1 To 10
    DropDownListAantal.Items.Add(i)
    Next
    End Sub
    Protected Sub ButtonUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click
    LabelPrijs.Text = "€ " & _prijs * DropDownListAantal.SelectedValue
    End Sub
    Protected Sub ButtonBestel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonBestel.Click
    Dim blVinyl As BLVinyl = New BLVinyl
    Dim blArtiest As BLArtiest = New BLArtiest

    Dim vinyl As Vinyl = blVinyl.GetVinylId(_id)
    Dim artiest As Artiest = blArtiest.GetArtiestId(vinyl.artiestId)

    Dim blLogin As BLLogin = New BLLogin

    If blLogin.IsAangemeld(Session("gebruikersnaam")) Then
    If vinyl.voorraad Is Nothing Or vinyl.voorraad = 0 Then
    LabelFout.Visible = True
    LabelFout.Text = "Deze vinyl is uit voorraad!"
    Else
    Dim orderlijn As New Orderlijn("VerwijderVinyl.aspx?id=" & vinyl.vinylId, vinyl.vinylId, Session("lidId"), vinyl.titel, artiest.naam, DropDownListAantal.SelectedValue, LabelPrijs.Text * DropDownListAantal.SelectedValue, Now)

    Dim aantal As Integer
    Dim stock As Integer

    Dim items As New List(Of Orderlijn)

    items = DirectCast(Session("karretje"), List(Of Orderlijn))

    For Each item As Orderlijn In items
    If item.VinylId = orderlijn.VinylId Then
    orderlijn.Aantal += 1
    End If
    Next

    If Not items.Contains(orderlijn) Then
    items.Add(orderlijn)
    End If

    For Each item In Session("karretje")
    aantal += 1

    Session("aantal") = "(" & aantal & ")"

    stock = vinyl.voorraad - DropDownListAantal.SelectedValue
    Next

    vinyl.voorraad = stock

    blVinyl.UpdateVinylVoorraad(vinyl)

    Response.Redirect("Vinyls.aspx")
    End If
    Else
    LabelFout.Visible = True
    LabelFout.Text = "You first have to login before you can order!"
    End If
    End Sub

    Protected Sub Voorraad()
    Dim blVinyl As BLVinyl = New BLVinyl
    Dim vinyl As Vinyl = blVinyl.GetVinylId(_id)

    Select Case vinyl.voorraad
    Case Is >= 6
    ImageVoorraad.ImageUrl = "images/voorraad.gif"
    Case Is > 4
    ImageVoorraad.ImageUrl = "images/voorraadHelft.gif"
    Case Is > 2
    ImageVoorraad.ImageUrl = "images/voorraadLeeg.gif"
    Case Is > 0
    ImageVoorraad.ImageUrl = "images/voorraadLeeg.gif"
    Case Else
    ImageVoorraad.Visible = False
    LabelStock.Visible = True
    LabelStock.Text = "Not in stock!"
    End Select
    End Sub
    End Class 
    This is the code for the order page. I'm sorry for the dutch words if you don't understand something just say it!
    Thanks again for helping me 
      
    Friday, January 9, 2009 4:24 AM
  • User-1760427068 posted

    Quick question: what is BL?  Possibly does it mean "current selection" as in the record that has just been selected?

    Deze vinyl is uit voorraad! -- I think this is "This record is out of stock!"  (we don't have any left so we would need to order more)

    I thought about asking you for your classes, but then I thought that if I "trace" through your code to reverse engineer it I will better understand your code which could make the next step easier.  I'll be putting my English translations next to words--let me know if something is wrong. 

    I suspect in your final version there will be more things in each class but that for this example we'll keep them to the minimum necessary.

    • vinyl  (name of record - example: "Roll With It")
    • artiest (artist - example: "Steve Winwood")
    • uitgever (record company - example: Virgin Records)
    • vinyl.afbeelding - afbeelding is name of image for album (example: rollwithitcover.jpg)
    • vinyl.vinylID - (my store will just have three records so it will be "1", "2" or "3")
    • vinyl.prijs - (price, every record will be $10)
    • vinyl.artiest - (artist)
    • vinyl.titel - (example: "Roll With It")
    • vinyl.voorraad (the number of records we have in our inventory)
    • blvinyl.GetVinylId (function that gets id from table "Vinyls" so info in table can be used later)
    • blvinyl.UpdateVinylVoorraad(function that first will write a line to a table, orders -- possibly in our example it justs prints the SQL)
    • artiest.naam (example: "Steve Winwood")
    • blartiest..GetArtiestId (function that gets id from table "Artiest" so info in table can be used later)
    • uitgever.naam (example: "Virgin Records")
    • bluitgever.GetUitgeverId (function that gets id from table "Uitgever" so info in table can be used later)
    • orderlign.VinylId (id of the record to be ordered)
    • orderlign.Aantal (number- possibly this is a number we use when processing the order?)

     

     

    Friday, January 9, 2009 9:08 AM
  • User1915774515 posted

     The BL stands for a class. I created a blclass for all my tables. In these bl classes there is for example the GetArtiestId.

     The orderlijn.aantal is the amount of the vinyls you ordered.

    The other translations are correct.

    Friday, January 9, 2009 9:31 AM
  • User1589032278 posted

    I had a suggestion to you which I used in one of my projects

    I used a stored procedure to add the products to a Shopping Cart which will check first if item already in the bascket, if yes it won't add it otherwise it will add it, Try it

     

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    GO
    
    CREATE PROCEDURE [dbo].[usp_AddToShoppingCart]
    	@UserlID varchar(50),
    	@ProductID int
    	
    AS
    BEGIN
    	-- SET NOCOUNT ON added to prevent extra result sets from
    	-- interfering with SELECT statements.
    	SET NOCOUNT ON;
    
        -- Insert statements for procedure here
    	UPDATE    ShoppingCart
    	SET DateAdded = getdate()
    	WHERE MemRefferalID = @UserID AND ProductID = @ProductID
    
    	IF @@rowcount = 0
    	
    	INSERT INTO ShoppingCart
                   (UserID, ProductID, DateAdded)
    	VALUES     (@MemRefferalID,@ProductID,getdate())
    
    END
    
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 2:13 PM
  • User1915774515 posted

     Thanks i wil try that!

    Saturday, January 10, 2009 2:18 PM