public void orderNewProduct(customer c) { productDAO dao = new productDAO(); ordersDAO dao2 = new ordersDAO(); int amountOfProducts; Console.WriteLine("======New order menu:======" + "\n enter product name:"); string newProduct = Console.ReadLine(); products selectedP = dao.GetProductbyName(newProduct); if (selectedP.amount > 0) { Console.WriteLine("How may of those do you want?"); amountOfProducts = Convert.ToInt32(Console.ReadLine()); if (amountOfProducts <= selectedP.amount && amountOfProducts > 0) { dao.removeProduct(newProduct, amountOfProducts); dao2.AddNewOrder(selectedP, c); Console.WriteLine("order went well(:"); } else { Console.WriteLine($"we dont have {amountOfProducts} in stock"); } } else { Console.WriteLine("dont have this product"); } }
public void AddNewProduct(supplier s) { products e = new products(); productDAO dao = new productDAO(); Console.WriteLine("enter the name of the product you want to Add"); string product = Console.ReadLine(); SqlCommand cmd = new SqlCommand(); cmd.Connection = new SqlConnection(@"Data Source=.;Initial Catalog=DBschool;Integrated Security=True"); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@product", product)); cmd.CommandText = $"SELECT * FROM products where product_name = '{product}'"; SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); if (reader.Read() == true) { { e.product_number = (int)reader["product_number"]; e.product_name = (string)reader["product_name"]; e.supplier_number = (int)reader["supplier_number"]; e.price = (int)reader["price"]; e.amount = (int)reader["amount"]; }; if (e.supplier_number == s.supplier_number) { Console.WriteLine("How many product do you want to Add to stock?"); int amount = Convert.ToInt32(Console.ReadLine()); dao.addExistingPoduct(product, amount); } else { Console.WriteLine("product exist at another supplier stock"); } } else { dao.AddNewProduct(product, s); } cmd.Connection.Close(); }