//Johann,Nils public static Employee LoginEmpleyee(int id, int pin) { MySql.Data.MySqlClient.MySqlParameter idPara = new MySql.Data.MySqlClient.MySqlParameter("@id", id); MySql.Data.MySqlClient.MySqlParameter pinPara = new MySql.Data.MySqlClient.MySqlParameter("@pin", pin); var reader = Database.ExcecuteCommand("SELECT * FROM mitarbeiter WHERE id = @id and PIN = @pin", new List <MySql.Data.MySqlClient.MySqlParameter> { idPara, pinPara }); if (!reader.HasRows) { // login falsch return(null); } Employee employee = new Employee(); employee.Id = id; reader.Read(); // Employee Bauen employee.FirstName = reader[1].ToString(); employee.LastName = reader[2].ToString(); return(employee); }
//Johann,Nils public Productgroup(int id) { MySqlParameter mySqlParameter = new MySqlParameter("@id", id); var reader = Database.ExcecuteCommand("SELECT * FROM Produktgruppe where ID = @id", new List <MySqlParameter> { mySqlParameter }); while (reader.Read()) { Id = reader.GetInt32(0); Description = reader.GetString(1); } }
//Johann,Nils public static List <Productgroup> GetAll() { var reader = Database.ExcecuteCommand("SELECT * FROM Produktgruppe"); List <Productgroup> productgroups = new List <Productgroup>(); while (reader.Read()) { Productgroup productgroup = new Productgroup(); productgroup.Id = reader.GetInt32(0); productgroup.Description = reader.GetString(1); productgroups.Add(productgroup); } return(productgroups); }
//Johann,Nils public static List <Product> GetAll() { var reader = Database.ExcecuteCommand("SELECT * FROM Produkt"); List <Product> products = new List <Product>(); while (reader.Read()) { Product produkt = new Product(); produkt.Id = reader.GetInt32(0); produkt.Description = reader.GetString(1); produkt.Price = reader.GetDecimal(2); products.Add(produkt); } return(products); }
//Johann,Nils public void GetAllProducts() { MySqlParameter para = new MySqlParameter("@id", this.Id); var reader = Database.ExcecuteCommand("SELECT * FROM Produkt where FK_Produktgruppe_ID = @id", new List <MySqlParameter> { para }); Products = new List <Product>(); while (reader.Read()) { Product produkt = new Product(); produkt.Id = reader.GetInt32(0); produkt.Description = reader.GetString(1); produkt.Price = reader.GetDecimal(2); Products.Add(produkt); } }
//Eric //Method save the order and oderpositions to the database public void SaveToDatabase() { if (this.shoppingCartItems != null) { Order order = new Order(); order.Date = DateTime.Now; Employee employee = new Employee(); employee.Id = 1; order.Employee = employee; //Insert order to database table bestellung string dateStr = order.Date.ToString("yyyy-MM-dd hh:mm:ss"); string sql = $"INSERT INTO bestellung (Datum,FK_Mitarbeiter_ID,MwSt) VALUES ('{dateStr}'," + $"{order.Employee.Id.ToString()},{MwSt})"; Database.ExcecuteCommand(sql); //Get last order id from database table bestellung sql = "SELECT max(id) as last_item FROM bestellung"; var myReader = Database.ExcecuteCommand(sql); while (myReader.Read()) { int tempID; int.TryParse(myReader["last_item"].ToString(), out tempID); //var anotherTempID = myReader["last_item"] as int?; order.Id = tempID; } //Insert all orderpositions to database table bestellposition with order id foreach (ShoppingCartItem item in shoppingCartItems) { sql = $"INSERT INTO bestellposition (Menge,FK_Produkt_ID," + $"FK_Bestellung_ID) VALUES( {item.Orderposition.Amount},{item.Orderposition.Product.Id}" + $",{order.Id})"; Database.ExcecuteCommand(sql); } } }