2017-09-21 4 views
0
  1. Je sauve les produits dans le tbl_ShopCart au tbl_Order
  2. Il peut y avoir plus d'un produit parce que j'utilise répéteur pour le magasin panier. Par exemple: Mon panier a 2 produits et j'appuie sur le bouton pour compléter mes achats et j'ai sauvegardé les données pour le tbl_Order. Mais le prix total est enregistré séparément pour les deux produits. Et je veux montrer le prix total en une ligne pour deux produits.

My DatabaseComment puis-je sauvegarder les données dans le répéteur à simple ligne

Et mon code aspx.cs:

protected void BtnCompleteOrder_Click(object sender, EventArgs e) 
{ 
    foreach(RepeaterItem item in Repeater1.Items) 
    { 
     if(item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) 
     { 
      Label lblproductid = (Label)item.FindControl("LblProductID"); 
      Image imgproductimage = (Image)item.FindControl("ImgProductImage"); 
      Label lblproductname = (Label)item.FindControl("LblProductName"); 
      Label lblprice = (Label)item.FindControl("LblPrice"); 
      Label lblpiece = (Label)item.FindControl("LblPiece"); 
      function.cmd("INSERT INTO tbl_Order(userid, productid, name, surname, email, identificationnumber, phone, productimage, productname, piece, cargo, totalprice, paymenttype, orderdate) VALUES('" + Session["userid"] + "', '" + lblproductid.Text + "', '" + Session["name"] + "', '" + Session["surname"] + "', '" + Session["email"] + "', '" + Session["identificationnumber"] + "', '" + Session["phone"] + "', '" + imgproductimage.ImageUrl + "', '" + lblproductname.Text + "', '" + lblpiece.Text + "', '" + Session["cargo"] + "', '" + LblTotalPrice.Text + "', '" + DrpDwnPaymentType.Text + "', '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')"); 
     } 
    } 
} 

// I add the cargo price on top of the total price, which gives us the lasttotal. 
decimal total = 0; 
decimal lasttotal = 0; 
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) 
{ 
    DataRowView item = e.Item.DataItem as DataRowView; 
    total += Convert.ToDecimal(item["price"]) * Convert.ToDecimal(item["piece"]); 
    LblShopCartTotal.Text = total.ToString(); 

    lasttotal = total + Convert.ToDecimal(LblCargo.Text); 
    LblTotalPrice.Text = lasttotal.ToString(); 
} 

Ceci est mon code de conception et la fenêtre de conception:

<table class="table shop-cart text-center"> 
    <thead> 
     <tr> 
      <th class="first"></th> 
      <th class="text-left text-uppercase font-weight-600 letter-spacing-2 text-small black-text">Product Name</th> 
      <th class="text-left text-uppercase font-weight-600 letter-spacing-2 text-small black-text">Price</th> 
      <th class="text-left text-uppercase font-weight-600 letter-spacing-2 text-small black-text">Piece</th> 
      <th></th> 
     </tr> 
    </thead> 
    <tbody> 
     <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater1_ItemDataBound"> 
      <ItemTemplate> 
       <tr> 
        <asp:Label ID="LblShopCartID" runat="server" Text='<%#Eval("shopcartid") %>' Visible="false"></asp:Label> 
        <asp:Label ID="LblProductID" runat="server" Text='<%#Eval("productid") %>' Visible="false"></asp:Label> 
        <td class="product-thumbnail text-left"><asp:Image ID="ImgProductImage" runat="server" Height="150px" Width="150px" ImageUrl='<%#Eval("productimage") %>' /></td> 
        <td class="text-left"><asp:Label ID="LblProductName" runat="server" Text='<%#Eval("productname") %>'></asp:Label></td> 
        <td class="text-left"><asp:Label ID="LblPrice" runat="server" Text='<%#Eval("price") %>'></asp:Label> TL</td> 
        <td class="product-subtotal text-left"><asp:Label ID="LblPiece" runat="server" Text='<%#Eval("piece") %>'></asp:Label></td> 
       </tr> 
      </ItemTemplate> 
     </asp:Repeater> 
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aytasarimConnectionString %>" SelectCommand="SELECT * FROM [tbl_ShopCart] WHERE ([userid] = @userid)"> 
      <SelectParameters> 
       <asp:SessionParameter Name="userid" SessionField="userid" Type="Int32" /> 
      </SelectParameters> 
     </asp:SqlDataSource> 
    </tbody> 
</table> 
<table class="table cart-total"> 
    <tbody> 
     <tr> 
      <th class="padding-two text-right no-padding-right text-uppercase font-weight-600 letter-spacing-2 text-small xs-no-padding">Shop Cart Total: </th> 
      <td class="padding-two text-uppercase text-right no-padding-right font-weight-600 black-text xs-no-padding"><asp:Label ID="LblShopCartTotal" Text="" runat="server"></asp:Label> ₺</td> 
     </tr> 
     <tr> 
      <th class="padding-two text-right no-padding-right text-uppercase font-weight-600 letter-spacing-2 text-small xs-no-padding">Cargo Price: </th> 
      <td class="padding-two text-uppercase text-right no-padding-right font-weight-600 black-text text-small xs-no-padding"><asp:Label ID="LblCargoPrice" runat="server" Text=""></asp:Label> ₺</td> 
     </tr> 
     <tr class="total"> 
      <th class="padding-two text-uppercase text-right no-padding-right font-weight-600 text-large xs-no-padding">Last Total: </th> 
      <td class="padding-two text-uppercase text-right no-padding-right font-weight-600 black-text text-large no-letter-spacing xs-no-padding"><asp:Label ID="LblTotalPrice" runat="server" Text=""></asp:Label> ₺</td> 
     </tr> 
    </tbody> 
</table> 

enter image description here Comment puis-je faire cela, tout des idées?

Répondre

0

Essayez quelque chose comme ceci: