public static void changePassword(int id_Custumer) { Console.Clear(); Method.ReadOnMember(); Console.WriteLine("- - - - Change Password - - - -"); Console.Write("Enter current password: "******"Enter again current password: "******"Enter new user password: "******"Enter new user password minimum of 8 characters and non-Space : "); pass1 = (Console.ReadLine()).Trim(); } Console.Write("Enter reenter password: "******"Enter again confirm password: "); data.members[pos].user_password = (Console.ReadLine()).Trim(); } Method.PushInDATA(); }
public static void Login(out bool IsAdmin, out int id_Custumer) { Method.ReadOnMember(); Console.Write("Enter User: "******"User not Exit! Re-enter the user: "******"Enter password: "******"Incorrect password! Re_enter the password: "); pass = (Console.ReadLine()).Trim(); } IsAdmin = data.members[index].Isadmin; id_Custumer = data.members[index].user_id; }
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 ShowAllOrderByCustumer(int id_Custumer) { Method.ReadOnMember(); int index = -1; for (int i = 0; i < data.custumers.Count; i++) { if (data.custumers[i].id_custumer == id_Custumer) { index = i; break; } } if (index != -1) { Console.WriteLine($"Custumer: {data.custumers[index].name_custumer}"); Console.WriteLine($"Adress: {data.custumers[index].adress_custumer}\n"); foreach (var oder in data.custumers[index].oders) { Console.WriteLine($"\tOrder Id: {oder.OrderId}"); Console.WriteLine($"\tTime order: {oder.timeOrder}"); Console.WriteLine($"\tStatus: {oder.status}\n"); Console.WriteLine($"\tCode\tName product\t\tprice\t\tquantity\tmoney"); foreach (var pro in oder.products) { Console.WriteLine($"\t{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 !"); } }
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 ShowAccounts() { Console.Clear(); Console.WriteLine("- - - - Account list - - - -"); Method.ReadOnMember(); Console.WriteLine("Id\tuser name\t\tuser mail\t\t\tuser password\t\tIsadmin"); foreach (var item in data.members) { Console.WriteLine(item.ToString()); } }
public static int FindIndexOfIdCustumer(int id_Custumer) { Method.ReadOnMember(); for (int i = 0; i < Method.data.custumers.Count; i++) { if (Method.data.custumers[i].id_custumer == id_Custumer) { return(i); } } return(-1); }
public static void ShowInformationCustumer() { Console.Clear(); Method.ReadOnMember(); Console.WriteLine("Show information Custumer: \n"); Console.WriteLine("id\t Name\t\t\t Adress\t\t\tGmail\t\t\t\tPhone"); for (int i = 0; i < data.members.Count; i++) { Console.WriteLine($"{data.members[i].user_id}\t{data.custumers[i].name_custumer}\t\t{data.custumers[i].adress_custumer}" + $"\t\t{data.members[i].user_mail}\t\t{data.custumers[i].number_phone}"); } }
public static int Find_IdOrder(int idorder, out int index_custumer) { Method.ReadOnMember(); for (int i = 0; i < data.custumers.Count; i++) { for (int j = 0; j < data.custumers[i].oders.Count; j++) { if (data.custumers[i].oders[j].OrderId == idorder) { index_custumer = i; return(j); } } } index_custumer = -1; return(-1); }
public static int FindIndexOderInOders(int id_Custumer, int id_Oder) { Method.ReadOnMember(); int pos_Custumer = Management.FindIndexOfIdCustumer(id_Custumer); if (pos_Custumer != -1) { for (int i = 0; i < Method.data.custumers[pos_Custumer].oders.Count; i++) { if (Method.data.custumers[pos_Custumer].oders[i].OrderItem == id_Oder) { return(i); } } return(-1); } return(-1); }
public static void FindOrderOFCustumer(int id_Custumer) { Method.ReadOnMember(); int index = -1, pos = -1; for (int i = 0; i < data.custumers.Count; i++) { if (data.custumers[i].id_custumer == id_Custumer) { index = i; break; } } int idorder = Management.CreateInteger("id order", 1); for (int i = 0; i < data.custumers[index].oders.Count; i++) { if (data.custumers[index].oders[i].OrderId == idorder) { pos = i; break; } } if (pos != -1) { Console.WriteLine($"\nId Order: {idorder}"); Console.WriteLine($"Custumer: {data.custumers[index].name_custumer}"); Console.WriteLine($"Adress: {data.custumers[index].adress_custumer}"); Console.WriteLine($"Phone: {data.custumers[index].number_phone}"); Console.WriteLine($"Time order: {data.custumers[index].oders[pos].timeOrder}"); Console.WriteLine($"Status: {data.custumers[index].oders[pos].status}\n"); Console.WriteLine($"Code\tName product\t\tprice\t\tquantity\tmoney"); foreach (var pro in data.custumers[index].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 CreateNewOrderForCUstumer() { int id_custumer, i; Method.ReadOnMember(); Console.Write("Enter name Custumer: "); string name = Method.RemoveWhitespace(Console.ReadLine().Trim()); for (i = 0; i < data.custumers.Count; i++) { if (data.custumers[i].name_custumer == name) { id_custumer = data.custumers[i].id_custumer; Management.CreateNewOder(id_custumer); break; } } if (i == data.custumers.Count) { Console.WriteLine("Not found Custumer!"); } }
public static void Find_Order_By_NameCustumer() { int i; Method.ReadOnMember(); Console.Write("Enter name Custumer: "); string name = Method.RemoveWhitespace(Console.ReadLine().Trim()); for (i = 0; i < data.custumers.Count; i++) { if (data.custumers[i].name_custumer == name) { Console.WriteLine($"Custumer: {name}"); Console.WriteLine($"Adress: {data.custumers[i].adress_custumer}\n"); for (int j = 0; j < data.custumers[i].oders.Count; j++) { Console.WriteLine($"\tOrder Id: {data.custumers[i].oders[j].OrderId}"); Console.WriteLine($"\tTime order: {data.custumers[i].oders[j].timeOrder}"); Console.WriteLine($"\tStatus: {data.custumers[i].oders[j].status}\n"); Console.WriteLine($"\tCode\tName product\t\tprice\t\tquantity\tmoney"); for (int k = 0; k < data.custumers[i].oders[j].products.Count; k++) { Console.WriteLine($"\t{data.custumers[i].oders[j].products[k].code_product}" + $"\t{data.custumers[i].oders[j].products[k].name_product}" + $"\t\t{data.custumers[i].oders[j].products[k].price_product}" + $"\t\t{data.custumers[i].oders[j].products[k].quantity_product}" + $"\t\t{data.custumers[i].oders[j].products[k].pay_money}"); } Console.WriteLine("\n"); } break; } } if (i == data.custumers.Count) { Console.WriteLine("Not found Custumer!"); } }
public static int FindIndexProductInOder(int id_Custumer, int id_Oder, string code_product) { Method.ReadOnMember(); int pos_Custumer = Management.FindIndexOfIdCustumer(id_Custumer); int pos_Oder = Management.FindIndexOderInOders(id_Custumer, id_Oder); if (pos_Custumer != -1) { if (pos_Oder != -1) { for (int i = 0; i < Method.data.custumers[pos_Custumer].oders[pos_Oder].products.Count; i++) { if (Method.data.custumers[pos_Custumer].oders[pos_Oder].products[i].code_product == code_product) { return(i); } } return(-1); } return(-1); } return(-1); }
public static void CreateNewOder(int id_Custumer) { Oder oder = new Oder(); Method.ReadOnMember(); int pos_Custumer = Management.FindIndexOfIdCustumer(id_Custumer); if (pos_Custumer != -1) { if (Method.data.custumers[pos_Custumer].oders.Count == 0) { oder.OrderItem = 1; } else { int max = Method.data.custumers[pos_Custumer].oders[0].OrderItem; for (int i = 1; i < Method.data.custumers[pos_Custumer].oders.Count; i++) { if (Method.data.custumers[pos_Custumer].oders[i].OrderItem > max) { max = Method.data.custumers[pos_Custumer].oders[i].OrderItem; } } oder.OrderItem = max + 1; } oder.status = "Waiting"; oder.OrderId = int.Parse($"{id_Custumer}{ oder.OrderItem}"); string key = "Y"; do { Product product = new Product(); Console.WriteLine("Product 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.listProduct[pos].name_product; product.price_product = management.listProduct[pos].price_product; product.quantity_product = Management.CreateInteger("quantity", 1, 10000); int j; if (oder.products.Count == 0) { oder.products.Add(product); } else { for (j = 0; j < oder.products.Count; j++) { if (oder.products[j].code_product == product.code_product) { oder.products[j].quantity_product += product.quantity_product; break; } } if (j == oder.products.Count) { oder.products.Add(product); } } Console.Write("Continue? (Y/N): "); key = Console.ReadLine(); }while (key.ToUpper() != "N"); Method.data.custumers[pos_Custumer].oders.Add(oder); Method.PushInDATA(); } }
static void ActionAdmin(int id_Custemer) { User ADMIN = new User(); ADMIN.Isadmin = true; int choose = -1; while (choose != 0) { Console.WriteLine("Please seclect of option: "); Console.WriteLine("1. Account processing"); Console.WriteLine("2. Manage orders"); Console.WriteLine("3. Manage all items in the store"); Console.WriteLine("4. Logout\n"); choose = Management.CreateInteger("choose", 1, 12); switch (choose) { case 1: Console.Clear(); Console.WriteLine(" Account processing"); Console.WriteLine(" - - - - - - - - - - - - - - \n"); int seclect = -1; while (seclect != 5) { Console.WriteLine("1. Create new Admin"); Console.WriteLine("2. Create new User "); Console.WriteLine("3. Change Password"); Console.WriteLine("4. Show accounts"); Console.WriteLine("5. Exit"); seclect = Management.CreateInteger("seclect", 1, 5); switch (seclect) { case 1: Console.Clear(); Console.WriteLine(" Create new Admin"); Console.WriteLine(" - - - - - - - - - - - - - - \n"); Method.Create_Admin(ADMIN); break; case 2: Console.Clear(); Console.WriteLine(" Create new User"); Console.WriteLine(" - - - - - - - - - - - - - - \n"); Method.Create_User(ADMIN); break; case 3: int i; Console.Clear(); Console.WriteLine(" Change password"); Console.WriteLine(" - - - - - - - - - - - - - - \n"); Console.Write("Enter the account name to change the password: "******"Not found account!"); } break; case 4: Console.Clear(); Console.WriteLine(" Show all accounts"); Console.WriteLine(" - - - - - - - - - - - - - - \n"); Method.ShowAccounts(); break; case 5: Console.Clear(); ActionAdmin(id_Custemer); break; } } break; case 2: Console.Clear(); Console.WriteLine(" Manage orders"); Console.WriteLine(" - - - - - - - - - - - - - - \n"); int seclect1 = -1; while (seclect1 != 7) { Console.WriteLine("1. Show information of Custumer"); Console.WriteLine("2. View all orders "); Console.WriteLine("3. Search for an order by orderId"); Console.WriteLine("4. Search for orders by Customer Name"); Console.WriteLine("5. Create orders for customers"); Console.WriteLine("6. Update orders according to order codes"); Console.WriteLine("7. Pay order"); Console.WriteLine("8. Exit"); seclect1 = Management.CreateInteger("seclect", 1, 8); Console.Clear(); switch (seclect1) { case 1: Console.WriteLine(" Show information of Custumer"); Console.WriteLine(" - - - - - - - - - - - - - - - - - - \n"); Method.ShowInformationCustumer(); break; case 2: Console.WriteLine(" View all orders"); Console.WriteLine(" - - - - - - - - - - - - - - \n"); Method.ViewAllOrders(); break; case 3: Console.WriteLine(" Search for an order by orderId"); Console.WriteLine(" - - - - - - - - - - - - - - - - - - - - - \n"); int idorder = Management.CreateInteger("id of Order", 1); Method.Find_Order_byIdOrder(idorder); break; case 4: Console.WriteLine(" Search for orders by Customer Name"); Console.WriteLine(" - - - - - - - - - - - - - - - - - - - - - \n"); Method.Find_Order_By_NameCustumer(); break; case 5: Console.WriteLine(" Create orders for customers"); Console.WriteLine(" - - - - - - - - - - - - - - - - - - \n"); Method.CreateNewOrderForCUstumer(); break; case 6: Console.WriteLine(" Update orders according to order codes"); Console.WriteLine(" - - - - - - - - - - - - - - - - - - - - - - - \n"); Method.UpdateOrdersAccording(); break; case 7: Console.WriteLine(" Payment orders"); Console.WriteLine(" - - - - - - - - - - - - - - \n"); Method.PayOrderByIdOrder(); break; case 8: ActionAdmin(id_Custemer); break; } } break; case 3: Console.Clear(); Console.WriteLine("Manage all items in the store"); Console.WriteLine(" - - - - - - - - - - - - - - "); choose = -1; while (choose != 0) { Console.WriteLine("\nAdministration of all items."); Console.WriteLine("1. Show Product"); Console.WriteLine("2. Add product."); Console.WriteLine("3. Update product."); Console.WriteLine("4. Delete product"); Console.WriteLine("5. Find product by codeProduct"); Console.WriteLine("6. Exit"); choose = Management.CreateInteger("choose", 1, 6); Console.Clear(); switch (choose) { case 1: Console.WriteLine(" * * Show Product * *\n"); Management.ShowProduct(); break; case 2: Management.AddProduct(); break; case 3: Console.WriteLine(" * * Update product * *\n"); Management.ShowProduct(); Console.WriteLine(); Management.UpdateProduct(); break; case 4: Console.WriteLine("* * Delete product * *\n"); Management.ShowProduct(); Console.WriteLine(); Management.RemoveProduct(); break; case 5: Management.FindProduct(); break; case 6: ActionAdmin(id_Custemer); break; } } break; case 4: Console.Clear(); Console.WriteLine("Logged out\n"); TakeAction(); break; } } }
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(); }