Example #1
0
        }    //rdy

        public void read_from_file(string filepath)
        {
            if (Validation1.file_check(filepath))
            {
                string jsonString     = File.ReadAllText(filepath);
                var    collection     = JsonSerializer.Deserialize <List <Object> >(jsonString);
                int    element_number = 0;
                Console.WriteLine($"{collection.GetType().Name}, {collection.Count()}, {collection.FirstOrDefault().GetType().Name}, {typeof(Object)}");
                foreach (var obj in collection)
                {
                    element_number++;
                    try
                    {
                        //Console.WriteLine($"xyi1{element_number}");
                        T to_add = JsonSerializer.Deserialize <T>(obj.ToString());
                        //Console.WriteLine($"xyi2{element_number}");
                        //Console.WriteLine(to_add);
                        if (validate_T(to_add, element_number))
                        {
                            //Console.WriteLine("added");
                            order_collection.Add(to_add);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        //Console.WriteLine("Error in data in element № {0}", element_number);
                        Console.WriteLine("Error in file (wrong json object structure)");
                    }
                }
            }
        }   //err
Example #2
0
        static int id_input()
        {
            int res;

            console_color_1();
            Console.WriteLine("Enter id of order:");
            string input = Console.ReadLine();

            while (!Validation1.check_if_int(input) || Convert.ToInt32(input) < 1)
            {
                Console.WriteLine("Reenter id of order. It must be a natural number.");
                input = Console.ReadLine();
            }
            console_color_2();
            res = Convert.ToInt32(input);
            return(res);
        }
Example #3
0
        static int menu()
        {
            int res;

            console_color_1();
            Console.WriteLine("YOU ARE NOW IN MAIN MENU");
            Console.WriteLine("ENTER YOIR CHOICE:");
            console_color_2();
            Console.WriteLine("1 - search some data through all info\n" +
                              "2 - sort collection by some argument\n" +
                              "3 - delete any order(by its id) and rewrite collection in file\n" +
                              "4 - add an order and rewrite collection in file\n" +
                              "5 - edit an order and rewrite collection in file\n" +
                              "6 - exit program\n");
            string choice = Console.ReadLine();

            while (!Validation1.check_if_int(choice) || Convert.ToInt32(choice) < 1 || Convert.ToInt32(choice) > 6)
            {
                Console.WriteLine("REENTER YOIR CHOICE:");
                choice = Console.ReadLine();
            }
            res = Convert.ToInt32(choice);
            return(res);
        }