Пример #1
0
        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!");
            }
        }
Пример #2
0
        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!");
            }
        }
Пример #3
0
        static void ActionUser(int id_Custumer)
        {
            int choose = -1;

            while (choose != 0)
            {
                Console.WriteLine("Please seclect of option: ");
                Console.WriteLine("1. Change password");
                Console.WriteLine("2. Create an order");
                Console.WriteLine("3. Show all order");
                Console.WriteLine("4. Find order by id");
                Console.WriteLine("5. Logout\n");
                choose = Management.CreateInteger("choose", 1, 5);
                Console.Clear();
                switch (choose)
                {
                case 1:
                    Method.changePassword(id_Custumer);
                    break;

                case 2:
                    Management.CreateNewOder(id_Custumer);
                    break;

                case 3:
                    Method.ShowAllOrderByCustumer(id_Custumer);
                    break;

                case 4:
                    Method.FindOrderOFCustumer(id_Custumer);
                    break;

                case 5:
                    Console.WriteLine("Logged out\n");
                    TakeAction();
                    break;
                }
            }
        }
Пример #4
0
        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();
        }
Пример #5
0
        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;
                }
            }
        }
Пример #6
0
        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();
            }
        }