private void fillOrdersGridView() { try { String currency = "€"; if (Request.QueryString["currency"] == null) { if (CookieUtil.CookieExists("currency")) { if (CookieUtil.GetCookieValue("currency").Equals("usd")) { currency = "$"; } } } else if (Request.QueryString["currency"].Equals("usd")) { currency = "$"; } customerOrders = new OrderService().getOrdersForCustomer(((Customer)Session["user"])); //Throws NoRecrdException DataTable orderTable = new DataTable(); orderTable.Columns.Add("Ordernumber"); orderTable.Columns.Add("Status"); orderTable.Columns.Add("Cost"); orderTable.Columns.Add("Date"); foreach (Order item in customerOrders) { DataRow orderRow = orderTable.NewRow(); orderRow[0] = item.order_id; orderRow[1] = item.orderstatus.name; OrderModel orderModel = new OrderModel(); orderRow[2] = currency + " " + setPriceInRightCurrency((float)orderModel.getOrderCost(item), currency); orderRow[3] = item.date.ToString("dd/MM/yyyy"); orderTable.Rows.Add(orderRow); } gvOrders.DataSource = orderTable; gvOrders.DataBind(); } catch (NoRecordException) { lblNoOrders.Visible = true; } }
protected void btnPay_Click(object sender, EventArgs e) { Customer user = (Customer)Session["user"]; if (user != null) { try { //get the order String orderID = lblStatus.Text; Order order = new OrderService().getByID(orderID); //Throws NoRecordException new OrderModel().payOrder(order); //Throws NoRecordException || DALException //get the orderLines List <OrderLine> orderLines = new OrderLineService().getByOrder(order); //Throws NoRecordException //check if all orderLines can be given a dvdCopy Boolean allInStock = hasAllInStock(orderLines); //send the user an order confirmation String currency = "€"; if (CookieUtil.CookieExists("currency")) { if (CookieUtil.GetCookieValue("currency").Equals("usd")) { currency = "$"; } } new EmailModel().sendOrderConfirmationEmail(user, order, orderLines, allInStock, currency); Response.Redirect("~/ThankYou.aspx"); } catch (NoRecordException) { } } else { lblStatus.Text = "Please log in to access this page"; } }
private void setupCurrencyLinks() { if (Request.QueryString.Count == 0) { //No query string exists, create one euroLink.HRef = Request.Url.AbsoluteUri + "?currency=euro"; dollerLink.HRef = Request.Url.AbsoluteUri + "?currency=usd"; } else { string url = HttpContext.Current.Request.Url.AbsoluteUri; string[] separateURL = url.Split('?'); NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(separateURL[1]); if (Request.QueryString["currency"] != null) { queryString.Remove("currency"); } //Extend the existing querystring euroLink.HRef = separateURL[0] + "?" + queryString.ToString() + "¤cy=euro"; dollerLink.HRef = separateURL[0] + "?" + queryString.ToString() + "¤cy=usd"; } //als de querystring het attribut currency bevat (als de gebruiker op één van de twee currencylinks heeft geklikt) if (Request.QueryString["currency"] != null) { //cookie aanmaken/updaten en currencysymbol updaten CookieUtil.CreateCookie("currency", Request.QueryString["currency"], 30); currencySymbol.Attributes["class"] = "glyphicon glyphicon-" + Request.QueryString["currency"]; } else { //kijken of de cookie bestaat if (CookieUtil.CookieExists("currency")) { //currencysymbol aanpassen adhv de waarde in de cookie currencySymbol.Attributes["class"] = "glyphicon glyphicon-" + CookieUtil.GetCookieValue("currency"); } } }
/*Displays the details of the selected order.*/ private void displayOrderDetails(String orderID) { try { String currency = "€"; if (Request.QueryString["currency"] == null) { if (CookieUtil.CookieExists("currency")) { if (CookieUtil.GetCookieValue("currency").Equals("usd")) { currency = "$"; } } } else if (Request.QueryString["currency"].Equals("usd")) { currency = "$"; } //show details pnlOrderDetails.Visible = true; //get the order info OrderService orderService = new OrderService(); Order selectedOrder = orderService.getByID(orderID); //Throws NoRecordException lblOrderStatus.Text = "(" + selectedOrder.orderstatus.name + ")"; //1 = new, 2 = paid, 3 = shipped lblOrderID.Text = selectedOrder.order_id.ToString(); //hide pay button if the order has already been paid if (selectedOrder.orderstatus.id != 1) { lblPay.Visible = false; btnPay.Visible = false; } else { lblPay.Visible = true; btnPay.Visible = true; } //get all articles in the order and display them Order order = orderService.getByID(orderID); //Throws NoRecordException List <OrderLine> orderLines = new OrderLineService().getByOrder(order); //Throws NoRecordException Boolean hasRentItems = false; foreach (OrderLine item in orderLines) { if (item.orderLineType.id == 1) { hasRentItems = true; } } DataTable orderTable = new DataTable(); orderTable.Columns.Add("Item number"); orderTable.Columns.Add("Name"); orderTable.Columns.Add("Type"); orderTable.Columns.Add("Price"); if (hasRentItems) { orderTable.Columns.Add("Start date"); orderTable.Columns.Add("End date"); } foreach (OrderLine item in orderLines) { DataRow orderRow = orderTable.NewRow(); orderRow[0] = item.orderline_id; orderRow[1] = item.dvdInfo.name; orderRow[2] = item.orderLineType.name; orderRow[3] = currency + " " + setPriceInRightCurrency(item.dvdInfo.buy_price, currency); if (item.orderLineType.name.Equals("Verhuur")) { orderRow[4] = item.startdate.ToString("dd/MM/yyyy"); orderRow[5] = item.enddate.ToString("dd/MM/yyyy"); } orderTable.Rows.Add(orderRow); } gvOrderDetails.DataSource = orderTable; gvOrderDetails.DataBind(); //total cost OrderModel orderModel = new OrderModel(); lblTotalCost.Text = currency + " " + setPriceInRightCurrency((float)orderModel.getOrderCost(order), currency); //user has already paid, check status of copies in cart if (selectedOrder.orderstatus.id > 1) { Boolean allInStock = hasAllInStock(orderLines); updateOrderStatusDetails(allInStock); } } catch (NoRecordException) { //order does not exist, reload the current page to update the gridview and close this order's panel Response.Redirect("Orders.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { String currency = "€"; wsCurrencyWebService.CurrencyWebService currencyWebService = new wsCurrencyWebService.CurrencyWebService(); dvdInfoLink.NavigateUrl = "~/detail.aspx?id=" + id; dvdInfoLink2.NavigateUrl = dvdInfoLink.NavigateUrl; imgDvdCover.ImageUrl = imageUrl; if (title.Length <= 40) { lblTitle.Text = title; } else { lblTitle.Text = title.Substring(0, 28) + "..."; } if (Request.QueryString["currency"] == null) { if (CookieUtil.CookieExists("currency")) { switch (CookieUtil.GetCookieValue("currency")) { case "usd": currency = "$"; buy_price = (float)currencyWebService.convert(buy_price, "usd"); rent_price = (float)currencyWebService.convert(rent_price, "usd"); break; } } } else { switch (Request.QueryString["currency"]) { case "usd": currency = "$"; buy_price = (float)currencyWebService.convert(buy_price, "usd"); rent_price = (float)currencyWebService.convert(rent_price, "usd"); break; } } //set buy button color and text if (AvailabilityModel.isAvailableForBuying(Convert.ToString(id))) { btnBuyB.Attributes.Add("Class", "btn btn-success price-box"); } else { btnBuyB.Attributes.Add("Class", "btn btn-warning price-box"); } btnBuyB.InnerText = "Buy " + currency + " " + buy_price; //set rent button properties and text btnRentB.Attributes.Add("CommandArgument", id); DvdInfoService dvdbll = new DvdInfoService(); try { DvdInfo thisDVD = dvdbll.getByID(Convert.ToString(id)); //Throws NoRecordExample List <DateTime> dates = new AvailabilityModel().getAvailabilities(thisDVD, DateTime.Now); //Throws NoRecordException if (dates.Count >= 14) { //fully available, green button btnRentB.Attributes.Add("Class", "btn btn-success price-box"); } else if (dates.Count > 0) { //available on some days, orange button btnRentB.Attributes.Add("Class", "btn btn-warning price-box"); } else { //not available at all, red button btnRentB.Attributes.Add("Class", "btn btn-danger price-box"); } } catch (NoRecordException) { } btnRentB.InnerText = "Rent " + currency + " " + rent_price; }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Customer user = (Customer)Session["user"]; OrderService orderService = new OrderService(); if (user != null) { String orderID = Request.QueryString["order"]; try { Order order = orderService.getByID(orderID); //Throws NoRecordException if (order.customer.customer_id == user.customer_id) { String currency = "€"; if (Request.QueryString["currency"] == null) { //Check if the user has set the currencypreference if (CookieUtil.CookieExists("currency")) { if (CookieUtil.GetCookieValue("currency").Equals("usd")) { currency = "$"; } } } else { switch (Request.QueryString["currency"]) { case "usd": currency = "$"; break; } } //all good lblStatus.Text = orderID; OrderModel helper = new OrderModel(); lblCost.Text = currency + " " + Math.Round(helper.getOrderCost(order), 2).ToString(); List <OrderLine> orderLines = new OrderLineService().getByOrder(order); //Throws NoRecordException Boolean hasRentItems = false; foreach (OrderLine item in orderLines) { if (item.orderLineType.id == 1) { hasRentItems = true; } } DataTable orderTable = new DataTable(); orderTable.Columns.Add("Item number"); orderTable.Columns.Add("Name"); orderTable.Columns.Add("Type"); orderTable.Columns.Add("Price"); if (hasRentItems) { orderTable.Columns.Add("Start date"); orderTable.Columns.Add("End date"); } foreach (OrderLine item in orderLines) { DataRow orderRow = orderTable.NewRow(); orderRow[0] = item.orderline_id; orderRow[1] = item.dvdInfo.name; orderRow[2] = item.orderLineType.name; if (item.orderLineType.id == 1) { double cost = item.dvdInfo.rent_price * (item.enddate - item.startdate).Days; orderRow[3] = currency + " " + Math.Round(cost, 2); orderRow[4] = item.startdate.ToString("dd/MM/yyyy"); orderRow[5] = item.enddate.ToString("dd/MM/yyyy"); } else { double cost = item.dvdInfo.buy_price; orderRow[3] = currency + " " + Math.Round(cost, 2); } orderTable.Rows.Add(orderRow); } //set gridview gvOrderDetails.DataSource = orderTable; gvOrderDetails.DataBind(); } else { //this order does not belong to the logged in user, access denied. lblStatus.Text = "Access denied"; } } catch (NoRecordException) { } } else { //not logged in, access denied lblStatus.Text = "Please log in to access this page"; } } }
private void setStatistics() { Customer user = (Customer)Session["user"]; if (user != null) { OrderModel orderModel = new OrderModel(); RentModel rentModel = new RentModel(); lblOrderTotal.Text = "You have purchased " + orderModel.getNumberOfOrderLinesForCustomer(user) + " items (" + orderModel.getItemsBoughtByCustomer(user).Count + " unique) so far."; lblActiveRentCopies.Text = "You are currently renting " + rentModel.getNumberOfActiveRentOrdersCopiesForCustomer(user) + " items:"; if (rentModel.getNumberOfActiveRentOrdersCopiesForCustomer(user) > 0) { List <OrderLine> orderLines = new OrderLineService().getActiveRentOrderLinesByCustomer(user); String currency = "€"; if (Request.QueryString["currency"] == null) { if (CookieUtil.CookieExists("currency")) { if (CookieUtil.GetCookieValue("currency").Equals("usd")) { currency = "$"; } } } else if (Request.QueryString["currency"].Equals("usd")) { currency = "$"; } Boolean hasRentItems = false; foreach (OrderLine item in orderLines) { if (item.orderLineType.id == 1) { hasRentItems = true; } } DataTable orderTable = new DataTable(); orderTable.Columns.Add("Item number"); orderTable.Columns.Add("Name"); orderTable.Columns.Add("Type"); orderTable.Columns.Add("Price"); if (hasRentItems) { orderTable.Columns.Add("Start date"); orderTable.Columns.Add("End date"); } foreach (OrderLine item in orderLines) { DataRow orderRow = orderTable.NewRow(); orderRow[0] = item.orderline_id; orderRow[1] = item.dvdInfo.name; orderRow[2] = item.orderLineType.name; orderRow[3] = currency + " " + setPriceInRightCurrency(item.dvdInfo.buy_price, currency); orderRow[4] = item.startdate.ToString("dd/MM/yyyy"); orderRow[5] = item.enddate.ToString("dd/MM/yyyy"); orderTable.Rows.Add(orderRow); } gvActiveRent.DataSource = orderTable; gvActiveRent.DataBind(); } } }
private void setupDvdInfo(String id) { try { wsCurrencyWebService.CurrencyWebService currencyWebService = new wsCurrencyWebService.CurrencyWebService(); String currency = "€"; DvdInfo dvdInfo = new DvdInfoService().getByID(id.ToString()); //Throws NoRecordException lblTitle.Text = dvdInfo.name + " "; linkYear.Text = "(" + dvdInfo.year + ")"; linkYear.NavigateUrl = "~/Catalog.aspx?year=" + dvdInfo.year; linkDirector.Text = dvdInfo.author; linkDirector.NavigateUrl = "~/Catalog.aspx?director=" + dvdInfo.author; if (!dvdInfo.actors[0].Equals("")) //even dvd's without actors contain 1 empty string element { foreach (String a in dvdInfo.actors) { HyperLink actor = new HyperLink(); actor.Text = a; actor.NavigateUrl = "~/Catalog.aspx?actor=" + a; actorLinks.Controls.Add(actor); Label l = new Label(); l.Text = ", "; actorLinks.Controls.Add(l); } int i = actorLinks.Controls.Count; actorLinks.Controls.RemoveAt(i - 1); actorLinks.Controls.Add(new LiteralControl("<br />")); } else { lblActors.Visible = false; } if (!dvdInfo.duration.Equals("")) { lblDuration.Text = dvdInfo.duration + " min"; } else { spanRuntime.Visible = false; } foreach (Genre g in dvdInfo.genres) { HyperLink genre = new HyperLink(); genre.Text = g.name; genre.NavigateUrl = "~/Catalog.aspx?genre=" + g.genre_id; genreLinks.Controls.Add(genre); Label l = new Label(); l.Text = ", "; genreLinks.Controls.Add(l); } int j = genreLinks.Controls.Count; if (j > 0) { genreLinks.Controls.RemoveAt(j - 1); } lblPlot.Text = dvdInfo.descripion; if (Request.QueryString["currency"] == null) { if (CookieUtil.CookieExists("currency")) { switch (CookieUtil.GetCookieValue("currency")) { case "usd": currency = "$"; dvdInfo.buy_price = (float)currencyWebService.convert(dvdInfo.buy_price, "usd"); dvdInfo.rent_price = (float)currencyWebService.convert(dvdInfo.rent_price, "usd"); break; } } } else { switch (Request.QueryString["currency"]) { case "usd": currency = "$"; dvdInfo.buy_price = (float)currencyWebService.convert(dvdInfo.buy_price, "usd"); dvdInfo.rent_price = (float)currencyWebService.convert(dvdInfo.rent_price, "usd"); break; } } if (AvailabilityModel.isAvailableForBuying(Request.QueryString["id"])) { lblBuyStatus.Text = ""; btnBuyB.Attributes.Add("Class", "btn btn-success"); } else { lblBuyStatus.Text = "Item currently out of stock!"; btnBuyB.Attributes.Add("Class", "btn btn-warning"); } btnBuyB.InnerText = "Buy " + currency + " " + dvdInfo.buy_price.ToString(); btnRent1.Text = "Rent 1 day " + currency + " " + dvdInfo.rent_price.ToString(); btnRent3.Text = "Rent 3 days " + currency + " " + (dvdInfo.rent_price * 3).ToString(); btnRent7.Text = "Rent 7 days " + currency + " " + (dvdInfo.rent_price * 7).ToString(); foreach (KeyValuePair <int, String> k in dvdInfo.media) { if (k.Key == 1) { imgDvdCoverFocus.ImageUrl = k.Value; } else if (k.Key == 2) { HtmlGenericControl div = new HtmlGenericControl("div"); div.Attributes["class"] = "col-xs-3 col-sm-3 col-md-3 col-lg-3 DocumentItem"; Image img = new Image(); img.ImageUrl = k.Value; div.Controls.Add(img); scrollrow.Controls.Add(div); } else if (k.Key == 3) { HtmlGenericControl div = new HtmlGenericControl("div"); div.Attributes["class"] = "col-xs-3 col-sm-3 col-md-3 col-lg-3 DocumentItem"; Literal youtube = new Literal(); youtube.Text = GetYouTubeScript(k.Value); div.Controls.Add(youtube); scrollrow.Controls.Add(div); } } } catch (NoRecordException) { } }
private void fillCartGridView() { try { List <ShoppingcartItem> cartContent = new ShoppingCartService().getCartContentForCustomer(((Customer)Session["user"])); //Throws NoRecordException Boolean hasRentItems = false; double totalCost = 0; divCartContent.Visible = true; divCartEmpty.Visible = false; foreach (ShoppingcartItem item in cartContent) { if (item.dvdCopyType.id == 1) { hasRentItems = true; } } DataTable cartTable = new DataTable(); cartTable.Columns.Add("Id"); cartTable.Columns.Add("Name"); cartTable.Columns.Add("Amount"); cartTable.Columns.Add("Price"); if (hasRentItems) { cartTable.Columns.Add("Start date"); cartTable.Columns.Add("End date"); } String currency = "€"; if (Request.QueryString["currency"] == null) { if (CookieUtil.CookieExists("currency")) { if (CookieUtil.GetCookieValue("currency").Equals("usd")) { currency = "$"; } } } else if (Request.QueryString["currency"].Equals("usd")) { currency = "$"; } foreach (ShoppingcartItem item in cartContent) { double cost = 0; DataRow cartRow = cartTable.NewRow(); cartRow[0] = item.shoppingcart_item_id; cartRow[1] = item.dvdInfo.name; cartRow[2] = 1; cartRow[3] = item.dvdInfo.buy_price; if (item.dvdCopyType.id == 1) { cost = item.dvdInfo.rent_price * (item.enddate - item.startdate).Days; cartRow[4] = item.startdate.ToString("dd/MM/yyyy"); cartRow[5] = item.enddate.ToString("dd/MM/yyyy"); } else { cost = item.dvdInfo.buy_price; } cost = setPriceInRightCurrency((float)cost, currency); totalCost += cost; cartRow[3] = currency + " " + Math.Round(cost, 2); cartTable.Rows.Add(cartRow); } lblTotalCost.Text = currency + " " + Math.Round(totalCost, 2).ToString(); gvCart.DataSource = cartTable; gvCart.DataBind(); } catch (NoRecordException) { divCartContent.Visible = false; divCartEmpty.Visible = true; } }