public string LoadProducts(string OrderID) { try { if (Context.User.IsInRole("Administrator")) { string HTML = ""; Guid myOrderID = Guid.Parse(OrderID.Trim()); List<OrderProduct> myProductItems = new OrdersLogic().RetrieveItemsByOrderID(myOrderID).ToList(); HTML += "<table>"; int Counter = 0; foreach (OrderProduct myProductItem in myProductItems) { HTML += "<tr class=\"GridViewTuple\">"; HTML += "<td>"; HTML += new ProductsLogic().RetrieveProductByID(myProductItem.ProductFK.ToString()).Name; HTML += "</td>"; HTML += "<td>"; HTML += "<div style=\"padding-top: 4px; float: left;\">x </div><input class=\"CatalogTextBox\" id=\"" + myProductItem.ProductFK + "\" Use=\"Quantity\" type=\"text\" value=\"" + myProductItem.Quantity.ToString() + "\">"; HTML += "</td>"; HTML += "<td>"; HTML += "<input type=\"button\" ProductID=\"" + myProductItem.ProductFK + "\" Use=\"Update\" value=\"Update\">"; HTML += "</td>"; HTML += "<td>"; HTML += "<input type=\"button\" ProductID=\"" + myProductItem.ProductFK + "\" Use=\"Remove\" value=\"Remove\">"; HTML += "</td>"; HTML += "<td>"; HTML += "<div Use=\"ErrorDiv\" ProductID=\"" + myProductItem.ProductFK + "\" class=\"MiniFontBlue\">Not Enough Stock</div>"; HTML += "</td>"; HTML += "</tr>"; Counter++; } HTML += "</table>"; return HTML; } else { return ""; } } catch (Exception Exception) { throw Exception; } }
protected void Page_Load(object sender, EventArgs e) { try { string StartDate = null; string EndDate = null; string Users = null; if((Request.QueryString["sd"] != null) && (Request.QueryString["ed"] != null)) { StartDate = Request.QueryString["sd"].ToString(); EndDate = Request.QueryString["ed"].ToString(); } else if (Request.QueryString["u"] != null) { Users = Request.QueryString["u"].ToString(); } else { Response.Redirect("~/pagenotfound.aspx"); } string HTML = ""; if (Users == null) { DateTime myStartDate = new DateTime(); DateTime myEndDate = new DateTime(); try { myStartDate = new DateTimeParser().ParseDate(StartDate.Replace('/', '-')); myEndDate = new DateTimeParser().ParseDate(EndDate.Replace('/', '-')); } catch (Exception) { Response.Redirect("~/pagenotfound.aspx"); } if (myStartDate > myEndDate) { DateTime myInitialStartDate = myStartDate; DateTime myInitialEndDate = myEndDate; myStartDate = myInitialEndDate; myEndDate = myInitialStartDate; } IQueryable<TopTenView> myTopTenList = new OrdersLogic().RetrieveTopTen(myStartDate, myEndDate); HTML = "<table style=\"font-family: Arial;\" cellpadding=\"6\">"; HTML += "<tr>"; HTML += "<td>"; HTML += "Start Date:"; HTML += "</td>"; HTML += "<td>"; HTML += myStartDate.ToShortDateString(); HTML += "</td>"; HTML += "</tr>"; HTML += "<tr>"; HTML += "<td>"; HTML += "End Date:"; HTML += "</td>"; HTML += "<td>"; HTML += myEndDate.ToShortDateString(); HTML += "</td>"; HTML += "</tr>"; HTML += "</table>"; HTML += "<br/>"; HTML += "<br/>"; HTML += "<table style=\"font-family: Arial;\" cellpadding=\"6\">"; HTML += "<tr>"; HTML += "<td>"; HTML += "Rank"; HTML += "</td>"; HTML += "<td>"; HTML += "Product Name"; HTML += "</td>"; HTML += "<td>"; HTML += "Product Description"; HTML += "</td>"; HTML += "<td>"; HTML += "Quantity Bought"; HTML += "</td>"; HTML += "<tr>"; int Counter = 0; foreach (TopTenView myTopTenItem in myTopTenList) { Counter++; if (Counter > 10) { break; } HTML += "<tr>"; HTML += "<td>"; HTML += Counter; HTML += "</td>"; HTML += "<td>"; HTML += myTopTenItem.ProductName; HTML += "</td>"; HTML += "<td>"; HTML += myTopTenItem.ProductDescription; HTML += "</td>"; HTML += "<td>"; HTML += myTopTenItem.QuantitySold; HTML += "</td>"; HTML += "</tr>"; } HTML += "</table>"; } else { IQueryable<TopTenClients> myTopTenList = new OrdersLogic().RetrieveTopTenClients(); HTML += "<table style=\"font-family: Arial;\" cellpadding=\"6\">"; HTML += "<tr>"; HTML += "<td>"; HTML += "Rank"; HTML += "</td>"; HTML += "<td>"; HTML += "Client Name"; HTML += "</td>"; HTML += "<td>"; HTML += "Quantity Bought"; HTML += "</td>"; HTML += "<tr>"; int Counter = 0; foreach (TopTenClients myTopTenItem in myTopTenList) { Counter++; if (Counter > 10) { break; } HTML += "<tr>"; HTML += "<td>"; HTML += Counter; HTML += "</td>"; HTML += "<td>"; HTML += myTopTenItem.ClientName; HTML += "</td>"; HTML += "<td>"; HTML += myTopTenItem.ProductCount; HTML += "</td>"; HTML += "</tr>"; } HTML += "</table>"; } lblOutput.Text = HTML; } catch (Exception Exception) { throw Exception; } }
public bool UpdateItem(string OrderID, string ProductID, string OrderType, string Quantity) { try { if (Context.User.IsInRole("Administrator")) { Guid myOrderID = Guid.Parse(OrderID); Guid myProductID = Guid.Parse(ProductID); int myQuantity = Convert.ToInt32(Quantity); bool UpdateSuccessful = false; if (OrderType.Trim() == "User") { UpdateSuccessful = new OrdersLogic().UpdateUserOrderItem(myOrderID, myProductID, myQuantity); return UpdateSuccessful; } else if (OrderType.Trim() == "Supplier") { UpdateSuccessful = new OrdersLogic().UpdateSupplierOrderItem(myOrderID, myProductID, myQuantity); return UpdateSuccessful; } return UpdateSuccessful; } else { return false; } } catch (Exception Exception) { throw Exception; } }
public bool RemoveItem(string OrderID, string ProductID, string OrderType) { try { if (Context.User.IsInRole("Administrator")) { Guid myOrderID = Guid.Parse(OrderID); Guid myProductID = Guid.Parse(ProductID); bool UpdateSuccessful = false; if (OrderType.Trim() == "User") { new OrdersLogic().RemoveUserOrderItem(myOrderID, myProductID); return true; } else if (OrderType.Trim() == "Supplier") { UpdateSuccessful = new OrdersLogic().RemoveSupplierOrderItem(myOrderID, myProductID); return UpdateSuccessful; } return UpdateSuccessful; } else { return false; } } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Occurs when the User Orders Grid View Selected Index is Changed /// Level: External /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gvUserOrders_SelectedIndexChanged(object sender, EventArgs e) { try { txtUserID.Visible = true; txtUserID.Text = gvUserOrders.SelectedValue.ToString(); Order myOrder = new OrdersLogic().RetrieveOrderByID(Guid.Parse(gvUserOrders.SelectedValue.ToString())); txtSupplierID.Text = ""; ddlOrderStatus.Visible = true; ddlOrderStatus.SelectedValue = myOrder.OrderStatus.Id.ToString(); btnUpdate.Visible = true; lblOrder.Visible = true; btnPrintContents.Visible = true; btnEditContents.Visible = true; } catch (Exception Exception) { throw Exception; } }
protected void Page_Load(object sender, EventArgs e) { try { if (Context.User.Identity.IsAuthenticated) { string myOrderID = Request.QueryString[0].ToString(); Guid myOrderGuid; if (Guid.TryParse(myOrderID, out myOrderGuid)) { Order myOrder = new OrdersLogic().RetrieveOrderByID(myOrderGuid); IQueryable<OrderProduct> myOrderItems = new OrdersLogic().RetrieveItemsByOrderID(myOrderGuid); bool HasAccess = false; if(Context.User.IsInRole("Administrator")) { HasAccess = true; } else { if (myOrder.UserFK == new UsersLogic().RetrieveUserByUsername(Context.User.Identity.Name).Id) { HasAccess = true; } } //User has access to the order if (HasAccess) { string HTML = "<table style=\"font-family: Arial;\" cellpadding=\"6\">"; HTML += "<tr>"; HTML += "<td>"; HTML += "Order ID: "; HTML += "</td>"; HTML += "<td>"; HTML += myOrder.Id; HTML += "</td>"; HTML += "</tr>"; if(myOrder.SupplierFK == null) { HTML += "<tr>"; HTML += "<td>"; HTML += "Name: "; HTML += "</td>"; HTML += "<td>"; HTML += myOrder.User.Name + " " + myOrder.User.Surname; HTML += "</td>"; HTML += "</tr>"; string[] Address = myOrder.User.StreetAddress.Split('|'); HTML += "<tr>"; HTML += "<td>"; HTML += "Address: "; HTML += "</td>"; HTML += "<td>"; HTML += Address[0]; HTML += "</td>"; HTML += "</tr>"; HTML += "<tr>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += Address[1]; HTML += "</td>"; HTML += "</tr>"; HTML += "<tr>"; HTML += "<td>"; HTML += "Town: "; HTML += "</td>"; HTML += "<td>"; HTML += myOrder.User.Town.Town1; HTML += "</td>"; HTML += "</tr>"; HTML += "<tr>"; HTML += "<td>"; HTML += "Country: "; HTML += "</td>"; HTML += "<td>"; HTML += myOrder.User.Town.Country.Country1; HTML += "</td>"; HTML += "</tr>"; } else { HTML += "<tr>"; HTML += "<td>"; HTML += "Supplier: "; HTML += "</td>"; HTML += "<td>"; HTML += myOrder.Supplier.Supplier1; HTML += "</td>"; HTML += "</tr>"; } HTML += "<tr>"; HTML += "<td>"; HTML += "Status: "; HTML += "</td>"; HTML += "<td>"; HTML += myOrder.OrderStatus.Status; HTML += "</td>"; HTML += "</tr>"; HTML += "<tr>"; HTML += "<td>"; HTML += "Date Placed: "; HTML += "</td>"; HTML += "<td>"; HTML += myOrder.OrderDate; HTML += "</td>"; HTML += "</tr>"; HTML += "</table>"; HTML += "<br/>"; HTML += "<table style=\"font-family: Arial;\" cellpadding=\"6\">"; HTML += "<tr>"; HTML += "<td>"; HTML += "Product"; HTML += "</td>"; HTML += "<td>"; HTML += "Quantity"; HTML += "</td>"; HTML += "<td>"; HTML += "Price"; HTML += "</td>"; HTML += "<td>"; HTML += "VAT Rate"; HTML += "</td>"; HTML += "<td>"; HTML += "Discount (Incl.)"; HTML += "</td>"; HTML += "</tr>"; double TotalPrice = 0; double TotalVat = 0; foreach (OrderProduct myOrderItem in myOrderItems) { Product myProduct = new ProductsLogic().RetrieveProductByID(myOrderItem.ProductFK.ToString()); User myUser = null; UserTypeProduct myPriceType = null; if (myOrder.UserFK != null) { myUser = new UsersLogic().RetrieveUserByID(Guid.Parse(myOrder.UserFK.ToString())); myPriceType = new PriceTypesLogic().RetrievePriceTypeByID(myUser.UserTypeFK, myProduct.Id); } else { UserType myUserType = new UserTypesLogic().RetrieveUserTypeByName("Wholesaler"); myPriceType = new PriceTypesLogic().RetrievePriceTypeByID(myUserType.Id, myProduct.Id); } HTML += "<tr>"; HTML += "<td>"; HTML += myProduct.Name; HTML += "</td>"; HTML += "<td>"; HTML += " x " + myOrderItem.Quantity; HTML += "</td>"; HTML += "<td>"; HTML += " at € " + myOrderItem.Price.ToString("F"); HTML += "</td>"; HTML += "<td>"; HTML += myProduct.Vatrate.Vatrate1 + "% VAT"; HTML += "</td>"; TotalPrice += myOrderItem.Price * myOrderItem.Quantity; TotalVat += ((myProduct.Vatrate.Vatrate1 / 100) * (myOrderItem.Price * myOrderItem.Quantity)); HTML += "<td>"; if((myOrder.OrderDate >= myPriceType.DiscountDateFrom) && (myOrder.OrderDate <= myPriceType.DiscountDateTo)) { HTML += myPriceType.DiscountPercentage + "% Discount"; } HTML += "</td>"; HTML += "</tr>"; } HTML += "<tr>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "Subtotal : "; HTML += "</td>"; HTML += "<td>"; HTML += "€ " + (TotalPrice - TotalVat).ToString("F"); HTML += "</td>"; HTML += "<tr>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "VAT : "; HTML += "</td>"; HTML += "<td>"; HTML += "€ " + TotalVat.ToString("F"); HTML += "</td>"; HTML += "</tr>"; HTML += "<tr>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "</td>"; HTML += "<td>"; HTML += "Total : "; HTML += "</td>"; HTML += "<td>"; HTML += "€ " + TotalPrice.ToString("F"); HTML += "</td>"; HTML += "</tr>"; HTML += "</table>"; lblOutput.Text = HTML; } else { Response.Redirect("~/default.aspx"); } } } else { Response.Redirect("~/default.aspx"); } } catch (Exception Exception) { throw Exception; } }