protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e) { // Get product ID string prodID = ""; Label tempProdID = DataList1.Items[e.Item.ItemIndex].FindControl("productId2") as Label; prodID = tempProdID.Text; // Check if the product is in the Customer's "Wish List" and "Shopping Cart" // If yes, delete those items, then only remove this from Seller Upload Table DataContextDataContext dbRemoveWishList = new DataContextDataContext(); var checkInWishList = (from p in dbRemoveWishList.WishLists where p.productID == int.Parse(prodID) select p).ToList(); dbRemoveWishList.WishLists.DeleteAllOnSubmit(checkInWishList.ToList()); dbRemoveWishList.SubmitChanges(); DataContextDataContext dbRemoveCart = new DataContextDataContext(); var checkInShoppingCart = (from p in dbRemoveCart.ShoppingCarts where p.productID == int.Parse(prodID) select p).ToList(); dbRemoveCart.ShoppingCarts.DeleteAllOnSubmit(checkInShoppingCart.ToList()); dbRemoveCart.SubmitChanges(); DataContextDataContext db = new DataContextDataContext(); ArtistUpload currentArtistUpload = db.ArtistUploads.Single(pId => pId.productID == int.Parse(prodID)); db.ArtistUploads.DeleteOnSubmit(currentArtistUpload); db.SubmitChanges(); BindUploadProduct(); }
protected void Button1_Click(object sender, EventArgs e) { int length = FileUpload2.PostedFile.ContentLength; byte[] pic = new byte[length]; FileUpload2.PostedFile.InputStream.Read(pic, 0, length); db = new DataContextDataContext(); ArtistUpload newArtistUpload = new ArtistUpload(); newArtistUpload.authorEmail = (string)Session["seller"]; newArtistUpload.description = artdescrip.Text; DateTime myDateTime = DateTime.ParseExact(Request.Form["date"], "yyyy-MM-dd", null); newArtistUpload.date = myDateTime; newArtistUpload.quantity = int.Parse(artquantity.Text); newArtistUpload.productname = ArtName.Text; newArtistUpload.productPrice = decimal.Parse(Price.Text); if (FileUpload2.HasFile == false) { Response.Write("<script>alert('Please choose an art to upload to proceed with selling it...')</script>"); } else { // Validate only allows the seller to upload image of type // jpg, JPG, jpeg, JPEG, png, PNG, gif, GIF, bmp, BMP Regex regex = new Regex(@"(.*?)\.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF|bmp|BMP)$"); if (regex.IsMatch(FileUpload2.FileName)) { newArtistUpload.artImage = pic; db.ArtistUploads.InsertOnSubmit(newArtistUpload); db.SubmitChanges(); Response.Write("<script>alert('Upload successful')</script>"); } else { Response.Write("<script>alert('Upload can only be image of type jpg, JPG, jpeg, JPEG, png, PNG, gif, GIF, bmp, BMP')</script>"); } } }
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e) { string prodID = ""; Label tempProdID = DataList1.Items[e.Item.ItemIndex].FindControl("productId1") as Label; prodID = tempProdID.Text; DataContextDataContext db = new DataContextDataContext(); ArtistUpload currentArtistUpload = db.ArtistUploads.Single(pId => pId.productID == int.Parse(prodID)); // Get updated image FileUpload updateImage = (FileUpload)DataList1.Items[DataList1.EditItemIndex].FindControl("FileUpload1"); byte[] img = new byte[updateImage.PostedFile.ContentLength]; updateImage.PostedFile.InputStream.Read(img, 0, img.Length); // If have update image then save into the database if (updateImage.HasFile) { // Validate only allows the seller to upload image of type // jpg, JPG, jpeg, JPEG, png, PNG, gif, GIF, bmp, BMP Regex regex = new Regex(@"(.*?)\.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF|bmp|BMP)$"); if (regex.IsMatch(updateImage.FileName)) { currentArtistUpload.artImage = img; } else { Response.Write("<script>alert('Upload can only be image of type jpg, JPG, jpeg, JPEG, png, PNG, gif, GIF, bmp, BMP, your changes made to this image has been rejected!')</script>"); } } TextBox txtTemp = DataList1.Items[e.Item.ItemIndex].FindControl("TextBox1") as TextBox; if (txtTemp != null) { currentArtistUpload.productname = txtTemp.Text; } txtTemp = DataList1.Items[e.Item.ItemIndex].FindControl("TextBox2") as TextBox; if (txtTemp != null) { currentArtistUpload.description = txtTemp.Text; } txtTemp = DataList1.Items[e.Item.ItemIndex].FindControl("TextBox3") as TextBox; if (txtTemp != null) { currentArtistUpload.quantity = int.Parse(txtTemp.Text); } txtTemp = DataList1.Items[e.Item.ItemIndex].FindControl("TextBox4") as TextBox; if (txtTemp != null) { currentArtistUpload.productPrice = decimal.Parse(txtTemp.Text); } db.SubmitChanges(); DataList1.EditItemIndex = -1; BindUploadProduct(); }
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "addToShoppingCart") { // Get Product ID int prodID = Convert.ToInt32(e.CommandArgument); // Get products from ArtistUpload Table with this prodID DataContextDataContext db1 = new DataContextDataContext(); ArtistUpload objArtistUpload = db1.ArtistUploads.Single(proID => proID.productID == prodID); //Validation if current quantity = 0, don't allow user to add to cart // Get Product quantity from seller and deduct it to see if it is 0 DataContextDataContext dba = new DataContextDataContext(); var deductProductQty = from p in dba.ArtistUploads join o in dba.WishLists on p.productID equals o.productID where p.productID == o.productID && p.productID == prodID select p; if (deductProductQty != null) { foreach (var deductQty in deductProductQty) { if (deductQty.quantity >= 1) { // If the item has already been added to the Shopping Cart then // Prompt the item has already been added to Shopping Cart // And remove the item from Wish List Boolean productAlreadyInCart = false; DataContextDataContext dbCheckShoppingCart = new DataContextDataContext(); var checkCShoppingCart = from p in dbCheckShoppingCart.ShoppingCarts where p.productID == prodID && p.customerEmail == (string)Session["user"] select p; foreach (var checkCart in checkCShoppingCart) { if (checkCart.productID == prodID) { productAlreadyInCart = true; } } if (productAlreadyInCart == true) { Response.Write("<script>alert('" + "This item " + deductQty.productname + " has already been added to the Shopping Cart! And will be romove from your Wish List!" + "')</script>"); // Delete this product from wish list DataContextDataContext dbDelete = new DataContextDataContext(); WishList deleteWishList = new WishList(); var query = dbDelete.WishLists.Where(wList => wList.productID == prodID).FirstOrDefault(); dbDelete.WishLists.DeleteOnSubmit(query); dbDelete.SubmitChanges(); HtmlMeta oScript = new HtmlMeta(); oScript.Attributes.Add("http-equiv", "REFRESH"); oScript.Attributes.Add("content", "0; url='CustomerWishList.aspx'"); Page.Header.Controls.Add(oScript); } if (productAlreadyInCart == false) { // Add this product to shopping cart DataContextDataContext db2 = new DataContextDataContext(); ShoppingCart newShoppingCart = new ShoppingCart(); newShoppingCart.productID = prodID; newShoppingCart.productName = objArtistUpload.productname; newShoppingCart.quantity = 1; newShoppingCart.unitPrice = objArtistUpload.productPrice; newShoppingCart.customerEmail = (string)Session["user"]; db2.ShoppingCarts.InsertOnSubmit(newShoppingCart); db2.SubmitChanges(); // Delete this product from wish list DataContextDataContext db3 = new DataContextDataContext(); WishList deleteWishList = new WishList(); var query = db3.WishLists.Where(wList => wList.productID == prodID).FirstOrDefault(); db3.WishLists.DeleteOnSubmit(query); db3.SubmitChanges(); // Send user back to this page Response.Write("<script>alert('" + "This item " + deductQty.productname + " has successfully been added to the Shopping Cart! And will be romove from your Wish List!" + "')</script>"); HtmlMeta oScript = new HtmlMeta(); oScript.Attributes.Add("http-equiv", "REFRESH"); oScript.Attributes.Add("content", "0; url='CustomerWishList.aspx'"); Page.Header.Controls.Add(oScript); } } else { Response.Write("<script>alert('" + "This item " + deductQty.productname + " is currently out of stock, please email the seller for more inquiry!" + "')</script>"); } } } } if (e.CommandName == "removeFromWishList") { // Get Wish list ID int wListID = Convert.ToInt32(e.CommandArgument); // Delete this product from wish list DataContextDataContext db = new DataContextDataContext(); WishList deleteWishList = new WishList(); var query = db.WishLists.Where(wList => wList.wishListID == wListID).FirstOrDefault(); db.WishLists.DeleteOnSubmit(query); db.SubmitChanges(); // Send user back to this page Response.Redirect("CustomerWishList.aspx"); } }