public static LinkedList <Ordder> GetAllOrders() { string query = "select * from Orders order by Date"; LinkedList <Ordder> ans = new LinkedList <Ordder>(); try { con.Open(); comand = new SqlCeCommand(query, con); SqlCeDataReader reader = comand.ExecuteReader(); while (reader.Read()) { // on new Order creation TotalPrice will calculated in Constructor Ordder order = new Ordder(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3), reader.GetInt32(4), reader.GetString(5), reader.GetString(6)); ans.AddLast(order); } } catch { } finally { con.Close(); } return(ans); }
// order the product for user // function that takes money from client doesn't exist for yet // redirect to client orders page public static string BuyItem(int ProductID, int userID, string addres) { // place for fields validation Item item = ConnectionClass.GetProductByID(ProductID); if (item == null || item.Quantity <= 0) { return("Cannot buy this product. Please try other one."); } User user = ConnectionClass.GetUserByID(userID); Ordder order = new Ordder(1, user.Id, ProductID, 1, item.Price, DateTime.Now.ToString("d.M.yyyy"), addres); ConnectionClass.AddOrder(order); ConnectionClass.ReduceQuantity(ProductID); // function that draws money from client //Response.Redirect("/Orders.aspx"); return(""); }
/****************** Orders **************************/ public static void AddOrder(Ordder order) { string query = "Insert into Orders (ClientID, ProductID, Ammount, Price, Date, Info, TotalPrice)" + " values(" + order.ClientID + "," + order.ProductID + "," + order.Ammount + "," + "" + order.Price + ", '" + order.Date + "', '" + order.Info + "', " + order.TotalPrice + ")"; try { con.Open(); comand = new SqlCeCommand(query, con); comand.ExecuteNonQuery(); } catch { } finally { con.Close(); } }