public static Prices GetLastPrice() { Prices price = null; String query = "SELECT * FROM price ORDER BY PRI_ID DESC LIMIT 1"; MySqlCommand cmd = new MySqlCommand(query, _dbConn); _dbConn.Open(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = (int)reader["PRI_ID"]; String pb95 = reader["PRI_PB95"].ToString(); String pb98 = reader["PRI_PB98"].ToString(); String on = reader["PRI_ON"].ToString(); String lpg = reader["PRI_LPG"].ToString(); String date = reader["PRI_DATE"].ToString(); price = new Prices(id, pb95, pb98, on, lpg, date); } reader.Close(); _dbConn.Close(); return(price); }
public static List <Prices> GetPrices() { List <Prices> prices = new List <Prices>(); String query = "SELECT * FROM price"; MySqlCommand cmd = new MySqlCommand(query, _dbConn); _dbConn.Open(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = (int)reader["PRI_ID"]; String pb95 = reader["PRI_PB95"].ToString(); String pb98 = reader["PRI_PB98"].ToString(); String on = reader["PRI_ON"].ToString(); String lpg = reader["PRI_LPG"].ToString(); String date = reader["PRI_DATE"].ToString(); Prices price = new Prices(id, pb95, pb98, on, lpg, date); prices.Add(price); } reader.Close(); _dbConn.Close(); return(prices); }
public static void AddNewPrice(Prices price) { String query = $"INSERT INTO price(PRI_PB95, PRI_PB98, PRI_ON, PRI_LPG, PRI_DATE) VALUES ('{price.PricePB95}','{price.PricePB98}','{price.PriceON}','{price.PriceLPG}','{price.PriceDate}')"; MySqlCommand cmd = new MySqlCommand(query, _dbConn); _dbConn.Open(); cmd.ExecuteNonQuery(); int id = (int)cmd.LastInsertedId; //User u = new User(id, u, p, m, n, s, a, r); _dbConn.Close(); }
public static Product RandomProduct(int i) { string item = null; int amount = 0; double price = 0; double sum = 0; Random rnd = new Random(); Random rndamt = new Random(); Prices prices = Prices.GetLastPrice(); int randItem = rnd.Next(1, 5 + i); switch (randItem) { case 1: item = "PB95"; amount = rndamt.Next(10, 50); price = Convert.ToDouble(prices.PricePB95); sum = amount * price; break; case 2: item = "PB98"; amount = rndamt.Next(10, 50); price = Convert.ToDouble(prices.PricePB98); sum = amount * price; break; case 3: item = "ON"; amount = rndamt.Next(10, 50); price = Convert.ToDouble(prices.PriceON); sum = amount * price; break; case 4: item = "LPG"; amount = rndamt.Next(30, 70); price = Convert.ToDouble(prices.PriceLPG); sum = amount * price; break; case 5: item = "Myjnia standardowa"; amount = rndamt.Next(5, 10); price = 19.99; sum = amount * price; break; case 6: item = "Myjnia woskowanie"; amount = rndamt.Next(5, 10); price = 34.99; sum = amount * price; break; default: MessageBox.Show("Nieznany błąd"); break; } Product product = new Product(item, amount.ToString(), price.ToString(), sum.ToString()); return(product); }