protected void AddOrderToDB(CartItem ci, int order_code) { UthDataContext db = new UthDataContext(); UthOrder order = new UthOrder(); //get current user order.cust_id = db.UthCustomers.Single(c => c.cust_mail.Equals(User.Identity.Name)).cust_id; order.ord_code = order_code; order.ord_date = DateTime.Now; order.ord_delivered = false; order.ord_quantity = ci.Quantity; order.prod_id = ci.ProductId; db.UthOrders.InsertOnSubmit(order); UthProduct product = db.UthProducts.Single(p => p.prod_id == ci.ProductId); //substract <quantity> units from stock for this product //we can't have negative values in stock! int tempstock = product.prod_stock - order.ord_quantity; if (product.prod_stock > 0 && tempstock > 0) { product.prod_stock = tempstock; } //write changes db.SubmitChanges(); }
protected void lvProdDetail_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; UthProduct p = (UthProduct)dataItem.DataItem; string img_medium = "m.jpg"; string img_large = "l.jpg"; Literal ltProdMan = (Literal)e.Item.FindControl("ltProdMan"); ltProdMan.Text += p.UthManufacter.man_name; Literal ltProdName = (Literal)e.Item.FindControl("ltProdName"); ltProdName.Text += p.prod_name; HyperLink hlEnlargeImage = (HyperLink)e.Item.FindControl("hlEnlargeImage"); hlEnlargeImage.NavigateUrl = "~/ViewImage.aspx?img=" + p.img_id.ToString() + img_large; hlEnlargeImage.Attributes.Add("rel", "lightbox"); hlEnlargeImage.Attributes.Add("title", p.UthManufacter.man_name + " " + p.prod_name); Image imgProductMedium = (Image)e.Item.FindControl("imgProductMedium"); imgProductMedium.ImageUrl = "~/ViewImage.aspx?img=" + p.img_id.ToString() + img_medium; Literal ltModel = (Literal)e.Item.FindControl("ltModel"); ltModel.Text += p.prod_model; Literal ltPrice = (Literal)e.Item.FindControl("ltPrice"); ltPrice.Text += p.prod_price.ToString(); HyperLink hlCategory = (HyperLink)e.Item.FindControl("hlCategory"); hlCategory.NavigateUrl = "~/Search.aspx?ucid=" + p.cat_id.ToString(); Literal ltStock = (Literal)e.Item.FindControl("ltStock"); ltStock.Text += p.prod_stock.ToString(); Literal ltProdDesc = (Literal)e.Item.FindControl("ltProdDesc"); ltProdDesc.Text += p.prod_desc; HyperLink hlAddToCart1 = (HyperLink)e.Item.FindControl("hlAddToCart1"); hlAddToCart1.NavigateUrl = "~/AddToCart.aspx?id=" + p.prod_id; hlAddToCart1.Attributes.Add("title", "Add this product to your cart"); HyperLink hlAddToCart2 = (HyperLink)e.Item.FindControl("hlAddToCart2"); hlAddToCart2.NavigateUrl = "~/AddToCart.aspx?id=" + p.prod_id; }
protected void lvProducts_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; UthProduct p = (UthProduct)dataItem.DataItem; string img_format = "s.jpg"; HyperLink prod_link1 = (HyperLink)e.Item.FindControl("prod_link1"); prod_link1.NavigateUrl = "~/ViewProduct.aspx?id=" + p.prod_id; HyperLink prod_link2 = (HyperLink)e.Item.FindControl("prod_link2"); prod_link2.NavigateUrl = "~/ViewProduct.aspx?id=" + p.prod_id; HyperLink addToCart = (HyperLink)e.Item.FindControl("addToCart"); addToCart.NavigateUrl = "~/AddToCart.aspx?id=" + p.prod_id; addToCart.Attributes.Add("title", "Add this product to your cart"); Literal prod_man = (Literal)e.Item.FindControl("prod_man"); prod_man.Text = p.UthManufacter.man_name; Literal prod_name = (Literal)e.Item.FindControl("prod_name"); prod_name.Text = p.prod_name; Literal prod_price = (Literal)e.Item.FindControl("prod_price"); prod_price.Text += p.prod_price.ToString(); Literal prod_model = (Literal)e.Item.FindControl("prod_model"); prod_model.Text += p.prod_model; Image prod_img = (Image)e.Item.FindControl("prod_img"); prod_img.ImageUrl = "~/ViewImage.aspx?img=" + p.img_id + img_format; DataPager dpProducts = (DataPager)lvProducts.FindControl("dpProducts"); dpProducts.Visible = (howManyResults > dpProducts.PageSize); }
protected void lvBargain_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; UthProduct p = (UthProduct)dataItem.DataItem; string img_format = "s.jpg"; HyperLink prod_link1B = (HyperLink)e.Item.FindControl("prod_link1B"); prod_link1B.NavigateUrl = "~/ViewProduct.aspx?id=" + p.prod_id; HyperLink prod_link2B = (HyperLink)e.Item.FindControl("prod_link2B"); prod_link2B.NavigateUrl = "~/ViewProduct.aspx?id=" + p.prod_id; HyperLink addToCartB = (HyperLink)e.Item.FindControl("addToCartB"); addToCartB.NavigateUrl = "~/AddToCart.aspx?id=" + p.prod_id; addToCartB.Attributes.Add("title", "Add this product to your cart"); Literal prod_manB = (Literal)e.Item.FindControl("prod_manB"); prod_manB.Text = p.UthManufacter.man_name.ToString(); Literal prod_nameB = (Literal)e.Item.FindControl("prod_nameB"); prod_nameB.Text = p.prod_name; Literal prod_priceB = (Literal)e.Item.FindControl("prod_priceB"); prod_priceB.Text += p.prod_price.ToString(); Literal prod_modelB = (Literal)e.Item.FindControl("prod_modelB"); prod_modelB.Text += p.prod_model; Image prod_imgB = (Image)e.Item.FindControl("prod_imgB"); prod_imgB.ImageUrl = "~/ViewImage.aspx?img=" + p.img_id + img_format; }
protected void lvAlsoBought_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; UthProduct p = (UthProduct)dataItem.DataItem; string img_format = "s.jpg"; HyperLink prod_link1 = (HyperLink)e.Item.FindControl("prod_link1"); prod_link1.NavigateUrl = "~/ViewProduct.aspx?id=" + p.prod_id; HyperLink prod_link2 = (HyperLink)e.Item.FindControl("prod_link2"); prod_link2.NavigateUrl = "~/ViewProduct.aspx?id=" + p.prod_id; HyperLink addToCart = (HyperLink)e.Item.FindControl("addToCart"); addToCart.NavigateUrl = "~/AddToCart.aspx?id=" + p.prod_id; Literal prod_man = (Literal)e.Item.FindControl("prod_man"); prod_man.Text = p.UthManufacter.man_name.ToString(); Literal prod_name = (Literal)e.Item.FindControl("prod_name"); prod_name.Text = p.prod_name; Literal prod_price = (Literal)e.Item.FindControl("prod_price"); prod_price.Text += p.prod_price.ToString(); Literal prod_model = (Literal)e.Item.FindControl("prod_model"); prod_model.Text += p.prod_model; Image prod_img = (Image)e.Item.FindControl("prod_img"); prod_img.ImageUrl = "~/ViewImage.aspx?img=" + p.img_id + img_format; }