public static void PayOrderByIdOrder() { Method.ReadOnMember(); int idorder = Management.CreateInteger("id Order", 1); int pos = Method.Find_IdOrder(idorder, out int index_custumer); if (pos != -1 && data.custumers[index_custumer].oders[pos].status == "Waiting") { string Path = @"E:\CODEGYM\Module2\BaitapModule2_lan2\BaitapModule2_lan2\Bai3\PayOrder"; string fileName = $"{DateTime.Now.ToString("dd-MM-yyyy")}__{idorder}"; PayOrder payOrder = new PayOrder(); payOrder.Id_Custumer = data.custumers[index_custumer].id_custumer; payOrder.Name_Custumer = data.custumers[index_custumer].name_custumer; payOrder.Adrres = data.custumers[index_custumer].adress_custumer; payOrder.Phone_number = data.custumers[index_custumer].number_phone; payOrder.status = "Payed"; payOrder.products = data.custumers[index_custumer].oders[pos].products; data.custumers[index_custumer].oders[pos].status = "Payed"; using (StreamWriter sw = File.CreateText($@"{Path}\{fileName}")) { var dada = JsonConvert.SerializeObject(payOrder); sw.Write(dada); } Method.PushInDATA(); Console.WriteLine("Payment success"); } else { Console.WriteLine("Not found Order or Order Payed!"); } }
public static void Find_Order_byIdOrder(int idorder) { Method.ReadOnMember(); int pos = Method.Find_IdOrder(idorder, out int index_custumer); if (pos != -1) { Console.WriteLine($"\nId Order: {idorder}"); Console.WriteLine($"Custumer: {data.custumers[index_custumer].name_custumer}"); Console.WriteLine($"Adress: {data.custumers[index_custumer].adress_custumer}"); Console.WriteLine($"Phone: {data.custumers[index_custumer].number_phone}"); Console.WriteLine($"Time order: {data.custumers[index_custumer].oders[pos].timeOrder}"); Console.WriteLine($"Status: {data.custumers[index_custumer].oders[pos].status}\n"); Console.WriteLine($"Code\tName product\t\tprice\t\tquantity\tmoney"); foreach (var pro in data.custumers[index_custumer].oders[pos].products) { Console.WriteLine($"{pro.code_product}\t{pro.name_product}\t\t{pro.price_product}\t\t{pro.quantity_product}\t\t{pro.pay_money}"); } Console.WriteLine("\n"); } else { Console.WriteLine("Not found Order!"); } }
public static void UpdateOrdersAccording() { Method.ReadOnMember(); int idorder = Management.CreateInteger("id of Order", 1); int pos1 = Method.Find_IdOrder(idorder, out int index_custumer); int keyof = index_custumer; if (pos1 != -1) { int choose = -1; while (choose != 4) { Find_Order_byIdOrder(idorder); Console.WriteLine("\n1. Add product on Order"); Console.WriteLine("2. Remove product on Order"); Console.WriteLine("3. Update product on Order"); Console.WriteLine("4. Exit"); choose = Management.CreateInteger("choose", 1, 4); Console.Clear(); Find_Order_byIdOrder(idorder); switch (choose) { case 1: string key = "Y"; do { Console.Clear(); Console.WriteLine("\n * * Add product on Order * * \n"); Find_Order_byIdOrder(idorder); Product product = new Product(); Console.WriteLine("\nProduct list in store"); Management.ShowProduct(); Console.Write("\nEnter the Code to select the product: "); string code = Console.ReadLine(); int pos = Management.Find(code); while (pos == -1) { Console.Write("\nNot found! Enter again the Code to select the product: "); code = Console.ReadLine(); pos = Management.Find(code); } product.code_product = code; product.name_product = Management.management.listProduct[pos].name_product; product.price_product = Management.management.listProduct[pos].price_product; product.quantity_product = Management.CreateInteger("quantity", 1, 10000); int j; if (data.custumers[keyof].oders[pos1].products.Count == 0) { data.custumers[keyof].oders[pos1].products.Add(product); } else { for (j = 0; j < data.custumers[keyof].oders[pos1].products.Count; j++) { if (data.custumers[keyof].oders[pos1].products[j].code_product == product.code_product) { data.custumers[keyof].oders[pos1].products[j].quantity_product += product.quantity_product; break; } } if (j == data.custumers[keyof].oders[pos1].products.Count) { data.custumers[keyof].oders[pos1].products.Add(product); } } Method.PushInDATA(); Console.Write("Continue? (Y/N): "); key = Console.ReadLine(); }while (key.ToUpper() != "N"); Console.Clear(); break; case 2: key = "Y"; do { Console.Clear(); Console.WriteLine("\n * * Update product on Order * * \n"); Find_Order_byIdOrder(idorder); //Management.ShowProduct(); Console.Write("\nEnter the Code to select the product: "); string code = Console.ReadLine(); for (int i = 0; i < data.custumers[keyof].oders[pos1].products.Count; i++) { if (data.custumers[keyof].oders[pos1].products[i].code_product == code) { data.custumers[keyof].oders[pos1].products.RemoveAt(i); Console.WriteLine("Product deleted"); break; } } Method.PushInDATA(); Console.Write("Continue? (Y/N): "); key = Console.ReadLine(); }while (key.ToUpper() != "N"); Console.Clear(); break; case 3: key = "Y"; do { Console.Clear(); Console.WriteLine("\n * * Remove product on Order * * \n"); Find_Order_byIdOrder(idorder); //Management.ShowProduct(); Console.Write("\nEnter the Code to select the product: "); string code = Console.ReadLine(); int quan = Management.CreateInteger("quantity", 1); for (int i = 0; i < data.custumers[keyof].oders[pos1].products.Count; i++) { if (data.custumers[keyof].oders[pos1].products[i].code_product == code) { data.custumers[keyof].oders[pos1].products[i].quantity_product = quan; Console.WriteLine("Purchase quantity has been changed"); break; } } Method.PushInDATA(); Console.Write("Continue? (Y/N): "); key = Console.ReadLine(); }while (key.ToUpper() != "N"); Console.Clear(); break; } } } else { Console.WriteLine("Not found Order!"); } //Method.PushInDATA(); }