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 List <products> watchAllProducts() { List <products> results = new List <products>(); SqlCommand cmd = new SqlCommand(); cmd.Connection = new SqlConnection(@"Data Source=.;Initial Catalog=DBschool;Integrated Security=True"); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; cmd.CommandText = ("SELECT * FROM products INNER JOIN suppliers ON products.supplier_number = suppliers.supplier_number"); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); List <Object> list = new List <object>(); while (reader.Read() == true) { Console.WriteLine($"product_number: {reader["product_number"]}, product_name: {reader["product_name"]}, price: {reader["price"]} how many in stock: {reader["amount"]}"); products e = new products { product_number = (int)reader["product_number"], product_name = (string)reader["product_name"], supplier_number = (int)reader["supplier_number"], price = (int)reader["price"], amount = (int)reader["amount"], }; list.Add(e); } cmd.Connection.Close(); return(results); }
public products GetProductbyName(string pName) { products e = new products(); SqlCommand cmd = new SqlCommand(); cmd.Connection = new SqlConnection(@"Data Source=.;Initial Catalog=DBschool;Integrated Security=True"); cmd.Connection.Open(); cmd.CommandType = CommandType.Text; cmd.CommandText = ($"select * from products where product_name = '{pName}'"); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); while (reader.Read() == true) { Console.WriteLine($" {reader["product_number"]} {reader["product_name"]} {reader["supplier_number"]} {reader["price"]} {reader["amount"]}"); { 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"]; }; } return(e); }
public List <products> viewAllMyProducts(supplier s) { List <products> results = new List <products>(); 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("@supId", s.supplier_number)); cmd.CommandText = "SELECT * FROM products INNER JOIN suppliers ON products.supplier_number = suppliers.supplier_number where suppliers.supplier_number = @supId"; SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default); while (reader.Read() == true) { Console.WriteLine($" product_number: {reader["product_number"]} product_name: {reader["product_name"]} price: {reader["price"]} amount: {reader["amount"]}"); products e = new products { product_number = (int)reader["product_number"], product_name = (string)reader["product_name"], supplier_number = (int)reader["supplier_number"], price = (int)reader["price"], amount = (int)reader["amount"] }; results.Add(e); } cmd.Connection.Close(); return(results); }
public override bool Equals(object obj) { if (obj == null) { return(false); } products other = obj as products; if (other == null) { return(false); } return(this.product_number == other.product_number); }
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(); }
public void AddNewOrder(products o, customer c) { 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("@customer_number", c.cust_id)); cmd.Parameters.Add(new SqlParameter("@product_number", o.product_number)); cmd.Parameters.Add(new SqlParameter("@orders_amount", o.amount)); cmd.Parameters.Add(new SqlParameter("@total_price", o.price)); cmd.Parameters.Add(new SqlParameter("@prodct_name", o.product_name)); cmd.CommandText = ("insert into orders(customer_number, product_number, orders_amount, total_price, prodct_name)" + "values(@customer_number, @product_number, @orders_amount, @total_price, @prodct_name)'"); Console.WriteLine("edding new order went well(:"); }