help for a poor student :S

This is a discussion on help for a poor student :S within the C# Programming forums, part of the General Programming Boards category; hey, im working on this code for an assignment and cant seem to get it to work, can anyone help ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    1

    help for a poor student :S

    hey, im working on this code for an assignment and cant seem to get it to work, can anyone help me? Its full of intentional errors, but i cant seem to work them all out I've got half of them, just the otha half. Just a pain cos im learning C# while i do this.

    Source below:

    Code:
    <%@ Import Namespace="System.Data.OleDb" %>
    <%@ Import Namespace="System.Data" %>
    
    <html>
    <head>
    <title>I170 Ecommerce Shopping Cart</title>
    <script runat="server" language="c#">
    
    OleDbConnection objConn = new OleDbConnection("");
    OleDbDataAdapter objDA;
    DataSet objDS = newDataSet();
    DataRow objCartDT;
    
    void Page_Load() {
      if (!IsPostBack) {
        objDA = new OleDbDataAdapter("SELECT * FROM EmployeeStore",
            objConn);
        objDA.Fill(objDS, "Store");
        dlItems.DataSource = objDS;
        dlItems.DataBind();
        
        pnlShowCart.Visible = false;
      }
      objCartDT = (DataTable)Session["Cart"];
      if (objCartDT == null) {
        objCartDT = new DataTable("Cart");
        objCartDT.Columns.Add("CartID", typeof(Int32));
        objCartDT.Columns["CartID"].AutoIncrement = true;
        objCartDT.Columns["CartID"].AutoIncrementSeed = 1;
        objCartDT.Columns.Add("ItemID", typeof(Int32));
        objCartDT.Columns.Add("Quantity", typeof(Int32));
        objCartDT.Columns.Add("Item", typeof(string));
        objCartDT.Columns.Add("Cost", typeof(Decimal));
        Session["Cart"] = objCartDT;
      }
    }
    }
    void AddToCart(Object s, DataListCommandEventArgs e) {
      pnlShowItems.Visible = false;
      pnlShowCart.Visible = true;
      
      int ItemID = Convert.ToInt32(
          dlItems.DataKeys[e.Item.ItemIndex]);
      DataSet objItemInfo = FindItem(ItemID);
      
      objDR = objCartDT.NewRow();
      objDR["ItemID"] = ItemID;
      objDR["Item"] =
          objItemInfo.Tables["ItemInfo"].Rows[0]["ItemName"];
      objDR["Quantity"] = 1;
      objDR["Cost"] = objItemInfo.Tables["ItemInfo"].Rows[0]["Cost"];
      objCartDT.Rows.Add(objDR);
      
      dgCart.DataSource = objCartDT;
      dgCart.DataBind();
    }
    }
    if (!blnMatch){
    objDR = objCartDT.NewRow();
    objDR["ItemID"] = ItemID;
    objDR["Item"] = objItemInfo.Tables["ItemInfo"].Rows[0]["ItemName"];
    objDR["Quantity"] = 1;
    objDR["Cost"] = objItemInfo.Tables["ItemInfo"].Rows[0]["Cost"];
    objCartDT.Rows.Add(objDR);
    }
    dgCart.DataSource = objCartDT;
    dgCart.DataBind();
    lblTotal.Text = "$" + GetItemTotal();
    }
    DataSet FindItem(int ItemID){
    DataSet objItemInfo = new DataSet();
    objDA = new OleDbDataAdapter("SELECT * FROM products WHERE ItemID=" + ItemID, objConn);
    objDA.Fill(objItemInfo, "ItemInfo");
    return objItemInfo;
    }
    Decimal GetItemTotal() {
      decimal decRunningTotal = 0;
      
      foreach (DataRow objDR in objCartDT.Rows) {
        decRunningTotal +=
            Decimal.Round(Convert.ToDecimal(objDR["Cost"]) *
                Convert.ToInt32(objDR["Quantity"]), 2);
      }
      
      return decRunningTotal;
    }
    void dgCart_Edit(Object s, DataGridCommandEventArgs e) {
    dgCart.EditItemIndex = e.Item.ItemIndex;
    dgCart.DataSource = objCartDT;
    dgCart.DataBind();
    }
    void dgCart_Cancel(Object s, DataGridCommandEventArgs e) {
    dgCart.EditItemIndex = -1;
    dgCart.DataSource = objCartDT;
    dgCart.DataBind();
    }
    void dgCart_Update(object s, DataGridCommandEventArgs e) {
    TextBox txtQuantity;
    int intCartID;
    intCartID = Convert.ToInt32(dgCart.DataKeys[e.Item.ItemIndex]);
    txtQuantity = (TextBox)e.Item.FindControl("txtQuantity");
    foreach (DataRow objDR in objCartDT.Rows){
    if (intCartID == (int)objDR["CartID"]){
    objDR["Quantity"] = Convert.ToInt32(txtQuantity.Text);
    break;
    }
    }
    lblTotal.Text = "$" + GetItemTotal();
    dgCart.EditItemIndex = -1;
    dgCart.DataSource = objCartDT;
    dgCart.DataBind();
    }
    void dgCart_Delete(Object s, DataGridCommandEventArgs e){
    objCartDT.Rows[e.Item.ItemIndex].Delete();
    dgCart.DataSource = objCartDT;
    dgCart.DataBind();
    lblTotal.Text = "$" + GetItemTotal();
    }
    void ContinueShopping(Object s, EventArgs e){
    pnlShowCart.Visible = false;
    pnlShowCart.Visible = true;
    }
    void CheckOut(Object s, EventArgs e){
    String cartBusiness = "r.dargie@ucol.ac.nz";
    String cartProduct;
    int cartQuantity;
    Decimal cartCost;
    int itemNumber = 1;
    cartBusiness = Server.UrlEncode(cartBusiness);
    String strPayPal = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1&business=" + cartBusiness;
    foreach (DataRow objDR in objCartDT.Rows){
    cartProduct = Server.UrlEncode((String)objDR["Item"]);
    cartQuantity = (int)objDR["Quantity"];
    cartCost = (Decimal)objDR["Cost"];
    strPayPal += "&Item_name_" + itemNumber + "=" + cartProduct;
    strPayPal += "&Item_number_" + itemNumber + "=" + cartQuantity; 
    strPayPal += "&amount_" + itemNumber + "=" + Decimal.Round(cartQuantity * cartCost, 2); 
    itemNumber++;
    }
    Response.Redirect(strPayPal);
    }
    </script>
    </head>
    <body>
    <form runat="server">
    <table width="100%" border="0" cellspacing="0" cellpadding="10">
    <tr>
    <td valign="top" width="160">
    <td valign="top">
    <asp:Panel id="pnlShowItems" runat="server">
    <h1>I170 Shopping Cart Assignment</h1>
    <asp:DataList id="dlItems" runat="server" DataKeyField="ItemID" OnEditCommand="AddToCart">
    <ItemTemplate>
    <table width="400" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="200" valign="top" align="center">
    <img src='<%# DataBinder.Eval(Container.DataItem, "ImageURL") %>' />
    </td>
    <td width="200">
    <strong><%# DataBinder.Eval(Container.DataItem, "ItemName") %></strong><br />
    Cost: $<%# DataBinder.Eval(COntainer.DataItem, "Cost") %><br /><br />
    <asp:Button id="btnAddToCart" runat="server" Text="Add To Cart" CommandName="Edit" />
    </td>
    </tr>
    <tr>
    <td colspan="2" width="400"><hr noshade height="1" /></td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:DataList>
    </asp:Panel>
    <asp:Panel id="pnlShowCart" runat="server">
    <h1>View Cart</h1>
    <asp:DataGrid id="dgCart" runat="server" AutoGenerateColumns="false" GridLines="None" CellPadding="3" Width="100%" DataKeyField="CartID" OnCancelCommand="dgCart_Cancel" OnDeleteCommand="dgCart_Delete" OnEditCommand="dgCart_Edit" OnUpdateCommand="dgCart_Update">
    <HeaderStyle Font-Name="arial" Backcolor="#003366" Forecolor="#FFFFFF" Font-Bold="true" Font-Size="10" />
    <ItemStyle Font-Name="arial" Font-Size="10" />
    <Columns>
    <asp:EditCommandColumn EditText="Change Quantity" CancelText="Cancel" UpdateText="Update" />
    <asp:ButtonColumn ButtonType="LinkButton" CommandName="Delete" Text="Remove" />
    <asp:BoundColumn DataField="Item" HeaderText="Product Name" ReadOnly="true" />
    <asp:TemplateColumn HeaderText="Quantity">
    <ItemTemplate>
    <%# DataBinder.Eval(container.DataItem, "Quantity") %>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox id="txtQuantity" Text='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' runat="server" Width="50" />
    </EditItemTemplate>
    </asp:TemplateColumn>
    
    </Columns>
    </asp:DataGrid>
    <p align="right"><strong>Total: <asp:Label id="lblTotal" runat="server" /></strong></p>
    <p align="right"><asp:LinkButton id="lbContinue" Text="Continue Shopping" runat="server" OnClick="Continue Shopping" />
    <asp:LinkButton id="lbCheckOut" Text="Checkout" runat="server" OnClick="CheckOut" /></p>
    </asp:Panel>
    </td>
    </tr>
    </table>
    </form>
    </html>

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Well, you don't have a </body> tag. But that tag's optional, anyway.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Erm, </body> isn't optional. You have to have that if you are coding under proper HTML syntax.

  4. #4
    Registered User
    Join Date
    Apr 2004
    Posts
    29

    closing tags

    Closing tags sometimes aren't needed in html, but as everyone moves to xhtml they are required, and all tags should be in lower case.

    EdCompSci

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21