Exemplo n.º 1
0
        public string GetTitle()
        {
            string end;

            Console.Write("Podaj nazwe pliku: ");
            title = Console.ReadLine();

            while (title.Length < 1)
            {
                Support.WriteCol("Nie podano nazwy pliku!", "DY");
                Console.Write("Podaj nazwe pliku: ");
                title = Console.ReadLine();
            }

            try
            {
                end = title.Substring(title.Length - 4);
            }
            catch
            {
                title = $"../../../{title}.txt";
                return(title);
            }

            if (!end.Equals(".txt", StringComparison.OrdinalIgnoreCase))
            {
                title += ".txt";
            }

            title = $"../../../{title}";

            return(title);
        }
Exemplo n.º 2
0
        public bool Read(Cars C)
        {
            try
            {
                using (StreamReader f = new StreamReader(title))
                {
                    string[] input = File.ReadAllLines(title);

                    foreach (var item in input)
                    {
                        Car c = new Car();

                        string[] temp = item.Split("\t");

                        c.Brand    = temp[0].ToString();
                        c.Model    = temp[1].ToString();
                        c.Year     = int.Parse(temp[2]);
                        c.Capacity = int.Parse(temp[3]);
                        c.Milleage = int.Parse(temp[4]);
                        c.Gearbox  = temp[5].ToString();

                        C.Push(c);
                    }
                }
            }
            catch
            {
                Support.WriteCol("Blad pliku!", "R");
                return(false);
            }
            Console.WriteLine("Pomyslnie odczytano dane.");
            return(true);
        }
Exemplo n.º 3
0
        public static int GetChoise(int a, int b)
        {
            int choise;

            while (true)
            {
                try
                {
                    Console.Write("Twoj wybor: ");
                    choise = int.Parse(Console.ReadLine());

                    if (choise < a || choise > b)
                    {
                        Support.WriteCol("Niewlasciwy wybor!", "DY");
                    }
                    else
                    {
                        break;
                    }
                }
                catch
                {
                    Support.WriteCol("Niepoprawny format", "R");
                }
            }

            Console.ResetColor();
            return(choise);
        }
Exemplo n.º 4
0
        public static int ConditionalList()
        {
            Support.WriteCol("--- MENU WARUNKOW ---", "G");
            Console.WriteLine();
            Console.WriteLine("Wyswietl wedlug:");
            Console.WriteLine("1. Marki");
            Console.WriteLine("2. Roku produkcji");
            Console.WriteLine("3. Pojemnosci silnika");
            Console.WriteLine("4. Przebiegu");
            Console.WriteLine("5. Rodzaju skrzyni biegów");
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Green;

            return(GetChoise(1, 5));
        }
Exemplo n.º 5
0
        public static int SortingList()
        {
            Support.WriteCol("--- MENU SORTOWANIA ---", "G");
            Console.WriteLine();
            Console.WriteLine("Sortuj wedlug:");
            Console.WriteLine("1. Marki alfabetycznie");
            Console.WriteLine("2. Modelu alfabetycznie");
            Console.WriteLine("3. Roku produkcji");
            Console.WriteLine("4. Pojemnosci silnika");
            Console.WriteLine("5. Przebiegu");
            Console.WriteLine("6. Rodzaju skrzyni biegów");
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Green;

            return(GetChoise(1, 6));
        }
Exemplo n.º 6
0
        public bool Save(Cars c)
        {
            int  mode;
            bool append;

            if (File.Exists(title))
            {
                Console.WriteLine("Plik o podanej nazwie istnieje.");
                Console.WriteLine("0 - aby go nadpisac, 1 - aby dopisac linie");
                mode = Menu.GetChoise(0, 1);

                if (mode == 0)
                {
                    File.Delete(title);
                    append = false;
                }
                else
                {
                    append = true;
                }
            }
            else
            {
                append = false;
            }

            using (StreamWriter f = new StreamWriter(title, append))
            {
                foreach (Car item in c.list)
                {
                    try
                    {
                        f.WriteLine($"{item.Brand}\t{item.Model}\t{item.Year}\t{item.Capacity}\t{item.Milleage}\t{item.Gearbox}");
                    }
                    catch
                    {
                        Support.WriteCol("Operacja nie powiodla sie!", "R");
                        return(false);
                    }
                }
            }

            Console.WriteLine("Pomyslnie zapisano dane.");
            return(true);
        }
Exemplo n.º 7
0
        public static void Clear(Cars c)
        {
            if (c.list.Count != 0)
            {
                string choise;

                Console.WriteLine("Baza danych programu zawiera juz dane. Czy chcesz je skasowac?");

                while (true)
                {
                    try
                    {
                        Console.Write("y - tak, n - nie: ");
                        choise = Console.ReadLine();

                        if (choise[0] == 'y')
                        {
                            c.list.Clear();
                            Console.WriteLine("Baza danych zostala oprozniona.");
                            break;
                        }
                        else if (choise[0] == 'n')
                        {
                            break;
                        }
                        else
                        {
                            Support.WriteCol("Niepoprawna wartosc!", "DY");
                        }
                    }
                    catch
                    {
                        Support.WriteCol("Niepoprawna wartosc!", "R");
                    }
                }
            }
        }
Exemplo n.º 8
0
        public static int MainList()
        {
            Support.WriteCol("--- MENU ---", "G");
            Console.WriteLine();
            Console.WriteLine("1. Wczytaj z pliku");
            Console.WriteLine("2. Zapisz wyniki w nowym pliku");
            Console.WriteLine();
            Console.WriteLine("3. Dodaj samochod");
            Console.WriteLine("4. Usun samochod");
            Console.WriteLine();
            Console.WriteLine("5. Wyswietl wszystkie samochody");
            Console.WriteLine("6. Wyswietl warunkowo liste samochodow");
            Console.WriteLine("7. Wyswietl dane pojedynczego samochodu");
            Console.WriteLine("8. Posortuj samochody");
            Console.WriteLine();
            Console.WriteLine("9. Wyjscie z programu");
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Green;

            int choise = GetChoise(1, 9);

            Console.Clear();
            return(choise);
        }
Exemplo n.º 9
0
 public static int SortingDeOrIn()
 {
     Support.WriteCol("0 - rosnaco, 1 - malejaco", "G");
     return(GetChoise(0, 1));
 }