Пример #1
0
            int IComparer.Compare(object ob1, object ob2)
            {
                StorageAuto p1 = (StorageAuto)ob1;
                StorageAuto p2 = (StorageAuto)ob2;

                if (p1.Quantity > p2.Quantity)
                {
                    return(1);
                }
                if (p1.Quantity < p2.Quantity)
                {
                    return(-1);
                }
                return(0);
            }
Пример #2
0
            int IComparer.Compare(object ob1, object ob2)
            {
                StorageAuto p1 = (StorageAuto)ob1;
                StorageAuto p2 = (StorageAuto)ob2;

                if (p1.Price > p2.Price)
                {
                    return(1);
                }
                if (p1.Price < p2.Price)
                {
                    return(-1);
                }
                return(0);
            }
Пример #3
0
        static void Main(string[] args)
        {
            List <StorageAuto> list = new List <StorageAuto>();
            int          n          = 0;
            StreamReader f          = new StreamReader("dbase.txt");
            string       s;
            int          i = 0;

            try
            {
                while ((s = f.ReadLine()) != null)
                {
                    list.Add(new StorageAuto(s));
                    ++i;
                }
                n = i - 1;



                foreach (var element in list)
                {
                    Console.WriteLine(element);
                }
                f.Close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Check the correct name and path to the file!");
                return;
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Very large file!");
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message); return;
            }
            Console.ReadLine();
            StorageAuto[] group = new StorageAuto[10];
            group[0] = list[0];
            group[1] = list[1];
            group[2] = list[2];
            group[3] = list[3];
            group[4] = list[4];
            group[5] = list[5];
            group[6] = list[6];
            group[7] = list[7];
            group[8] = list[8];
            group[9] = list[9];
            Console.WriteLine("sort is Price:");
            Array.Sort(group, new StorageAuto.SortByPrice());
            foreach (StorageAuto elem in group)
            {
                elem.ToString();
            }
            foreach (var element in group)
            {
                Console.WriteLine(element);
            }
            Console.WriteLine("sort is Quantity:");
            Array.Sort(group, new StorageAuto.SortByQuantity());
            foreach (StorageAuto elem in group)
            {
                elem.ToString();
            }
            Console.ReadLine();
            foreach (var element in group)
            {
                Console.WriteLine(element);
            }

            Console.WriteLine("Enter text if you want to add a line in database: ");
            string names;

            while ((names = Console.ReadLine()) != "")
            {
                StorageAuto add = new StorageAuto();
                Console.WriteLine("Enter the line you want to add: ");
                string numberOfLineToAdd = Console.ReadLine();
                add.AppendAllText("dbase.txt", numberOfLineToAdd);
            }

            Console.WriteLine("Enter text if you want to delete a line in database: ");
            string nam;

            while ((nam = Console.ReadLine()) != "")
            {
                StorageAuto del = new StorageAuto();
                Console.WriteLine("Enter the line you want to delete: ");
                int numberOfLineToDelete = Convert.ToInt32(Console.ReadLine());
                del.Delete("dbase.txt", numberOfLineToDelete);
            }
        }