private void sendReceipt(Order order, List <Order_Artwork> oaList, string emailAddress) { string subject = "Thank you for your purchase!"; string body = "<h1>Your order has been successfully confirmed</h1>" + "\n<h2>Order ID: " + order.OrderId + "</h2>" + "\n<h2>Order Date: " + order.OrderDate + "</h2>" + "\n<h3>Delivering to: " + order.DeliveryAddress + "</h2>" + "\n<hr/>" + "\n<h4>Order Items</h5>"; foreach (Order_Artwork oa in oaList) { // Get artpiece name ArtpieceDao artpieceDao = new ArtpieceDao(); Classes.Artpiece artpiece = artpieceDao.Get("ARTPIECEID", oa.ArtpieceId); // Get artist name ArtistDao artistDao = new ArtistDao(); Classes.Artist artist = artistDao.Get("ARTISTID", artpiece.ArtistId); body += "<b>" + artpiece.Title + "</b> by <i>" + artist.DisplayName + "</i> ( x" + oa.Quantity + " )<br/>"; } // Display total body += "\n<h4>Total: RM" + Quick.FormatPrice(order.TotalPrice) + "</h4>"; // Send email Email.SendEmail(emailAddress, subject, body); }
private void pay() { // Get customer details Customer customer = (Customer)Net.GetSession("customer"); // Get count List <Order_Artwork> oaList = (List <Order_Artwork>)Net.GetSession("oaList"); int itemCount = oaList.Count; double total = 0; // Create order Order order = (Order)Net.GetSession("order"); IdGen IdGen = new IdGen(); order.OrderId = IdGen.GenerateId("custorder"); order.OrderDate = DateTime.Now; order.IsCanceled = false; order.CustomerId = customer.Id; order.DeliveryAddress = txtAddress.Text; foreach (Order_Artwork oa in oaList) { // Cumulate price ArtpieceDao dao = new ArtpieceDao(); Classes.Artpiece artpiece = dao.Get("ARTPIECEID", oa.ArtpieceId); total += oa.Quantity * artpiece.Price; // Set Foreign Keys oa.ArtpieceId = artpiece.ArtpieceId; oa.OrderId = order.OrderId; // Update stocks artpiece.Stocks = artpiece.Stocks - oa.Quantity; // Update artpiece ArtpieceDao artpieceDao = new ArtpieceDao(); artpieceDao.Update(artpiece); } // Set cumulated price as total price order.TotalPrice = total; // Insert order CustorderDao custorderDao = new CustorderDao(); custorderDao.Add(order); // Insert OrderArtwork foreach (Order_Artwork oa in oaList) { OrderArtworkDao orderArtworkDao = new OrderArtworkDao(); orderArtworkDao.Add(oa); } // Send receipt sendReceipt(order, oaList, customer.Email); // Clear cart Net.SetSession("order", new Order()); Net.SetSession("oaList", new List <Order_Artwork>()); Net.SetSession("cartSaved", false); }
protected void Page_Load(object sender, EventArgs e) { // Initialize FormatLbl = new FormatLabel(lblEditError); artpiece = new Classes.Artpiece(); // To ensure that a valid username is entered string artpieceId = ""; try { artpieceId = Request.QueryString["id"].ToString(); } catch (Exception ex) { //Show error msg } // Get from DB ArtpieceDao dao = new ArtpieceDao(); artpiece = dao.Get("ARTPIECEID", artpieceId); // Validate artpiece ID if (artpiece == null) { Net.Redirect("Artpiece.aspx?id=UNKNOWN"); } else { // Get Artist info ArtistDao artistDao = new ArtistDao(); artist = artistDao.Get("ARTISTID", artpiece.ArtistId); // Will be null if currently logged in user is not an artist Artist currentArtist = (Artist)Session["Artist"]; // Redirect if not original artist if (currentArtist == null || artpiece.ArtistId != currentArtist.Id) { Net.Redirect("Artpiece.aspx?id=" + artpiece.ArtpieceId); } else { // Show private artpiece to the original artist if (!artpiece.IsPublic && currentArtist.Id == artist.Id) { if (!IsPostBack) { //Display artpiece details lblArtist.Text = artist.DisplayName; lblDescription.Text = artpiece.About; lblTitle.Text = artpiece.Title + "(PRIVATE ARTPIECE)"; txtStocks.Text = artpiece.Stocks + ""; artpieceImg.ImageUrl = artpiece.ImageLink; lblArtpiecePrice.Text = Quick.FormatPrice(artpiece.Price); if (!artpiece.IsForSale) { lblForSale.Text = "NOT FOR SALE"; lblForSale.CssClass = "notforsale"; } } } else // Show public artpiece { if (!IsPostBack) { //Display artpiece details lblArtist.Text = artist.DisplayName; lblDescription.Text = artpiece.About; lblTitle.Text = artpiece.Title; txtStocks.Text = artpiece.Stocks + ""; lblArtpiecePrice.Text = Quick.FormatPrice(artpiece.Price); artpieceImg.ImageUrl = artpiece.ImageLink; if (!artpiece.IsForSale) { lblForSale.Text = "NOT FOR SALE"; lblForSale.CssClass = "notforsale"; } } } } } }
protected void Page_Load(object sender, EventArgs e) { artpiece = new Classes.Artpiece(); // Hide edit button first btnEdit.Visible = false; //Hide buttons first btnAddToWishlist.Visible = false; btnAddToCart.Visible = false; btnViewArtist.Visible = false; // To ensure that a valid username is entered string artpieceId = ""; try { artpieceId = Request.QueryString["id"].ToString(); } catch (Exception ex) { //Show error msg } // Get from DB ArtpieceDao dao = new ArtpieceDao(); artpiece = dao.Get("ARTPIECEID", artpieceId); // Validate artpiece ID if (artpiece == null) { lblTitle.Text = "Artpiece does not exist"; } else { // Get Artist info ArtistDao artistDao = new ArtistDao(); artist = artistDao.Get("ARTISTID", artpiece.ArtistId); // Will be null if currently logged in user is not an artist Artist currentArtist = (Artist)Session["Artist"]; // Block private artpiece from customer if (!artpiece.IsPublic && currentArtist == null) { lblTitle.Text = "Artpiece is private"; } else { // Block private artpiece from other artists if (!artpiece.IsPublic && currentArtist.Id != artist.Id) { lblTitle.Text = "Artpiece is private"; } // Show private artpiece to the original artist else if (!artpiece.IsPublic && currentArtist.Id == artist.Id) { //Display artpiece details lblArtist.Text = artist.DisplayName; lblDescription.Text = artpiece.About; lblTitle.Text = artpiece.Title + "(PRIVATE ARTPIECE)"; lblStocks.Text = artpiece.Stocks + ""; artpieceImg.ImageUrl = artpiece.ImageLink; lblArtpiecePrice.Text = Quick.FormatPrice(artpiece.Price); if (!artpiece.IsForSale) { lblForSale.Text = "NOT FOR SALE"; lblForSale.CssClass = "notforsale"; } } else // Show public artpiece { LoadBt(); // Make buttons visible btnViewArtist.Visible = true; //Display artpiece details lblArtist.Text = artist.DisplayName; lblDescription.Text = artpiece.About; lblTitle.Text = artpiece.Title; lblStocks.Text = artpiece.Stocks + ""; lblArtpiecePrice.Text = Quick.FormatPrice(artpiece.Price); artpieceImg.ImageUrl = artpiece.ImageLink; if (!artpiece.IsForSale) { lblForSale.Text = "NOT FOR SALE"; lblForSale.CssClass = "notforsale"; } } // Show edit button if this is the original artist if (currentArtist != null && currentArtist.Id == artist.Id) { btnEdit.Visible = true; } } } }
protected void uploadBt_Click(object sender, EventArgs e) { // Validate form first string errorMsg = ValidateForm(); if (errorMsg != null) // If there is an error { // Set the error msg lblUploadError = FormatLbl.Error(errorMsg); } else // If there is no error { // Obtain artist info Artist artist = (Artist)Session["artist"]; // Generate Artpiece Id IdGen IdGen = new IdGen(); String ArtpieceId = IdGen.GenerateId("Artpiece"); // Obtain the values from the form Classes.Artpiece artpiece = new Classes.Artpiece(); artpiece.ArtpieceId = ArtpieceId; artpiece.ArtistId = artist.Id; artpiece.Tags = txtTags.Text; artpiece.About = txtDescription.Text; artpiece.Title = txtTitle.Text; artpiece.Price = Convert.ToDouble(txtPrice.Text); artpiece.Stocks = Convert.ToInt32(txtStocks.Text); // Need to validate // NOTE! NEED TO CHANGE TO DROPDOWNLIST if (rblForSale.SelectedValue == "yes") // If the artpiece is for sale { artpiece.IsForSale = true; } else { artpiece.IsForSale = false; } // NOTE! NEED TO CHANGE TO DROPDOWNLIST if (rblIsPublic.SelectedValue == "yes") // If the artpiece is public { artpiece.IsPublic = true; } else { artpiece.IsPublic = false; } //debug Quick.Print("selected forsale is " + rblIsPublic.SelectedValue); FileUtil file = new FileUtil(fileBt, "~/Pics/"); // Set image link artpiece.ImageLink = file.GetAddress(); // VERIFY THAT IMAGE LINK DOES NOT HAVE DUPLICATE NAME ArtpieceDao linkCheckDao = new ArtpieceDao(); Classes.Artpiece checkArtpiece = linkCheckDao.Get("IMAGELINK", file.GetAddress()); if (checkArtpiece != null) // If there is a duplicate file name { // Set the error msg lblUploadError = FormatLbl.Error("An image with that name already exists. Please rename."); } else // If there is no duplicate { Quick.Print(file.GetFileName().Substring(file.GetFileName().Length - 4)); // Check file type if (file.GetFileName().Substring(file.GetFileName().Length - 4) != ".jpg" && file.GetFileName().Substring(file.GetFileName().Length - 4) != ".png" && file.GetFileName().Substring(file.GetFileName().Length - 5) != ".jpeg") { // Show error lblUploadError = FormatLbl.Error("File must be a picture file that ends in jpg, png, or jpeg"); } else { // Perform file upload file.PerformUpload(); // Perform database insert ArtpieceDao dao = new ArtpieceDao(); dao.Add(artpiece); //To redirect user to the new artpiece Response.Redirect("~/Pages/artpiece.aspx?Id=" + artpiece.ArtpieceId); } } } }
protected void saveBt_Click(object sender, EventArgs e) { bool outOfStocksError = false; // Get count List <Order_Artwork> oaList = (List <Order_Artwork>)Net.GetSession("oaList"); Order order = (Order)Net.GetSession("order"); order.TotalPrice = 0; // Clear first int itemCount = oaList.Count; for (int i = 1; i <= itemCount; i++) { // Get quantity and price labels of artpiece order HiddenField lblQuantity = new HiddenField(); lblQuantity = (HiddenField)gallery.FindControl("quantityHidden" + i); Label lblPrice = new Label(); lblPrice = (Label)gallery.FindControl("priceHidden" + i); // Get the string value string quantityStr = lblQuantity.Value; string priceStr = lblPrice.Text; //Get artpiece ArtpieceDao artpieceDao = new ArtpieceDao(); Classes.Artpiece artpiece = artpieceDao.Get("ARTPIECEID", oaList[i - 1].ArtpieceId); // Check for sufficient stocks if (Convert.ToInt32(quantityStr) > artpiece.Stocks) { // Show insufficient stock message Quick.Print("Insufficient stock! Ordering " + oaList[i - 1].Quantity + " while Artpiece stock is " + artpiece.Stocks); string error = "Not enough stocks for artpiece \"" + artpiece.Title + "\""; Net.SetSession("cartOutOfStocks", error); outOfStocksError = true; } else { order.TotalPrice += Convert.ToDouble(priceStr) * Convert.ToInt32(quantityStr); // Save to oa object oaList[i - 1].Quantity = Convert.ToInt32(quantityStr); Quick.Print("Quantity ordered: " + oaList[i - 1].Quantity); } } // Clear error if no error if (!outOfStocksError) { Net.SetSession("cartOutOfStocks", null); } lblPrice.Text = "RM " + Quick.FormatPrice(order.TotalPrice); // Save to session Net.SetSession("oaList", oaList); Net.SetSession("order", order); // Show that cart is saved if (oaList.Count > 0) { Net.SetSession("cartSaved", true); } //Refresh page Net.RefreshPage(); }
protected void Page_Load(object sender, EventArgs e) { Net.AllowOnly("customer"); // Check for out of stock error if any string errorMsg = (string)Net.GetSession("cartOutOfStocks"); if (errorMsg != null) { lblErrorMsg.Text = errorMsg; } bool cartSaved = false; // Get orders from Session List <Order_Artwork> oaList = (List <Order_Artwork>)Net.GetSession("oaList"); Order order = (Order)Net.GetSession("order"); if (Net.GetSession("cartSaved") == null || errorMsg != null) { checkoutBt.Visible = false; } else { cartSaved = (bool)Net.GetSession("cartSaved"); } if (!cartSaved) { checkoutBt.Visible = false; } /* ---------------------------------------------------------------------------------------------------- * Get session attributes to manipulate * ---------------------------------------------------------------------------------------------------- */ Customer customer = (Customer)Net.GetSession("customer"); if (customer == null) { Net.Redirect("~/Pages/LoginRegister.aspx"); // Redirect if not logged in as customer } /* FOR DEBUG PURPOSES */ //oaList = new List<Order_Artwork>(); //oaList.Add(new Order_Artwork("testorder", "MILO", 1, oaList)); //oaList.Add(new Order_Artwork("testorder", "LILO", 5, oaList)); /* END */ /* ---------------------------------------------------------------------------------------------------- * Initialise daos to use * ---------------------------------------------------------------------------------------------------- */ ArtpieceDao artpieceDao = new ArtpieceDao(); ArtistDao artistDao = new ArtistDao(); /* ---------------------------------------------------------------------------------------------------- * Display statics in page header * ---------------------------------------------------------------------------------------------------- */ // TODO TODO TODO // TODO TODO TODO // TODO TODO TODO // TODO TODO TODO // TODO TODO TODO /* ---------------------------------------------------------------------------------------------------- * Display items in cart * ---------------------------------------------------------------------------------------------------- */ Control gallery = this.FindControl("gallery"); int loopCounter = 0; // if cart is empty if (oaList == null || oaList.Count == 0) { // Don't show checkout button checkoutBt.Visible = false; } else { lblItems.Text = oaList.Count + ""; gallery.Controls.Add(new LiteralControl("<table class='gallery'>")); foreach (Order_Artwork orderArtwork in oaList) { // Get corresponding artpiece and artist Classes.Artpiece artpiece = artpieceDao.Get("ArtpieceId", orderArtwork.ArtpieceId); Artist artist = artistDao.Get("ArtistId", artpiece.ArtistId); if (loopCounter % 3 == 0) { if (loopCounter != 0) { gallery.Controls.Add(new LiteralControl("</tr>")); } gallery.Controls.Add(new LiteralControl("<tr>")); } // --- gallery.Controls.Add(new LiteralControl("" + "<td>" + "<a href='#'>")); // --- Image image = new Image(); image.ImageUrl = artpiece.ImageLink; gallery.Controls.Add(image); // --- gallery.Controls.Add(new LiteralControl("" + "</a>" + "<div class='details'>" + "<div class='of_artpiece'>")); // --- /*Label lblTitle = new Label(); * lblTitle.ID = "lblTitle" + loopCounter.ToString(); * lblTitle.Text = artpiece.Title; * lblTitle.CssClass = "label title"; * * gallery.Controls.Add(lblTitle);*/ //gallery.Controls.Add(new LiteralControl("<asp:Label ID='lblTitle" + loopCounter + "' runat='server' Text='" + artpiece.Title + "' CssClass='label title'></asp:Label>")); gallery.Controls.Add(new LiteralControl("<a class='title'>" + artpiece.Title + "</a>")); /*Label lblArtist = new Label(); * lblArtist.ID = "lblArtist" + loopCounter.ToString(); * lblArtist.Text = artist.DisplayName; * lblTitle.CssClass = "label artist"; * * gallery.Controls.Add(lblArtist);*/ //gallery.Controls.Add(new LiteralControl("<asp:Label ID='lblArtist" + loopCounter + "' runat='server' Text='" + artist.DisplayName + "' CssClass='label artist'></asp:Label>")); gallery.Controls.Add(new LiteralControl("<a class='artist'>" + artist.DisplayName + "</a>")); // --- gallery.Controls.Add(new LiteralControl("" + "</div>" + "<div class='of_order'>" + "<div class='quantity'>")); // --- /*Button btnDecrement = new Button(); * btnDecrement.ID = "btnDecrement" + (loopCounter + 1).ToString(); * btnDecrement.Text = "-"; * btnDecrement.CssClass = "decrement"; * //btnDecrement.Click += Decrement; * * gallery.Controls.Add(btnDecrement);*/ gallery.Controls.Add(new LiteralControl("<input type='button' id='btnDecrement" + (loopCounter + 1).ToString() + "' class='decrement' value='-'>")); Label lblQuantity = new Label(); lblQuantity.ID = "lblQuantity" + (loopCounter + 1).ToString(); lblQuantity.Text = orderArtwork.Quantity.ToString() + " PCS"; lblQuantity.CssClass = "label"; lblQuantity.Visible = false; gallery.Controls.Add(lblQuantity); gallery.Controls.Add(new LiteralControl("<a id='quantity" + (loopCounter + 1).ToString() + "'>" + orderArtwork.Quantity.ToString() + " PCS</a>")); /*Button btnIncrement = new Button(); * btnIncrement.ID = "btnIncrement" + (loopCounter + 1).ToString(); * btnIncrement.Text = "+"; * btnIncrement.CssClass = "increment"; * //btnIncrement.Click += Increment; * * gallery.Controls.Add(btnIncrement);*/ gallery.Controls.Add(new LiteralControl("<input type='button' id='btnIncrement" + (loopCounter + 1).ToString() + "' class='increment' value='+'>")); // --- gallery.Controls.Add(new LiteralControl("" + "</div>" + "<div class='subtotal'>" + "<a class='caption'>SUBTOTAL</a>")); // --- Label priceHidden = new Label(); priceHidden.ID = "priceHidden" + (loopCounter + 1).ToString(); priceHidden.Text = Convert.ToString(artpiece.Price); priceHidden.CssClass = "label value"; priceHidden.Visible = false; gallery.Controls.Add(priceHidden); HiddenField quantityHidden = new HiddenField(); quantityHidden.ID = "quantityHidden" + (loopCounter + 1).ToString(); quantityHidden.Value = Convert.ToString(orderArtwork.Quantity); gallery.Controls.Add(quantityHidden); gallery.Controls.Add(new LiteralControl("<input type='hidden' class='value' value='" + artpiece.Price + "' id='hiddenPriceHTML" + (loopCounter + 1).ToString() + "'/>")); //string priceStr = (artpiece.Price * (double)orderArtwork.Quantity).ToString(); gallery.Controls.Add(new LiteralControl("<a class='value' id='subtotal" + (loopCounter + 1).ToString() + "'>RM " + Quick.FormatPrice((artpiece.Price * (double)orderArtwork.Quantity)) + "</a>")); // --- gallery.Controls.Add(new LiteralControl("" + "</div>" + "</div>" + "</div>" + "</td>")); // --- loopCounter++; } if (oaList.Count > 0) { gallery.Controls.Add(new LiteralControl("</tr>")); } gallery.Controls.Add(new LiteralControl("</table>")); // Set total price lblPrice.Text = "RM " + Quick.FormatPrice(order.TotalPrice); } }