protected void Page_Load(object sender, EventArgs e) { KlassBibliotek sqlStuff = new KlassBibliotek(); string kategori = ""; if (Request["pennor"] != null) { kategori = "Pennor"; jsonLiteral.Text = JsonConvert.SerializeObject(sqlStuff.ReadAllArtiklar(kategori), Formatting.Indented); } if (Request["papper"] != null) { kategori = "Papper"; jsonLiteral.Text = JsonConvert.SerializeObject(sqlStuff.ReadAllArtiklar(kategori), Formatting.Indented); } if (Request["haftapparater"] != null) { kategori = "häftapparater"; jsonLiteral.Text = JsonConvert.SerializeObject(sqlStuff.ReadAllArtiklar(kategori), Formatting.Indented); } if (Request["gem"] != null) { kategori = "Gem"; jsonLiteral.Text = JsonConvert.SerializeObject(sqlStuff.ReadAllArtiklar(kategori), Formatting.Indented); } //KlassBibliotek sqlStuff = new KlassBibliotek(); // jsonLiteral.Text = JsonConvert.SerializeObject(sqlStuff.ReadAllArtiklar(kategori), Formatting.Indented); }
protected void buttonBuy_Click(object sender, EventArgs e) { KlassBibliotek sqlBibliotek = new KlassBibliotek(); if (Request.Cookies["loggedInUser"] != null) { int kundID = int.Parse(Request.Cookies["loggedInUser"].Value); int orderID = sqlBibliotek.OrderRegistrering(kundID); List <Artiklar> artikelList = sqlBibliotek.ReadAllArtiklar(); List <Artiklar> artiklariVarukorgen = new List <Artiklar>(); string cookieData = Request.Cookies["shoppingCart"].Value; cookieData = cookieData.Replace("%2C", ","); Response.Cookies["shoppingCart"].Value = cookieData; Response.Cookies["shoppingCart"].Expires = DateTime.Now.AddDays(1); if (cookieData != null) { string[] data = cookieData.Split(','); foreach (var artikel in data) { if (artikel != "") { Artiklar artikelIVarukorgen = artikelList.FirstOrDefault(x => x.AID == int.Parse(artikel)); if (artikelIVarukorgen != null) { artiklariVarukorgen.Add(artikelIVarukorgen); } } } } IEnumerable <int> unikaArtiklarIVarukorgen = artiklariVarukorgen.Select(x => x.AID).Distinct(); foreach (var artikelID in unikaArtiklarIVarukorgen) { int antal = artiklariVarukorgen.Where(x => x.AID == artikelID).Count(); int pris = artiklariVarukorgen.FirstOrDefault(x => x.AID == artikelID).pris; sqlBibliotek.VarukorgsRegistrering(artikelID, pris, antal, kundID, orderID); } Response.Cookies["shoppingCart"].Value = ""; Response.Cookies["shoppingCart"].Expires = DateTime.Now.AddDays(-1d); Response.Redirect("/OrderPlaced.aspx?orderID=" + orderID); } else { buyLoggedInLabel.Text = "Du måste logga in först!"; } }
protected void KundDelete_Click(object sender, EventArgs e) { if (Request.Cookies["loggedInUser"] != null) { int kundID = int.Parse(Request.Cookies["loggedInUser"].Value); KlassBibliotek klass = new KlassBibliotek(); klass.TaBortKundRegister(kundID); Response.Cookies["loggedInUser"].Value = ""; Response.Cookies["loggedInUser"].Expires = DateTime.Now.AddDays(-1d); Response.Redirect("/Index_1.aspx"); } }
protected void ButtonReg_Click(object sender, EventArgs e) { KlassBibliotek klassBibliotek = new KlassBibliotek(); string nick = NickName.Text; string pass = Password.Text; string name = Name.Text; string street = Street.Text; string zip = Zip.Text; string city = City.Text; string ssn = SSN.Text; string phone = Telefon.Text; string mail = Epost.Text; bool reg = klassBibliotek.KundRegistrering(name, nick, pass, phone, mail, street, city, zip, ssn); if (reg) { Response.Redirect("/Index_1.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["orderID"] != null) { KlassBibliotek klassBibliotek = new KlassBibliotek(); List <Kunder> customerList = klassBibliotek.ReadAllContacts(); string inloggad; if (Request.Cookies["loggedInUser"] != null) { inloggad = Request.Cookies["loggedInUser"].Value; Kunder loggedInCustomer = customerList.FirstOrDefault(x => x.kundID.ToString() == inloggad); string orderId = Request["orderID"].ToString(); orderLabel.Text = $"Order {orderId} har skickats till {loggedInCustomer.Street}, {loggedInCustomer.Zip} {loggedInCustomer.City}"; } } } }
void LoadOrders() { if (Request.Cookies["loggedInUser"] != null) { int kundID = int.Parse(Request.Cookies["loggedInUser"].Value); KlassBibliotek klass = new KlassBibliotek(); List <Order> allaOrdrar = klass.ReadAllOrders(); if (allaOrdrar != null) { var ordrarFrånKundID = allaOrdrar.Where(x => x.KID == kundID); if (ordrarFrånKundID != null) { foreach (var order in ordrarFrånKundID) { historikText.Items.Add($"{order.OID}"); } } } } }
private void LoadShoppingCart() { //Laddar cookien och plockar ut artikelid för artiklarna i varukorgen. Genererar HTML-tabell. if (Request.Cookies["shoppingCart"] != null) { string cookieData = Request.Cookies["shoppingCart"].Value; cookieData = cookieData.Replace("%2C", ","); Response.Cookies["shoppingCart"].Value = cookieData; Response.Cookies["shoppingCart"].Expires = DateTime.Now.AddDays(1); string[] data = cookieData.Split(','); KlassBibliotek sqlBibliotek = new KlassBibliotek(); List <Artiklar> artikelList = sqlBibliotek.ReadAllArtiklar(); foreach (var artikel in data) { if (artikel != "") { bool exists = false; Artiklar artikelInfo = artikelList.FirstOrDefault(x => x.AID == int.Parse(artikel)); if (artikelInfo != null) { for (int i = 0; i < shoppingCartTable.Rows.Count; i++) { if (artikelInfo.AID.ToString() == shoppingCartTable.Rows[i].Cells[0].Text) { TextBox superTextBox = (TextBox)shoppingCartTable.Rows[i].Cells[2].Controls[0]; int numberOf = int.Parse(superTextBox.Text); numberOf++; int totalPrice = numberOf * artikelInfo.pris; superTextBox.Text = numberOf.ToString(); shoppingCartTable.Rows[i].Cells[4].Text = $"{totalPrice.ToString()}"; exists = true; } } if (!exists) { { TableRow newRow = new TableRow(); TableCell newCell1 = new TableCell(); TableCell newCell2 = new TableCell(); TableCell newCell3 = new TableCell(); TableCell newCell4 = new TableCell(); TableCell newCell5 = new TableCell(); TextBox numberBox = new TextBox(); numberBox.Attributes.Add("type", "number"); numberBox.Attributes.Add("min", "1"); numberBox.Attributes.Add("runat", "server"); numberBox.Attributes.Add("class", "numberBoxes"); numberBox.Text = "1"; numberBox.Attributes.Add("OnTextChanged", "ChangeNumberText"); Button deleteButton = new Button(); deleteButton.Text = "Ta bort Samtliga"; deleteButton.Attributes.Add("class", "deleteButton"); //numberBox.Attributes.Add("autopostback", "true"); numberBox.Attributes.Add("ID", $"numberBox{shoppingCartTable.Rows.Count - 1}"); newCell1.Text = artikelInfo.AID.ToString(); newCell2.Text = artikelInfo.artikelnamn; newCell3.Controls.Add(numberBox); newCell3.Controls.Add(deleteButton); //newCell3.Text = $"<asp:TextBox ID=\"numberTextBox{}\" type=\"number\" min=\"1\" runat=\"server\">1</asp:TextBox>"; newCell4.Text = $"{artikelInfo.pris.ToString()}"; newCell5.Text = $"{artikelInfo.pris.ToString()}"; newCell5.CssClass = "sum"; newRow.Cells.Add(newCell1); newRow.Cells.Add(newCell2); newRow.Cells.Add(newCell3); newRow.Cells.Add(newCell4); newRow.Cells.Add(newCell5); shoppingCartTable.Rows.AddAt(shoppingCartTable.Rows.Count - 1, newRow); } } } } } int superSum = 0; for (int i = 0; i < shoppingCartTable.Rows.Count; i++) { if (shoppingCartTable.Rows[i].Cells[4].CssClass == "sum") { superSum += int.Parse(shoppingCartTable.Rows[i].Cells[4].Text); } } sumOfAll.Text = $"{superSum.ToString()}"; } else { buttonBuy.Visible = false; } }